summaryrefslogtreecommitdiffstats
path: root/source/Items
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-01-12 05:46:01 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-01-12 05:46:01 +0100
commit43e684071933adef93040e8d4b830d5c6b71cf9a (patch)
tree014e5300feb1cdbbb8f24e4e42594eeb841f0be2 /source/Items
parentFixed rclk in doublechests (diff)
downloadcuberite-43e684071933adef93040e8d4b830d5c6b71cf9a.tar
cuberite-43e684071933adef93040e8d4b830d5c6b71cf9a.tar.gz
cuberite-43e684071933adef93040e8d4b830d5c6b71cf9a.tar.bz2
cuberite-43e684071933adef93040e8d4b830d5c6b71cf9a.tar.lz
cuberite-43e684071933adef93040e8d4b830d5c6b71cf9a.tar.xz
cuberite-43e684071933adef93040e8d4b830d5c6b71cf9a.tar.zst
cuberite-43e684071933adef93040e8d4b830d5c6b71cf9a.zip
Diffstat (limited to 'source/Items')
-rw-r--r--source/Items/ItemBed.h47
-rw-r--r--source/Items/ItemBrewingStand.h32
-rw-r--r--source/Items/ItemBucket.h12
-rw-r--r--source/Items/ItemCauldron.h32
-rw-r--r--source/Items/ItemDoor.h33
-rw-r--r--source/Items/ItemDye.h4
-rw-r--r--source/Items/ItemFlowerPot.h32
-rw-r--r--source/Items/ItemHandler.cpp50
-rw-r--r--source/Items/ItemHandler.h56
-rw-r--r--source/Items/ItemLeaves.h20
-rw-r--r--source/Items/ItemLighter.h24
-rw-r--r--source/Items/ItemRedstoneDust.h18
-rw-r--r--source/Items/ItemRedstoneRepeater.h20
-rw-r--r--source/Items/ItemSapling.h18
-rw-r--r--source/Items/ItemSeeds.h51
-rw-r--r--source/Items/ItemSign.h41
-rw-r--r--source/Items/ItemSlab.h4
-rw-r--r--source/Items/ItemSpawnEgg.h10
-rw-r--r--source/Items/ItemSugarcane.h24
19 files changed, 344 insertions, 184 deletions
diff --git a/source/Items/ItemBed.h b/source/Items/ItemBed.h
index 1b2c54cbd..c9fec9064 100644
--- a/source/Items/ItemBed.h
+++ b/source/Items/ItemBed.h
@@ -3,23 +3,54 @@
#include "ItemHandler.h"
#include "../World.h"
+#include "../Blocks/BlockBed.h"
-class cItemBedHandler : public cItemHandler
+
+
+
+
+class cItemBedHandler :
+ public cItemHandler
{
public:
- cItemBedHandler(int a_ItemType)
- : cItemHandler(a_ItemType)
+ cItemBedHandler(int a_ItemType) :
+ cItemHandler(a_ItemType)
{
-
}
- virtual bool IsPlaceable() override
+
+ virtual bool IsPlaceable(void) override
{
return true;
}
- virtual BLOCKTYPE GetBlockType() override
+ virtual bool GetPlacementBlockTypeMeta(
+ cWorld * a_World, cPlayer * a_Player,
+ int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
+ int a_CursorX, int a_CursorY, int a_CursorZ,
+ BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
+ ) override
{
- return E_BLOCK_BED;
+ if (a_BlockFace != BLOCK_FACE_TOP)
+ {
+ // Can only be placed on the floor
+ return false;
+ }
+
+ a_BlockMeta = cBlockBedHandler::RotationToMetaData(a_Player->GetRotation());
+
+ // Check if there is empty space for the foot section:
+ Vector3i Direction = cBlockBedHandler::MetaDataToDirection(a_BlockMeta);
+ if (a_World->GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) != E_BLOCK_AIR)
+ {
+ return false;
+ }
+
+ a_BlockType = E_BLOCK_BED;
+ return true;
}
-}; \ No newline at end of file
+} ;
+
+
+
+
diff --git a/source/Items/ItemBrewingStand.h b/source/Items/ItemBrewingStand.h
index a4fe6bcbe..07ee7dfeb 100644
--- a/source/Items/ItemBrewingStand.h
+++ b/source/Items/ItemBrewingStand.h
@@ -3,23 +3,39 @@
#include "ItemHandler.h"
-class cItemBrewingStandHandler : public cItemHandler
+
+
+
+
+class cItemBrewingStandHandler :
+ public cItemHandler
{
public:
- cItemBrewingStandHandler(int a_ItemType)
- : cItemHandler(a_ItemType)
+ cItemBrewingStandHandler(int a_ItemType) :
+ cItemHandler(a_ItemType)
{
-
}
- virtual bool IsPlaceable() override
+
+ virtual bool IsPlaceable(void) override
{
return true;
}
- virtual BLOCKTYPE GetBlockType() override
+
+ virtual bool GetPlacementBlockTypeMeta(
+ cWorld * a_World, cPlayer * a_Player,
+ int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
+ int a_CursorX, int a_CursorY, int a_CursorZ,
+ BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
+ ) override
{
- return E_BLOCK_BREWING_STAND;
+ a_BlockType = E_BLOCK_BREWING_STAND;
+ a_BlockMeta = 0;
+ return true;
}
+} ;
+
+
+
-}; \ No newline at end of file
diff --git a/source/Items/ItemBucket.h b/source/Items/ItemBucket.h
index 3490300ae..18b344914 100644
--- a/source/Items/ItemBucket.h
+++ b/source/Items/ItemBucket.h
@@ -37,13 +37,13 @@ public:
- bool ScoopUpFluid(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir)
+ bool ScoopUpFluid(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace)
{
- if (a_Dir < 0)
+ if (a_BlockFace < 0)
{
return false;
}
- AddDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir);
+ AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
BLOCKTYPE ClickedBlock;
NIBBLETYPE ClickedMeta;
a_World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, ClickedBlock, ClickedMeta);
@@ -100,9 +100,9 @@ public:
}
- bool PlaceFluid(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir, BLOCKTYPE a_FluidBlock)
+ bool PlaceFluid(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_FluidBlock)
{
- if (a_Dir < 0)
+ if (a_BlockFace < 0)
{
return false;
}
@@ -112,7 +112,7 @@ public:
if (!CanWashAway)
{
// The block pointed at cannot be washed away, so put fluid on top of it / on its sides
- AddDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir);
+ AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
CurrentBlock = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
}
if (
diff --git a/source/Items/ItemCauldron.h b/source/Items/ItemCauldron.h
index 96ddf6c05..216766cf8 100644
--- a/source/Items/ItemCauldron.h
+++ b/source/Items/ItemCauldron.h
@@ -3,23 +3,39 @@
#include "ItemHandler.h"
-class cItemCauldronHandler : public cItemHandler
+
+
+
+
+class cItemCauldronHandler :
+ public cItemHandler
{
public:
- cItemCauldronHandler(int a_ItemType)
- : cItemHandler(a_ItemType)
+ cItemCauldronHandler(int a_ItemType) :
+ cItemHandler(a_ItemType)
{
-
}
- virtual bool IsPlaceable() override
+
+ virtual bool IsPlaceable(void) override
{
return true;
}
- virtual BLOCKTYPE GetBlockType() override
+
+ virtual bool GetPlacementBlockTypeMeta(
+ cWorld * a_World, cPlayer * a_Player,
+ int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
+ int a_CursorX, int a_CursorY, int a_CursorZ,
+ BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
+ ) override
{
- return E_BLOCK_CAULDRON;
+ a_BlockType = E_BLOCK_CAULDRON;
+ a_BlockMeta = 0;
+ return true;
}
+} ;
+
+
+
-}; \ No newline at end of file
diff --git a/source/Items/ItemDoor.h b/source/Items/ItemDoor.h
index 949ad833a..6ebeab43a 100644
--- a/source/Items/ItemDoor.h
+++ b/source/Items/ItemDoor.h
@@ -4,23 +4,42 @@
#include "ItemHandler.h"
#include "../World.h"
-class cItemDoorHandler : public cItemHandler
+
+
+
+
+class cItemDoorHandler :
+ public cItemHandler
{
public:
- cItemDoorHandler(int a_ItemType)
- : cItemHandler(a_ItemType)
+ cItemDoorHandler(int a_ItemType) :
+ cItemHandler(a_ItemType)
{
}
- virtual bool IsPlaceable() override
+ virtual bool IsPlaceable(void) override
{
return true;
}
- virtual BLOCKTYPE GetBlockType() override
+ virtual bool GetPlacementBlockTypeMeta(
+ cWorld * a_World, cPlayer * a_Player,
+ int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
+ int a_CursorX, int a_CursorY, int a_CursorZ,
+ BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
+ ) override
{
- return (m_ItemType == E_ITEM_WOODEN_DOOR) ? E_BLOCK_WOODEN_DOOR : E_BLOCK_IRON_DOOR;
+ a_BlockType = (m_ItemType == E_ITEM_WOODEN_DOOR) ? E_BLOCK_WOODEN_DOOR : E_BLOCK_IRON_DOOR;
+ return BlockHandler(a_BlockType)->GetPlacementBlockTypeMeta(
+ a_World, a_Player,
+ a_BlockX, a_BlockY, a_BlockZ, a_BlockFace,
+ a_CursorX, a_CursorY, a_CursorZ,
+ a_BlockType, a_BlockMeta
+ );
}
+} ;
+
+
+
-}; \ No newline at end of file
diff --git a/source/Items/ItemDye.h b/source/Items/ItemDye.h
index 28512c74d..020117c97 100644
--- a/source/Items/ItemDye.h
+++ b/source/Items/ItemDye.h
@@ -23,13 +23,13 @@ public:
{
// TODO: Handle coloring the sheep, too (OnItemUseOnEntity maybe)
// Handle growing the plants:
- if (a_Item->m_ItemHealth == E_META_DYE_WHITE)
+ if (a_Item->m_ItemDamage == E_META_DYE_WHITE)
{
if (a_World->GrowRipePlant(a_BlockX, a_BlockY, a_BlockZ, true))
{
if (a_Player->GetGameMode() != eGameMode_Creative)
{
- cItem Item(a_Item->m_ItemType, 1, a_Item->m_ItemHealth);
+ cItem Item(a_Item->m_ItemType, 1, a_Item->m_ItemDamage);
a_Player->GetInventory().RemoveItem(Item);
return true;
}
diff --git a/source/Items/ItemFlowerPot.h b/source/Items/ItemFlowerPot.h
index fe4b3dd61..0e55ddb51 100644
--- a/source/Items/ItemFlowerPot.h
+++ b/source/Items/ItemFlowerPot.h
@@ -3,23 +3,39 @@
#include "ItemHandler.h"
-class cItemFlowerPotHandler : public cItemHandler
+
+
+
+
+class cItemFlowerPotHandler :
+ public cItemHandler
{
public:
- cItemFlowerPotHandler(int a_ItemType)
- : cItemHandler(a_ItemType)
+ cItemFlowerPotHandler(int a_ItemType) :
+ cItemHandler(a_ItemType)
{
-
}
- virtual bool IsPlaceable() override
+
+ virtual bool IsPlaceable(void) override
{
return true;
}
- virtual BLOCKTYPE GetBlockType() override
+
+ virtual bool GetPlacementBlockTypeMeta(
+ cWorld * a_World, cPlayer * a_Player,
+ int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
+ int a_CursorX, int a_CursorY, int a_CursorZ,
+ BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
+ ) override
{
- return E_BLOCK_FLOWER_POT;
+ a_BlockType = E_BLOCK_FLOWER_POT;
+ a_BlockMeta = 0;
+ return true;
}
+} ;
+
+
+
-}; \ No newline at end of file
diff --git a/source/Items/ItemHandler.cpp b/source/Items/ItemHandler.cpp
index 6426ce212..1200fa27a 100644
--- a/source/Items/ItemHandler.cpp
+++ b/source/Items/ItemHandler.cpp
@@ -386,50 +386,38 @@ bool cItemHandler::CanHarvestBlock(BLOCKTYPE a_BlockType)
-BLOCKTYPE cItemHandler::GetBlockType()
+bool cItemHandler::GetPlacementBlockTypeMeta(
+ cWorld * a_World, cPlayer * a_Player,
+ int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
+ int a_CursorX, int a_CursorY, int a_CursorZ,
+ BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
+)
{
ASSERT(m_ItemType < 256); // Items with IDs above 255 should all be handled by specific handlers
- #ifdef _DEBUG
if (m_ItemType > 256)
{
- LOGERROR("Item %d has no valid block!", m_ItemType);
+ LOGERROR("%s: Item %d has no valid block!", __FUNCTION__, m_ItemType);
+ return false;
}
- #endif // _DEBUG
- return (BLOCKTYPE) m_ItemType;
+ cBlockHandler * BlockH = BlockHandler(m_ItemType);
+ return BlockH->GetPlacementBlockTypeMeta(
+ a_World, a_Player,
+ a_BlockX, a_BlockY, a_BlockZ, a_BlockFace,
+ a_CursorX, a_CursorY, a_CursorZ,
+ a_BlockType, a_BlockMeta
+ );
+ a_BlockType = (BLOCKTYPE) m_ItemType;
+ a_BlockMeta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage & 0x0f); // This keeps most textures. The few other items have to override this
+ return true;
}
-NIBBLETYPE cItemHandler::GetBlockMeta(short a_ItemDamage)
-{
- return (NIBBLETYPE)a_ItemDamage & 0x0f; // This keeps most textures. The few other items have to override this
-}
-
-
-
-
-
-void cItemHandler::PlaceBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir)
-{
- BLOCKTYPE Block = GetBlockType();
- cBlockHandler *Handler = cBlockHandler::GetBlockHandler(Block);
- Handler->PlaceBlock(a_World, a_Player, GetBlockMeta(a_Item->m_ItemHealth), a_BlockX, a_BlockY, a_BlockZ, a_Dir);
- if(a_Player->GetGameMode() == eGameMode_Survival)
- {
- cItem Item(a_Item->m_ItemType, 1);
- a_Player->GetInventory().RemoveItem(Item);
- }
-}
-
-
-
-
-
-bool cItemHandler::EatItem(cPlayer *a_Player, cItem *a_Item)
+bool cItemHandler::EatItem(cPlayer * a_Player, cItem * a_Item)
{
FoodInfo Info = GetFoodInfo();
diff --git a/source/Items/ItemHandler.h b/source/Items/ItemHandler.h
index da32ed19e..f03184704 100644
--- a/source/Items/ItemHandler.h
+++ b/source/Items/ItemHandler.h
@@ -1,6 +1,8 @@
#pragma once
+
#include "../Defines.h"
+#include "../Item.h"
@@ -18,13 +20,17 @@ class cItemHandler
{
public:
cItemHandler(int a_ItemType);
- // Called when the player tries to use the item. Return false to make the item unusable. DEFAULT: False
+
+ /// Called when the player tries to use the item. Return false to make the item unusable. DEFAULT: False
virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir); //eg for fishing or hoes
- // Called while the player diggs a block using this item
+
+ /// Called while the player diggs a block using this item
virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, cItem * a_HeldItem, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace);
- // Called when the player destroys a block using this item. This also calls the drop function for the destroyed block
+
+ /// Called when the player destroys a block using this item. This also calls the drop function for the destroyed block
virtual void OnBlockDestroyed(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_X, int a_Y, int a_Z);
- // Called after the player has eaten this item.
+
+ /// Called after the player has eaten this item.
virtual void OnFoodEaten(cWorld *a_World, cPlayer *a_Player, cItem *a_Item);
/// Returns the maximum stack size for a given item
@@ -43,33 +49,39 @@ public:
char PoisionChance; //0 - 100
};
- // Returns the FoodInfo for this item. (FoodRecovery, Saturation and PoisionChance)
+ /// Returns the FoodInfo for this item. (FoodRecovery, Saturation and PoisionChance)
virtual FoodInfo GetFoodInfo();
- // Lets the player eat a selected item. Returns true if the player ate the item
+ /// Lets the player eat a selected item. Returns true if the player ate the item
virtual bool EatItem(cPlayer *a_Player, cItem *a_Item);
- // Places the current block and removes the item from the player inventory
- virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir);
+ /// Indicates if this item is a tool
+ virtual bool IsTool(void);
+
+ /// Indicates if this item is food
+ virtual bool IsFood(void);
- // Indicates if this item is a tool
- virtual bool IsTool();
- // Indicates if this item is food
- virtual bool IsFood();
- //Blocks simply get placed
- virtual bool IsPlaceable();
-
- // Returns the block type on placement
- virtual BLOCKTYPE GetBlockType();
- //Returns the block meta on placement
- virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage);
- // Returns whether this tool/item can harvest a specific block (e.g. wooden pickaxe can harvest stone, but wood canīt) DEFAULT: False
+ /// Blocks simply get placed
+ virtual bool IsPlaceable(void);
+
+ /** Called before a block is placed into a world.
+ The handler should return true to allow placement, false to refuse.
+ Also, the handler should set a_BlockType and a_BlockMeta to correct values for the newly placed block.
+ */
+ virtual bool GetPlacementBlockTypeMeta(
+ cWorld * a_World, cPlayer * a_Player,
+ int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
+ int a_CursorX, int a_CursorY, int a_CursorZ,
+ BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
+ );
+
+ /// Returns whether this tool/item can harvest a specific block (e.g. wooden pickaxe can harvest stone, but wood canīt) DEFAULT: False
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType);
- static cItemHandler *GetItemHandler(int a_ItemType);
+ static cItemHandler * GetItemHandler(int a_ItemType);
+ static cItemHandler * GetItemHandler(const cItem & a_Item) { return GetItemHandler(a_Item.m_ItemType); }
static void Deinit();
-
protected:
int m_ItemType;
diff --git a/source/Items/ItemLeaves.h b/source/Items/ItemLeaves.h
index 053bf6fb0..14d63a630 100644
--- a/source/Items/ItemLeaves.h
+++ b/source/Items/ItemLeaves.h
@@ -10,15 +10,29 @@
class cItemLeavesHandler :
public cItemHandler
{
+ typedef cItemHandler super;
+
public:
cItemLeavesHandler(int a_ItemType)
: cItemHandler(a_ItemType)
{
}
-
- virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage) override
+
+ virtual bool GetPlacementBlockTypeMeta(
+ cWorld * a_World, cPlayer * a_Player,
+ int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
+ int a_CursorX, int a_CursorY, int a_CursorZ,
+ BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
+ ) override
{
- return (NIBBLETYPE)(a_ItemDamage & 0x0f) | 0x4; //0x4 bit set means this is a player-placed leaves block, not to be decayed
+ bool res = super::GetPlacementBlockTypeMeta(
+ a_World, a_Player,
+ a_BlockX, a_BlockY, a_BlockZ, a_BlockFace,
+ a_CursorX, a_CursorY, a_CursorZ,
+ a_BlockType, a_BlockMeta
+ );
+ a_BlockMeta = a_BlockMeta | 0x4; //0x4 bit set means this is a player-placed leaves block, not to be decayed
+ return res;
}
} ;
diff --git a/source/Items/ItemLighter.h b/source/Items/ItemLighter.h
index afa6c4fd5..8c4d068a9 100644
--- a/source/Items/ItemLighter.h
+++ b/source/Items/ItemLighter.h
@@ -1,32 +1,40 @@
+
#pragma once
#include "ItemHandler.h"
#include "../World.h"
#include "../Player.h"
-class cItemLighterHandler : public cItemHandler
+
+
+
+
+class cItemLighterHandler :
+ public cItemHandler
{
public:
- cItemLighterHandler(int a_ItemType)
- : cItemHandler(a_ItemType)
+ cItemLighterHandler(int a_ItemType) :
+ cItemHandler(a_ItemType)
{
-
}
- virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
+ virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) override
{
- if (a_Dir < 0)
+ if (a_BlockFace < 0)
{
return false;
}
a_Player->UseEquippedItem();
- AddDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir);
+ AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_FIRE, 0); //0 -> new fire TODO: Make Firesimulator use this
return false;
}
+} ;
+
+
+
-}; \ No newline at end of file
diff --git a/source/Items/ItemRedstoneDust.h b/source/Items/ItemRedstoneDust.h
index 69e57bab2..4179893d7 100644
--- a/source/Items/ItemRedstoneDust.h
+++ b/source/Items/ItemRedstoneDust.h
@@ -15,19 +15,21 @@ public:
{
}
- virtual bool IsPlaceable() override
+ virtual bool IsPlaceable(void) override
{
return true;
}
- virtual BLOCKTYPE GetBlockType() override
+ virtual bool GetPlacementBlockTypeMeta(
+ cWorld * a_World, cPlayer * a_Player,
+ int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
+ int a_CursorX, int a_CursorY, int a_CursorZ,
+ BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
+ ) override
{
- return E_BLOCK_REDSTONE_WIRE;
- }
-
- virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage) override
- {
- return 0;
+ a_BlockType = E_BLOCK_REDSTONE_WIRE;
+ a_BlockMeta = 0;
+ return true;
}
} ;
diff --git a/source/Items/ItemRedstoneRepeater.h b/source/Items/ItemRedstoneRepeater.h
index b55ebc52e..ce3008d01 100644
--- a/source/Items/ItemRedstoneRepeater.h
+++ b/source/Items/ItemRedstoneRepeater.h
@@ -2,12 +2,14 @@
#pragma once
#include "ItemHandler.h"
+#include "../Simulator/RedstoneSimulator.h"
-class cItemRedstoneRepeaterHandler : public cItemHandler
+class cItemRedstoneRepeaterHandler :
+ public cItemHandler
{
public:
cItemRedstoneRepeaterHandler(int a_ItemType)
@@ -20,14 +22,16 @@ public:
return true;
}
- virtual BLOCKTYPE GetBlockType() override
+ virtual bool GetPlacementBlockTypeMeta(
+ cWorld * a_World, cPlayer * a_Player,
+ int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
+ int a_CursorX, int a_CursorY, int a_CursorZ,
+ BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
+ ) override
{
- return ::E_BLOCK_REDSTONE_REPEATER_OFF;
- }
-
- virtual NIBBLETYPE GetBlockMeta(short a_ItemMeta) override
- {
- return 0;
+ a_BlockType = E_BLOCK_REDSTONE_REPEATER_OFF;
+ a_BlockMeta = cRedstoneSimulator::RepeaterRotationToMetaData(a_Player->GetRotation());
+ return true;
}
} ;
diff --git a/source/Items/ItemSapling.h b/source/Items/ItemSapling.h
index ed635d265..313968ea5 100644
--- a/source/Items/ItemSapling.h
+++ b/source/Items/ItemSapling.h
@@ -9,6 +9,8 @@
class cItemSaplingHandler : public cItemHandler
{
+ typedef cItemHandler super;
+
public:
cItemSaplingHandler(int a_ItemType)
: cItemHandler(a_ItemType)
@@ -16,10 +18,22 @@ public:
}
- virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage) override
+ virtual bool GetPlacementBlockTypeMeta(
+ cWorld * a_World, cPlayer * a_Player,
+ int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
+ int a_CursorX, int a_CursorY, int a_CursorZ,
+ BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
+ ) override
{
+ bool res = super::GetPlacementBlockTypeMeta(
+ a_World, a_Player,
+ a_BlockX, a_BlockY, a_BlockZ, a_BlockFace,
+ a_CursorX, a_CursorY, a_CursorZ,
+ a_BlockType, a_BlockMeta
+ );
// Only the lowest 3 bits are important
- return (NIBBLETYPE)(a_ItemDamage & 0x07);
+ a_BlockMeta = a_BlockMeta & 0x7;
+ return res;
}
} ;
diff --git a/source/Items/ItemSeeds.h b/source/Items/ItemSeeds.h
index f013af3be..d6df8bdd0 100644
--- a/source/Items/ItemSeeds.h
+++ b/source/Items/ItemSeeds.h
@@ -12,54 +12,49 @@ class cItemSeedsHandler :
public cItemHandler
{
public:
- cItemSeedsHandler(int a_ItemType)
- : cItemHandler(a_ItemType)
+ cItemSeedsHandler(int a_ItemType) :
+ cItemHandler(a_ItemType)
{
}
- virtual bool IsPlaceable() override
+ virtual bool IsPlaceable(void) override
{
return true;
}
- virtual BLOCKTYPE GetBlockType() override
+ virtual bool GetPlacementBlockTypeMeta(
+ cWorld * a_World, cPlayer * a_Player,
+ int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
+ int a_CursorX, int a_CursorY, int a_CursorZ,
+ BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
+ ) override
{
- switch(m_ItemType)
- {
- case E_ITEM_SEEDS: return E_BLOCK_CROPS;
- case E_ITEM_MELON_SEEDS: return E_BLOCK_MELON_STEM;
- case E_ITEM_PUMPKIN_SEEDS: return E_BLOCK_PUMPKIN_STEM;
- default: return E_BLOCK_AIR;
- }
- }
-
- virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage) override
- {
- return 0; //Not grown yet
- }
-
-
- virtual void PlaceBlock(cWorld *a_World, cPlayer *a_Player, cItem *a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
- {
- if (a_Dir != BLOCK_FACE_TOP)
+ if (a_BlockFace != BLOCK_FACE_TOP)
{
// Only allow planting seeds from the top side of the block
- return;
+ return false;
}
+ // Only allow placement on farmland
int X = a_BlockX;
int Y = a_BlockY;
int Z = a_BlockZ;
-
- AddDirection(X, Y, Z, a_Dir, true);
-
+ AddFaceDirection(X, Y, Z, a_BlockFace, true);
if (a_World->GetBlock(X, Y, Z) != E_BLOCK_FARMLAND)
{
- return;
+ return false;
}
- return cItemHandler::PlaceBlock(a_World, a_Player, a_Item, a_BlockX, a_BlockY, a_BlockZ, a_Dir);
+ a_BlockMeta = 0;
+ switch (m_ItemType)
+ {
+ case E_ITEM_SEEDS: a_BlockType = E_BLOCK_CROPS; return true;
+ case E_ITEM_MELON_SEEDS: a_BlockType = E_BLOCK_MELON_STEM; return true;
+ case E_ITEM_PUMPKIN_SEEDS: a_BlockType = E_BLOCK_PUMPKIN_STEM; return true;
+ default: a_BlockType = E_BLOCK_AIR; return true;
+ }
+ return false;
}
} ;
diff --git a/source/Items/ItemSign.h b/source/Items/ItemSign.h
index b5593a010..758e08c4d 100644
--- a/source/Items/ItemSign.h
+++ b/source/Items/ItemSign.h
@@ -3,24 +3,49 @@
#include "ItemHandler.h"
#include "../World.h"
+#include "../Sign.h"
-class cItemSignHandler : public cItemHandler
+
+
+
+
+class cItemSignHandler :
+ public cItemHandler
{
public:
- cItemSignHandler(int a_ItemType)
- : cItemHandler(a_ItemType)
+ cItemSignHandler(int a_ItemType) :
+ cItemHandler(a_ItemType)
{
-
}
- virtual bool IsPlaceable() override
+
+ virtual bool IsPlaceable(void) override
{
return true;
}
- virtual BLOCKTYPE GetBlockType() override
+
+ virtual bool GetPlacementBlockTypeMeta(
+ cWorld * a_World, cPlayer * a_Player,
+ int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
+ int a_CursorX, int a_CursorY, int a_CursorZ,
+ BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
+ ) override
{
- return E_BLOCK_SIGN_POST;
+ if (a_BlockFace == BLOCK_FACE_TOP)
+ {
+ a_BlockMeta = cSign::RotationToMetaData(a_Player->GetRotation());
+ a_BlockType = E_BLOCK_SIGN_POST;
+ }
+ else
+ {
+ a_BlockMeta = cSign::DirectionToMetaData(a_BlockFace);
+ a_BlockType = E_BLOCK_WALLSIGN;
+ }
+ return true;
}
+} ;
+
+
+
-}; \ No newline at end of file
diff --git a/source/Items/ItemSlab.h b/source/Items/ItemSlab.h
index 174beae22..42311d54d 100644
--- a/source/Items/ItemSlab.h
+++ b/source/Items/ItemSlab.h
@@ -27,9 +27,9 @@ public:
((a_Dir == 0) || (a_Dir == 1)) // Only when clicking on top or on bottom of the block
&& ((Block == E_BLOCK_WOODEN_SLAB) || (Block == E_BLOCK_STONE_SLAB)) // It is a slab
&& (Block == a_Item->m_ItemType) // Same slab
- && ((Meta & 0x7) == (a_Item->m_ItemHealth & 0x7))) // Same Texture
+ && ((Meta & 0x7) == (a_Item->m_ItemDamage & 0x7))) // Same Texture
{
- if(a_Player->GetGameMode() == eGameMode_Creative)
+ if (a_Player->GetGameMode() == eGameMode_Creative)
{
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, Block - 1, Meta); // Block - 1 simple hack to save one if statement
return true;
diff --git a/source/Items/ItemSpawnEgg.h b/source/Items/ItemSpawnEgg.h
index 33a1e1d55..1557fb59c 100644
--- a/source/Items/ItemSpawnEgg.h
+++ b/source/Items/ItemSpawnEgg.h
@@ -19,23 +19,23 @@ public:
}
- virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
+ virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, cItem * a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) override
{
- if (a_Dir < 0)
+ if (a_BlockFace < 0)
{
return false;
}
- AddDirection(a_BlockX, a_BlockY, a_BlockZ, a_Dir);
+ AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
- if (a_Dir == BLOCK_FACE_BOTTOM)
+ if (a_BlockFace == BLOCK_FACE_BOTTOM)
{
a_BlockY--;
}
if (a_World->SpawnMob(a_BlockX + 0.5, a_BlockY, a_BlockZ + 0.5, a_Item->m_ItemDamage) >= 0)
{
- if(a_Player->GetGameMode() != 1)
+ if (a_Player->GetGameMode() != 1)
{
// The mob was spawned, "use" the item:
a_Player->GetInventory().RemoveItem(a_Player->GetInventory().GetEquippedItem());
diff --git a/source/Items/ItemSugarcane.h b/source/Items/ItemSugarcane.h
index 60b6ff262..9a0875939 100644
--- a/source/Items/ItemSugarcane.h
+++ b/source/Items/ItemSugarcane.h
@@ -2,7 +2,6 @@
#pragma once
#include "ItemHandler.h"
-#include "../World.h"
@@ -12,25 +11,26 @@ class cItemSugarcaneHandler :
public cItemHandler
{
public:
- cItemSugarcaneHandler(int a_ItemType)
- : cItemHandler(a_ItemType)
+ cItemSugarcaneHandler(int a_ItemType) :
+ cItemHandler(a_ItemType)
{
-
}
- virtual bool IsPlaceable() override
+ virtual bool IsPlaceable(void) override
{
return true;
}
- virtual BLOCKTYPE GetBlockType() override
+ virtual bool GetPlacementBlockTypeMeta(
+ cWorld * a_World, cPlayer * a_Player,
+ int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
+ int a_CursorX, int a_CursorY, int a_CursorZ,
+ BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
+ ) override
{
- return E_BLOCK_SUGARCANE;
- }
-
- virtual NIBBLETYPE GetBlockMeta(short a_ItemDamage) override
- {
- return 0; //Not grown yet
+ a_BlockType = E_BLOCK_SUGARCANE;
+ a_BlockMeta = 0;
+ return true;
}
} ;