summaryrefslogtreecommitdiffstats
path: root/src/Blocks
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-10-23 14:59:42 +0200
committerHowaner <franzi.moos@googlemail.com>2014-10-23 14:59:42 +0200
commit72bb299a4a4f74840c3b368c6669ddc3d32006ee (patch)
tree748fee756010b1f36aa95162f762e21ee0d19c0a /src/Blocks
parentMerge branch 'master' into ChunkLoader (diff)
parentFixed a crash in redstone simulator. (diff)
downloadcuberite-72bb299a4a4f74840c3b368c6669ddc3d32006ee.tar
cuberite-72bb299a4a4f74840c3b368c6669ddc3d32006ee.tar.gz
cuberite-72bb299a4a4f74840c3b368c6669ddc3d32006ee.tar.bz2
cuberite-72bb299a4a4f74840c3b368c6669ddc3d32006ee.tar.lz
cuberite-72bb299a4a4f74840c3b368c6669ddc3d32006ee.tar.xz
cuberite-72bb299a4a4f74840c3b368c6669ddc3d32006ee.tar.zst
cuberite-72bb299a4a4f74840c3b368c6669ddc3d32006ee.zip
Diffstat (limited to '')
-rw-r--r--src/Blocks/BlockDeadBush.h24
-rw-r--r--src/Blocks/BlockDirt.h2
-rw-r--r--src/Blocks/BlockHandler.cpp8
-rw-r--r--src/Blocks/BlockHandler.h2
-rw-r--r--src/Blocks/BlockLeaves.h2
-rw-r--r--src/Blocks/BlockPiston.cpp2
-rw-r--r--src/Blocks/BlockSignPost.h2
-rw-r--r--src/Blocks/BlockTallGrass.h52
-rw-r--r--src/Blocks/BlockVine.h22
-rw-r--r--src/Blocks/BroadcastInterface.h4
10 files changed, 84 insertions, 36 deletions
diff --git a/src/Blocks/BlockDeadBush.h b/src/Blocks/BlockDeadBush.h
index 5b687c710..09df16893 100644
--- a/src/Blocks/BlockDeadBush.h
+++ b/src/Blocks/BlockDeadBush.h
@@ -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
{
- 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;
+ }
}
} ;
diff --git a/src/Blocks/BlockDirt.h b/src/Blocks/BlockDirt.h
index 89dfc963d..aae6719e2 100644
--- a/src/Blocks/BlockDirt.h
+++ b/src/Blocks/BlockDirt.h
@@ -72,7 +72,7 @@ public:
int BlockY = a_RelY + OfsY;
int BlockZ = a_RelZ + OfsZ;
cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(BlockX, BlockZ);
- if (Chunk == NULL)
+ if (Chunk == nullptr)
{
// Unloaded chunk
continue;
diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp
index b6ef5dd6f..60f13a747 100644
--- a/src/Blocks/BlockHandler.cpp
+++ b/src/Blocks/BlockHandler.cpp
@@ -99,9 +99,9 @@ public:
for (BLOCKTYPE Type = 0; Type < E_BLOCK_MAX_TYPE_ID; Type++)
{
cBlockHandler * Handler = cBlockInfo::GetHandler(Type);
- if (Handler == NULL)
+ if (Handler == nullptr)
{
- printf("NULL handler for block type %d!\n", Type);
+ printf("nullptr handler for block type %d!\n", Type);
continue;
}
AString BlockName = ItemTypeToString(Type);
@@ -441,7 +441,7 @@ void cBlockHandler::DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterfac
if (a_CanDrop)
{
- if ((a_Digger != NULL) && (a_Digger->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchSilkTouch) > 0))
+ if ((a_Digger != nullptr) && (a_Digger->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchSilkTouch) > 0))
{
switch (m_BlockType)
{
@@ -562,7 +562,7 @@ void cBlockHandler::Check(cChunkInterface & a_ChunkInterface, cBlockPluginInterf
{
int BlockX = a_RelX + a_Chunk.GetPosX() * cChunkDef::Width;
int BlockZ = a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width;
- DropBlock(a_ChunkInterface, *a_Chunk.GetWorld(), a_PluginInterface, NULL, BlockX, a_RelY, BlockZ);
+ DropBlock(a_ChunkInterface, *a_Chunk.GetWorld(), a_PluginInterface, nullptr, BlockX, a_RelY, BlockZ);
}
a_Chunk.SetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_AIR, 0);
diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h
index 83de836cb..f2298afb5 100644
--- a/src/Blocks/BlockHandler.h
+++ b/src/Blocks/BlockHandler.h
@@ -78,7 +78,7 @@ public:
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta);
/** Handles the dropping, but not destruction, of a block based on what ConvertTo(Verbatim)Pickups() returns, including the spawning of pickups and alertion of plugins
- @param a_Digger The entity causing the drop; it may be NULL
+ @param a_Digger The entity causing the drop; it may be nullptr
@param a_CanDrop Informs the handler whether the block should be dropped at all. One example when this is false is when stone is destroyed by hand
@param a_DropVerbatim Calls ConvertToVerbatimPickups() instead of its counterpart, meaning the block itself is dropped by default (due to a speical tool or enchantment)
*/
diff --git a/src/Blocks/BlockLeaves.h b/src/Blocks/BlockLeaves.h
index add571675..bd9a7414e 100644
--- a/src/Blocks/BlockLeaves.h
+++ b/src/Blocks/BlockLeaves.h
@@ -109,7 +109,7 @@ public:
}
// Decay the leaves:
- DropBlock(a_ChunkInterface, a_WorldInterface, a_PluginInterface, NULL, BlockX, a_RelY, BlockZ);
+ DropBlock(a_ChunkInterface, a_WorldInterface, a_PluginInterface, nullptr, BlockX, a_RelY, BlockZ);
a_ChunkInterface.DigBlock(a_WorldInterface, BlockX, a_RelY, BlockZ);
}
} ;
diff --git a/src/Blocks/BlockPiston.cpp b/src/Blocks/BlockPiston.cpp
index 34d11f675..8d245cabe 100644
--- a/src/Blocks/BlockPiston.cpp
+++ b/src/Blocks/BlockPiston.cpp
@@ -139,7 +139,7 @@ void cBlockPistonHandler::ExtendPiston(int a_BlockX, int a_BlockY, int a_BlockZ,
{
cChunkInterface ChunkInterface(a_World->GetChunkMap());
cBlockInServerPluginInterface PluginInterface(*a_World);
- Handler->DropBlock(ChunkInterface, *a_World, PluginInterface, NULL, a_BlockX, a_BlockY, a_BlockZ);
+ Handler->DropBlock(ChunkInterface, *a_World, PluginInterface, nullptr, a_BlockX, a_BlockY, a_BlockZ);
}
}
diff --git a/src/Blocks/BlockSignPost.h b/src/Blocks/BlockSignPost.h
index 40e15c253..d97501651 100644
--- a/src/Blocks/BlockSignPost.h
+++ b/src/Blocks/BlockSignPost.h
@@ -35,7 +35,7 @@ public:
}
BLOCKTYPE Type = a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ);
- return ((Type == E_BLOCK_SIGN_POST) || cBlockInfo::IsSolid(Type));
+ return ((Type == E_BLOCK_SIGN_POST) || (Type == E_BLOCK_WALLSIGN) || cBlockInfo::IsSolid(Type));
}
diff --git a/src/Blocks/BlockTallGrass.h b/src/Blocks/BlockTallGrass.h
index f520414a7..8e821b899 100644
--- a/src/Blocks/BlockTallGrass.h
+++ b/src/Blocks/BlockTallGrass.h
@@ -2,6 +2,7 @@
#pragma once
#include "BlockHandler.h"
+#include "ChunkInterface.h"
@@ -10,6 +11,7 @@
class cBlockTallGrassHandler :
public cBlockHandler
{
+ typedef cBlockHandler super;
public:
cBlockTallGrassHandler(BLOCKTYPE a_BlockType)
: cBlockHandler(a_BlockType)
@@ -26,32 +28,58 @@ public:
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
// Drop seeds, sometimes
- MTRand r1;
- if (r1.randInt(10) == 5)
+ cFastRandom Random;
+ if (Random.NextInt(8) == 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
+ virtual void DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_BlockPluginInterface, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, bool a_CanDrop) override
{
- NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
-
- if ((!a_Player->IsGameModeCreative()) && (a_Player->GetEquippedItem().m_ItemType == E_ITEM_SHEARS))
+ if (a_CanDrop && (a_Digger != NULL) && (a_Digger->GetEquippedWeapon().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();
+ NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
+ cItems Drops;
+ Drops.Add(m_BlockType, 1, Meta);
+
+ // Allow plugins to modify the pickups:
+ a_BlockPluginInterface.CallHookBlockToPickups(a_Digger, a_BlockX, a_BlockY, a_BlockZ, m_BlockType, Meta, Drops);
+
+ // Spawn the pickups:
+ if (!Drops.empty())
+ {
+ MTRand r1;
+
+ // Mid-block position first
+ double MicroX, MicroY, MicroZ;
+ MicroX = a_BlockX + 0.5;
+ MicroY = a_BlockY + 0.5;
+ MicroZ = a_BlockZ + 0.5;
+
+ // Add random offset second
+ MicroX += r1.rand(1) - 0.5;
+ MicroZ += r1.rand(1) - 0.5;
+
+ a_WorldInterface.SpawnItemPickups(Drops, MicroX, MicroY, MicroZ);
+ }
+ return;
}
+
+ super::DropBlock(a_ChunkInterface, a_WorldInterface, a_BlockPluginInterface, a_Digger, a_BlockX, a_BlockY, a_BlockZ, a_CanDrop);
}
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);
}
} ;
diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h
index 213324cc1..00d7a69b8 100644
--- a/src/Blocks/BlockVine.h
+++ b/src/Blocks/BlockVine.h
@@ -23,10 +23,6 @@ public:
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
) override
{
- UNUSED(a_Player);
- UNUSED(a_CursorX);
- UNUSED(a_CursorY);
- UNUSED(a_CursorZ);
// TODO: Disallow placement where the vine doesn't attach to something properly
BLOCKTYPE BlockType = 0;
NIBBLETYPE BlockMeta;
@@ -80,7 +76,21 @@ public:
/// Returns true if the specified block type is good for vines to attach to
static bool IsBlockAttachable(BLOCKTYPE a_BlockType)
{
- return ((a_BlockType == E_BLOCK_LEAVES) || (a_BlockType == E_BLOCK_NEW_LEAVES) || cBlockInfo::IsSolid(a_BlockType));
+ switch (a_BlockType)
+ {
+ case E_BLOCK_GLASS:
+ case E_BLOCK_STAINED_GLASS:
+ case E_BLOCK_CHEST:
+ case E_BLOCK_TRAPPED_CHEST:
+ {
+ // You can't attach a vine to this solid blocks.
+ return false;
+ }
+ default:
+ {
+ return cBlockInfo::IsSolid(a_BlockType);
+ }
+ }
}
@@ -138,7 +148,7 @@ public:
{
int BlockX = a_RelX + a_Chunk.GetPosX() * cChunkDef::Width;
int BlockZ = a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width;
- DropBlock(a_ChunkInterface, *a_Chunk.GetWorld(), a_PluginInterface, NULL, BlockX, a_RelY, BlockZ);
+ DropBlock(a_ChunkInterface, *a_Chunk.GetWorld(), a_PluginInterface, nullptr, BlockX, a_RelY, BlockZ);
}
a_Chunk.SetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_AIR, 0);
return;
diff --git a/src/Blocks/BroadcastInterface.h b/src/Blocks/BroadcastInterface.h
index cf332b153..bf464627d 100644
--- a/src/Blocks/BroadcastInterface.h
+++ b/src/Blocks/BroadcastInterface.h
@@ -7,6 +7,6 @@ public:
virtual ~cBroadcastInterface() {}
virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) = 0;
- virtual void BroadcastSoundEffect(const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL) = 0;
- virtual void BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL) = 0;
+ virtual void BroadcastSoundEffect(const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = nullptr) = 0;
+ virtual void BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = nullptr) = 0;
};