diff options
Diffstat (limited to 'source/Blocks')
-rw-r--r-- | source/Blocks/BlockDoor.cpp | 28 | ||||
-rw-r--r-- | source/Blocks/BlockDoor.h | 7 | ||||
-rw-r--r-- | source/Blocks/BlockFenceGate.h | 56 | ||||
-rw-r--r-- | source/Blocks/BlockHandler.cpp | 2 |
4 files changed, 82 insertions, 11 deletions
diff --git a/source/Blocks/BlockDoor.cpp b/source/Blocks/BlockDoor.cpp index c0d616b37..1976e2f20 100644 --- a/source/Blocks/BlockDoor.cpp +++ b/source/Blocks/BlockDoor.cpp @@ -54,15 +54,6 @@ void cBlockDoorHandler::OnDestroyed(cWorld * a_World, int a_BlockX, int a_BlockY -void cBlockDoorHandler::OnDigging(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ)
-{
- cDoors::ChangeDoor(a_World, a_BlockX, a_BlockY, a_BlockZ);
-}
-
-
-
-
-
void cBlockDoorHandler::OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ)
{
cDoors::ChangeDoor(a_World, a_BlockX, a_BlockY, a_BlockZ);
@@ -77,7 +68,24 @@ void cBlockDoorHandler::PlaceBlock(cWorld * a_World, cPlayer * a_Player, NIBBLET if (a_World->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ) == E_BLOCK_AIR)
{
a_BlockMeta = cDoors::RotationToMetaData(a_Player->GetRotation());
- a_World->SetBlock(a_BlockX, a_BlockY + 1, a_BlockZ, m_BlockType, a_BlockMeta + 8);
+ char a_TopBlockMeta = 8;
+ if((a_BlockMeta == 0) && (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ - 1) == m_BlockType))
+ {
+ a_TopBlockMeta = 9;
+ }
+ else if((a_BlockMeta == 1) && (a_World->GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ) == m_BlockType))
+ {
+ a_TopBlockMeta = 9;
+ }
+ else if((a_BlockMeta == 2) && (a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1) == m_BlockType))
+ {
+ a_TopBlockMeta = 9;
+ }
+ else if((a_BlockMeta == 3) && (a_World->GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ) == m_BlockType))
+ {
+ a_TopBlockMeta = 9;
+ }
+ a_World->SetBlock(a_BlockX, a_BlockY + 1, a_BlockZ, m_BlockType, a_TopBlockMeta);
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, a_BlockMeta);
OnPlacedByPlayer(a_World, a_Player, a_BlockX, a_BlockY, a_BlockZ, a_Dir);
}
diff --git a/source/Blocks/BlockDoor.h b/source/Blocks/BlockDoor.h index 7499e9c82..37584895f 100644 --- a/source/Blocks/BlockDoor.h +++ b/source/Blocks/BlockDoor.h @@ -2,6 +2,7 @@ #pragma once
#include "BlockHandler.h"
+#include "../World.h"
@@ -14,7 +15,6 @@ public: cBlockDoorHandler(BLOCKTYPE a_BlockType);
virtual void OnPlaced(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, int a_Dir) override;
virtual void OnDestroyed(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override;
- virtual void OnDigging(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override;
virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override;
virtual const char * GetStepSound(void) override;
@@ -34,6 +34,11 @@ public: {
return false;
}
+
+ virtual bool CanBeAt(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override
+ {
+ return a_World->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ);
+ }
} ;
diff --git a/source/Blocks/BlockFenceGate.h b/source/Blocks/BlockFenceGate.h new file mode 100644 index 000000000..072eb9c3a --- /dev/null +++ b/source/Blocks/BlockFenceGate.h @@ -0,0 +1,56 @@ +
+#pragma once
+
+#include "BlockHandler.h"
+#include "../Doors.h"
+
+
+
+
+
+class cBlockFenceGateHandler :
+ public cBlockHandler
+{
+public:
+ cBlockFenceGateHandler(BLOCKTYPE a_BlockType)
+ : cBlockHandler(a_BlockType)
+ {
+ }
+
+ void OnPlaced(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, int a_Dir)
+ {
+
+ }
+
+ void PlaceBlock(cWorld * a_World, cPlayer * a_Player, NIBBLETYPE a_BlockMeta, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir)
+ {
+ a_BlockMeta = cDoors::RotationToMetaData(a_Player->GetRotation() + 270);
+ a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, a_BlockMeta);
+ OnPlacedByPlayer(a_World, a_Player, a_BlockX, a_BlockY, a_BlockZ, a_Dir);
+ }
+
+ void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ)
+ {
+ char OldMetaData = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
+ char NewMetaData = cDoors::RotationToMetaData(a_Player->GetRotation() + 270);
+ OldMetaData ^= 4; //Toggle the gate
+ if((OldMetaData & 1) == (NewMetaData & 1)){
+ //Standing in front of the gate - apply new direction
+ a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, (OldMetaData & 4) | (NewMetaData & 3));
+ }
+ else
+ {
+ //Standing aside - use last direction
+ a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, OldMetaData);
+ }
+ }
+
+ virtual bool IsUseable() override
+ {
+ return true;
+ }
+} ;
+
+
+
+
diff --git a/source/Blocks/BlockHandler.cpp b/source/Blocks/BlockHandler.cpp index 1572efa9e..13342117e 100644 --- a/source/Blocks/BlockHandler.cpp +++ b/source/Blocks/BlockHandler.cpp @@ -49,6 +49,7 @@ #include "BlockRail.h"
#include "BlockGlass.h"
#include "BlockEnderchest.h"
+#include "BlockFenceGate.h"
@@ -104,6 +105,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_EMERALD_ORE: return new cBlockOreHandler (a_BlockType);
case E_BLOCK_ENDER_CHEST: return new cBlockEnderchestHandler (a_BlockType);
case E_BLOCK_FARMLAND: return new cBlockFarmlandHandler;
+ case E_BLOCK_FENCE_GATE: return new cBlockFenceGateHandler (a_BlockType);
case E_BLOCK_FIRE: return new cBlockFireHandler (a_BlockType);
case E_BLOCK_FURNACE: return new cBlockFurnaceHandler (a_BlockType);
case E_BLOCK_GLOWSTONE: return new cBlockGlowstoneHandler (a_BlockType);
|