5 #include "../Entities/Player.h" 6 #include "../FastRandom.h" 7 #include "../BlockInServerPluginInterface.h" 61 #include "../Blocks/BlockHandler.h" 341 int a_BlockX,
int a_BlockY,
int a_BlockZ,
eBlockFace a_BlockFace,
342 int a_CursorX,
int a_CursorY,
int a_CursorZ
360 a_World.
GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, ClickedBlock, ClickedBlockMeta);
365 Vector3i absPos(a_BlockX, a_BlockY, a_BlockZ);
366 if (blockHandler->DoesIgnoreBuildCollision(ChunkInterface, absPos, a_Player, ClickedBlockMeta))
382 a_World.
GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, PlaceBlock, PlaceMeta);
386 if (!
BlockHandler(PlaceBlock)->DoesIgnoreBuildCollision(ChunkInterface, { a_BlockX, a_BlockY, a_BlockZ }, a_Player, PlaceMeta))
396 if (!
GetBlocksToPlace(a_World, a_Player, a_EquippedItem, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, blocks))
399 for (
const auto & blk: blocks)
401 a_World.
SendBlockTo(blk.GetX(), blk.GetY(), blk.GetZ(), a_Player);
403 a_World.
SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
430 int a_BlockX,
int a_BlockY,
int a_BlockZ,
eBlockFace a_BlockFace,
431 int a_CursorX,
int a_CursorY,
int a_CursorZ,
437 if (!
GetPlacementBlockTypeMeta(&a_World, &a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta))
441 a_BlocksToSet.emplace_back(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta);
451 int a_BlockX,
int a_BlockY,
int a_BlockZ,
eBlockFace a_BlockFace
456 UNUSED(a_PluginInterface);
767 default:
return true;
777 int a_BlockX,
int a_BlockY,
int a_BlockZ,
eBlockFace a_BlockFace,
778 int a_CursorX,
int a_CursorY,
int a_CursorZ,
786 LOGERROR(
"%s: Item %d is not eligible for direct block placement!", __FUNCTION__,
m_ItemType);
793 ChunkInterface, *a_Player,
794 a_BlockX, a_BlockY, a_BlockZ, a_BlockFace,
795 a_CursorX, a_CursorY, a_CursorZ,
796 a_BlockType, a_BlockMeta
static bool m_HandlerInitialized
cItemHandler(int a_ItemType)
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType)
Returns whether this tool / item can harvest a specific block (e.g.
virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, cBlockPluginInterface &a_PluginInterface, const cItem &a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace)
Called when the player tries to use the item (right mouse button).
unsigned char BLOCKTYPE
The datatype used by blockdata.
bool RemoveOneEquippedItem(void)
Removes one item out of the currently equipped item stack, returns true if successful, false if empty-handed.
static cItemHandler * CreateItemHandler(int m_ItemType)
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block)
Returns the strength to break a specific block.
virtual char GetMaxStackSize(void)
Returns the maximum stack size for a given item.
virtual bool CanRepairWithRawMaterial(short a_ItemType)
Can the anvil repair this item, when a_Item is the second input?
static cItemHandler * GetItemHandler(int a_ItemType)
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action)
Get the durability lost which the item will get, when a specified action was performed.
virtual bool GetBlocksToPlace(cWorld &a_World, cPlayer &a_Player, const cItem &a_EquippedItem, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, sSetBlockVector &a_BlocksToSet)
Called from OnPlayerPlace() to determine the blocks that the current placement operation should set...
virtual bool GetPlacementBlockTypeMeta(cChunkInterface &a_ChunkInterface, cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta)
Called before a block is placed into a world.
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
bool DropBlockAsPickups(Vector3i a_BlockPos, const cEntity *a_Digger=nullptr, const cItem *a_Tool=nullptr)
Digs the specified block, and spawns the appropriate pickups for it.
virtual bool OnDiggingBlock(cWorld *a_World, cPlayer *a_Player, const cItem &a_HeldItem, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace)
Called while the player digs a block using this item.
void LOGERROR(const char *a_Format, fmt::ArgList a_ArgList)
virtual void OnFoodEaten(cWorld *a_World, cPlayer *a_Player, cItem *a_Item)
Called after the player has eaten this item.
bool PlaceBlocks(const sSetBlockVector &a_Blocks)
Calls the block placement hooks and places the blocks in the world.
This interface is used to decouple block handlers from the cPluginManager dependency through cWorld...
void AddFaceDirection(int &a_BlockX, int &a_BlockY, int &a_BlockZ, eBlockFace a_BlockFace, bool a_bInverse=false)
void SendEquippedSlot()
Sends the equipped item slot to the client.
bool GetBlockTypeMeta(Vector3i a_BlockPos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta)
Retrieves the block type and meta at the specified coords.
virtual FoodInfo GetFoodInfo(const cItem *a_Item)
Returns the FoodInfo for this item.
static cItemHandler * m_ItemHandler[E_ITEM_LAST+1]
virtual bool IsTool(void)
Indicates if this item is a tool.
virtual bool OnPlayerPlace(cWorld &a_World, cPlayer &a_Player, const cItem &a_EquippedItem, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
Called when the player tries to place the item (right mouse button, IsPlaceable() == true)...
bool Feed(int a_Food, double a_Saturation)
Adds to FoodLevel and FoodSaturationLevel, returns true if any food has been consumed, false if player "full".
virtual bool GetPlacementBlockTypeMeta(cWorld *a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta)
Called when the player right-clicks with this item and IsPlaceable() == true, and OnPlayerPlace() is ...
cBlockHandler * BlockHandler(BLOCKTYPE a_BlockType)
cChunkMap * GetChunkMap(void)
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
virtual bool IsPlaceable(void)
Blocks simply get placed.
bool IsGameModeSurvival(void) const
Returns true if the player is in Survival mode, either explicitly, or by inheriting from current worl...
Maximum BlockType number used.
virtual bool IsDrinkable(short a_ItemDamage)
Indicates if this item is drinkable.
void UseEquippedItem(short a_Damage=1)
Damage the player's equipped item by a_Damage, possibly less if the equipped item is enchanted...
virtual void OnEntityAttack(cPlayer *a_Attacker, cEntity *a_AttackedEntity)
Called when a player attacks a other entity.
cInventory & GetInventory(void)
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
eDurabilityLostAction
Actions that may cause durability of an item may be lost, where the magnitude of the loss depends on ...
virtual bool IsFood(void)
Indicates if this item is food.
std::vector< sSetBlock > sSetBlockVector
virtual void SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer &a_Player) override
Sends the block on those coords to the player.
virtual bool EatItem(cPlayer *a_Player, cItem *a_Item)
Lets the player eat a selected item.