diff options
author | lapayo94@gmail.com <lapayo94@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-07-16 15:30:33 +0200 |
---|---|---|
committer | lapayo94@gmail.com <lapayo94@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-07-16 15:30:33 +0200 |
commit | ba70a151915bb14ddbe0527d8807508000819df6 (patch) | |
tree | 3d6d465e35067921809d3c5dc5c45d796934ad85 /source/blocks | |
parent | A new Block handling system :o (diff) | |
download | cuberite-ba70a151915bb14ddbe0527d8807508000819df6.tar cuberite-ba70a151915bb14ddbe0527d8807508000819df6.tar.gz cuberite-ba70a151915bb14ddbe0527d8807508000819df6.tar.bz2 cuberite-ba70a151915bb14ddbe0527d8807508000819df6.tar.lz cuberite-ba70a151915bb14ddbe0527d8807508000819df6.tar.xz cuberite-ba70a151915bb14ddbe0527d8807508000819df6.tar.zst cuberite-ba70a151915bb14ddbe0527d8807508000819df6.zip |
Diffstat (limited to 'source/blocks')
-rw-r--r-- | source/blocks/Block.cpp | 15 | ||||
-rw-r--r-- | source/blocks/Block.h | 3 | ||||
-rw-r--r-- | source/blocks/BlockLadder.h | 12 | ||||
-rw-r--r-- | source/blocks/BlockOre.h | 58 | ||||
-rw-r--r-- | source/blocks/BlockRedstoneOre.h | 26 | ||||
-rw-r--r-- | source/blocks/BlockRedstoneTorch.h | 12 | ||||
-rw-r--r-- | source/blocks/BlockTorch.h | 12 |
7 files changed, 101 insertions, 37 deletions
diff --git a/source/blocks/Block.cpp b/source/blocks/Block.cpp index 047caa989..1fd7a1af8 100644 --- a/source/blocks/Block.cpp +++ b/source/blocks/Block.cpp @@ -34,10 +34,10 @@ #include "BlockCactus.h"
#include "BlockStems.h"
#include "BlockGlowstone.h"
-#include "BlockRedstoneOre.h"
#include "BlockStone.h"
#include "BlockMelon.h"
#include "BlockIce.h"
+#include "BlockOre.h"
bool cBlockHandler::m_HandlerInitialized = false;
cBlockHandler *cBlockHandler::m_BlockHandler[256];
@@ -144,9 +144,15 @@ cBlockHandler *cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockID) return new cBlockStemsHandler(a_BlockID);
case E_BLOCK_GLOWSTONE:
return new cBlockGlowstoneHandler(a_BlockID);
+ case E_BLOCK_DIAMOND_ORE:
+ case E_BLOCK_GOLD_ORE:
case E_BLOCK_REDSTONE_ORE:
case E_BLOCK_REDSTONE_ORE_GLOWING:
- return new cBlockRedstoneOreHandler(a_BlockID);
+ case E_BLOCK_EMERALD_ORE:
+ case E_BLOCK_IRON_ORE:
+ case E_BLOCK_LAPIS_ORE:
+ case E_BLOCK_COAL_ORE:
+ return new cBlockOreHandler(a_BlockID);
case E_BLOCK_STONE:
case E_BLOCK_COBBLESTONE:
return new cBlockStoneHandler(a_BlockID);
@@ -261,6 +267,11 @@ void cBlockHandler::DropBlock(cWorld *a_World, int a_X, int a_Y, int a_Z) }
}
+bool cBlockHandler::CanBePlacedAt(cWorld *a_World, int a_X, int a_Y, int a_Z, char a_Dir)
+{
+ return CanBeAt(a_World, a_X, a_Y, a_Z);
+}
+
bool cBlockHandler::CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z)
{
return true;
diff --git a/source/blocks/Block.h b/source/blocks/Block.h index 09cff8487..f55ee7dd2 100644 --- a/source/blocks/Block.h +++ b/source/blocks/Block.h @@ -28,7 +28,10 @@ public: virtual bool NeedsRandomTicks();
//Item is -2 if it wasn´t a player
virtual void DropBlock(cWorld *a_World, int a_X, int a_Y, int a_Z);
+ //Checks if the block can stay at
virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z);
+ //Checks if the block can be placed at Default:CanBeAt(...) NOTE: In the block is not placed
+ virtual bool CanBePlacedAt(cWorld *a_World, int a_X, int a_Y, int a_Z, char a_Dir);
//This gets called if the player tries to place a block ontop of this block (Only if he aims directly on this block)
virtual bool AllowBlockOnTop();
virtual bool IsUseable();
diff --git a/source/blocks/BlockLadder.h b/source/blocks/BlockLadder.h index 0b63cc8e6..b32f8081d 100644 --- a/source/blocks/BlockLadder.h +++ b/source/blocks/BlockLadder.h @@ -18,11 +18,17 @@ public: OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir);
}
- virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z)
+ virtual bool CanBePlacedAt(cWorld *a_World, int a_X, int a_Y, int a_Z, char a_Dir) override
{
- char Dir = cLadder::MetaDataToDirection(a_World->GetBlockMeta( a_X, a_Y, a_Z));
- AddDirection( a_X, a_Y, a_Z, Dir, true );
+ AddDirection( a_X, a_Y, a_Z, a_Dir, true );
return a_World->GetBlock( a_X, a_Y, a_Z ) != E_BLOCK_AIR;
}
+
+
+ virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override
+ {
+ char Dir = cLadder::MetaDataToDirection(a_World->GetBlockMeta( a_X, a_Y, a_Z));
+ return CanBePlacedAt(a_World, a_X, a_Y, a_Z, Dir);
+ }
};
\ No newline at end of file diff --git a/source/blocks/BlockOre.h b/source/blocks/BlockOre.h new file mode 100644 index 000000000..d1714f1af --- /dev/null +++ b/source/blocks/BlockOre.h @@ -0,0 +1,58 @@ +#pragma once
+#include "Block.h"
+#include "../MersenneTwister.h"
+#include "../cWorld.h"
+
+class cBlockOreHandler : public cBlockHandler
+{
+public:
+ cBlockOreHandler(BLOCKTYPE a_BlockID)
+ : cBlockHandler(a_BlockID)
+ {
+ }
+
+ virtual char GetDropCount() override
+ {
+ MTRand r1;
+ switch(m_BlockID)
+ {
+ case E_BLOCK_LAPIS_ORE:
+ return 4 + (char)r1.randInt(4);
+ case E_BLOCK_REDSTONE_ORE:
+ case E_BLOCK_REDSTONE_ORE_GLOWING:
+ return 4 + (char)r1.randInt(1);
+ default:
+ return 1;
+ }
+ }
+
+ virtual char GetDropMeta(char a_Meta) override
+ {
+ switch(m_BlockID)
+ {
+ case E_BLOCK_LAPIS_ORE:
+ return 4;
+ default:
+ return 0;
+ }
+ }
+
+ virtual int GetDropID() override
+ {
+ switch(m_BlockID)
+ {
+ case E_BLOCK_DIAMOND_ORE:
+ return E_ITEM_DIAMOND;
+ case E_BLOCK_REDSTONE_ORE:
+ case E_BLOCK_REDSTONE_ORE_GLOWING:
+ return E_ITEM_REDSTONE_DUST;
+ case E_BLOCK_EMERALD_ORE:
+ return E_ITEM_EMERALD;
+ case E_BLOCK_LAPIS_ORE:
+ return E_ITEM_DYE;
+ case E_BLOCK_COAL_ORE:
+ return E_ITEM_COAL;
+ }
+ return m_BlockID;
+ }
+};
\ No newline at end of file diff --git a/source/blocks/BlockRedstoneOre.h b/source/blocks/BlockRedstoneOre.h deleted file mode 100644 index 5658d76ad..000000000 --- a/source/blocks/BlockRedstoneOre.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once
-#include "Block.h"
-#include "../MersenneTwister.h"
-#include "../cWorld.h"
-
-class cBlockRedstoneOreHandler : public cBlockHandler
-{
-public:
- cBlockRedstoneOreHandler(BLOCKTYPE a_BlockID)
- : cBlockHandler(a_BlockID)
- {
- }
-
- virtual int GetDropID()
- {
- return E_ITEM_REDSTONE_DUST;
- }
-
- virtual char GetDropCount()
- {
- MTRand r1;
- return 4 + r1.randInt(1);
- }
-
-
-};
\ No newline at end of file diff --git a/source/blocks/BlockRedstoneTorch.h b/source/blocks/BlockRedstoneTorch.h index 6ae37cd1e..927cf3d7c 100644 --- a/source/blocks/BlockRedstoneTorch.h +++ b/source/blocks/BlockRedstoneTorch.h @@ -11,13 +11,19 @@ public: {
}
- virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z)
+ virtual bool CanBePlacedAt(cWorld *a_World, int a_X, int a_Y, int a_Z, char a_Dir) override
{
- char Dir = cTorch::MetaDataToDirection(a_World->GetBlockMeta( a_X, a_Y, a_Z));
- AddDirection( a_X, a_Y, a_Z, Dir, true );
+ AddDirection( a_X, a_Y, a_Z, a_Dir, true );
return a_World->GetBlock( a_X, a_Y, a_Z ) != E_BLOCK_AIR;
}
+
+ virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override
+ {
+ char Dir = cTorch::MetaDataToDirection(a_World->GetBlockMeta( a_X, a_Y, a_Z));
+ return CanBePlacedAt(a_World, a_X, a_Y, a_Z, Dir);
+ }
+
virtual int GetDropID()
{
return E_ITEM_REDSTONE_TORCH_ON;
diff --git a/source/blocks/BlockTorch.h b/source/blocks/BlockTorch.h index 1e4827ac1..9a2325994 100644 --- a/source/blocks/BlockTorch.h +++ b/source/blocks/BlockTorch.h @@ -16,10 +16,16 @@ public: return false;
}
- virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z)
+ virtual bool CanBePlacedAt(cWorld *a_World, int a_X, int a_Y, int a_Z, char a_Dir) override
{
- char Dir = cTorch::MetaDataToDirection(a_World->GetBlockMeta( a_X, a_Y, a_Z));
- AddDirection( a_X, a_Y, a_Z, Dir, true );
+ AddDirection( a_X, a_Y, a_Z, a_Dir, true );
return a_World->GetBlock( a_X, a_Y, a_Z ) != E_BLOCK_AIR;
}
+
+
+ virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override
+ {
+ char Dir = cTorch::MetaDataToDirection(a_World->GetBlockMeta( a_X, a_Y, a_Z));
+ return CanBePlacedAt(a_World, a_X, a_Y, a_Z, Dir);
+ }
};
\ No newline at end of file |