diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-10-01 23:08:15 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-10-01 23:08:15 +0200 |
commit | 85164fab8e5298ce1c0582b2aebb7e6a283d4a0c (patch) | |
tree | 6fdaf7f724044a025ecc9f1a8cadf8ee61d9355d /source | |
parent | Added some missing block enums (diff) | |
download | cuberite-85164fab8e5298ce1c0582b2aebb7e6a283d4a0c.tar cuberite-85164fab8e5298ce1c0582b2aebb7e6a283d4a0c.tar.gz cuberite-85164fab8e5298ce1c0582b2aebb7e6a283d4a0c.tar.bz2 cuberite-85164fab8e5298ce1c0582b2aebb7e6a283d4a0c.tar.lz cuberite-85164fab8e5298ce1c0582b2aebb7e6a283d4a0c.tar.xz cuberite-85164fab8e5298ce1c0582b2aebb7e6a283d4a0c.tar.zst cuberite-85164fab8e5298ce1c0582b2aebb7e6a283d4a0c.zip |
Diffstat (limited to 'source')
42 files changed, 856 insertions, 507 deletions
diff --git a/source/Blocks/BlockBed.h b/source/Blocks/BlockBed.h index b7b055aa8..0fe2a1e07 100644 --- a/source/Blocks/BlockBed.h +++ b/source/Blocks/BlockBed.h @@ -1,10 +1,17 @@ +
#pragma once
+
#include "BlockHandler.h"
#include "../World.h"
#include "../Sign.h"
#include "../Player.h"
-class cBlockBedHandler : public cBlockHandler
+
+
+
+
+class cBlockBedHandler :
+ public cBlockHandler
{
public:
cBlockBedHandler(BLOCKTYPE a_BlockID)
@@ -12,27 +19,26 @@ public: {
}
- virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override;
- virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override;
- virtual void OnUse(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) override;
+ virtual void PlaceBlock(cWorld * a_World, cPlayer * a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override;
+ virtual void OnDestroyed(cWorld * a_World, int a_X, int a_Y, int a_Z) override;
+ virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z) override;
- virtual bool IsUseable() override
+
+ virtual bool IsUseable(void) override
{
return true;
}
+
- virtual int GetDropID() override
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- return E_ITEM_BED;
+ // Reset meta to zero
+ a_Pickups.push_back(cItem(E_ITEM_BED, 1, 0));
}
- virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override
- {
- return 0;
- }
- virtual bool AllowBlockOnTop() override
+ virtual bool DoesAllowBlockOnTop() override
{
return false;
}
@@ -41,7 +47,7 @@ public: // Bed specific helper functions
- static NIBBLETYPE RotationToMetaData( float a_Rotation )
+ static NIBBLETYPE RotationToMetaData(float a_Rotation)
{
a_Rotation += 180 + (180/4); // So its not aligned with axis
if( a_Rotation > 360.f ) a_Rotation -= 360.f;
@@ -51,19 +57,24 @@ public: return ((char)a_Rotation+2) % 4;
}
- static Vector3i MetaDataToDirection( NIBBLETYPE a_MetaData )
+
+ static Vector3i MetaDataToDirection(NIBBLETYPE a_MetaData)
{
- switch( a_MetaData )
+ switch (a_MetaData)
{
- case 0: // south +z
- return Vector3i(0, 0, 1);
- case 1: // west -x
- return Vector3i(-1, 0, 0);
- case 2: // north -z
- return Vector3i(0, 0, -1);
- case 3: // east +x
- return Vector3i(1, 0, 0);
+ case 0: // south +z
+ return Vector3i(0, 0, 1);
+ case 1: // west -x
+ return Vector3i(-1, 0, 0);
+ case 2: // north -z
+ return Vector3i(0, 0, -1);
+ case 3: // east +x
+ return Vector3i(1, 0, 0);
};
return Vector3i();
}
-};
+} ;
+
+
+
+
diff --git a/source/Blocks/BlockCactus.h b/source/Blocks/BlockCactus.h index 964646299..6eec866be 100644 --- a/source/Blocks/BlockCactus.h +++ b/source/Blocks/BlockCactus.h @@ -1,5 +1,6 @@ #pragma once
+
#include "BlockHandler.h"
@@ -16,9 +17,10 @@ public: }
- virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- return 0;
+ // Reset meta to 0
+ a_Pickups.push_back(cItem(m_BlockID, 1, 0));
}
@@ -46,18 +48,17 @@ public: }
- virtual bool CanBePlacedOnSide() override
+ virtual bool CanBePlacedOnSide(void) override
{
return false;
}
- virtual AString GetStepSound(void) override
+ virtual const char * GetStepSound(void) override
{
return "step.cloth";
}
-
-};
+} ;
diff --git a/source/Blocks/BlockChest.h b/source/Blocks/BlockChest.h index db67fe1c8..ef00fce19 100644 --- a/source/Blocks/BlockChest.h +++ b/source/Blocks/BlockChest.h @@ -1,26 +1,38 @@ +
#pragma once
+
#include "BlockEntity.h"
#include "../World.h"
#include "../Piston.h"
#include "../Player.h"
-class cBlockChestHandler : public cBlockEntityHandler
+
+
+
+
+class cBlockChestHandler :
+ public cBlockEntityHandler
{
public:
cBlockChestHandler(BLOCKTYPE a_BlockID)
: cBlockEntityHandler(a_BlockID)
{
}
+
- virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override
+ virtual void PlaceBlock(cWorld * a_World, cPlayer * a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override
{
a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cPiston::RotationPitchToMetaData(a_Player->GetRotation(), 0));
OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir);
}
- virtual AString GetStepSound(void) override
+
+ virtual const char * GetStepSound(void) override
{
return "step.wood";
}
-
-};
+} ;
+
+
+
+
diff --git a/source/Blocks/BlockCloth.h b/source/Blocks/BlockCloth.h index 452ad2237..eb92b313a 100644 --- a/source/Blocks/BlockCloth.h +++ b/source/Blocks/BlockCloth.h @@ -1,8 +1,14 @@ +
#pragma once
+
#include "BlockHandler.h"
-class cBlockClothHandler : public cBlockHandler
+
+
+
+class cBlockClothHandler :
+ public cBlockHandler
{
public:
cBlockClothHandler(BLOCKTYPE a_BlockID)
@@ -10,14 +16,19 @@ public: {
}
- virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override
+
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- return a_BlockMeta;
+ a_Pickups.push_back(cItem(E_ITEM_WOOL, 1, a_BlockMeta));
}
- virtual AString GetStepSound(void) override
+
+ virtual const char * GetStepSound(void) override
{
return "step.cloth";
}
-
-};
+} ;
+
+
+
+
diff --git a/source/Blocks/BlockCrops.h b/source/Blocks/BlockCrops.h index b30139e79..d288a597f 100644 --- a/source/Blocks/BlockCrops.h +++ b/source/Blocks/BlockCrops.h @@ -11,54 +11,47 @@ public: {
}
- virtual bool NeedsRandomTicks() override
- {
- return true;
- }
- virtual bool AllowBlockOnTop() override
+ virtual bool DoesAllowBlockOnTop() override
{
return false;
}
- virtual int GetDropID() override
- {
- return E_ITEM_EMPTY;
- }
-
- virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override
+
+ virtual void OnDestroyed(cWorld * a_World, int a_X, int a_Y, int a_Z) override
{
MTRand rand;
NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z);
cItems Drops;
- if(Meta & 0x7) //Is Wheat
+ if (Meta & 0x7) // Is Wheat
{
Drops.push_back(cItem(E_ITEM_WHEAT, 1, 0));
}
- if(rand.randInt(3) == 0)
- { //Drop an second seed
- Drops.push_back(cItem(E_ITEM_SEEDS, 1, 0));
- }
- Drops.push_back(cItem(E_ITEM_SEEDS, 1, 0));
+ Drops.push_back(cItem(E_ITEM_SEEDS, (rand.randInt(3) == 0) ? 2 : 1, 0));
a_World->SpawnItemPickups(Drops, a_X, a_Y, a_Z);
}
- void OnUpdate(cWorld *a_World, int a_X, int a_Y, int a_Z) override
+
+ void OnUpdate(cWorld * a_World, int a_X, int a_Y, int a_Z) override
{
-
- //TODO: Handle Growing here
+ // TODO: Handle Growing here
}
- virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override
+
+ virtual bool CanBeAt(cWorld * a_World, int a_X, int a_Y, int a_Z) override
{
return a_World->GetBlock(a_X, a_Y - 1, a_Z) == E_BLOCK_FARMLAND;
}
- virtual AString GetStepSound(void) override
+
+ virtual const char * GetStepSound(void) override
{
return "step.grass";
}
-
-};
+} ;
+
+
+
+
diff --git a/source/Blocks/BlockDirt.h b/source/Blocks/BlockDirt.h index 5a2487f1b..346815846 100644 --- a/source/Blocks/BlockDirt.h +++ b/source/Blocks/BlockDirt.h @@ -1,9 +1,17 @@ +
#pragma once
+
#include "BlockHandler.h"
#include "../MersenneTwister.h"
#include "../World.h"
-class cBlockDirtHandler : public cBlockHandler
+
+
+
+
+/// Handler used for both dirt and grass
+class cBlockDirtHandler :
+ public cBlockHandler
{
public:
cBlockDirtHandler(BLOCKTYPE a_BlockID)
@@ -12,18 +20,13 @@ public: }
- virtual bool NeedsRandomTicks() override
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- return m_BlockID == E_BLOCK_GRASS;
- }
-
- virtual int GetDropID() override
- {
- return E_BLOCK_DIRT;
+ a_Pickups.push_back(cItem(E_ITEM_DIRT, 1, 0));
}
- void OnUpdate(cWorld *a_World, int a_X, int a_Y, int a_Z) override
+ void OnUpdate(cWorld * a_World, int a_X, int a_Y, int a_Z) override
{
if (m_BlockID != E_BLOCK_GRASS)
{
@@ -64,9 +67,13 @@ public: } // for i - repeat twice
}
- virtual AString GetStepSound(void) override
+
+ virtual const char * GetStepSound(void) override
{
return "step.gravel";
}
-
-};
+} ;
+
+
+
+
diff --git a/source/Blocks/BlockDoor.cpp b/source/Blocks/BlockDoor.cpp index deed8a256..da9b7d161 100644 --- a/source/Blocks/BlockDoor.cpp +++ b/source/Blocks/BlockDoor.cpp @@ -1,3 +1,4 @@ +
#include "Globals.h"
#include "BlockDoor.h"
#include "../Item.h"
@@ -6,17 +7,28 @@ #include "../Player.h"
+
+
+
cBlockDoorHandler::cBlockDoorHandler(BLOCKTYPE a_BlockID)
: cBlockHandler(a_BlockID)
{
}
-void cBlockDoorHandler::OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir)
+
+
+
+
+void cBlockDoorHandler::OnPlaced(cWorld * a_World, int a_X, int a_Y, int a_Z, int a_Dir)
{
}
-void cBlockDoorHandler::OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z)
+
+
+
+
+void cBlockDoorHandler::OnDestroyed(cWorld * a_World, int a_X, int a_Y, int a_Z)
{
char OldMeta = a_World->GetBlockMeta(a_X, a_Y, a_Z);
@@ -38,22 +50,29 @@ void cBlockDoorHandler::OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) }
}
-void cBlockDoorHandler::OnDigging(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z)
+
+
+
+
+void cBlockDoorHandler::OnDigging(cWorld * a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z)
{
cDoors::ChangeDoor(a_World, a_X, a_Y, a_Z);
}
-void cBlockDoorHandler::OnUse(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z)
+
+
+
+
+void cBlockDoorHandler::OnUse(cWorld * a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z)
{
cDoors::ChangeDoor(a_World, a_X, a_Y, a_Z);
}
-char cBlockDoorHandler::GetDropCount()
-{
- return 1;
-}
-void cBlockDoorHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir)
+
+
+
+void cBlockDoorHandler::PlaceBlock(cWorld * a_World, cPlayer * a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir)
{
if (a_World->GetBlock(a_X, a_Y + 1, a_Z) == E_BLOCK_AIR)
{
@@ -64,11 +83,15 @@ void cBlockDoorHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYP }
}
-AString cBlockDoorHandler::GetStepSound(void)
-{
- if (m_BlockID == E_BLOCK_WOODEN_DOOR)
- return "step.wood";
- else
- return "step.stone";
+
+
+
+const char * cBlockDoorHandler::GetStepSound(void)
+{
+ return (m_BlockID == E_BLOCK_WOODEN_DOOR) ? "step.wood" : "step.stone";
}
+
+
+
+
diff --git a/source/Blocks/BlockDoor.h b/source/Blocks/BlockDoor.h index 3316f50a4..4d9d2dd4d 100644 --- a/source/Blocks/BlockDoor.h +++ b/source/Blocks/BlockDoor.h @@ -1,17 +1,28 @@ +
#pragma once
+
#include "BlockHandler.h"
-class cBlockDoorHandler : public cBlockHandler
+
+
+
+class cBlockDoorHandler :
+ public cBlockHandler
{
public:
cBlockDoorHandler(BLOCKTYPE a_BlockID);
- virtual void OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir) override;
- virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override;
- virtual void OnDigging(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) override;
- virtual void OnUse(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) override;
- virtual AString GetStepSound(void) override;
- virtual char GetDropCount() override;
+ virtual void OnPlaced(cWorld * a_World, int a_X, int a_Y, int a_Z, int a_Dir) override;
+ virtual void OnDestroyed(cWorld * a_World, int a_X, int a_Y, int a_Z) override;
+ virtual void OnDigging(cWorld * a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z) override;
+ virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z) override;
+ virtual const char * GetStepSound(void) override;
+
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
+ {
+ a_Pickups.push_back(cItem((m_BlockID == E_BLOCK_WOODEN_DOOR) ? E_ITEM_WOODEN_DOOR : E_ITEM_IRON_DOOR, 1, 0));
+ }
+
virtual bool IsUseable() override
{
return true;
@@ -19,13 +30,12 @@ public: virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override;
- virtual int GetDropID() override
- {
- return (m_BlockID == E_BLOCK_WOODEN_DOOR) ? E_ITEM_WOODEN_DOOR : E_ITEM_IRON_DOOR;
- }
-
- virtual bool CanBePlacedOnSide() override
+ virtual bool CanBePlacedOnSide(void) override
{
return false;
}
-};
\ No newline at end of file +} ;
+
+
+
+
diff --git a/source/Blocks/BlockFire.h b/source/Blocks/BlockFire.h index 1fecf9a14..73a8a64b9 100644 --- a/source/Blocks/BlockFire.h +++ b/source/Blocks/BlockFire.h @@ -1,8 +1,14 @@ +
#pragma once
+
#include "BlockHandler.h"
-class cBlockFireHandler : public cBlockHandler
+
+
+
+class cBlockFireHandler :
+ public cBlockHandler
{
public:
cBlockFireHandler(BLOCKTYPE a_BlockID)
@@ -10,24 +16,27 @@ public: {
}
- virtual void OnDigging(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) override
+ virtual void OnDigging(cWorld * a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z) override
{
a_World->DigBlock(a_X, a_Y, a_Z);
}
- virtual char GetDropCount() override
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- return -1;
+ // No pickups from this block
}
- virtual bool IsClickedThrough() override
+ virtual bool IsClickedThrough(void) override
{
return true;
}
- virtual AString GetStepSound(void) override
+ virtual const char * GetStepSound(void) override
{
return "step.wood";
}
+} ;
+
+
+
-};
diff --git a/source/Blocks/BlockFlower.h b/source/Blocks/BlockFlower.h index 35a55fcac..4763d6911 100644 --- a/source/Blocks/BlockFlower.h +++ b/source/Blocks/BlockFlower.h @@ -1,8 +1,14 @@ +
#pragma once
+
#include "BlockHandler.h"
-class cBlockFlowerHandler : public cBlockHandler
+
+
+
+class cBlockFlowerHandler :
+ public cBlockHandler
{
public:
cBlockFlowerHandler(BLOCKTYPE a_BlockID)
@@ -10,29 +16,38 @@ public: {
}
- virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override
+
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- return 0;
+ // Reset meta to 0
+ a_Pickups.push_back(cItem(m_BlockID, 1, 0));
}
- virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override
+
+ virtual bool CanBeAt(cWorld * a_World, int a_X, int a_Y, int a_Z) override
{
return IsBlockTypeOfDirt(a_World->GetBlock(a_X, a_Y - 1, a_Z));
}
- virtual bool AllowBlockOnTop() override
+
+ virtual bool DoesAllowBlockOnTop(void) override
{
return false;
}
- virtual bool CanBePlacedOnSide() override
+
+ virtual bool CanBePlacedOnSide(void) override
{
return false;
}
- virtual AString GetStepSound(void) override
+
+ virtual const char * GetStepSound(void) override
{
return "step.grass";
}
+} ;
+
+
+
-};
diff --git a/source/Blocks/BlockFluid.h b/source/Blocks/BlockFluid.h index c5ac660b0..1fc1b9a14 100644 --- a/source/Blocks/BlockFluid.h +++ b/source/Blocks/BlockFluid.h @@ -1,8 +1,14 @@ +
#pragma once
+
#include "BlockHandler.h"
-class cBlockFluidHandler : public cBlockHandler
+
+
+
+class cBlockFluidHandler :
+ public cBlockHandler
{
public:
cBlockFluidHandler(BLOCKTYPE a_BlockID)
@@ -11,10 +17,15 @@ public: }
- virtual bool IgnoreBuildCollision() override
+
+ virtual bool DoesIgnoreBuildCollision(void) override
{
return true;
}
-
-};
\ No newline at end of file + // TODO: Implement proper fluid physics here
+} ;
+
+
+
+
diff --git a/source/Blocks/BlockFurnace.h b/source/Blocks/BlockFurnace.h index 4157b5049..ef78ba901 100644 --- a/source/Blocks/BlockFurnace.h +++ b/source/Blocks/BlockFurnace.h @@ -1,10 +1,17 @@ +
#pragma once
+
#include "BlockEntity.h"
#include "../World.h"
#include "../Piston.h"
#include "../Player.h"
-class cBlockFurnaceHandler : public cBlockEntityHandler
+
+
+
+
+class cBlockFurnaceHandler :
+ public cBlockEntityHandler
{
public:
cBlockFurnaceHandler(BLOCKTYPE a_BlockID)
@@ -12,16 +19,20 @@ public: {
}
- virtual int GetDropID() override
+
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- return E_ITEM_FURNACE;
+ a_Pickups.push_back(cItem(E_ITEM_FURNACE, 1, 0));
}
+
- virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override
+ virtual void PlaceBlock(cWorld * a_World, cPlayer * a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override
{
a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cPiston::RotationPitchToMetaData(a_Player->GetRotation(), 0));
OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir);
}
-
-
-};
\ No newline at end of file +} ;
+
+
+
+
diff --git a/source/Blocks/BlockGlowstone.h b/source/Blocks/BlockGlowstone.h index 0b906e2fe..a04b1a567 100644 --- a/source/Blocks/BlockGlowstone.h +++ b/source/Blocks/BlockGlowstone.h @@ -1,8 +1,14 @@ +
#pragma once
+
#include "BlockHandler.h"
-class cBlockGlowstoneHandler : public cBlockHandler
+
+
+
+class cBlockGlowstoneHandler :
+ public cBlockHandler
{
public:
cBlockGlowstoneHandler(BLOCKTYPE a_BlockID)
@@ -10,13 +16,15 @@ public: {
}
- virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override
- {
- return 0;
- }
- virtual int GetDropID() override
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- return E_ITEM_GLOWSTONE_DUST;
+ // Reset meta to 0
+ // TODO: More drops?
+ a_Pickups.push_back(cItem(E_ITEM_GLOWSTONE_DUST, 1, 0));
}
-};
\ No newline at end of file +} ;
+
+
+
+
diff --git a/source/Blocks/BlockGravel.h b/source/Blocks/BlockGravel.h index da47db9bb..432df5f0a 100644 --- a/source/Blocks/BlockGravel.h +++ b/source/Blocks/BlockGravel.h @@ -1,8 +1,14 @@ +
#pragma once
+
#include "BlockHandler.h"
-class cBlockGravelHandler : public cBlockHandler
+
+
+
+class cBlockGravelHandler :
+ public cBlockHandler
{
public:
cBlockGravelHandler(BLOCKTYPE a_BlockID)
@@ -10,9 +16,12 @@ public: {
}
- virtual AString GetStepSound(void) override
+ virtual const char * GetStepSound(void) override
{
return "step.gravel";
}
-
-};
+} ;
+
+
+
+
diff --git a/source/Blocks/BlockHandler.cpp b/source/Blocks/BlockHandler.cpp index 419b20de0..ae138db92 100644 --- a/source/Blocks/BlockHandler.cpp +++ b/source/Blocks/BlockHandler.cpp @@ -317,43 +317,24 @@ void cBlockHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_ -char cBlockHandler::GetDropCount()
+void cBlockHandler::ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta)
{
- return 1;
+ // Setting the meta to a_BlockMeta keeps most textures. The few other blocks have to override this.
+ a_Pickups.push_back(cItem(m_BlockID, 1, a_BlockMeta));
}
-int cBlockHandler::GetDropID()
+void cBlockHandler::DropBlock(cWorld * a_World, int a_X, int a_Y, int a_Z)
{
- return m_BlockID;
-}
-
-
-
-
-
-NIBBLETYPE cBlockHandler::GetDropMeta(NIBBLETYPE a_BlockMeta)
-{
- return a_BlockMeta; //This keeps most textures. The few other blocks have to override this
-}
-
-
-
-
-
-void cBlockHandler::DropBlock(cWorld *a_World, int a_X, int a_Y, int a_Z)
-{
- cItems Drops;
+ cItems Pickups;
NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z);
- char DropCount = GetDropCount();
- short DropItem = (short)GetDropID();
- if (DropCount > 0 && (DropItem != E_ITEM_EMPTY))
+ ConvertToPickups(Pickups, Meta);
+ if (!Pickups.empty())
{
- Drops.push_back(cItem(DropItem, DropCount, GetDropMeta(Meta)));
- a_World->SpawnItemPickups(Drops, a_X, a_Y, a_Z);
+ a_World->SpawnItemPickups(Pickups, a_X, a_Y, a_Z);
}
}
@@ -361,7 +342,8 @@ void cBlockHandler::DropBlock(cWorld *a_World, int a_X, int a_Y, int a_Z) -AString cBlockHandler::GetStepSound() {
+const char * cBlockHandler::GetStepSound()
+{
return "step.stone";
}
@@ -396,7 +378,7 @@ bool cBlockHandler::IsUseable() -bool cBlockHandler::IsClickedThrough()
+bool cBlockHandler::IsClickedThrough(void)
{
return false;
}
@@ -405,25 +387,16 @@ bool cBlockHandler::IsClickedThrough() -bool cBlockHandler::IgnoreBuildCollision()
+bool cBlockHandler::DoesIgnoreBuildCollision(void)
{
- return m_BlockID == E_BLOCK_AIR;
-}
-
-
-
-
-
-bool cBlockHandler::NeedsRandomTicks()
-{
- return false;
+ return (m_BlockID == E_BLOCK_AIR);
}
-bool cBlockHandler::AllowBlockOnTop()
+bool cBlockHandler::DoesAllowBlockOnTop(void)
{
return true;
}
@@ -432,7 +405,7 @@ bool cBlockHandler::AllowBlockOnTop() -bool cBlockHandler::CanBePlacedOnSide()
+bool cBlockHandler::CanBePlacedOnSide(void)
{
return true;
}
@@ -441,7 +414,7 @@ bool cBlockHandler::CanBePlacedOnSide() -bool cBlockHandler::DropOnUnsuitable()
+bool cBlockHandler::DoesDropOnUnsuitable(void)
{
return true;
}
diff --git a/source/Blocks/BlockHandler.h b/source/Blocks/BlockHandler.h index 859870c4a..4ac7b2338 100644 --- a/source/Blocks/BlockHandler.h +++ b/source/Blocks/BlockHandler.h @@ -1,11 +1,21 @@ +
#pragma once
+
#include "../Defines.h"
+#include "../Item.h"
+
+
+
+
+// fwd:
class cWorld;
class cPlayer;
+
+
class cBlockHandler
{
public:
@@ -14,68 +24,78 @@ public: // Called when the block gets ticked either by a random tick or by a queued tick
virtual void OnUpdate(cWorld *a_World, int a_X, int a_Y, int a_Z);
- // Will be called by cBlockHandler::PlaceBlock after the player has placed a new block
- virtual void OnPlacedByPlayer(cWorld *a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z, int a_Dir);
- // Will be called before the player has destroyed a block
- virtual void OnDestroyedByPlayer(cWorld *a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z);
- // Will be called when a new block was placed. Will be called before OnPlacedByPlayer
- virtual void OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir);
- // Will be called before a block gets destroyed / replaced with air
- virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z);
- // Will be called when a direct neighbor of this block has been changed (The position is the own position, not the neighbor position)
- virtual void OnNeighborChanged(cWorld *a_World, int a_X, int a_Y, int a_Z);
- // Notifies all neighbors of the give block about a change
- static void NeighborChanged(cWorld *a_World, int a_X, int a_Y, int a_Z);
- // Will be called while the player diggs the block.
- virtual void OnDigging(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z);
- // Will be called if the user right clicks the block and the block is useable
- virtual void OnUse(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z);
- // This function handles the real block placement for the give block by a player and also calls the OnPlacedByPlayer function
- virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir);
-
- // Indicates how much items are dropped DEFAULT: 1
- virtual char GetDropCount();
- // Indicates the id dropped by this block DEFAULT: BlockID
- virtual int GetDropID();
- // Indicates the Drop Meta data based on the block meta DEFAULT: BlockMeta
- virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta);
- // This function handles the dropping of a block based on the Drop id, drop count and drop meta. This will not destroy the block
- virtual void DropBlock(cWorld *a_World, int a_X, int a_Y, int a_Z);
- /// Returns step sound name of block
- virtual AString GetStepSound();
+ /// Called by cBlockHandler::PlaceBlock after the player has placed a new block
+ virtual void OnPlacedByPlayer(cWorld * a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z, int a_Dir);
+
+ /// Called before the player has destroyed a block
+ virtual void OnDestroyedByPlayer(cWorld * a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z);
+
+ /// Called when a new block was placed. Called before OnPlacedByPlayer
+ virtual void OnPlaced(cWorld * a_World, int a_X, int a_Y, int a_Z, int a_Dir);
+
+ /// Called before a block gets destroyed / replaced with air
+ virtual void OnDestroyed(cWorld * a_World, int a_X, int a_Y, int a_Z);
+
+ /// Called when a direct neighbor of this block has been changed (The position is the own position, not the neighbor position)
+ virtual void OnNeighborChanged(cWorld * a_World, int a_X, int a_Y, int a_Z);
+
+ /// Notifies all neighbors of the given block about a change
+ static void NeighborChanged(cWorld * a_World, int a_X, int a_Y, int a_Z);
+
+ /// Called while the player diggs the block.
+ virtual void OnDigging(cWorld * a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z);
- // Indicates whether this block needs random ticks DEFAULT: False
- virtual bool NeedsRandomTicks();
+ /// Called if the user right clicks the block and the block is useable
+ virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z);
+
+ /// This function handles the real block placement for the give block by a player and also calls OnPlacedByPlayer()
+ virtual void PlaceBlock(cWorld * a_World, cPlayer * a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir);
+
+ /// Called when the item is mined to convert it into pickups. Pickups may specify multiple items.
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta);
+
+ /// Handles the dropping of a block based on what ConvertToDrops() returns. This will not destroy the block
+ virtual void DropBlock(cWorld * a_World, int a_X, int a_Y, int a_Z);
+
+ /// Returns step sound name of block
+ virtual const char * GetStepSound(void);
/// Checks if the block can stay at the specified coords in the world
- virtual bool CanBeAt(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ);
+ virtual bool CanBeAt(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ);
- /// Checks if the block can be placed at this point. Default: CanBeAt(...) NOTE: This call doesn't actually place the block
+ /** Checks if the block can be placed at this point.
+ Default: CanBeAt(...)
+ NOTE: This call doesn't actually place the block
+ */
virtual bool CanBePlacedAt(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir);
/// Called when the player tries to place a block on top of this block (Only if he aims directly on this block); return false to disallow
- virtual bool AllowBlockOnTop(void);
+ virtual bool DoesAllowBlockOnTop(void);
/// Called to check whether this block supports a rclk action. If it returns true, OnUse() is called
virtual bool IsUseable(void);
- // Indicates whether the client will click through this block. For example digging a fire will hit the block below the fire so fire is clicked through
+ /** Indicates whether the client will click through this block.
+ For example digging a fire will hit the block below the fire so fire is clicked through
+ */
virtual bool IsClickedThrough(void);
- // Checks if the player can build "inside" this block. For example blocks placed "on" snow will be placed at the same position. So: Snow ignores Build collision
- virtual bool IgnoreBuildCollision(void);
+ /** Checks if the player can build "inside" this block.
+ For example blocks placed "on" snow will be placed at the same position. So: Snow ignores Build collision
+ */
+ virtual bool DoesIgnoreBuildCollision(void);
/// Indicates this block can be placed on the side of other blocks. Default: true
- virtual bool CanBePlacedOnSide();
+ virtual bool CanBePlacedOnSide(void);
/// Does this block drop if it gets destroyed by an unsuitable situation? Default: true
- virtual bool DropOnUnsuitable();
+ virtual bool DoesDropOnUnsuitable(void);
- // Static function to get the blockhandler for an specific block id
+ /// Get the blockhandler for a specific block id
static cBlockHandler * GetBlockHandler(BLOCKTYPE a_BlockID);
- // Deletes all initialised block handlers
+ /// Deletes all initialised block handlers
static void Deinit();
protected:
@@ -86,5 +106,16 @@ protected: static bool m_HandlerInitialized; //used to detect if the blockhandlers are initialized
};
+
+
+
+
// Shortcut to get the blockhandler for a specific block
-inline cBlockHandler *BlockHandler(BLOCKTYPE a_BlockID) { return cBlockHandler::GetBlockHandler(a_BlockID); }
\ No newline at end of file +inline cBlockHandler *BlockHandler(BLOCKTYPE a_BlockID)
+{
+ return cBlockHandler::GetBlockHandler(a_BlockID);
+}
+
+
+
+
diff --git a/source/Blocks/BlockIce.h b/source/Blocks/BlockIce.h index cc5cc8920..31a92db53 100644 --- a/source/Blocks/BlockIce.h +++ b/source/Blocks/BlockIce.h @@ -1,9 +1,15 @@ +
#pragma once
+
#include "BlockHandler.h"
-#include "../MersenneTwister.h"
#include "../World.h"
-class cBlockIceHandler : public cBlockHandler
+
+
+
+
+class cBlockIceHandler :
+ public cBlockHandler
{
public:
cBlockIceHandler(BLOCKTYPE a_BlockID)
@@ -11,16 +17,21 @@ public: {
}
- virtual int GetDropID() override
+
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- return E_ITEM_EMPTY;
+ // No pickups
}
- virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override
+
+ virtual void OnDestroyed(cWorld * a_World, int a_X, int a_Y, int a_Z) override
{
+ // TODO: Ice destroyed with air below it should turn into air instead of water
a_World->FastSetBlock(a_X, a_Y, a_Z, E_BLOCK_STATIONARY_WATER, 8);
- //This is called later than the real destroying of this ice block
+ // This is called later than the real destroying of this ice block
}
-
-
-};
\ No newline at end of file +} ;
+
+
+
+
diff --git a/source/Blocks/BlockLadder.h b/source/Blocks/BlockLadder.h index ee48df848..a783b7074 100644 --- a/source/Blocks/BlockLadder.h +++ b/source/Blocks/BlockLadder.h @@ -1,40 +1,51 @@ +
#pragma once
+
#include "BlockHandler.h"
#include "../World.h"
#include "../Ladder.h"
-class cBlockLadderHandler : public cBlockHandler
+
+
+
+
+class cBlockLadderHandler :
+ public cBlockHandler
{
public:
cBlockLadderHandler(BLOCKTYPE a_BlockID)
: cBlockHandler(a_BlockID)
{
-
}
- virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override
+
+ virtual void PlaceBlock(cWorld * a_World, cPlayer * a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override
{
a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cLadder::DirectionToMetaData(a_Dir));
OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir);
}
- virtual bool CanBePlacedAt(cWorld *a_World, int a_X, int a_Y, int a_Z, char a_Dir) override
+
+ virtual bool CanBePlacedAt(cWorld * a_World, int a_X, int a_Y, int a_Z, char a_Dir) override
{
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
+ 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);
}
- virtual AString GetStepSound(void) override
+ virtual const char * GetStepSound(void) override
{
return "step.wood";
}
-
-};
+} ;
+
+
+
+
diff --git a/source/Blocks/BlockLeaves.h b/source/Blocks/BlockLeaves.h index 65c47f8de..e8e1d0f46 100644 --- a/source/Blocks/BlockLeaves.h +++ b/source/Blocks/BlockLeaves.h @@ -6,6 +6,8 @@ +
+
// Leaves can be this many blocks that away (inclusive) from the log not to decay
#define LEAVES_CHECK_DISTANCE 6
@@ -20,7 +22,10 @@ bool HasNearLog(cBlockArea &a_Area, int a_BlockX, int a_BlockY, int a_BlockZ); -class cBlockLeavesHandler : public cBlockHandler
+
+
+class cBlockLeavesHandler :
+ public cBlockHandler
{
public:
cBlockLeavesHandler(BLOCKTYPE a_BlockID)
@@ -28,19 +33,27 @@ public: {
}
- virtual int GetDropID() override
+
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
MTRand rand;
- if(rand.randInt(5) == 0)
+ // Only the first 2 bits contain the display information, the others are for growing
+ if (rand.randInt(5) == 0)
{
- return E_ITEM_SAPLING;
+ a_Pickups.push_back(cItem(E_ITEM_SAPLING, 1, a_BlockMeta & 3));
+ }
+ if ((a_BlockMeta & 3) == E_META_SAPLING_APPLE)
+ {
+ if (rand.rand(100) == 0)
+ {
+ a_Pickups.push_back(cItem(E_ITEM_RED_APPLE, 1, 0));
+ }
}
-
- return E_ITEM_EMPTY;
}
- void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override
+
+ void OnDestroyed(cWorld * a_World, int a_X, int a_Y, int a_Z) override
{
cBlockHandler::OnDestroyed(a_World, a_X, a_Y, a_Z);
@@ -56,18 +69,15 @@ public: }
}
- virtual void OnNeighborChanged(cWorld *a_World, int a_X, int a_Y, int a_Z) override
+
+ virtual void OnNeighborChanged(cWorld * a_World, int a_X, int a_Y, int a_Z) override
{
NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z);
- a_World->SetBlockMeta(a_X, a_Y, a_Z, Meta & 0x7); //Unset 0x8 bit so it gets checked for decay
+ a_World->SetBlockMeta(a_X, a_Y, a_Z, Meta & 0x7); // Unset 0x8 bit so it gets checked for decay
}
- virtual bool NeedsRandomTicks() override
- {
- return true;
- }
- virtual void OnUpdate(cWorld *a_World, int a_X, int a_Y, int a_Z) override
+ virtual void OnUpdate(cWorld * a_World, int a_X, int a_Y, int a_Z) override
{
NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z);
if ((Meta & 0x04) != 0)
@@ -76,7 +86,7 @@ public: return;
}
- if (Meta & 0x8)
+ if ((Meta & 0x8) != 0)
{
// These leaves have been checked for decay lately and nothing around them changed
return;
@@ -109,14 +119,18 @@ public: }
- virtual AString GetStepSound(void) override
+
+ virtual const char * GetStepSound(void) override
{
return "step.grass";
}
-};
+} ;
+
-bool HasNearLog(cBlockArea &a_Area, int a_BlockX, int a_BlockY, int a_BlockZ)
+
+
+bool HasNearLog(cBlockArea & a_Area, int a_BlockX, int a_BlockY, int a_BlockZ)
{
// Filter the blocks into a {leaves, log, other (air)} set:
BLOCKTYPE * Types = a_Area.GetBlockTypes();
@@ -165,3 +179,6 @@ bool HasNearLog(cBlockArea &a_Area, int a_BlockX, int a_BlockY, int a_BlockZ) return false;
}
+
+
+
diff --git a/source/Blocks/BlockMelon.h b/source/Blocks/BlockMelon.h index 87fb7e1e8..62c1e2dd8 100644 --- a/source/Blocks/BlockMelon.h +++ b/source/Blocks/BlockMelon.h @@ -1,8 +1,14 @@ +
#pragma once
+
#include "BlockHandler.h"
-class cBlockMelonHandler : public cBlockHandler
+
+
+
+class cBlockMelonHandler :
+ public cBlockHandler
{
public:
cBlockMelonHandler(BLOCKTYPE a_BlockID)
@@ -11,19 +17,19 @@ public: }
- virtual int GetDropID() override
- {
- return E_ITEM_MELON_SLICE;
- }
-
- virtual char GetDropCount() override
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
MTRand r1;
- return (char)(3 + r1.randInt(4));
+ a_Pickups.push_back(cItem(E_ITEM_MELON_SLICE, (char)(3 + r1.randInt(4)), 0));
}
- virtual AString GetStepSound(void) override
+
+ virtual const char * GetStepSound(void) override
{
return "step.wood";
}
-};
+} ;
+
+
+
+
diff --git a/source/Blocks/BlockMushroom.h b/source/Blocks/BlockMushroom.h index c4119bad0..a74eacbc3 100644 --- a/source/Blocks/BlockMushroom.h +++ b/source/Blocks/BlockMushroom.h @@ -1,8 +1,14 @@ +
#pragma once
+
#include "BlockHandler.h"
-class cBlockMushroomHandler : public cBlockHandler
+
+
+
+class cBlockMushroomHandler :
+ public cBlockHandler
{
public:
cBlockMushroomHandler(BLOCKTYPE a_BlockID)
@@ -10,12 +16,15 @@ public: {
}
- virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override
+
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- return 0;
+ // Reset meta to 0
+ a_Pickups.push_back(cItem(m_BlockID, 1, 0));
}
- virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override
+
+ virtual bool CanBeAt(cWorld * a_World, int a_X, int a_Y, int a_Z) override
{
switch (a_World->GetBlock(a_X, a_Y - 1, a_Z))
{
@@ -24,24 +33,32 @@ public: case E_BLOCK_ICE:
case E_BLOCK_LEAVES:
case E_BLOCK_AIR:
+ {
return false;
+ }
}
return true;
}
- virtual bool AllowBlockOnTop() override
+
+ virtual bool DoesAllowBlockOnTop(void) override
{
return false;
}
- virtual bool CanBePlacedOnSide() override
+ virtual bool CanBePlacedOnSide(void) override
{
return false;
}
+
- virtual AString GetStepSound(void) override
+ virtual const char * GetStepSound(void) override
{
return "step.grass";
}
-};
+} ;
+
+
+
+
diff --git a/source/Blocks/BlockOre.h b/source/Blocks/BlockOre.h index 556a215ce..86688b761 100644 --- a/source/Blocks/BlockOre.h +++ b/source/Blocks/BlockOre.h @@ -1,9 +1,16 @@ +
#pragma once
+
#include "BlockHandler.h"
#include "../MersenneTwister.h"
#include "../World.h"
-class cBlockOreHandler : public cBlockHandler
+
+
+
+
+class cBlockOreHandler :
+ public cBlockHandler
{
public:
cBlockOreHandler(BLOCKTYPE a_BlockID)
@@ -11,48 +18,63 @@ public: {
}
- virtual char GetDropCount() override
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
+ short ItemType = E_ITEM_EMPTY;
+ char Count = 1;
+ short Meta = 0;
+
MTRand r1;
- switch(m_BlockID)
+ 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;
+ case E_BLOCK_LAPIS_ORE:
+ {
+ ItemType = E_ITEM_DYE;
+ Count = 4 + (char)r1.randInt(4);
+ Meta = 4;
+ break;
+ }
+ case E_BLOCK_REDSTONE_ORE:
+ case E_BLOCK_REDSTONE_ORE_GLOWING:
+ {
+ Count = 4 + (char)r1.randInt(1);
+ break;
+ }
+ default:
+ {
+ Count = 1;
+ break;
+ }
}
- }
- virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_Meta) override
- {
- switch(m_BlockID)
+ switch (m_BlockID)
{
- case E_BLOCK_LAPIS_ORE:
- return 4;
- default:
- return 0;
+ case E_BLOCK_DIAMOND_ORE:
+ {
+ ItemType = E_ITEM_DIAMOND;
+ break;
+ }
+ case E_BLOCK_REDSTONE_ORE:
+ case E_BLOCK_REDSTONE_ORE_GLOWING:
+ {
+ ItemType = E_ITEM_REDSTONE_DUST;
+ break;
+ }
+ case E_BLOCK_EMERALD_ORE:
+ {
+ ItemType = E_ITEM_EMERALD;
+ break;
+ }
+ case E_BLOCK_COAL_ORE:
+ {
+ ItemType = E_ITEM_COAL;
+ break;
+ }
}
+ a_Pickups.push_back(cItem(ItemType, Count, Meta));
}
+} ;
+
+
+
- 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/BlockRedstone.h b/source/Blocks/BlockRedstone.h index 9b83b1b29..fa9aeef01 100644 --- a/source/Blocks/BlockRedstone.h +++ b/source/Blocks/BlockRedstone.h @@ -1,32 +1,40 @@ +
#pragma once
+
#include "BlockHandler.h"
#include "../World.h"
-class cBlockRedstoneHandler : public cBlockHandler
+
+
+
+
+class cBlockRedstoneHandler :
+ public cBlockHandler
{
public:
cBlockRedstoneHandler(BLOCKTYPE a_BlockID);
- virtual void OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir) override;
- virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override;
+ virtual void OnPlaced(cWorld * a_World, int a_X, int a_Y, int a_Z, int a_Dir) override;
+ virtual void OnDestroyed(cWorld * a_World, int a_X, int a_Y, int a_Z) override;
- virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override;
+ virtual void PlaceBlock(cWorld * a_World, cPlayer * a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override;
- virtual bool AllowBlockOnTop() override
+ virtual bool DoesAllowBlockOnTop(void) override
{
return false;
}
- virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override
+ virtual bool CanBeAt(cWorld * a_World, int a_X, int a_Y, int a_Z) override
{
return a_World->GetBlock(a_X, a_Y - 1, a_Z) != E_BLOCK_AIR;
}
- virtual int GetDropID() override
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- return E_ITEM_REDSTONE_DUST;
+ // Reset meta to 0
+ a_Pickups.push_back(cItem(E_ITEM_REDSTONE_DUST, 1));
}
- virtual bool CanBePlacedOnSide() override
+ virtual bool CanBePlacedOnSide(void) override
{
return false;
}
diff --git a/source/Blocks/BlockRedstoneRepeater.h b/source/Blocks/BlockRedstoneRepeater.h index a928f554f..dda3d31a7 100644 --- a/source/Blocks/BlockRedstoneRepeater.h +++ b/source/Blocks/BlockRedstoneRepeater.h @@ -1,52 +1,64 @@ +
#pragma once
+
#include "BlockHandler.h"
#include "../World.h"
-class cBlockRedstoneRepeaterHandler : public cBlockHandler
+
+
+
+
+class cBlockRedstoneRepeaterHandler :
+ public cBlockHandler
{
public:
cBlockRedstoneRepeaterHandler(BLOCKTYPE a_BlockID);
- virtual void OnPlaced(cWorld *a_World, int a_X, int a_Y, int a_Z, int a_Dir) override;
- virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override;
+ virtual void OnPlaced(cWorld * a_World, int a_X, int a_Y, int a_Z, int a_Dir) override;
+ virtual void OnDestroyed(cWorld * a_World, int a_X, int a_Y, int a_Z) override;
- virtual void OnDigging(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) override;
- virtual void OnUse(cWorld *a_World, cPlayer *a_Player, int a_X, int a_Y, int a_Z) override;
+ virtual void OnDigging(cWorld * a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z) override;
+ virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z) override;
- virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override
- {
- return 0;
- }
- virtual int GetDropID() override
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- return E_ITEM_REDSTONE_REPEATER;
+ // Reset meta to 0
+ a_Pickups.push_back(cItem(E_ITEM_REDSTONE_REPEATER, 1, 0));
}
- virtual bool IsUseable() override
+
+ virtual bool IsUseable(void) override
{
return true;
}
- virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override;
+
+ virtual void PlaceBlock(cWorld * a_World, cPlayer * a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override;
- virtual bool AllowBlockOnTop() override
+
+ virtual bool DoesAllowBlockOnTop(void) override
{
return false;
}
- virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override
+
+ virtual bool CanBeAt(cWorld * a_World, int a_X, int a_Y, int a_Z) override
{
return a_World->GetBlock(a_X, a_Y - 1, a_Z) != E_BLOCK_AIR;
}
- virtual bool CanBePlacedOnSide() override
+ virtual bool CanBePlacedOnSide(void) override
{
return false;
}
- virtual AString GetStepSound(void) override
+ virtual const char * GetStepSound(void) override
{
return "step.wood";
}
-};
+} ;
+
+
+
+
diff --git a/source/Blocks/BlockRedstoneTorch.h b/source/Blocks/BlockRedstoneTorch.h index eeb2afc5c..857c61761 100644 --- a/source/Blocks/BlockRedstoneTorch.h +++ b/source/Blocks/BlockRedstoneTorch.h @@ -1,5 +1,6 @@ #pragma once
+
#include "BlockRedstone.h"
#include "BlockTorch.h"
#include "../Torch.h"
@@ -8,7 +9,8 @@ -class cBlockRedstoneTorchHandler : public cBlockTorchHandler
+class cBlockRedstoneTorchHandler :
+ public cBlockTorchHandler
{
public:
cBlockRedstoneTorchHandler(BLOCKTYPE a_BlockID)
@@ -16,13 +18,20 @@ public: {
}
- virtual int GetDropID(void) override
+
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- return E_ITEM_REDSTONE_TORCH_ON;
+ // Always drop the ON torch, meta 0
+ a_Pickups.push_back(cItem(E_ITEM_REDSTONE_TORCH_ON, 1, 0));
}
- virtual AString GetStepSound(void) override
+
+ virtual const char * GetStepSound(void) override
{
return "step.wood";
}
-};
+} ;
+
+
+
+
diff --git a/source/Blocks/BlockSand.h b/source/Blocks/BlockSand.h index 69fda5ec6..0cd4064ae 100644 --- a/source/Blocks/BlockSand.h +++ b/source/Blocks/BlockSand.h @@ -1,8 +1,14 @@ +
#pragma once
+
#include "BlockHandler.h"
-class cBlockSandHandler : public cBlockHandler
+
+
+
+class cBlockSandHandler :
+ public cBlockHandler
{
public:
cBlockSandHandler(BLOCKTYPE a_BlockID)
@@ -10,9 +16,13 @@ public: {
}
- virtual AString GetStepSound(void) override
+ virtual const char * GetStepSound(void) override
{
return "step.sand";
}
};
+
+
+
+
diff --git a/source/Blocks/BlockSapling.h b/source/Blocks/BlockSapling.h index c9862349a..0c133568e 100644 --- a/source/Blocks/BlockSapling.h +++ b/source/Blocks/BlockSapling.h @@ -1,8 +1,15 @@ +
#pragma once
+
#include "BlockHandler.h"
#include "../World.h"
-class cBlockSaplingHandler : public cBlockHandler
+
+
+
+
+class cBlockSaplingHandler :
+ public cBlockHandler
{
public:
cBlockSaplingHandler(BLOCKTYPE a_BlockID)
@@ -10,27 +17,27 @@ public: {
}
- virtual bool NeedsRandomTicks() override
- {
- return true;
- }
- virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- return a_BlockMeta & 3; //Only the first 2 bits contain the display information the others are for growing
+ // Only the first 2 bits contain the display information, the others are for growing
+ a_Pickups.push_back(cItem(E_ITEM_SAPLING, 1, a_BlockMeta & 3));
}
+
virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override
{
return IsBlockTypeOfDirt(a_World->GetBlock(a_X, a_Y - 1, a_Z));
}
- virtual bool AllowBlockOnTop() override
+
+ virtual bool DoesAllowBlockOnTop(void) override
{
return false;
}
+
- void OnUpdate(cWorld *a_World, int a_X, int a_Y, int a_Z) override
+ void OnUpdate(cWorld * a_World, int a_X, int a_Y, int a_Z) override
{
NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z);
@@ -44,13 +51,19 @@ public: }
}
+
virtual bool CanBePlacedOnSide() override
{
return false;
}
- virtual AString GetStepSound(void) override
+
+ virtual const char * GetStepSound(void) override
{
return "step.grass";
}
-};
+} ;
+
+
+
+
diff --git a/source/Blocks/BlockSign.h b/source/Blocks/BlockSign.h index dd82605b3..9c6bf3ec6 100644 --- a/source/Blocks/BlockSign.h +++ b/source/Blocks/BlockSign.h @@ -1,27 +1,36 @@ +
#pragma once
+
#include "BlockHandler.h"
#include "../World.h"
#include "../Sign.h"
#include "../Player.h"
-class cBlockSignHandler : public cBlockHandler
+
+
+
+
+class cBlockSignHandler :
+ public cBlockHandler
{
public:
cBlockSignHandler(BLOCKTYPE a_BlockID)
: cBlockHandler(a_BlockID)
{
-
}
+
- virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override
+ virtual void PlaceBlock(cWorld * a_World, cPlayer * a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override
{
BLOCKTYPE Block;
NIBBLETYPE Meta;
- if(a_Dir == 1)
+ if (a_Dir == BLOCK_FACE_TOP)
{
Meta = cSign::RotationToMetaData(a_Player->GetRotation());
Block = E_BLOCK_SIGN_POST;
- }else{
+ }
+ else
+ {
Meta = cSign::DirectionToMetaData(a_Dir);
Block = E_BLOCK_WALLSIGN;
}
@@ -30,18 +39,25 @@ public: OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir);
}
- virtual int GetDropID() override
+
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- return E_ITEM_SIGN;
+ a_Pickups.push_back(cItem(E_ITEM_SIGN, 1, 0));
}
+
- virtual bool AllowBlockOnTop() override
+ virtual bool DoesAllowBlockOnTop(void) override
{
return false;
}
+
- virtual AString GetStepSound(void) override
+ virtual const char * GetStepSound(void) override
{
return "step.wood";
}
-};
+} ;
+
+
+
+
diff --git a/source/Blocks/BlockSlab.h b/source/Blocks/BlockSlab.h index ad9970d67..2e9a6faf4 100644 --- a/source/Blocks/BlockSlab.h +++ b/source/Blocks/BlockSlab.h @@ -1,8 +1,14 @@ +
#pragma once
+
#include "BlockHandler.h"
-class cBlockSlabHandler : public cBlockHandler
+
+
+
+class cBlockSlabHandler :
+ public cBlockHandler
{
public:
cBlockSlabHandler(BLOCKTYPE a_BlockID)
@@ -10,17 +16,11 @@ public: {
}
- virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override
- {
- return a_BlockMeta;
- }
-
- virtual char GetDropCount() override
+
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- if(m_BlockID == E_BLOCK_DOUBLE_STONE_SLAB
- || m_BlockID == E_BLOCK_DOUBLE_WOODEN_SLAB)
- return 2;
- return 1;
+ char Count = ((m_BlockID == E_BLOCK_DOUBLE_STONE_SLAB) || (m_BlockID == E_BLOCK_DOUBLE_WOODEN_SLAB)) ? 2 : 1;
+ a_Pickups.push_back(cItem(m_BlockID, Count, a_BlockMeta));
}
@@ -30,6 +30,7 @@ public: OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir);
}
+
static char DirectionToMetaData( char a_Direction, NIBBLETYPE Meta )
{
char result = Meta;
@@ -40,12 +41,13 @@ public: return result;
}
- virtual AString GetStepSound(void) override
- {
- if (m_BlockID == E_BLOCK_WOODEN_SLAB || m_BlockID ==E_BLOCK_DOUBLE_WOODEN_SLAB)
- return "step.wood";
- else
- return "step.stone";
+ virtual const char * GetStepSound(void) override
+ {
+ return ((m_BlockID == E_BLOCK_WOODEN_SLAB) || (m_BlockID == E_BLOCK_DOUBLE_WOODEN_SLAB)) ? "step.wood" : "step.stone";
}
-};
+} ;
+
+
+
+
diff --git a/source/Blocks/BlockSnow.h b/source/Blocks/BlockSnow.h index c8e6b4c1c..9a1a4170c 100644 --- a/source/Blocks/BlockSnow.h +++ b/source/Blocks/BlockSnow.h @@ -1,8 +1,14 @@ +
#pragma once
+
#include "BlockHandler.h"
-class cBlockSnowHandler : public cBlockHandler
+
+
+
+class cBlockSnowHandler :
+ public cBlockHandler
{
public:
cBlockSnowHandler(BLOCKTYPE a_BlockID)
@@ -10,35 +16,37 @@ public: {
}
- virtual bool IgnoreBuildCollision() override
+
+ virtual bool DoesIgnoreBuildCollision(void) override
{
return true;
}
+
- virtual int GetDropID() override
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- return E_ITEM_SNOWBALL;
+ a_Pickups.push_back(cItem(E_ITEM_SNOWBALL, 4, 0));
}
- virtual char GetDropCount() override
- {
- return 4;
- }
-
- virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override
+ virtual bool CanBeAt(cWorld * a_World, int a_X, int a_Y, int a_Z) override
{
- return a_World->GetBlock(a_X, a_Y - 1, a_Z) != E_BLOCK_AIR;
+ return (a_World->GetBlock(a_X, a_Y - 1, a_Z) != E_BLOCK_AIR);
}
- virtual bool DropOnUnsuitable() override
+
+ virtual bool DoesDropOnUnsuitable(void) override
{
return false;
}
+
- virtual AString GetStepSound(void) override
+ virtual const char * GetStepSound(void) override
{
return "step.cloth";
}
-
-};
+} ;
+
+
+
+
diff --git a/source/Blocks/BlockStems.h b/source/Blocks/BlockStems.h index be4519a52..468a6f212 100644 --- a/source/Blocks/BlockStems.h +++ b/source/Blocks/BlockStems.h @@ -1,9 +1,16 @@ +
#pragma once
+
#include "BlockHandler.h"
#include "../MersenneTwister.h"
#include "../World.h"
-class cBlockStemsHandler : public cBlockHandler
+
+
+
+
+class cBlockStemsHandler :
+ public cBlockHandler
{
public:
cBlockStemsHandler(BLOCKTYPE a_BlockID)
@@ -11,36 +18,31 @@ public: {
}
- virtual bool NeedsRandomTicks() override
- {
- return true;
- }
-
- virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- return 0;
+ int ItemType = (m_BlockID == E_BLOCK_MELON_STEM) ? E_ITEM_MELON_SEEDS : E_ITEM_PUMPKIN_SEEDS;
+ a_Pickups.push_back(cItem(ItemType, 1, 0));
}
- virtual int GetDropID() override
- {
- if(m_BlockID == E_BLOCK_MELON_STEM)
- return E_ITEM_MELON_SEEDS;
- return E_ITEM_PUMPKIN_SEEDS;
- }
- void OnUpdate(cWorld *a_World, int a_X, int a_Y, int a_Z) override
+ void OnUpdate(cWorld * a_World, int a_X, int a_Y, int a_Z) override
{
- //TODO: Handle Growing here
+ // TODO: Handle Growing here
}
- virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override
+
+ virtual bool CanBeAt(cWorld * a_World, int a_X, int a_Y, int a_Z) override
{
return a_World->GetBlock(a_X, a_Y - 1, a_Z) == E_BLOCK_FARMLAND;
}
- virtual AString GetStepSound(void) override
+
+ virtual const char * GetStepSound(void) override
{
return "step.wood";
}
-
-};
+} ;
+
+
+
+
diff --git a/source/Blocks/BlockStone.h b/source/Blocks/BlockStone.h index 8b645bf1e..c4faf2498 100644 --- a/source/Blocks/BlockStone.h +++ b/source/Blocks/BlockStone.h @@ -1,9 +1,16 @@ +
#pragma once
+
#include "BlockHandler.h"
#include "../MersenneTwister.h"
#include "../World.h"
-class cBlockStoneHandler : public cBlockHandler
+
+
+
+
+class cBlockStoneHandler :
+ public cBlockHandler
{
public:
cBlockStoneHandler(BLOCKTYPE a_BlockID)
@@ -11,8 +18,12 @@ public: {
}
- virtual int GetDropID() override
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- return E_ITEM_COBBLESTONE;
- }
-};
\ No newline at end of file + a_Pickups.push_back(cItem(E_BLOCK_STONE, 1, 0));
+ }
+} ;
+
+
+
+
diff --git a/source/Blocks/BlockSugarcane.h b/source/Blocks/BlockSugarcane.h index 1d477b42b..28ffd8aa6 100644 --- a/source/Blocks/BlockSugarcane.h +++ b/source/Blocks/BlockSugarcane.h @@ -1,5 +1,6 @@ #pragma once
+
#include "BlockHandler.h"
@@ -16,15 +17,9 @@ public: }
- virtual bool NeedsRandomTicks() override
- {
- return true;
- }
-
-
- virtual int GetDropID() override
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- return E_ITEM_SUGARCANE;
+ a_Pickups.push_back(cItem(E_ITEM_SUGARCANE, 1, 0));
}
@@ -50,7 +45,7 @@ public: void OnUpdate(cWorld * a_World, int a_X, int a_Y, int a_Z) override
{
- //TODO: Handle Growing here
+ // TODO: Handle Growing here
}
@@ -59,12 +54,11 @@ public: return false;
}
- virtual AString GetStepSound(void) override
+ virtual const char * GetStepSound(void) override
{
return "step.grass";
}
-
-};
+} ;
diff --git a/source/Blocks/BlockTallGrass.h b/source/Blocks/BlockTallGrass.h index f5bb1b373..20714832f 100644 --- a/source/Blocks/BlockTallGrass.h +++ b/source/Blocks/BlockTallGrass.h @@ -1,8 +1,14 @@ +
#pragma once
+
#include "BlockHandler.h"
-class cBlockTallGrassHandler : public cBlockHandler
+
+
+
+class cBlockTallGrassHandler :
+ public cBlockHandler
{
public:
cBlockTallGrassHandler(BLOCKTYPE a_BlockID)
@@ -10,32 +16,36 @@ public: {
}
- virtual bool IgnoreBuildCollision() override
+
+ virtual bool DoesIgnoreBuildCollision(void) override
{
return true;
}
- virtual int GetDropID() override
- {
- return E_ITEM_SEEDS;
- }
-
- virtual char GetDropCount() override
+
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
+ // Drop seeds, sometimes
MTRand r1;
- if(r1.randInt(10) == 5)
- return 1;
- return 0;
+ if (r1.randInt(10) == 5)
+ {
+ a_Pickups.push_back(cItem(E_ITEM_SEEDS, 1, 0));
+ }
}
- virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override
+
+ virtual bool CanBeAt(cWorld * a_World, int a_X, int a_Y, int a_Z) override
{
return a_World->GetBlock(a_X, a_Y - 1, a_Z) != E_BLOCK_AIR;
}
+
- virtual AString GetStepSound(void) override
+ virtual const char * GetStepSound(void) override
{
return "step.grass";
}
+} ;
+
+
+
-};
diff --git a/source/Blocks/BlockTorch.h b/source/Blocks/BlockTorch.h index 450b5ecab..e65a973d2 100644 --- a/source/Blocks/BlockTorch.h +++ b/source/Blocks/BlockTorch.h @@ -1,5 +1,6 @@ #pragma once
+
#include "BlockHandler.h"
#include "../Torch.h"
#include "../World.h"
@@ -8,7 +9,8 @@ -class cBlockTorchHandler : public cBlockHandler
+class cBlockTorchHandler :
+ public cBlockHandler
{
public:
cBlockTorchHandler(BLOCKTYPE a_BlockID)
@@ -19,12 +21,14 @@ public: virtual void PlaceBlock(cWorld * a_World, cPlayer * a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override
{
- if(!TorchCanBePlacedAt(a_World, a_X, a_Y, a_Z, a_Dir))
+ if (!TorchCanBePlacedAt(a_World, a_X, a_Y, a_Z, a_Dir))
{
a_Dir = FindSuitableDirection(a_World, a_X, a_Y, a_Z);
- if(a_Dir == BLOCK_FACE_BOTTOM)
+ if (a_Dir == BLOCK_FACE_BOTTOM)
+ {
return;
+ }
}
a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cTorch::DirectionToMetaData(a_Dir));
@@ -32,7 +36,7 @@ public: }
- virtual bool AllowBlockOnTop(void) override
+ virtual bool DoesAllowBlockOnTop(void) override
{
return false;
}
@@ -116,25 +120,31 @@ public: // How to propagate that change up?
// Simon: The easiest way is to calculate the position two times, shouldn´t cost much cpu power :)
- if(a_Dir == BLOCK_FACE_BOTTOM)
+ if (a_Dir == BLOCK_FACE_BOTTOM)
+ {
return false;
+ }
AddDirection( a_X, a_Y, a_Z, a_Dir, true );
return CanBePlacedOn(a_World->GetBlock( a_X, a_Y, a_Z ), a_Dir);
}
- // Finds a suitable Direction for the Torch. Returns BLOCK_FACE_BOTTOM on failure
+
+ /// Finds a suitable Direction for the Torch. Returns BLOCK_FACE_BOTTOM on failure
static char FindSuitableDirection(cWorld * a_World, int a_X, int a_Y, int a_Z)
{
- for(int i = 1; i <= 5; i++)
+ for (int i = 1; i <= 5; i++)
{
- if(TorchCanBePlacedAt(a_World, a_X, a_Y, a_Z, i))
+ if (TorchCanBePlacedAt(a_World, a_X, a_Y, a_Z, i))
+ {
return i;
+ }
}
return BLOCK_FACE_BOTTOM;
}
+
virtual bool CanBePlacedAt(cWorld * a_World, int a_X, int a_Y, int a_Z, char a_Dir) override
{
if(TorchCanBePlacedAt(a_World, a_X, a_Y, a_Z, a_Dir))
@@ -150,16 +160,19 @@ public: return TorchCanBePlacedAt(a_World, a_X, a_Y, a_Z, Dir);
}
- virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override
+
+ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
- return 0;
+ // Always drop meta = 0
+ a_Pickups.push_back(cItem(m_BlockID, 1, 0));
}
- virtual AString GetStepSound(void) override
+
+ virtual const char * GetStepSound(void) override
{
return "step.wood";
}
-};
+} ;
diff --git a/source/Blocks/BlockVine.h b/source/Blocks/BlockVine.h index 56317219a..f489a5c5c 100644 --- a/source/Blocks/BlockVine.h +++ b/source/Blocks/BlockVine.h @@ -1,8 +1,15 @@ +
#pragma once
+
#include "BlockHandler.h"
#include "../Vine.h"
-class cBlockVineHandler : public cBlockHandler
+
+
+
+
+class cBlockVineHandler :
+ public cBlockHandler
{
public:
cBlockVineHandler(BLOCKTYPE a_BlockID)
@@ -10,26 +17,32 @@ public: {
}
- virtual bool IgnoreBuildCollision() override
+
+ virtual bool DoesIgnoreBuildCollision(void) override
{
return true;
}
- virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override
+
+ virtual void PlaceBlock(cWorld * a_World, cPlayer * a_Player, NIBBLETYPE a_BlockMeta, int a_X, int a_Y, int a_Z, char a_Dir) override
{
a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cVine::DirectionToMetaData(a_Dir));
OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir);
}
- virtual bool AllowBlockOnTop() override
+ virtual bool DoesAllowBlockOnTop(void) override
{
return false;
}
- virtual AString GetStepSound(void) override
+
+ virtual const char * GetStepSound(void) override
{
return "step.grass";
}
-
-};
+} ;
+
+
+
+
diff --git a/source/Blocks/BlockWood.h b/source/Blocks/BlockWood.h index d71d5d71c..d3fcacf7d 100644 --- a/source/Blocks/BlockWood.h +++ b/source/Blocks/BlockWood.h @@ -1,7 +1,12 @@ +
#pragma once
+
#include "BlockHandler.h"
+
+
+
class cBlockWoodHandler : public cBlockHandler
{
public:
@@ -9,14 +14,14 @@ public: : cBlockHandler(a_BlockID)
{
}
- NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override
- {
- return a_BlockMeta;
- }
- virtual AString GetStepSound(void) override
+
+ virtual const char * GetStepSound(void) override
{
return "step.wood";
}
-
-};
+} ;
+
+
+
+
diff --git a/source/Blocks/BlockWorkbench.h b/source/Blocks/BlockWorkbench.h index c1c004dc5..f6158b979 100644 --- a/source/Blocks/BlockWorkbench.h +++ b/source/Blocks/BlockWorkbench.h @@ -1,4 +1,6 @@ +
#pragma once
+
#include "BlockHandler.h"
#include "../UI/Window.h"
#include "../Player.h"
@@ -16,21 +18,26 @@ public: {
}
- virtual void OnUse(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
{
cWindow * Window = new cCraftingWindow(a_BlockX, a_BlockY, a_BlockZ);
a_Player->OpenWindow(Window);
}
- virtual bool IsUseable() override
+
+ virtual bool IsUseable(void) override
{
return true;
}
- virtual AString GetStepSound(void) override
+
+ virtual const char * GetStepSound(void) override
{
return "step.wood";
}
-
-
-};
\ No newline at end of file +} ;
+
+
+
+
diff --git a/source/Chunk.cpp b/source/Chunk.cpp index 606134f38..ec0ad01e0 100644 --- a/source/Chunk.cpp +++ b/source/Chunk.cpp @@ -430,9 +430,9 @@ void cChunk::CheckBlocks(void) Vector3i WorldPos = PositionToWorldPosition( BlockPos ); cBlockHandler * Handler = BlockHandler(GetBlock(index)); - if(!Handler->CanBeAt(m_World, WorldPos.x, WorldPos.y, WorldPos.z)) + if (!Handler->CanBeAt(m_World, WorldPos.x, WorldPos.y, WorldPos.z)) { - if(Handler->DropOnUnsuitable()) + if (Handler->DoesDropOnUnsuitable()) { Handler->DropBlock(m_World, WorldPos.x, WorldPos.y, WorldPos.z); } @@ -503,10 +503,7 @@ void cChunk::TickBlocks(MTRand & a_TickRandom) { cBlockHandler * Handler = BlockHandler(ID); ASSERT(Handler != NULL); // Happenned on server restart, FS #243 - if (Handler->NeedsRandomTicks()) - { - Handler->OnUpdate(m_World, m_BlockTickX + m_PosX * Width, m_BlockTickY, m_BlockTickZ + m_PosZ * Width); - } + Handler->OnUpdate(m_World, m_BlockTickX + m_PosX * Width, m_BlockTickY, m_BlockTickZ + m_PosZ * Width); break; } } diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp index 8ac773d48..6292df107 100644 --- a/source/ClientHandle.cpp +++ b/source/ClientHandle.cpp @@ -656,7 +656,7 @@ void cClientHandle::HandleBlockPlace(int a_BlockX, int a_BlockY, int a_BlockZ, c BLOCKTYPE ClickedBlock = World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); cBlockHandler *Handler = cBlockHandler::GetBlockHandler(ClickedBlock); - if(Handler->IgnoreBuildCollision()) + if (Handler->DoesIgnoreBuildCollision()) { Handler->OnDestroyedByPlayer(World, m_Player, a_BlockX, a_BlockY, a_BlockZ); // World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); @@ -665,7 +665,7 @@ void cClientHandle::HandleBlockPlace(int a_BlockX, int a_BlockY, int a_BlockZ, c { AddDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); // Check for Blocks not allowing placement on top - if ((a_BlockFace == BLOCK_FACE_TOP) && !Handler->AllowBlockOnTop()) + if ((a_BlockFace == BLOCK_FACE_TOP) && !Handler->DoesAllowBlockOnTop()) { // Resend the old block // Some times the client still places the block O.o @@ -676,7 +676,7 @@ void cClientHandle::HandleBlockPlace(int a_BlockX, int a_BlockY, int a_BlockZ, c BLOCKTYPE PlaceBlock = m_Player->GetWorld()->GetBlock(a_BlockX, a_BlockY, a_BlockZ); - if (!BlockHandler(PlaceBlock)->IgnoreBuildCollision()) + if (!BlockHandler(PlaceBlock)->DoesIgnoreBuildCollision()) { // Tried to place a block *into* another? return; // Happens when you place a block aiming at side of block like torch or stem diff --git a/source/FluidSimulator.cpp b/source/FluidSimulator.cpp index 8cbe5054e..40fc1e606 100644 --- a/source/FluidSimulator.cpp +++ b/source/FluidSimulator.cpp @@ -350,14 +350,14 @@ void cFluidSimulator::Simulate( float a_Dt ) if( bIsFed ) { - char DownID = m_World->GetBlock( pos.x, pos.y-1, pos.z ); - bool bWashedAwayItem = CanWashAway( DownID ); - if( (IsPassableForFluid(DownID) || bWashedAwayItem) && !IsStationaryBlock(DownID) ) // free for fluid + char DownID = m_World->GetBlock(pos.x, pos.y - 1, pos.z); + bool bWashedAwayItem = CanWashAway(DownID); + if ((IsPassableForFluid(DownID) || bWashedAwayItem) && !IsStationaryBlock(DownID) ) // free for fluid { - if( bWashedAwayItem ) + if (bWashedAwayItem) { cBlockHandler * Handler = BlockHandler(DownID); - if(Handler->DropOnUnsuitable()) + if (Handler->DoesDropOnUnsuitable()) { Handler->DropBlock(m_World, pos.x, pos.y - 1, pos.z); } @@ -393,13 +393,13 @@ void cFluidSimulator::Simulate( float a_Dt ) if (bWashedAwayItem) { cBlockHandler * Handler = BlockHandler(DownID); - if(Handler->DropOnUnsuitable()) + if (Handler->DoesDropOnUnsuitable()) { Handler->DropBlock(m_World, p.x, p.y, p.z); } } - if( p.y == pos.y ) + if (p.y == pos.y) { m_World->FastSetBlock(p.x, p.y, p.z, m_FluidBlock, Meta + m_FlowReduction); } diff --git a/source/Piston.cpp b/source/Piston.cpp index 750d76bb0..a235da879 100644 --- a/source/Piston.cpp +++ b/source/Piston.cpp @@ -67,7 +67,7 @@ void cPiston::ExtendPiston( int pistx, int pisty, int pistz ) if (currBlock != E_BLOCK_AIR) { cBlockHandler * Handler = BlockHandler(currBlock); - if(Handler->DropOnUnsuitable()) + if (Handler->DoesDropOnUnsuitable()) { Handler->DropBlock(m_World, pistx, pisty, pistz); } |