summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-10-21 22:02:30 +0200
committerMattes D <github@xoft.cz>2014-10-21 22:02:30 +0200
commita42fa071bc3ac1615e7c9b9d59fb4c882cc6097d (patch)
treeecd4214f8c2c11abb7bc0ff87cef26dd79ee6063
parentFixed trailing whitespace. (diff)
downloadcuberite-a42fa071bc3ac1615e7c9b9d59fb4c882cc6097d.tar
cuberite-a42fa071bc3ac1615e7c9b9d59fb4c882cc6097d.tar.gz
cuberite-a42fa071bc3ac1615e7c9b9d59fb4c882cc6097d.tar.bz2
cuberite-a42fa071bc3ac1615e7c9b9d59fb4c882cc6097d.tar.lz
cuberite-a42fa071bc3ac1615e7c9b9d59fb4c882cc6097d.tar.xz
cuberite-a42fa071bc3ac1615e7c9b9d59fb4c882cc6097d.tar.zst
cuberite-a42fa071bc3ac1615e7c9b9d59fb4c882cc6097d.zip
-rw-r--r--src/Bindings/AllToLua.pkg2
-rw-r--r--src/Bindings/CMakeLists.txt2
-rw-r--r--src/Entities/HangingEntity.cpp30
-rw-r--r--src/Entities/HangingEntity.h29
-rw-r--r--src/Entities/ItemFrame.cpp16
-rw-r--r--src/Entities/ItemFrame.h17
-rw-r--r--src/Protocol/Protocol17x.cpp2
-rw-r--r--src/Protocol/Protocol18x.cpp2
-rw-r--r--src/WorldStorage/NBTChunkSerializer.cpp24
-rw-r--r--src/WorldStorage/WSSAnvil.cpp43
10 files changed, 100 insertions, 67 deletions
diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg
index 179e9742f..1bff26b0e 100644
--- a/src/Bindings/AllToLua.pkg
+++ b/src/Bindings/AllToLua.pkg
@@ -41,6 +41,8 @@ $cfile "../Entities/FireChargeEntity.h"
$cfile "../Entities/FireworkEntity.h"
$cfile "../Entities/Floater.h"
$cfile "../Entities/GhastFireballEntity.h"
+$cfile "../Entities/HangingEntity.h"
+$cfile "../Entities/ItemFrame.h"
$cfile "../Entities/Pawn.h"
$cfile "../Entities/Player.h"
$cfile "../Entities/Painting.h"
diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt
index 6880a51dd..d47579cd6 100644
--- a/src/Bindings/CMakeLists.txt
+++ b/src/Bindings/CMakeLists.txt
@@ -82,6 +82,8 @@ set(BINDING_DEPENDENCIES
../Entities/FireworkEntity.h
../Entities/Floater.h
../Entities/GhastFireballEntity.h
+ ../Entities/HangingEntity.h
+ ../Entities/ItemFrame.h
../Entities/Pawn.h
../Entities/Player.h
../Entities/Painting.h
diff --git a/src/Entities/HangingEntity.cpp b/src/Entities/HangingEntity.cpp
index 3276bc4a0..a6b9c40c8 100644
--- a/src/Entities/HangingEntity.cpp
+++ b/src/Entities/HangingEntity.cpp
@@ -9,9 +9,9 @@
-cHangingEntity::cHangingEntity(eEntityType a_EntityType, eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z)
- : cEntity(a_EntityType, a_X, a_Y, a_Z, 0.8, 0.8)
- , m_BlockFace(a_BlockFace)
+cHangingEntity::cHangingEntity(eEntityType a_EntityType, eBlockFace a_Facing, double a_X, double a_Y, double a_Z) :
+ cEntity(a_EntityType, a_X, a_Y, a_Z, 0.8, 0.8),
+ m_Facing(a_Facing)
{
SetMaxHealth(1);
SetHealth(1);
@@ -21,15 +21,23 @@ cHangingEntity::cHangingEntity(eEntityType a_EntityType, eBlockFace a_BlockFace,
-void cHangingEntity::SetDirection(eBlockFace a_BlockFace)
+void cHangingEntity::SetFacing(eBlockFace a_Facing)
{
- if ((a_BlockFace < 2) || (a_BlockFace > 5))
+ // Y-based faces are not allowed:
+ switch (a_Facing)
{
- ASSERT(!"Tried to set a bad direction!");
- return;
+ case BLOCK_FACE_NONE:
+ case BLOCK_FACE_YM:
+ case BLOCK_FACE_YP:
+ {
+ LOGWARNING("%s: Invalid facing: %d. Ignoring.", __FUNCTION__, a_Facing);
+ ASSERT(!"Tried to set a bad facing!");
+ return;
+ }
+ default: break;
}
- m_BlockFace = a_BlockFace;
+ m_Facing = a_Facing;
}
@@ -41,7 +49,7 @@ void cHangingEntity::SpawnOn(cClientHandle & a_ClientHandle)
int Dir = 0;
// The client uses different values for item frame directions and block faces. Our constants are for the block faces, so we convert them here to item frame faces
- switch (m_BlockFace)
+ switch (m_Facing)
{
case BLOCK_FACE_ZP: Dir = 0; break;
case BLOCK_FACE_ZM: Dir = 2; break;
@@ -49,8 +57,8 @@ void cHangingEntity::SpawnOn(cClientHandle & a_ClientHandle)
case BLOCK_FACE_XP: Dir = 3; break;
default:
{
- LOGINFO("Invalid face (%d) in a cHangingEntity at {%d, %d, %d}, adjusting to BLOCK_FACE_XP.",
- m_BlockFace, (int)GetPosX(), (int)GetPosY(), (int)GetPosZ()
+ LOGINFO("Invalid facing (%d) in a cHangingEntity at {%d, %d, %d}, adjusting to BLOCK_FACE_XP.",
+ m_Facing, (int)GetPosX(), (int)GetPosY(), (int)GetPosZ()
);
Dir = 3;
}
diff --git a/src/Entities/HangingEntity.h b/src/Entities/HangingEntity.h
index 1cc0034e1..67146a20b 100644
--- a/src/Entities/HangingEntity.h
+++ b/src/Entities/HangingEntity.h
@@ -11,36 +11,41 @@
class cHangingEntity :
public cEntity
{
- // tolua_end
typedef cEntity super;
public:
+ // tolua_end
+
CLASS_PROTODEF(cHangingEntity)
cHangingEntity(eEntityType a_EntityType, eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z);
- /** Returns the orientation from the hanging entity */
- eBlockFace GetDirection() const { return m_BlockFace; } // tolua_export
+ // tolua_begin
+
+ /** Returns the direction in which the entity is facing. */
+ eBlockFace GetFacing() const { return m_Facing; }
- /** Set the orientation from the hanging entity */
- void SetDirection(eBlockFace a_BlockFace); // tolua_export
+ /** Set the direction in which the entity is facing. */
+ void SetFacing(eBlockFace a_Facing);
- /** Returns the X coord. */
- int GetTileX() const { return POSX_TOINT; } // tolua_export
+ /** Returns the X coord of the block in which the entity resides. */
+ int GetBlockX() const { return POSX_TOINT; }
- /** Returns the Y coord. */
- int GetTileY() const { return POSY_TOINT; } // tolua_export
+ /** Returns the Y coord of the block in which the entity resides. */
+ int GetBlockY() const { return POSY_TOINT; }
- /** Returns the Z coord. */
- int GetTileZ() const { return POSZ_TOINT; } // tolua_export
+ /** Returns the Z coord of the block in which the entity resides. */
+ int GetBlockZ() const { return POSZ_TOINT; }
+
+ // tolua_end
private:
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
virtual void Tick(float a_Dt, cChunk & a_Chunk) override {}
- eBlockFace m_BlockFace;
+ eBlockFace m_Facing;
}; // tolua_export
diff --git a/src/Entities/ItemFrame.cpp b/src/Entities/ItemFrame.cpp
index f512324eb..6704c05b4 100644
--- a/src/Entities/ItemFrame.cpp
+++ b/src/Entities/ItemFrame.cpp
@@ -9,10 +9,10 @@
-cItemFrame::cItemFrame(eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z)
- : cHangingEntity(etItemFrame, a_BlockFace, a_X, a_Y, a_Z)
- , m_Item(E_BLOCK_AIR)
- , m_Rotation(0)
+cItemFrame::cItemFrame(eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z) :
+ cHangingEntity(etItemFrame, a_BlockFace, a_X, a_Y, a_Z),
+ m_Item(E_BLOCK_AIR),
+ m_ItemRotation(0)
{
}
@@ -27,10 +27,10 @@ void cItemFrame::OnRightClicked(cPlayer & a_Player)
if (!m_Item.IsEmpty())
{
// Item not empty, rotate, clipping values to zero to three inclusive
- m_Rotation++;
- if (m_Rotation >= 8)
+ m_ItemRotation++;
+ if (m_ItemRotation >= 8)
{
- m_Rotation = 0;
+ m_ItemRotation = 0;
}
}
else if (!a_Player.GetEquippedItem().IsEmpty())
@@ -72,7 +72,7 @@ void cItemFrame::KilledBy(TakeDamageInfo & a_TDI)
SetHealth(GetMaxHealth());
m_Item.Empty();
- m_Rotation = 0;
+ m_ItemRotation = 0;
SetInvulnerableTicks(0);
GetWorld()->BroadcastEntityMetadata(*this);
}
diff --git a/src/Entities/ItemFrame.h b/src/Entities/ItemFrame.h
index a63b78b70..3642662f9 100644
--- a/src/Entities/ItemFrame.h
+++ b/src/Entities/ItemFrame.h
@@ -11,26 +11,31 @@
class cItemFrame :
public cHangingEntity
{
- // tolua_end
typedef cHangingEntity super;
public:
+ // tolua_end
+
CLASS_PROTODEF(cItemFrame)
cItemFrame(eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z);
+ // tolua_begin
+
/** Returns the item in the frame */
- const cItem & GetItem(void) { return m_Item; } // tolua_export
+ const cItem & GetItem(void) { return m_Item; }
/** Set the item in the frame */
- void SetItem(cItem & a_Item) { m_Item = a_Item; } // tolua_export
+ void SetItem(cItem & a_Item) { m_Item = a_Item; }
/** Returns the rotation from the item in the frame */
- Byte GetRotation(void) const { return m_Rotation; } // tolua_export
+ Byte GetItemRotation(void) const { return m_ItemRotation; }
/** Set the rotation from the item in the frame */
- void SetRotation(Byte a_Rotation) { m_Rotation = a_Rotation; } // tolua_export
+ void SetRotation(Byte a_ItemRotation) { m_ItemRotation = a_ItemRotation; }
+
+ // tolua_end
private:
@@ -39,7 +44,7 @@ private:
virtual void GetDrops(cItems & a_Items, cEntity * a_Killer) override;
cItem m_Item;
- Byte m_Rotation;
+ Byte m_ItemRotation;
}; // tolua_export
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 204691ede..f4779d83b 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -2803,7 +2803,7 @@ void cProtocol172::cPacketizer::WriteEntityMetadata(const cEntity & a_Entity)
WriteByte(0xA2);
WriteItem(Frame.GetItem());
WriteByte(0x3);
- WriteByte(Frame.GetRotation() / 2);
+ WriteByte(Frame.GetItemRotation() / 2);
break;
}
default: break;
diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp
index c9118c239..39046e2ed 100644
--- a/src/Protocol/Protocol18x.cpp
+++ b/src/Protocol/Protocol18x.cpp
@@ -3109,7 +3109,7 @@ void cProtocol180::cPacketizer::WriteEntityMetadata(const cEntity & a_Entity)
WriteByte(0xA8);
WriteItem(Frame.GetItem());
WriteByte(0x09);
- WriteByte(Frame.GetRotation());
+ WriteByte(Frame.GetItemRotation());
break;
}
default: break;
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index 28b9dd042..80d9ab6d2 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -685,21 +685,21 @@ void cNBTChunkSerializer::AddProjectileEntity(cProjectileEntity * a_Projectile)
void cNBTChunkSerializer::AddHangingEntity(cHangingEntity * a_Hanging)
{
- m_Writer.AddByte("Direction", (unsigned char)a_Hanging->GetDirection());
- m_Writer.AddInt("TileX", a_Hanging->GetTileX());
- m_Writer.AddInt("TileY", a_Hanging->GetTileY());
- m_Writer.AddInt("TileZ", a_Hanging->GetTileZ());
- switch (a_Hanging->GetDirection())
+ m_Writer.AddInt("TileX", a_Hanging->GetBlockX());
+ m_Writer.AddInt("TileY", a_Hanging->GetBlockY());
+ m_Writer.AddInt("TileZ", a_Hanging->GetBlockZ());
+ switch (a_Hanging->GetFacing())
{
- case BLOCK_FACE_YM: m_Writer.AddByte("Dir", (unsigned char)2); break;
- case BLOCK_FACE_YP: m_Writer.AddByte("Dir", (unsigned char)1); break;
- case BLOCK_FACE_ZM: m_Writer.AddByte("Dir", (unsigned char)0); break;
- case BLOCK_FACE_ZP: m_Writer.AddByte("Dir", (unsigned char)3); break;
+ case BLOCK_FACE_XM: m_Writer.AddByte("Facing", 1); break;
+ case BLOCK_FACE_XP: m_Writer.AddByte("Facing", 3); break;
+ case BLOCK_FACE_ZM: m_Writer.AddByte("Facing", 2); break;
+ case BLOCK_FACE_ZP: m_Writer.AddByte("Facing", 0); break;
- case BLOCK_FACE_XM:
- case BLOCK_FACE_XP:
+ case BLOCK_FACE_YM:
+ case BLOCK_FACE_YP:
case BLOCK_FACE_NONE:
{
+ // These directions are invalid, but they may have been previously loaded, so keep them.
break;
}
}
@@ -740,7 +740,7 @@ void cNBTChunkSerializer::AddItemFrameEntity(cItemFrame * a_ItemFrame)
AddBasicEntity(a_ItemFrame, "ItemFrame");
AddHangingEntity(a_ItemFrame);
AddItem(a_ItemFrame->GetItem(), -1, "Item");
- m_Writer.AddByte("ItemRotation", (unsigned char)a_ItemFrame->GetRotation());
+ m_Writer.AddByte("ItemRotation", (unsigned char)a_ItemFrame->GetItemRotation());
m_Writer.AddFloat("ItemDropChance", 1.0F);
m_Writer.EndCompound();
}
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index 092b9514c..eba21c659 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -1660,30 +1660,41 @@ void cWSSAnvil::LoadExpOrbFromNBT(cEntityList & a_Entities, const cParsedNBT & a
void cWSSAnvil::LoadHangingFromNBT(cHangingEntity & a_Hanging, const cParsedNBT & a_NBT, int a_TagIdx)
{
- int Direction = a_NBT.FindChildByName(a_TagIdx, "Direction");
- if (Direction > 0)
+ // "Facing" tag is the prime source of the Facing; if not available, translate from older "Direction" or "Dir"
+ int Facing = a_NBT.FindChildByName(a_TagIdx, "Facing");
+ if (Facing > 0)
{
- Direction = (int)a_NBT.GetByte(Direction);
- if ((Direction < 2) || (Direction > 5))
+ Facing = (int)a_NBT.GetByte(Facing);
+ if ((Facing >= 2) && (Facing <= 5))
{
- a_Hanging.SetDirection(BLOCK_FACE_NORTH);
- }
- else
- {
- a_Hanging.SetDirection(static_cast<eBlockFace>(Direction));
+ a_Hanging.SetFacing(static_cast<eBlockFace>(Facing));
}
}
else
{
- Direction = a_NBT.FindChildByName(a_TagIdx, "Dir");
- if (Direction > 0)
+ Facing = a_NBT.FindChildByName(a_TagIdx, "Direction");
+ if (Facing > 0)
+ {
+ switch ((int)a_NBT.GetByte(Facing))
+ {
+ case 0: a_Hanging.SetFacing(BLOCK_FACE_ZM); break;
+ case 1: a_Hanging.SetFacing(BLOCK_FACE_XM); break;
+ case 2: a_Hanging.SetFacing(BLOCK_FACE_ZP); break;
+ case 3: a_Hanging.SetFacing(BLOCK_FACE_XP); break;
+ }
+ }
+ else
{
- switch ((int)a_NBT.GetByte(Direction))
+ Facing = a_NBT.FindChildByName(a_TagIdx, "Dir"); // Has values 0 and 2 swapped
+ if (Facing > 0)
{
- case 0: a_Hanging.SetDirection(BLOCK_FACE_NORTH); break;
- case 1: a_Hanging.SetDirection(BLOCK_FACE_TOP); break;
- case 2: a_Hanging.SetDirection(BLOCK_FACE_BOTTOM); break;
- case 3: a_Hanging.SetDirection(BLOCK_FACE_SOUTH); break;
+ switch ((int)a_NBT.GetByte(Facing))
+ {
+ case 0: a_Hanging.SetFacing(BLOCK_FACE_ZP); break;
+ case 1: a_Hanging.SetFacing(BLOCK_FACE_XM); break;
+ case 2: a_Hanging.SetFacing(BLOCK_FACE_ZM); break;
+ case 3: a_Hanging.SetFacing(BLOCK_FACE_XP); break;
+ }
}
}
}