summaryrefslogtreecommitdiffstats
path: root/src/Items/ItemMobHead.h
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2020-04-21 22:19:22 +0200
committerGitHub <noreply@github.com>2020-04-21 22:19:22 +0200
commit487f9a2aa9b5497495cef1ac3b9c7a603e69f862 (patch)
tree054a846942f414060e29c72f4a717c8a89e70893 /src/Items/ItemMobHead.h
parentDelet SpawnObject params (diff)
downloadcuberite-487f9a2aa9b5497495cef1ac3b9c7a603e69f862.tar
cuberite-487f9a2aa9b5497495cef1ac3b9c7a603e69f862.tar.gz
cuberite-487f9a2aa9b5497495cef1ac3b9c7a603e69f862.tar.bz2
cuberite-487f9a2aa9b5497495cef1ac3b9c7a603e69f862.tar.lz
cuberite-487f9a2aa9b5497495cef1ac3b9c7a603e69f862.tar.xz
cuberite-487f9a2aa9b5497495cef1ac3b9c7a603e69f862.tar.zst
cuberite-487f9a2aa9b5497495cef1ac3b9c7a603e69f862.zip
Diffstat (limited to '')
-rw-r--r--src/Items/ItemMobHead.h61
1 files changed, 44 insertions, 17 deletions
diff --git a/src/Items/ItemMobHead.h b/src/Items/ItemMobHead.h
index d732327a5..036893c15 100644
--- a/src/Items/ItemMobHead.h
+++ b/src/Items/ItemMobHead.h
@@ -22,52 +22,60 @@ public:
}
+
+
+
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
+ cWorld & a_World,
+ cPlayer & a_Player,
+ const cItem & a_EquippedItem,
+ const Vector3i a_ClickedBlockPos,
+ eBlockFace a_ClickedBlockFace,
+ const Vector3i a_CursorPos
) override
{
// Cannot place a head at "no face" and from the bottom:
- if ((a_BlockFace == BLOCK_FACE_NONE) || (a_BlockFace == BLOCK_FACE_BOTTOM))
+ if ((a_ClickedBlockFace == BLOCK_FACE_NONE) || (a_ClickedBlockFace == BLOCK_FACE_BOTTOM))
{
return true;
}
- auto placedX = a_BlockX, placedY = a_BlockY, placedZ = a_BlockZ;
- AddFaceDirection(placedY, placedY, placedZ, a_BlockFace);
+ const auto PlacePos = AddFaceDirection(a_ClickedBlockPos, a_ClickedBlockFace);
// If the placed head is a wither, try to spawn the wither first:
if (a_EquippedItem.m_ItemDamage == E_META_HEAD_WITHER)
{
- if (TrySpawnWitherAround(a_World, a_Player, {placedX, placedY, placedZ}))
+ if (TrySpawnWitherAround(a_World, a_Player, PlacePos))
{
return true;
}
// Wither not created, proceed with regular head placement
}
- cItem itemCopy(a_EquippedItem); // Make a copy in case this is the player's last head item and OnPlayerPlace removes it
- if (!Super::OnPlayerPlace(a_World, a_Player, a_EquippedItem, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ))
+ cItem ItemCopy(a_EquippedItem); // Make a copy in case this is the player's last head item and OnPlayerPlace removes it
+ if (!Super::OnPlayerPlace(a_World, a_Player, a_EquippedItem, a_ClickedBlockPos, a_ClickedBlockFace, a_CursorPos))
{
return false;
}
- RegularHeadPlaced(a_World, a_Player, itemCopy, placedX, placedY, placedZ, a_BlockFace);
+ RegularHeadPlaced(a_World, a_Player, ItemCopy, PlacePos, a_ClickedBlockFace);
return true;
}
+
+
+
/** Called after placing a regular head block with no mob spawning.
Adjusts the mob head entity based on the equipped item's data. */
void RegularHeadPlaced(
cWorld & a_World, cPlayer & a_Player, const cItem & a_EquippedItem,
- int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace
+ const Vector3i a_PlacePos, eBlockFace a_ClickedBlockFace
)
{
auto HeadType = static_cast<eMobHeadType>(a_EquippedItem.m_ItemDamage);
- auto BlockMeta = static_cast<NIBBLETYPE>(a_BlockFace);
+ auto BlockMeta = static_cast<NIBBLETYPE>(a_ClickedBlockFace);
// Use a callback to set the properties of the mob head block entity:
- a_World.DoWithBlockEntityAt(a_BlockX, a_BlockY, a_BlockZ, [&](cBlockEntity & a_BlockEntity)
+ a_World.DoWithBlockEntityAt(a_PlacePos.x, a_PlacePos.y, a_PlacePos.z, [&](cBlockEntity & a_BlockEntity)
{
if (a_BlockEntity.GetBlockType() != E_BLOCK_HEAD)
{
@@ -90,11 +98,14 @@ public:
}
+
+
+
/** Spawns a wither if the wither skull placed at the specified coords completes wither's spawning formula.
Returns true if the wither was created. */
bool TrySpawnWitherAround(
cWorld & a_World, cPlayer & a_Player,
- Vector3i a_BlockPos
+ const Vector3i a_BlockPos
)
{
// No wither can be created at Y < 2 - not enough space for the formula:
@@ -183,6 +194,9 @@ public:
}
+
+
+
/** Tries to spawn a wither from the specified image at the specified offset from the placed head block.
PlacedHead coords are used to override the block query - at those coords the block is not queried from the world,
but assumed to be a head instead.
@@ -265,6 +279,9 @@ public:
}
+
+
+
/** Awards the achievement to all players close to the specified point. */
void AwardSpawnWitherAchievement(cWorld & a_World, Vector3i a_BlockPos)
{
@@ -283,6 +300,9 @@ public:
}
+
+
+
/** Converts the block face of the placement (which face of the block was clicked to place the head)
into the block's metadata value. */
static NIBBLETYPE BlockFaceToBlockMeta(int a_BlockFace)
@@ -303,21 +323,28 @@ public:
}
+
+
+
virtual bool IsPlaceable(void) override
{
return true;
}
+
+
+
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,
+ const Vector3i a_PlacedBlockPos,
+ eBlockFace a_ClickedBlockFace,
+ const Vector3i a_CursorPos,
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
) override
{
a_BlockType = E_BLOCK_HEAD;
- a_BlockMeta = BlockFaceToBlockMeta(a_BlockFace);
+ a_BlockMeta = BlockFaceToBlockMeta(a_ClickedBlockFace);
return true;
}
} ;