1
0

Slight refactoring of BlockHandlers - dropping unneeded virtual functions

( http://forum.mc-server.org/showthread.php?tid=434&pid=4734#pid4734 )

git-svn-id: http://mc-server.googlecode.com/svn/trunk@917 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2012-10-01 21:08:15 +00:00
parent 673fdcd768
commit 85164fab8e
42 changed files with 862 additions and 513 deletions

View File

@ -1,10 +1,17 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
#include "../World.h" #include "../World.h"
#include "../Sign.h" #include "../Sign.h"
#include "../Player.h" #include "../Player.h"
class cBlockBedHandler : public cBlockHandler
class cBlockBedHandler :
public cBlockHandler
{ {
public: public:
cBlockBedHandler(BLOCKTYPE a_BlockID) 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 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 OnUse(cWorld *a_World, cPlayer *a_Player, 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;
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; 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; return false;
} }
@ -41,7 +47,7 @@ public:
// Bed specific helper functions // 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 a_Rotation += 180 + (180/4); // So its not aligned with axis
if( a_Rotation > 360.f ) a_Rotation -= 360.f; if( a_Rotation > 360.f ) a_Rotation -= 360.f;
@ -51,19 +57,24 @@ public:
return ((char)a_Rotation+2) % 4; 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 case 0: // south +z
return Vector3i(0, 0, 1); return Vector3i(0, 0, 1);
case 1: // west -x case 1: // west -x
return Vector3i(-1, 0, 0); return Vector3i(-1, 0, 0);
case 2: // north -z case 2: // north -z
return Vector3i(0, 0, -1); return Vector3i(0, 0, -1);
case 3: // east +x case 3: // east +x
return Vector3i(1, 0, 0); return Vector3i(1, 0, 0);
}; };
return Vector3i(); return Vector3i();
} }
}; } ;

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "BlockHandler.h" #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; return false;
} }
virtual AString GetStepSound(void) override virtual const char * GetStepSound(void) override
{ {
return "step.cloth"; return "step.cloth";
} }
} ;
};

View File

@ -1,26 +1,38 @@
#pragma once #pragma once
#include "BlockEntity.h" #include "BlockEntity.h"
#include "../World.h" #include "../World.h"
#include "../Piston.h" #include "../Piston.h"
#include "../Player.h" #include "../Player.h"
class cBlockChestHandler : public cBlockEntityHandler
class cBlockChestHandler :
public cBlockEntityHandler
{ {
public: public:
cBlockChestHandler(BLOCKTYPE a_BlockID) cBlockChestHandler(BLOCKTYPE a_BlockID)
: cBlockEntityHandler(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)); 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); 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"; return "step.wood";
} }
} ;
};

View File

@ -1,8 +1,14 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
class cBlockClothHandler : public cBlockHandler
class cBlockClothHandler :
public cBlockHandler
{ {
public: public:
cBlockClothHandler(BLOCKTYPE a_BlockID) 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"; return "step.cloth";
} }
} ;
};

View File

@ -11,54 +11,47 @@ public:
{ {
} }
virtual bool NeedsRandomTicks() override
{
return true;
}
virtual bool AllowBlockOnTop() override virtual bool DoesAllowBlockOnTop() override
{ {
return false; return false;
} }
virtual int GetDropID() override
{ virtual void OnDestroyed(cWorld * a_World, int a_X, int a_Y, int a_Z) override
return E_ITEM_EMPTY;
}
virtual void OnDestroyed(cWorld *a_World, int a_X, int a_Y, int a_Z) override
{ {
MTRand rand; MTRand rand;
NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z); NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z);
cItems Drops; cItems Drops;
if(Meta & 0x7) //Is Wheat if (Meta & 0x7) // Is Wheat
{ {
Drops.push_back(cItem(E_ITEM_WHEAT, 1, 0)); Drops.push_back(cItem(E_ITEM_WHEAT, 1, 0));
} }
if(rand.randInt(3) == 0) Drops.push_back(cItem(E_ITEM_SEEDS, (rand.randInt(3) == 0) ? 2 : 1, 0));
{ //Drop an second seed
Drops.push_back(cItem(E_ITEM_SEEDS, 1, 0));
}
Drops.push_back(cItem(E_ITEM_SEEDS, 1, 0));
a_World->SpawnItemPickups(Drops, a_X, a_Y, a_Z); 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; 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"; return "step.grass";
} }
} ;
};

View File

@ -1,9 +1,17 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
#include "../MersenneTwister.h" #include "../MersenneTwister.h"
#include "../World.h" #include "../World.h"
class cBlockDirtHandler : public cBlockHandler
/// Handler used for both dirt and grass
class cBlockDirtHandler :
public cBlockHandler
{ {
public: public:
cBlockDirtHandler(BLOCKTYPE a_BlockID) 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; a_Pickups.push_back(cItem(E_ITEM_DIRT, 1, 0));
}
virtual int GetDropID() override
{
return E_BLOCK_DIRT;
} }
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) if (m_BlockID != E_BLOCK_GRASS)
{ {
@ -64,9 +67,13 @@ public:
} // for i - repeat twice } // for i - repeat twice
} }
virtual AString GetStepSound(void) override
virtual const char * GetStepSound(void) override
{ {
return "step.gravel"; return "step.gravel";
} }
} ;
};

View File

@ -1,3 +1,4 @@
#include "Globals.h" #include "Globals.h"
#include "BlockDoor.h" #include "BlockDoor.h"
#include "../Item.h" #include "../Item.h"
@ -6,17 +7,28 @@
#include "../Player.h" #include "../Player.h"
cBlockDoorHandler::cBlockDoorHandler(BLOCKTYPE a_BlockID) cBlockDoorHandler::cBlockDoorHandler(BLOCKTYPE a_BlockID)
: cBlockHandler(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); 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); 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); 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) 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";
} }

View File

@ -1,17 +1,28 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
class cBlockDoorHandler : public cBlockHandler
class cBlockDoorHandler :
public cBlockHandler
{ {
public: public:
cBlockDoorHandler(BLOCKTYPE a_BlockID); 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 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 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 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 OnUse(cWorld * a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z) override;
virtual AString GetStepSound(void) override; virtual const char * GetStepSound(void) override;
virtual char GetDropCount() 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 virtual bool IsUseable() override
{ {
return true; 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 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 virtual bool CanBePlacedOnSide(void) override
{
return (m_BlockID == E_BLOCK_WOODEN_DOOR) ? E_ITEM_WOODEN_DOOR : E_ITEM_IRON_DOOR;
}
virtual bool CanBePlacedOnSide() override
{ {
return false; return false;
} }
}; } ;

View File

@ -1,8 +1,14 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
class cBlockFireHandler : public cBlockHandler
class cBlockFireHandler :
public cBlockHandler
{ {
public: public:
cBlockFireHandler(BLOCKTYPE a_BlockID) 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); 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; return true;
} }
virtual AString GetStepSound(void) override virtual const char * GetStepSound(void) override
{ {
return "step.wood"; return "step.wood";
} }
} ;
};

View File

@ -1,8 +1,14 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
class cBlockFlowerHandler : public cBlockHandler
class cBlockFlowerHandler :
public cBlockHandler
{ {
public: public:
cBlockFlowerHandler(BLOCKTYPE a_BlockID) 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)); return IsBlockTypeOfDirt(a_World->GetBlock(a_X, a_Y - 1, a_Z));
} }
virtual bool AllowBlockOnTop() override
virtual bool DoesAllowBlockOnTop(void) override
{ {
return false; return false;
} }
virtual bool CanBePlacedOnSide() override
virtual bool CanBePlacedOnSide(void) override
{ {
return false; return false;
} }
virtual AString GetStepSound(void) override
virtual const char * GetStepSound(void) override
{ {
return "step.grass"; return "step.grass";
} }
} ;
};

View File

@ -1,8 +1,14 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
class cBlockFluidHandler : public cBlockHandler
class cBlockFluidHandler :
public cBlockHandler
{ {
public: public:
cBlockFluidHandler(BLOCKTYPE a_BlockID) cBlockFluidHandler(BLOCKTYPE a_BlockID)
@ -11,10 +17,15 @@ public:
} }
virtual bool IgnoreBuildCollision() override
virtual bool DoesIgnoreBuildCollision(void) override
{ {
return true; return true;
} }
// TODO: Implement proper fluid physics here
}; } ;

View File

@ -1,10 +1,17 @@
#pragma once #pragma once
#include "BlockEntity.h" #include "BlockEntity.h"
#include "../World.h" #include "../World.h"
#include "../Piston.h" #include "../Piston.h"
#include "../Player.h" #include "../Player.h"
class cBlockFurnaceHandler : public cBlockEntityHandler
class cBlockFurnaceHandler :
public cBlockEntityHandler
{ {
public: public:
cBlockFurnaceHandler(BLOCKTYPE a_BlockID) 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)); 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); OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir);
} }
} ;
};

View File

@ -1,8 +1,14 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
class cBlockGlowstoneHandler : public cBlockHandler
class cBlockGlowstoneHandler :
public cBlockHandler
{ {
public: public:
cBlockGlowstoneHandler(BLOCKTYPE a_BlockID) 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));
} }
}; } ;

View File

@ -1,8 +1,14 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
class cBlockGravelHandler : public cBlockHandler
class cBlockGravelHandler :
public cBlockHandler
{ {
public: public:
cBlockGravelHandler(BLOCKTYPE a_BlockID) cBlockGravelHandler(BLOCKTYPE a_BlockID)
@ -10,9 +16,12 @@ public:
{ {
} }
virtual AString GetStepSound(void) override virtual const char * GetStepSound(void) override
{ {
return "step.gravel"; return "step.gravel";
} }
} ;
};

View File

@ -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; cItems Pickups;
}
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;
NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z); NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z);
char DropCount = GetDropCount(); ConvertToPickups(Pickups, Meta);
short DropItem = (short)GetDropID(); if (!Pickups.empty())
if (DropCount > 0 && (DropItem != E_ITEM_EMPTY))
{ {
Drops.push_back(cItem(DropItem, DropCount, GetDropMeta(Meta))); a_World->SpawnItemPickups(Pickups, a_X, a_Y, a_Z);
a_World->SpawnItemPickups(Drops, 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"; return "step.stone";
} }
@ -396,7 +378,7 @@ bool cBlockHandler::IsUseable()
bool cBlockHandler::IsClickedThrough() bool cBlockHandler::IsClickedThrough(void)
{ {
return false; return false;
} }
@ -405,25 +387,16 @@ bool cBlockHandler::IsClickedThrough()
bool cBlockHandler::IgnoreBuildCollision() bool cBlockHandler::DoesIgnoreBuildCollision(void)
{ {
return m_BlockID == E_BLOCK_AIR; return (m_BlockID == E_BLOCK_AIR);
} }
bool cBlockHandler::NeedsRandomTicks() bool cBlockHandler::DoesAllowBlockOnTop(void)
{
return false;
}
bool cBlockHandler::AllowBlockOnTop()
{ {
return true; return true;
} }
@ -432,7 +405,7 @@ bool cBlockHandler::AllowBlockOnTop()
bool cBlockHandler::CanBePlacedOnSide() bool cBlockHandler::CanBePlacedOnSide(void)
{ {
return true; return true;
} }
@ -441,7 +414,7 @@ bool cBlockHandler::CanBePlacedOnSide()
bool cBlockHandler::DropOnUnsuitable() bool cBlockHandler::DoesDropOnUnsuitable(void)
{ {
return true; return true;
} }

View File

@ -1,11 +1,21 @@
#pragma once
#include "../Defines.h"
#pragma once
#include "../Defines.h"
#include "../Item.h"
// fwd:
class cWorld; class cWorld;
class cPlayer; class cPlayer;
class cBlockHandler class cBlockHandler
{ {
public: public:
@ -14,68 +24,78 @@ public:
// Called when the block gets ticked either by a random tick or by a queued tick // 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); 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 /// 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); 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();
// Indicates whether this block needs random ticks DEFAULT: False /// Called before the player has destroyed a block
virtual bool NeedsRandomTicks(); 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);
/// 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 /// 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); 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 /// 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 /// Called to check whether this block supports a rclk action. If it returns true, OnUse() is called
virtual bool IsUseable(void); 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); 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 /** Checks if the player can build "inside" this block.
virtual bool IgnoreBuildCollision(void); 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 /// 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 /// 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); static cBlockHandler * GetBlockHandler(BLOCKTYPE a_BlockID);
// Deletes all initialised block handlers /// Deletes all initialised block handlers
static void Deinit(); static void Deinit();
protected: protected:
@ -86,5 +106,16 @@ protected:
static bool m_HandlerInitialized; //used to detect if the blockhandlers are initialized static bool m_HandlerInitialized; //used to detect if the blockhandlers are initialized
}; };
// Shortcut to get the blockhandler for a specific block // Shortcut to get the blockhandler for a specific block
inline cBlockHandler *BlockHandler(BLOCKTYPE a_BlockID) { return cBlockHandler::GetBlockHandler(a_BlockID); } inline cBlockHandler *BlockHandler(BLOCKTYPE a_BlockID)
{
return cBlockHandler::GetBlockHandler(a_BlockID);
}

View File

@ -1,9 +1,15 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
#include "../MersenneTwister.h"
#include "../World.h" #include "../World.h"
class cBlockIceHandler : public cBlockHandler
class cBlockIceHandler :
public cBlockHandler
{ {
public: public:
cBlockIceHandler(BLOCKTYPE a_BlockID) 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); 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
} }
} ;
};

View File

@ -1,40 +1,51 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
#include "../World.h" #include "../World.h"
#include "../Ladder.h" #include "../Ladder.h"
class cBlockLadderHandler : public cBlockHandler
class cBlockLadderHandler :
public cBlockHandler
{ {
public: public:
cBlockLadderHandler(BLOCKTYPE a_BlockID) cBlockLadderHandler(BLOCKTYPE a_BlockID)
: cBlockHandler(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)); 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); 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 ); AddDirection( a_X, a_Y, a_Z, a_Dir, true );
return a_World->GetBlock( a_X, a_Y, a_Z ) != E_BLOCK_AIR; 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)); char Dir = cLadder::MetaDataToDirection(a_World->GetBlockMeta( a_X, a_Y, a_Z));
return CanBePlacedAt(a_World, a_X, a_Y, a_Z, Dir); 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"; return "step.wood";
} }
} ;
};

View File

@ -6,6 +6,8 @@
// Leaves can be this many blocks that away (inclusive) from the log not to decay // Leaves can be this many blocks that away (inclusive) from the log not to decay
#define LEAVES_CHECK_DISTANCE 6 #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: public:
cBlockLeavesHandler(BLOCKTYPE a_BlockID) 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; 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); 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); 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); NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z);
if ((Meta & 0x04) != 0) if ((Meta & 0x04) != 0)
@ -76,7 +86,7 @@ public:
return; return;
} }
if (Meta & 0x8) if ((Meta & 0x8) != 0)
{ {
// These leaves have been checked for decay lately and nothing around them changed // These leaves have been checked for decay lately and nothing around them changed
return; return;
@ -109,14 +119,18 @@ public:
} }
virtual AString GetStepSound(void) override
virtual const char * GetStepSound(void) override
{ {
return "step.grass"; 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: // Filter the blocks into a {leaves, log, other (air)} set:
BLOCKTYPE * Types = a_Area.GetBlockTypes(); 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; return false;
} }

View File

@ -1,8 +1,14 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
class cBlockMelonHandler : public cBlockHandler
class cBlockMelonHandler :
public cBlockHandler
{ {
public: public:
cBlockMelonHandler(BLOCKTYPE a_BlockID) cBlockMelonHandler(BLOCKTYPE a_BlockID)
@ -11,19 +17,19 @@ public:
} }
virtual int GetDropID() override virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
return E_ITEM_MELON_SLICE;
}
virtual char GetDropCount() override
{ {
MTRand r1; 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"; return "step.wood";
} }
}; } ;

View File

@ -1,8 +1,14 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
class cBlockMushroomHandler : public cBlockHandler
class cBlockMushroomHandler :
public cBlockHandler
{ {
public: public:
cBlockMushroomHandler(BLOCKTYPE a_BlockID) 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)) switch (a_World->GetBlock(a_X, a_Y - 1, a_Z))
{ {
@ -24,24 +33,32 @@ public:
case E_BLOCK_ICE: case E_BLOCK_ICE:
case E_BLOCK_LEAVES: case E_BLOCK_LEAVES:
case E_BLOCK_AIR: case E_BLOCK_AIR:
{
return false; return false;
}
} }
return true; return true;
} }
virtual bool AllowBlockOnTop() override
virtual bool DoesAllowBlockOnTop(void) override
{ {
return false; return false;
} }
virtual bool CanBePlacedOnSide() override virtual bool CanBePlacedOnSide(void) override
{ {
return false; return false;
} }
virtual AString GetStepSound(void) override virtual const char * GetStepSound(void) override
{ {
return "step.grass"; return "step.grass";
} }
}; } ;

View File

@ -1,9 +1,16 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
#include "../MersenneTwister.h" #include "../MersenneTwister.h"
#include "../World.h" #include "../World.h"
class cBlockOreHandler : public cBlockHandler
class cBlockOreHandler :
public cBlockHandler
{ {
public: public:
cBlockOreHandler(BLOCKTYPE a_BlockID) 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; MTRand r1;
switch(m_BlockID) switch (m_BlockID)
{ {
case E_BLOCK_LAPIS_ORE: case E_BLOCK_LAPIS_ORE:
return 4 + (char)r1.randInt(4); {
case E_BLOCK_REDSTONE_ORE: ItemType = E_ITEM_DYE;
case E_BLOCK_REDSTONE_ORE_GLOWING: Count = 4 + (char)r1.randInt(4);
return 4 + (char)r1.randInt(1); Meta = 4;
default: break;
return 1; }
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: case E_BLOCK_DIAMOND_ORE:
return 4; {
default: ItemType = E_ITEM_DIAMOND;
return 0; 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;
}
};

View File

@ -1,32 +1,40 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
#include "../World.h" #include "../World.h"
class cBlockRedstoneHandler : public cBlockHandler
class cBlockRedstoneHandler :
public cBlockHandler
{ {
public: public:
cBlockRedstoneHandler(BLOCKTYPE a_BlockID); 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 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 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; 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; 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; return false;
} }

View File

@ -1,52 +1,64 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
#include "../World.h" #include "../World.h"
class cBlockRedstoneRepeaterHandler : public cBlockHandler
class cBlockRedstoneRepeaterHandler :
public cBlockHandler
{ {
public: public:
cBlockRedstoneRepeaterHandler(BLOCKTYPE a_BlockID); 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 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 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 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 OnUse(cWorld * a_World, cPlayer * a_Player, int a_X, int a_Y, int a_Z) override;
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(E_ITEM_REDSTONE_REPEATER, 1, 0));
} }
virtual int GetDropID() override
{
return E_ITEM_REDSTONE_REPEATER;
}
virtual bool IsUseable() override virtual bool IsUseable(void) override
{ {
return true; 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; 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; 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; return false;
} }
virtual AString GetStepSound(void) override virtual const char * GetStepSound(void) override
{ {
return "step.wood"; return "step.wood";
} }
}; } ;

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "BlockRedstone.h" #include "BlockRedstone.h"
#include "BlockTorch.h" #include "BlockTorch.h"
#include "../Torch.h" #include "../Torch.h"
@ -8,7 +9,8 @@
class cBlockRedstoneTorchHandler : public cBlockTorchHandler class cBlockRedstoneTorchHandler :
public cBlockTorchHandler
{ {
public: public:
cBlockRedstoneTorchHandler(BLOCKTYPE a_BlockID) 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"; return "step.wood";
} }
}; } ;

View File

@ -1,8 +1,14 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
class cBlockSandHandler : public cBlockHandler
class cBlockSandHandler :
public cBlockHandler
{ {
public: public:
cBlockSandHandler(BLOCKTYPE a_BlockID) cBlockSandHandler(BLOCKTYPE a_BlockID)
@ -10,9 +16,13 @@ public:
{ {
} }
virtual AString GetStepSound(void) override virtual const char * GetStepSound(void) override
{ {
return "step.sand"; return "step.sand";
} }
}; };

View File

@ -1,8 +1,15 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
#include "../World.h" #include "../World.h"
class cBlockSaplingHandler : public cBlockHandler
class cBlockSaplingHandler :
public cBlockHandler
{ {
public: public:
cBlockSaplingHandler(BLOCKTYPE a_BlockID) cBlockSaplingHandler(BLOCKTYPE a_BlockID)
@ -10,27 +17,27 @@ public:
{ {
} }
virtual bool NeedsRandomTicks() override
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{ {
return true; // 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 NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override
{
return a_BlockMeta & 3; //Only the first 2 bits contain the display information the others are for growing
}
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)); return IsBlockTypeOfDirt(a_World->GetBlock(a_X, a_Y - 1, a_Z));
} }
virtual bool AllowBlockOnTop() override
virtual bool DoesAllowBlockOnTop(void) override
{ {
return false; 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); NIBBLETYPE Meta = a_World->GetBlockMeta(a_X, a_Y, a_Z);
@ -44,13 +51,19 @@ public:
} }
} }
virtual bool CanBePlacedOnSide() override virtual bool CanBePlacedOnSide() override
{ {
return false; return false;
} }
virtual AString GetStepSound(void) override
virtual const char * GetStepSound(void) override
{ {
return "step.grass"; return "step.grass";
} }
}; } ;

View File

@ -1,27 +1,36 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
#include "../World.h" #include "../World.h"
#include "../Sign.h" #include "../Sign.h"
#include "../Player.h" #include "../Player.h"
class cBlockSignHandler : public cBlockHandler
class cBlockSignHandler :
public cBlockHandler
{ {
public: public:
cBlockSignHandler(BLOCKTYPE a_BlockID) cBlockSignHandler(BLOCKTYPE a_BlockID)
: cBlockHandler(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; BLOCKTYPE Block;
NIBBLETYPE Meta; NIBBLETYPE Meta;
if(a_Dir == 1) if (a_Dir == BLOCK_FACE_TOP)
{ {
Meta = cSign::RotationToMetaData(a_Player->GetRotation()); Meta = cSign::RotationToMetaData(a_Player->GetRotation());
Block = E_BLOCK_SIGN_POST; Block = E_BLOCK_SIGN_POST;
}else{ }
else
{
Meta = cSign::DirectionToMetaData(a_Dir); Meta = cSign::DirectionToMetaData(a_Dir);
Block = E_BLOCK_WALLSIGN; Block = E_BLOCK_WALLSIGN;
} }
@ -30,18 +39,25 @@ public:
OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); 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; return false;
} }
virtual AString GetStepSound(void) override virtual const char * GetStepSound(void) override
{ {
return "step.wood"; return "step.wood";
} }
}; } ;

View File

@ -1,8 +1,14 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
class cBlockSlabHandler : public cBlockHandler
class cBlockSlabHandler :
public cBlockHandler
{ {
public: public:
cBlockSlabHandler(BLOCKTYPE a_BlockID) cBlockSlabHandler(BLOCKTYPE a_BlockID)
@ -10,17 +16,11 @@ public:
{ {
} }
virtual NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{ {
return a_BlockMeta; 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));
virtual char GetDropCount() override
{
if(m_BlockID == E_BLOCK_DOUBLE_STONE_SLAB
|| m_BlockID == E_BLOCK_DOUBLE_WOODEN_SLAB)
return 2;
return 1;
} }
@ -30,6 +30,7 @@ public:
OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir); OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir);
} }
static char DirectionToMetaData( char a_Direction, NIBBLETYPE Meta ) static char DirectionToMetaData( char a_Direction, NIBBLETYPE Meta )
{ {
char result = Meta; char result = Meta;
@ -40,12 +41,13 @@ public:
return result; 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 virtual const char * GetStepSound(void) override
return "step.stone"; {
return ((m_BlockID == E_BLOCK_WOODEN_SLAB) || (m_BlockID == E_BLOCK_DOUBLE_WOODEN_SLAB)) ? "step.wood" : "step.stone";
} }
}; } ;

View File

@ -1,8 +1,14 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
class cBlockSnowHandler : public cBlockHandler
class cBlockSnowHandler :
public cBlockHandler
{ {
public: public:
cBlockSnowHandler(BLOCKTYPE a_BlockID) cBlockSnowHandler(BLOCKTYPE a_BlockID)
@ -10,35 +16,37 @@ public:
{ {
} }
virtual bool IgnoreBuildCollision() override
virtual bool DoesIgnoreBuildCollision(void) override
{ {
return true; return true;
} }
virtual int GetDropID() override
{
return E_ITEM_SNOWBALL;
}
virtual char GetDropCount() override
{
return 4;
}
virtual bool CanBeAt(cWorld *a_World, int a_X, int a_Y, int a_Z) override
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{ {
return a_World->GetBlock(a_X, a_Y - 1, a_Z) != E_BLOCK_AIR; a_Pickups.push_back(cItem(E_ITEM_SNOWBALL, 4, 0));
}
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 DropOnUnsuitable() override
virtual bool DoesDropOnUnsuitable(void) override
{ {
return false; return false;
} }
virtual AString GetStepSound(void) override virtual const char * GetStepSound(void) override
{ {
return "step.cloth"; return "step.cloth";
} }
} ;
};

View File

@ -1,9 +1,16 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
#include "../MersenneTwister.h" #include "../MersenneTwister.h"
#include "../World.h" #include "../World.h"
class cBlockStemsHandler : public cBlockHandler
class cBlockStemsHandler :
public cBlockHandler
{ {
public: public:
cBlockStemsHandler(BLOCKTYPE a_BlockID) cBlockStemsHandler(BLOCKTYPE a_BlockID)
@ -11,36 +18,31 @@ public:
{ {
} }
virtual bool NeedsRandomTicks() override virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{ {
return true; 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 NIBBLETYPE GetDropMeta(NIBBLETYPE a_BlockMeta) override
{
return 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; 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"; return "step.wood";
} }
} ;
};

View File

@ -1,9 +1,16 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
#include "../MersenneTwister.h" #include "../MersenneTwister.h"
#include "../World.h" #include "../World.h"
class cBlockStoneHandler : public cBlockHandler
class cBlockStoneHandler :
public cBlockHandler
{ {
public: public:
cBlockStoneHandler(BLOCKTYPE a_BlockID) 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; a_Pickups.push_back(cItem(E_BLOCK_STONE, 1, 0));
} }
}; } ;

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
@ -16,15 +17,9 @@ public:
} }
virtual bool NeedsRandomTicks() override virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{ {
return true; a_Pickups.push_back(cItem(E_ITEM_SUGARCANE, 1, 0));
}
virtual int GetDropID() override
{
return E_ITEM_SUGARCANE;
} }
@ -50,7 +45,7 @@ public:
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
} }
@ -59,12 +54,11 @@ public:
return false; return false;
} }
virtual AString GetStepSound(void) override virtual const char * GetStepSound(void) override
{ {
return "step.grass"; return "step.grass";
} }
} ;
};

View File

@ -1,8 +1,14 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
class cBlockTallGrassHandler : public cBlockHandler
class cBlockTallGrassHandler :
public cBlockHandler
{ {
public: public:
cBlockTallGrassHandler(BLOCKTYPE a_BlockID) cBlockTallGrassHandler(BLOCKTYPE a_BlockID)
@ -10,32 +16,36 @@ public:
{ {
} }
virtual bool IgnoreBuildCollision() override
virtual bool DoesIgnoreBuildCollision(void) override
{ {
return true; return true;
} }
virtual int GetDropID() override
{ virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
return E_ITEM_SEEDS;
}
virtual char GetDropCount() override
{ {
// Drop seeds, sometimes
MTRand r1; MTRand r1;
if(r1.randInt(10) == 5) if (r1.randInt(10) == 5)
return 1; {
return 0; 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; 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"; return "step.grass";
} }
} ;
};

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
#include "../Torch.h" #include "../Torch.h"
#include "../World.h" #include "../World.h"
@ -8,7 +9,8 @@
class cBlockTorchHandler : public cBlockHandler class cBlockTorchHandler :
public cBlockHandler
{ {
public: public:
cBlockTorchHandler(BLOCKTYPE a_BlockID) 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 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); a_Dir = FindSuitableDirection(a_World, a_X, a_Y, a_Z);
if(a_Dir == BLOCK_FACE_BOTTOM) if (a_Dir == BLOCK_FACE_BOTTOM)
{
return; return;
}
} }
a_World->SetBlock(a_X, a_Y, a_Z, m_BlockID, cTorch::DirectionToMetaData(a_Dir)); 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; return false;
} }
@ -116,25 +120,31 @@ public:
// How to propagate that change up? // How to propagate that change up?
// Simon: The easiest way is to calculate the position two times, shouldn´t cost much cpu power :) // 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; return false;
}
AddDirection( a_X, a_Y, a_Z, a_Dir, true ); AddDirection( a_X, a_Y, a_Z, a_Dir, true );
return CanBePlacedOn(a_World->GetBlock( a_X, a_Y, a_Z ), a_Dir); 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) 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 i;
}
} }
return BLOCK_FACE_BOTTOM; return BLOCK_FACE_BOTTOM;
} }
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
{ {
if(TorchCanBePlacedAt(a_World, a_X, a_Y, a_Z, a_Dir)) 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); 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"; return "step.wood";
} }
}; } ;

View File

@ -1,8 +1,15 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
#include "../Vine.h" #include "../Vine.h"
class cBlockVineHandler : public cBlockHandler
class cBlockVineHandler :
public cBlockHandler
{ {
public: public:
cBlockVineHandler(BLOCKTYPE a_BlockID) cBlockVineHandler(BLOCKTYPE a_BlockID)
@ -10,26 +17,32 @@ public:
{ {
} }
virtual bool IgnoreBuildCollision() override
virtual bool DoesIgnoreBuildCollision(void) override
{ {
return true; 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)); 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); OnPlacedByPlayer(a_World, a_Player, a_X, a_Y, a_Z, a_Dir);
} }
virtual bool AllowBlockOnTop() override virtual bool DoesAllowBlockOnTop(void) override
{ {
return false; return false;
} }
virtual AString GetStepSound(void) override
virtual const char * GetStepSound(void) override
{ {
return "step.grass"; return "step.grass";
} }
} ;
};

View File

@ -1,7 +1,12 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
class cBlockWoodHandler : public cBlockHandler class cBlockWoodHandler : public cBlockHandler
{ {
public: public:
@ -9,14 +14,14 @@ public:
: cBlockHandler(a_BlockID) : 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"; return "step.wood";
} }
} ;
};

View File

@ -1,4 +1,6 @@
#pragma once #pragma once
#include "BlockHandler.h" #include "BlockHandler.h"
#include "../UI/Window.h" #include "../UI/Window.h"
#include "../Player.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); cWindow * Window = new cCraftingWindow(a_BlockX, a_BlockY, a_BlockZ);
a_Player->OpenWindow(Window); a_Player->OpenWindow(Window);
} }
virtual bool IsUseable() override
virtual bool IsUseable(void) override
{ {
return true; return true;
} }
virtual AString GetStepSound(void) override
virtual const char * GetStepSound(void) override
{ {
return "step.wood"; return "step.wood";
} }
} ;
};

View File

@ -430,9 +430,9 @@ void cChunk::CheckBlocks(void)
Vector3i WorldPos = PositionToWorldPosition( BlockPos ); Vector3i WorldPos = PositionToWorldPosition( BlockPos );
cBlockHandler * Handler = BlockHandler(GetBlock(index)); 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); Handler->DropBlock(m_World, WorldPos.x, WorldPos.y, WorldPos.z);
} }
@ -503,10 +503,7 @@ void cChunk::TickBlocks(MTRand & a_TickRandom)
{ {
cBlockHandler * Handler = BlockHandler(ID); cBlockHandler * Handler = BlockHandler(ID);
ASSERT(Handler != NULL); // Happenned on server restart, FS #243 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; break;
} }
} }

View File

@ -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); BLOCKTYPE ClickedBlock = World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
cBlockHandler *Handler = cBlockHandler::GetBlockHandler(ClickedBlock); cBlockHandler *Handler = cBlockHandler::GetBlockHandler(ClickedBlock);
if(Handler->IgnoreBuildCollision()) if (Handler->DoesIgnoreBuildCollision())
{ {
Handler->OnDestroyedByPlayer(World, m_Player, a_BlockX, a_BlockY, a_BlockZ); Handler->OnDestroyedByPlayer(World, m_Player, a_BlockX, a_BlockY, a_BlockZ);
// World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); // 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); AddDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
// Check for Blocks not allowing placement on top // 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 // Resend the old block
// Some times the client still places the block O.o // 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); 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? // Tried to place a block *into* another?
return; // Happens when you place a block aiming at side of block like torch or stem return; // Happens when you place a block aiming at side of block like torch or stem

View File

@ -350,14 +350,14 @@ void cFluidSimulator::Simulate( float a_Dt )
if( bIsFed ) if( bIsFed )
{ {
char DownID = m_World->GetBlock( pos.x, pos.y-1, pos.z ); char DownID = m_World->GetBlock(pos.x, pos.y - 1, pos.z);
bool bWashedAwayItem = CanWashAway( DownID ); bool bWashedAwayItem = CanWashAway(DownID);
if( (IsPassableForFluid(DownID) || bWashedAwayItem) && !IsStationaryBlock(DownID) ) // free for fluid if ((IsPassableForFluid(DownID) || bWashedAwayItem) && !IsStationaryBlock(DownID) ) // free for fluid
{ {
if( bWashedAwayItem ) if (bWashedAwayItem)
{ {
cBlockHandler * Handler = BlockHandler(DownID); cBlockHandler * Handler = BlockHandler(DownID);
if(Handler->DropOnUnsuitable()) if (Handler->DoesDropOnUnsuitable())
{ {
Handler->DropBlock(m_World, pos.x, pos.y - 1, pos.z); Handler->DropBlock(m_World, pos.x, pos.y - 1, pos.z);
} }
@ -393,13 +393,13 @@ void cFluidSimulator::Simulate( float a_Dt )
if (bWashedAwayItem) if (bWashedAwayItem)
{ {
cBlockHandler * Handler = BlockHandler(DownID); cBlockHandler * Handler = BlockHandler(DownID);
if(Handler->DropOnUnsuitable()) if (Handler->DoesDropOnUnsuitable())
{ {
Handler->DropBlock(m_World, p.x, p.y, p.z); 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); m_World->FastSetBlock(p.x, p.y, p.z, m_FluidBlock, Meta + m_FlowReduction);
} }

View File

@ -67,7 +67,7 @@ void cPiston::ExtendPiston( int pistx, int pisty, int pistz )
if (currBlock != E_BLOCK_AIR) if (currBlock != E_BLOCK_AIR)
{ {
cBlockHandler * Handler = BlockHandler(currBlock); cBlockHandler * Handler = BlockHandler(currBlock);
if(Handler->DropOnUnsuitable()) if (Handler->DoesDropOnUnsuitable())
{ {
Handler->DropBlock(m_World, pistx, pisty, pistz); Handler->DropBlock(m_World, pistx, pisty, pistz);
} }