summaryrefslogtreecommitdiffstats
path: root/src/Items
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2019-10-16 10:06:34 +0200
committerGitHub <noreply@github.com>2019-10-16 10:06:34 +0200
commit221cc4ec5cb6301743e947eaabed3fecedba796f (patch)
tree4e44c8bb7523e5d1d04468fc906ae24674c10abc /src/Items
parentFixed crash in hopper while pulling items from blockentity above itself (#4412) (diff)
downloadcuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar
cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar.gz
cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar.bz2
cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar.lz
cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar.xz
cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar.zst
cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.zip
Diffstat (limited to 'src/Items')
-rw-r--r--src/Items/ItemBucket.h12
-rw-r--r--src/Items/ItemChest.h14
-rw-r--r--src/Items/ItemHandler.cpp28
-rw-r--r--src/Items/ItemHandler.h5
-rw-r--r--src/Items/ItemShears.h8
-rw-r--r--src/Items/ItemShovel.h26
6 files changed, 27 insertions, 66 deletions
diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h
index f5acb25b3..36caf667b 100644
--- a/src/Items/ItemBucket.h
+++ b/src/Items/ItemBucket.h
@@ -114,6 +114,8 @@ public:
+
+
bool PlaceFluid(
cWorld * a_World, cPlayer * a_Player, cBlockPluginInterface & a_PluginInterface, const cItem & a_Item,
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, BLOCKTYPE a_FluidBlock
@@ -164,13 +166,7 @@ public:
// Plugin disagrees with the washing-away
return false;
}
-
- cBlockHandler * Handler = BlockHandler(CurrentBlockType);
- if (Handler->DoesDropOnUnsuitable())
- {
- cChunkInterface ChunkInterface(a_World->GetChunkMap());
- Handler->DropBlock(ChunkInterface, *a_World, a_PluginInterface, a_Player, BlockPos.x, BlockPos.y, BlockPos.z);
- }
+ a_World->DropBlockAsPickups(BlockPos, a_Player, nullptr);
a_PluginInterface.CallHookPlayerBrokenBlock(*a_Player, BlockPos.x, BlockPos.y, BlockPos.z, EntryFace, CurrentBlockType, CurrentBlockMeta);
}
@@ -180,6 +176,8 @@ public:
+
+
bool GetBlockFromTrace(cWorld * a_World, cPlayer * a_Player, Vector3i & a_BlockPos)
{
class cCallbacks :
diff --git a/src/Items/ItemChest.h b/src/Items/ItemChest.h
index 58f6fbc6e..817020a25 100644
--- a/src/Items/ItemChest.h
+++ b/src/Items/ItemChest.h
@@ -40,13 +40,15 @@ public:
}
// Check if the block ignores build collision (water, grass etc.):
- BLOCKTYPE ClickedBlock;
- NIBBLETYPE ClickedBlockMeta;
- a_World.GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, ClickedBlock, ClickedBlockMeta);
+ BLOCKTYPE clickedBlock;
+ NIBBLETYPE clickedBlockMeta;
+ Vector3i blockPos(a_BlockX, a_BlockY, a_BlockZ);
+ a_World.GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, clickedBlock, clickedBlockMeta);
cChunkInterface ChunkInterface(a_World.GetChunkMap());
- if (BlockHandler(ClickedBlock)->DoesIgnoreBuildCollision(ChunkInterface, { a_BlockX, a_BlockY, a_BlockZ }, a_Player, ClickedBlockMeta))
+ auto blockHandler = BlockHandler(clickedBlock);
+ if (blockHandler->DoesIgnoreBuildCollision(ChunkInterface, blockPos, a_Player, clickedBlockMeta))
{
- BlockHandler(ClickedBlock)->OnDestroyedByPlayer(ChunkInterface, a_World, a_Player, a_BlockX, a_BlockY, a_BlockZ);
+ blockHandler->OnPlayerBreakingBlock(ChunkInterface, a_World, a_Player, blockPos);
}
else
{
@@ -64,7 +66,7 @@ public:
// Clicked on side of block, make sure that placement won't be cancelled if there is a slab able to be double slabbed.
// No need to do combinability (dblslab) checks, client will do that here.
- if (BlockHandler(ClickedBlock)->DoesIgnoreBuildCollision(ChunkInterface, { a_BlockX, a_BlockY, a_BlockZ }, a_Player, ClickedBlockMeta))
+ if (blockHandler->DoesIgnoreBuildCollision(ChunkInterface, blockPos, a_Player, clickedBlockMeta))
{
// Tried to place a block into another?
// Happens when you place a block aiming at side of block with a torch on it or stem beside it
diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp
index 489ef4f28..ecc4a9ace 100644
--- a/src/Items/ItemHandler.cpp
+++ b/src/Items/ItemHandler.cpp
@@ -361,9 +361,11 @@ bool cItemHandler::OnPlayerPlace(
cChunkInterface ChunkInterface(a_World.GetChunkMap());
// Check if the block ignores build collision (water, grass etc.):
- if (BlockHandler(ClickedBlock)->DoesIgnoreBuildCollision(ChunkInterface, { a_BlockX, a_BlockY, a_BlockZ }, a_Player, ClickedBlockMeta))
+ auto blockHandler = BlockHandler(ClickedBlock);
+ Vector3i absPos(a_BlockX, a_BlockY, a_BlockZ);
+ if (blockHandler->DoesIgnoreBuildCollision(ChunkInterface, absPos, a_Player, ClickedBlockMeta))
{
- BlockHandler(ClickedBlock)->OnDestroyedByPlayer(ChunkInterface, a_World, a_Player, a_BlockX, a_BlockY, a_BlockZ);
+ a_World.DropBlockAsPickups(absPos, &a_Player, nullptr);
}
else
{
@@ -482,28 +484,6 @@ bool cItemHandler::OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cI
-void cItemHandler::OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ)
-{
- UNUSED(a_Item);
-
- BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
- cBlockHandler * Handler = cBlockInfo::GetHandler(Block);
-
- if (a_Player->IsGameModeSurvival())
- {
- cChunkInterface ChunkInterface(a_World->GetChunkMap());
- cBlockInServerPluginInterface PluginInterface(*a_World);
- Handler->DropBlock(ChunkInterface, *a_World, PluginInterface, a_Player, a_BlockX, a_BlockY, a_BlockZ, CanHarvestBlock(Block));
- }
-
- auto Action = (cBlockInfo::IsOneHitDig(Block) ? dlaBreakBlockInstant : dlaBreakBlock);
- a_Player->UseEquippedItem(Action);
-}
-
-
-
-
-
void cItemHandler::OnEntityAttack(cPlayer * a_Attacker, cEntity * a_AttackedEntity)
{
UNUSED(a_AttackedEntity);
diff --git a/src/Items/ItemHandler.h b/src/Items/ItemHandler.h
index 26703f573..ea0684dd1 100644
--- a/src/Items/ItemHandler.h
+++ b/src/Items/ItemHandler.h
@@ -99,12 +99,9 @@ public:
UNUSED(a_Item);
}
- /** Called while the player diggs a block using this item */
+ /** Called while the player digs a block using this item */
virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_HeldItem, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace);
- /** Called when the player destroys a block using this item. This also calls the drop function for the destroyed block */
- virtual void OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ);
-
/** Called when a player attacks a other entity. */
virtual void OnEntityAttack(cPlayer * a_Attacker, cEntity * a_AttackedEntity);
diff --git a/src/Items/ItemShears.h b/src/Items/ItemShears.h
index 6cbb37b2a..9a6baa5e1 100644
--- a/src/Items/ItemShears.h
+++ b/src/Items/ItemShears.h
@@ -73,14 +73,6 @@ public:
}
- virtual void OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ) override
- {
- BLOCKTYPE Block;
- NIBBLETYPE BlockMeta;
- a_World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, Block, BlockMeta);
-
- super::OnBlockDestroyed(a_World, a_Player, a_Item, a_BlockX, a_BlockY, a_BlockZ);
- }
diff --git a/src/Items/ItemShovel.h b/src/Items/ItemShovel.h
index 49ecf3348..0715f8d99 100644
--- a/src/Items/ItemShovel.h
+++ b/src/Items/ItemShovel.h
@@ -36,21 +36,7 @@ public:
- virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override
- {
- BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
- if (Block == E_BLOCK_SNOW)
- {
- cChunkInterface ChunkInterface(a_World->GetChunkMap());
- cBlockInServerPluginInterface PluginInterface(*a_World);
- BlockHandler(Block)->DropBlock(ChunkInterface, *a_World, PluginInterface, a_Player, a_BlockX, a_BlockY, a_BlockZ);
- a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
- a_Player->UseEquippedItem(cItemHandler::dlaBreakBlock);
- return true;
- }
- return false;
- }
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) override
{
@@ -61,6 +47,10 @@ public:
return super::CanHarvestBlock(a_BlockType);
}
+
+
+
+
virtual bool CanRepairWithRawMaterial(short a_ItemType) override
{
switch (m_ItemType)
@@ -74,6 +64,10 @@ public:
return false;
}
+
+
+
+
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) override
{
switch (a_Block)
@@ -101,9 +95,7 @@ public:
}
break;
}
- default: return super::GetBlockBreakingStrength(a_Block);
}
- ASSERT(!"Something is wrong here... Maybe they are shovels out of a new material?");
- return 1.0f;
+ return super::GetBlockBreakingStrength(a_Block);
}
};