summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-03-28 23:51:30 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-03-28 23:51:30 +0100
commit283a66bcae5f26d2b5038ba0959314a687c4d8b6 (patch)
tree390c60125c07c39f4277e0a86a1e64e36d722f4a
parentImplemented lilypad placement (diff)
downloadcuberite-283a66bcae5f26d2b5038ba0959314a687c4d8b6.tar
cuberite-283a66bcae5f26d2b5038ba0959314a687c4d8b6.tar.gz
cuberite-283a66bcae5f26d2b5038ba0959314a687c4d8b6.tar.bz2
cuberite-283a66bcae5f26d2b5038ba0959314a687c4d8b6.tar.lz
cuberite-283a66bcae5f26d2b5038ba0959314a687c4d8b6.tar.xz
cuberite-283a66bcae5f26d2b5038ba0959314a687c4d8b6.tar.zst
cuberite-283a66bcae5f26d2b5038ba0959314a687c4d8b6.zip
Diffstat (limited to '')
-rw-r--r--src/BlockInfo.cpp3
-rw-r--r--src/Blocks/BlockLilypad.h66
-rw-r--r--src/Items/ItemHandler.cpp2
-rw-r--r--src/Items/ItemLilypad.h106
-rw-r--r--src/Simulator/FluidSimulator.cpp1
5 files changed, 116 insertions, 62 deletions
diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp
index 7d438ba3e..6fb5aa5b3 100644
--- a/src/BlockInfo.cpp
+++ b/src/BlockInfo.cpp
@@ -365,7 +365,7 @@ void cBlockInfo::Initialize(void)
ms_Info[E_BLOCK_WOODEN_SLAB ].m_IsSolid = false;
- // Torch placeable blocks:
+ // Blocks that fully occupy their voxel - used as a guide for torch placeable blocks, amongst other things:
ms_Info[E_BLOCK_NEW_LOG ].m_FullyOccupiesVoxel = true;
ms_Info[E_BLOCK_BEDROCK ].m_FullyOccupiesVoxel = true;
ms_Info[E_BLOCK_BLOCK_OF_COAL ].m_FullyOccupiesVoxel = true;
@@ -397,6 +397,7 @@ void cBlockInfo::Initialize(void)
ms_Info[E_BLOCK_HAY_BALE ].m_FullyOccupiesVoxel = true;
ms_Info[E_BLOCK_HUGE_BROWN_MUSHROOM ].m_FullyOccupiesVoxel = true;
ms_Info[E_BLOCK_HUGE_RED_MUSHROOM ].m_FullyOccupiesVoxel = true;
+ ms_Info[E_BLOCK_ICE ].m_FullyOccupiesVoxel = true;
ms_Info[E_BLOCK_IRON_BLOCK ].m_FullyOccupiesVoxel = true;
ms_Info[E_BLOCK_IRON_ORE ].m_FullyOccupiesVoxel = true;
ms_Info[E_BLOCK_JACK_O_LANTERN ].m_FullyOccupiesVoxel = true;
diff --git a/src/Blocks/BlockLilypad.h b/src/Blocks/BlockLilypad.h
index 3db280d80..2dd4ec768 100644
--- a/src/Blocks/BlockLilypad.h
+++ b/src/Blocks/BlockLilypad.h
@@ -2,10 +2,7 @@
#pragma once
#include "BlockHandler.h"
-#include "../Entities/Player.h"
-#include "Vector3.h"
-#include "../LineBlockTracer.h"
-
+#include "Entities/Pickup.h"
@@ -13,69 +10,16 @@
class cBlockLilypadHandler :
public cBlockHandler
{
- typedef cBlockHandler super;
-
public:
cBlockLilypadHandler(BLOCKTYPE a_BlockType)
: cBlockHandler(a_BlockType)
{
-
}
-
- virtual bool GetPlacementBlockTypeMeta(
- cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
- int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
- int a_CursorX, int a_CursorY, int a_CursorZ,
- BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
- ) override
+
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- if (a_BlockFace > 0)
- {
- return false;
- }
-
- class cCallbacks :
- public cBlockTracer::cCallbacks
- {
- public:
- cCallbacks(void) :
- m_HasHitFluid(false)
- {
- }
-
- virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override
- {
- if (IsBlockWater(a_BlockType) || IsBlockLava(a_BlockType))
- {
- if ((a_BlockMeta != 0) || (a_EntryFace == BLOCK_FACE_NONE)) // The hit block should be a source. The FACE_NONE check is for AddFaceDir below
- {
- return false;
- }
- m_HasHitFluid = true;
- AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, (eBlockFace)a_EntryFace);
- m_Pos.Set(a_BlockX, a_BlockY, a_BlockZ);
- return true;
- }
- return false;
- }
-
- Vector3i m_Pos;
- bool m_HasHitFluid;
-
- } Callbacks;
-
- cLineBlockTracer Tracer(*a_Player->GetWorld(), Callbacks);
- Vector3d Start(a_Player->GetEyePosition() + a_Player->GetLookVector());
- Vector3d End(a_Player->GetEyePosition() + a_Player->GetLookVector() * 5);
-
- Tracer.Trace(Start.x, Start.y, Start.z, End.x, End.y, End.z);
-
- if (Callbacks.m_HasHitFluid)
- {
- a_Player->GetWorld()->SetBlock(Callbacks.m_Pos.x, Callbacks.m_Pos.y, Callbacks.m_Pos.z, E_BLOCK_LILY_PAD, 0);
- }
-
- return false;
+ // Reset meta to zero
+ a_Pickups.push_back(cItem(E_BLOCK_LILY_PAD, 1, 0));
}
};
diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp
index 454fabdd7..337b3a83c 100644
--- a/src/Items/ItemHandler.cpp
+++ b/src/Items/ItemHandler.cpp
@@ -27,6 +27,7 @@
#include "ItemHoe.h"
#include "ItemLeaves.h"
#include "ItemLighter.h"
+#include "ItemLilypad.h"
#include "ItemMap.h"
#include "ItemMinecart.h"
#include "ItemNetherWart.h"
@@ -115,6 +116,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
case E_ITEM_FISHING_ROD: return new cItemFishingRodHandler(a_ItemType);
case E_ITEM_FLINT_AND_STEEL: return new cItemLighterHandler(a_ItemType);
case E_ITEM_FLOWER_POT: return new cItemFlowerPotHandler(a_ItemType);
+ case E_BLOCK_LILY_PAD: return new cItemLilypadHandler(a_ItemType);
case E_ITEM_MAP: return new cItemMapHandler();
case E_ITEM_ITEM_FRAME: return new cItemItemFrameHandler(a_ItemType);
case E_ITEM_NETHER_WART: return new cItemNetherWartHandler(a_ItemType);
diff --git a/src/Items/ItemLilypad.h b/src/Items/ItemLilypad.h
new file mode 100644
index 000000000..8496b9f31
--- /dev/null
+++ b/src/Items/ItemLilypad.h
@@ -0,0 +1,106 @@
+
+#pragma once
+
+#include "ItemHandler.h"
+#include "../Entities/Player.h"
+#include "Vector3.h"
+#include "../LineBlockTracer.h"
+#include "BlockInfo.h"
+
+
+
+
+
+class cItemLilypadHandler :
+ public cItemHandler
+{
+ typedef cItemHandler super;
+
+public:
+ cItemLilypadHandler(BLOCKTYPE a_BlockType)
+ : cItemHandler(a_BlockType)
+ {
+
+ }
+
+ virtual bool IsPlaceable(void) override
+ {
+ return false; // Set as not placeable so OnItemUse is called
+ }
+
+ virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override
+ {
+ if (a_BlockFace > BLOCK_FACE_NONE)
+ {
+ // Clicked on the side of a submerged block; vanilla allows placement, so should we
+ AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
+ a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_LILY_PAD, 0);
+ if (!a_Player->IsGameModeCreative())
+ a_Player->GetInventory().RemoveOneEquippedItem();
+ return true;
+ }
+
+ class cCallbacks :
+ public cBlockTracer::cCallbacks
+ {
+ public:
+ cCallbacks(cWorld * a_World) :
+ m_HasHitFluid(false),
+ m_World(a_World)
+ {
+ }
+
+ virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override
+ {
+ if (IsBlockWater(a_BlockType))
+ {
+ if ((a_BlockMeta != 0) || (a_EntryFace == BLOCK_FACE_NONE)) // The hit block should be a source. The FACE_NONE check is clicking whilst submerged
+ {
+ return false;
+ }
+ a_EntryFace = BLOCK_FACE_YP; // Always place pad at top of water block
+ AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, (eBlockFace)a_EntryFace);
+ BLOCKTYPE Block = m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
+ if (
+ !IsBlockWater(Block) &&
+ cBlockInfo::FullyOccupiesVoxel(Block)
+ )
+ {
+ // Can't place lilypad on air/in another block!
+ return true;
+ }
+ m_HasHitFluid = true;
+ m_Pos.Set(a_BlockX, a_BlockY, a_BlockZ);
+ return true;
+ }
+ return false;
+ }
+
+ Vector3i m_Pos;
+ bool m_HasHitFluid;
+ cWorld * m_World;
+
+ };
+
+ cCallbacks Callbacks(a_World);
+ cLineBlockTracer Tracer(*a_Player->GetWorld(), Callbacks);
+ Vector3d Start(a_Player->GetEyePosition() + a_Player->GetLookVector());
+ Vector3d End(a_Player->GetEyePosition() + a_Player->GetLookVector() * 5);
+
+ Tracer.Trace(Start.x, Start.y, Start.z, End.x, End.y, End.z);
+
+ if (Callbacks.m_HasHitFluid)
+ {
+ a_World->SetBlock(Callbacks.m_Pos.x, Callbacks.m_Pos.y, Callbacks.m_Pos.z, E_BLOCK_LILY_PAD, 0);
+ if (!a_Player->IsGameModeCreative())
+ a_Player->GetInventory().RemoveOneEquippedItem();
+ return true;
+ }
+
+ return false;
+ }
+};
+
+
+
+
diff --git a/src/Simulator/FluidSimulator.cpp b/src/Simulator/FluidSimulator.cpp
index 61c93ed73..7779573d7 100644
--- a/src/Simulator/FluidSimulator.cpp
+++ b/src/Simulator/FluidSimulator.cpp
@@ -36,6 +36,7 @@ bool cFluidSimulator::CanWashAway(BLOCKTYPE a_BlockType)
case E_BLOCK_COBWEB:
case E_BLOCK_CROPS:
case E_BLOCK_DEAD_BUSH:
+ case E_BLOCK_LILY_PAD:
case E_BLOCK_RAIL:
case E_BLOCK_REDSTONE_TORCH_OFF:
case E_BLOCK_REDSTONE_TORCH_ON: