1
0

Corrected drops from dead bush, tall grass and cobweb.

This commit is contained in:
Howaner 2014-10-07 18:21:39 +02:00
parent e8e428a806
commit a5e09155c0
5 changed files with 67 additions and 42 deletions

View File

@ -17,15 +17,25 @@ public:
} }
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
// Don't drop anything
}
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{ {
return (a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) == E_BLOCK_SAND); if (a_RelY <= 0)
{
return false;
}
BLOCKTYPE BelowBlock = a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ);
switch (BelowBlock)
{
case E_BLOCK_CLAY:
case E_BLOCK_HARDENED_CLAY:
case E_BLOCK_STAINED_CLAY:
case E_BLOCK_SAND:
{
return true;
}
default: return false;
}
} }
} ; } ;

View File

@ -26,32 +26,23 @@ public:
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{ {
// Drop seeds, sometimes // Drop seeds, sometimes
MTRand r1; cFastRandom Random;
if (r1.randInt(10) == 5) if (Random.NextInt(8) == 0)
{ {
a_Pickups.push_back(cItem(E_ITEM_SEEDS, 1, 0)); a_Pickups.push_back(cItem(E_ITEM_SEEDS, 1, 0));
} }
} }
virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override
{
NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
if ((!a_Player->IsGameModeCreative()) && (a_Player->GetEquippedItem().m_ItemType == E_ITEM_SHEARS))
{
cItems Pickups;
Pickups.Add(E_BLOCK_TALL_GRASS, 1, Meta);
a_WorldInterface.SpawnItemPickups(Pickups, a_BlockX, a_BlockY, a_BlockZ);
a_Player->UseEquippedItem();
}
}
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{ {
return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR)); if (a_RelY <= 0)
{
return false;
}
BLOCKTYPE BelowBlock = a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ);
return IsBlockTypeOfDirt(BelowBlock);
} }
} ; } ;

View File

@ -1113,6 +1113,12 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo
cWorld * World = m_Player->GetWorld(); cWorld * World = m_Player->GetWorld();
cItemHandler * ItemHandler = cItemHandler::GetItemHandler(m_Player->GetEquippedItem()); cItemHandler * ItemHandler = cItemHandler::GetItemHandler(m_Player->GetEquippedItem());
if (a_OldBlock == E_BLOCK_AIR)
{
LOGD("Dug air - what the function?");
return;
}
if (cRoot::Get()->GetPluginManager()->CallHookPlayerBreakingBlock(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_OldBlock, a_OldMeta)) if (cRoot::Get()->GetPluginManager()->CallHookPlayerBreakingBlock(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_OldBlock, a_OldMeta))
{ {
// A plugin doesn't agree with the breaking. Bail out. Send the block back to the client, so that it knows: // A plugin doesn't agree with the breaking. Bail out. Send the block back to the client, so that it knows:
@ -1120,12 +1126,6 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo
return; return;
} }
if (a_OldBlock == E_BLOCK_AIR)
{
LOGD("Dug air - what the function?");
return;
}
m_Player->AddFoodExhaustion(0.025); m_Player->AddFoodExhaustion(0.025);
ItemHandler->OnBlockDestroyed(World, m_Player, m_Player->GetEquippedItem(), a_BlockX, a_BlockY, a_BlockZ); ItemHandler->OnBlockDestroyed(World, m_Player, m_Player->GetEquippedItem(), a_BlockX, a_BlockY, a_BlockZ);
// The ItemHandler is also responsible for spawning the pickups // The ItemHandler is also responsible for spawning the pickups

View File

@ -572,6 +572,8 @@ bool cItemHandler::CanHarvestBlock(BLOCKTYPE a_BlockType)
case E_BLOCK_COBBLESTONE: case E_BLOCK_COBBLESTONE:
case E_BLOCK_COBBLESTONE_STAIRS: case E_BLOCK_COBBLESTONE_STAIRS:
case E_BLOCK_COBBLESTONE_WALL: case E_BLOCK_COBBLESTONE_WALL:
case E_BLOCK_COBWEB:
case E_BLOCK_DEAD_BUSH:
case E_BLOCK_DIAMOND_BLOCK: case E_BLOCK_DIAMOND_BLOCK:
case E_BLOCK_DIAMOND_ORE: case E_BLOCK_DIAMOND_ORE:
case E_BLOCK_DOUBLE_NEW_STONE_SLAB: case E_BLOCK_DOUBLE_NEW_STONE_SLAB:
@ -587,6 +589,7 @@ bool cItemHandler::CanHarvestBlock(BLOCKTYPE a_BlockType)
case E_BLOCK_IRON_TRAPDOOR: case E_BLOCK_IRON_TRAPDOOR:
case E_BLOCK_LAPIS_BLOCK: case E_BLOCK_LAPIS_BLOCK:
case E_BLOCK_LAPIS_ORE: case E_BLOCK_LAPIS_ORE:
case E_BLOCK_LEAVES:
case E_BLOCK_LIT_FURNACE: case E_BLOCK_LIT_FURNACE:
case E_BLOCK_MOB_SPAWNER: case E_BLOCK_MOB_SPAWNER:
case E_BLOCK_MOSSY_COBBLESTONE: case E_BLOCK_MOSSY_COBBLESTONE:
@ -594,6 +597,7 @@ bool cItemHandler::CanHarvestBlock(BLOCKTYPE a_BlockType)
case E_BLOCK_NETHER_BRICK_STAIRS: case E_BLOCK_NETHER_BRICK_STAIRS:
case E_BLOCK_NETHER_BRICK_FENCE: case E_BLOCK_NETHER_BRICK_FENCE:
case E_BLOCK_NETHERRACK: case E_BLOCK_NETHERRACK:
case E_BLOCK_NEW_LEAVES:
case E_BLOCK_NEW_STONE_SLAB: case E_BLOCK_NEW_STONE_SLAB:
case E_BLOCK_OBSIDIAN: case E_BLOCK_OBSIDIAN:
case E_BLOCK_PACKED_ICE: case E_BLOCK_PACKED_ICE:

View File

@ -28,21 +28,25 @@ 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 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); BLOCKTYPE Block;
NIBBLETYPE BlockMeta;
a_World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, Block, BlockMeta);
if ((Block == E_BLOCK_LEAVES) || (Block == E_BLOCK_NEW_LEAVES)) if ((Block == E_BLOCK_LEAVES) || (Block == E_BLOCK_NEW_LEAVES))
{ {
NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); cItems Drops;
cBlockHandler * Handler = cBlockInfo::GetHandler(Block); cBlockHandler * Handler = cBlockInfo::GetHandler(Block);
cItems Drops; Handler->ConvertToPickups(Drops, BlockMeta);
Handler->ConvertToPickups(Drops, Meta); Drops.Add(Block, 1, BlockMeta & 3);
Drops.push_back(cItem(Block, 1, Meta & 3));
a_World->SpawnItemPickups(Drops, a_BlockX, a_BlockY, a_BlockZ); a_World->SpawnItemPickups(Drops, a_BlockX, a_BlockY, a_BlockZ);
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
a_World->SpawnItemPickups(Drops, a_BlockX, a_BlockY, a_BlockZ);
a_Player->UseEquippedItem(); a_Player->UseEquippedItem();
return true; return true;
} }
return false; return false;
} }
@ -53,12 +57,10 @@ public:
{ {
case E_BLOCK_COBWEB: case E_BLOCK_COBWEB:
case E_BLOCK_VINES: case E_BLOCK_VINES:
case E_BLOCK_LEAVES:
case E_BLOCK_NEW_LEAVES:
{ {
return true; return true;
} }
} // switch (a_BlockType) }
return super::CanHarvestBlock(a_BlockType); return super::CanHarvestBlock(a_BlockType);
} }
@ -71,14 +73,32 @@ public:
virtual void OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ) override virtual void OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ) override
{ {
super::OnBlockDestroyed(a_World, a_Player, a_Item, a_BlockX, a_BlockY, a_BlockZ); BLOCKTYPE Block;
NIBBLETYPE BlockMeta;
a_World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, Block, BlockMeta);
BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); if ((Block == E_BLOCK_TALL_GRASS) && !a_Player->IsGameModeCreative())
if ((Block == E_BLOCK_TRIPWIRE) || (Block == E_BLOCK_VINES)) {
cItems Drops;
Drops.Add(Block, 1, BlockMeta);
a_World->SpawnItemPickups(Drops, a_BlockX, a_BlockY, a_BlockZ);
a_Player->UseEquippedItem();
return;
}
super::OnBlockDestroyed(a_World, a_Player, a_Item, a_BlockX, a_BlockY, a_BlockZ);
switch (Block)
{
case E_BLOCK_COBWEB:
case E_BLOCK_DEAD_BUSH:
case E_BLOCK_TRIPWIRE:
case E_BLOCK_VINES:
case E_BLOCK_WOOL:
{ {
a_Player->UseEquippedItem(); a_Player->UseEquippedItem();
} }
} }
}
} ; } ;