summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/blocks/Block.cpp15
-rw-r--r--source/blocks/Block.h3
-rw-r--r--source/blocks/BlockLadder.h12
-rw-r--r--source/blocks/BlockOre.h58
-rw-r--r--source/blocks/BlockRedstoneOre.h26
-rw-r--r--source/blocks/BlockRedstoneTorch.h12
-rw-r--r--source/blocks/BlockTorch.h12
-rw-r--r--source/cClientHandle.cpp2
-rw-r--r--source/items/ItemPickaxe.h1
9 files changed, 103 insertions, 38 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
diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp
index 53852438d..76aaf2724 100644
--- a/source/cClientHandle.cpp
+++ b/source/cClientHandle.cpp
@@ -948,7 +948,7 @@ void cClientHandle::HandleBlockPlace(cPacket_BlockPlace * a_Packet)
if(Dir != 1 && !NewBlock->CanBePlacedOnSide())
return;
- if(NewBlock->CanBeAt(World, X, Y, Z))
+ if(NewBlock->CanBePlacedAt(World, X, Y, Z, Dir))
{
ItemHandler->PlaceBlock(World, m_Player, &m_Player->GetInventory().GetEquippedItem(), X, Y, Z, a_Packet->m_Direction);
}else{
diff --git a/source/items/ItemPickaxe.h b/source/items/ItemPickaxe.h
index 1be3745de..c9b36ae7b 100644
--- a/source/items/ItemPickaxe.h
+++ b/source/items/ItemPickaxe.h
@@ -68,5 +68,6 @@ public:
case E_BLOCK_NETHER_BRICK_STAIRS:
return PickaxeLevel() >= 1;
}
+ return false;
}
}; \ No newline at end of file