From daf5127b28f3c6884e94fc066b3e5e117a6b5d35 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 25 Sep 2014 18:37:24 +0200 Subject: Fixed hanging direction bugs. --- src/Entities/HangingEntity.cpp | 15 +++++++++++++++ src/Entities/HangingEntity.h | 2 +- src/WorldStorage/WSSAnvil.cpp | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Entities/HangingEntity.cpp b/src/Entities/HangingEntity.cpp index 8c70c606e..e789f5f18 100644 --- a/src/Entities/HangingEntity.cpp +++ b/src/Entities/HangingEntity.cpp @@ -21,6 +21,21 @@ cHangingEntity::cHangingEntity(eEntityType a_EntityType, eBlockFace a_BlockFace, +void cHangingEntity::SetDirection(eBlockFace a_BlockFace) +{ + if ((a_BlockFace < 2) || (a_BlockFace > 5)) + { + ASSERT(!"Tried to set a bad direction!"); + return; + } + + m_BlockFace = a_BlockFace; +} + + + + + void cHangingEntity::SpawnOn(cClientHandle & a_ClientHandle) { int Dir = 0; diff --git a/src/Entities/HangingEntity.h b/src/Entities/HangingEntity.h index 3593f9ede..455f2f23f 100644 --- a/src/Entities/HangingEntity.h +++ b/src/Entities/HangingEntity.h @@ -24,7 +24,7 @@ public: eBlockFace GetDirection() const { return m_BlockFace; } // tolua_export /** Set the orientation from the hanging entity */ - void SetDirection(eBlockFace a_BlockFace) { m_BlockFace = a_BlockFace; } // tolua_export + void SetDirection(eBlockFace a_BlockFace); // tolua_export /** Returns the X coord. */ int GetTileX() const { return POSX_TOINT; } // tolua_export diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index bd814e2c7..7a9490cd4 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1664,7 +1664,7 @@ void cWSSAnvil::LoadHangingFromNBT(cHangingEntity & a_Hanging, const cParsedNBT if (Direction > 0) { Direction = (int)a_NBT.GetByte(Direction); - if ((Direction < 0) || (Direction > 5)) + if ((Direction < 2) || (Direction > 5)) { a_Hanging.SetDirection(BLOCK_FACE_NORTH); } -- cgit v1.2.3 From 67fe834499b2f0f93cdba1132a80ccb1924e199c Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 25 Sep 2014 18:37:36 +0200 Subject: Fixed dispender direction bug --- src/BlockEntities/DispenserEntity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index c02c68afa..f8830bf25 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -203,7 +203,7 @@ void cDispenserEntity::SpawnProjectileFromDispenser(int a_BlockX, int a_BlockY, Vector3d cDispenserEntity::GetShootVector(NIBBLETYPE a_Meta) { - switch (a_Meta) + switch (a_Meta & 0x7) { case E_META_DROPSPENSER_FACING_YP: return Vector3d( 0, 1, 0); case E_META_DROPSPENSER_FACING_YM: return Vector3d( 0, -1, 0); -- cgit v1.2.3 From 12621e3800ec353bca179243d521580e0da6eae9 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 25 Sep 2014 18:49:55 +0200 Subject: Use the json writer to write sign texts. Without this change the client disconnects if the text contains " --- src/Protocol/Protocol18x.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp index f62d350fe..a92ab5f54 100644 --- a/src/Protocol/Protocol18x.cpp +++ b/src/Protocol/Protocol18x.cpp @@ -1391,13 +1391,18 @@ void cProtocol180::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) void cProtocol180::SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) { ASSERT(m_State == 3); // In game mode? - + cPacketizer Pkt(*this, 0x33); Pkt.WritePosition(a_BlockX, a_BlockY, a_BlockZ); - Pkt.WriteString(Printf("{\"text\": \"%s\"}", a_Line1.c_str())); - Pkt.WriteString(Printf("{\"text\": \"%s\"}", a_Line2.c_str())); - Pkt.WriteString(Printf("{\"text\": \"%s\"}", a_Line3.c_str())); - Pkt.WriteString(Printf("{\"text\": \"%s\"}", a_Line4.c_str())); + + Json::StyledWriter JsonWriter; + AString Lines[] = { a_Line1, a_Line2, a_Line3, a_Line4 }; + for (size_t i = 0; i < ARRAYCOUNT(Lines); i++) + { + Json::Value RootValue; + RootValue["text"] = Lines[i]; + Pkt.WriteString(JsonWriter.write(RootValue).c_str()); + } } -- cgit v1.2.3 From 7cdcf0a8833b56a98d60a87a341607fed988cac7 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 25 Sep 2014 19:01:44 +0200 Subject: Anvil: Arrow Tile tags are a short in Vanilla --- src/WorldStorage/NBTChunkSerializer.cpp | 6 +++--- src/WorldStorage/WSSAnvil.cpp | 25 +++++++++++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 08ed893f5..849e9eb77 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -637,9 +637,9 @@ void cNBTChunkSerializer::AddProjectileEntity(cProjectileEntity * a_Projectile) { cArrowEntity * Arrow = (cArrowEntity *)a_Projectile; - m_Writer.AddInt("xTile", (Int16)Arrow->GetBlockHit().x); - m_Writer.AddInt("yTile", (Int16)Arrow->GetBlockHit().y); - m_Writer.AddInt("zTile", (Int16)Arrow->GetBlockHit().z); + m_Writer.AddShort("xTile", (Int16)Arrow->GetBlockHit().x); + m_Writer.AddShort("yTile", (Int16)Arrow->GetBlockHit().y); + m_Writer.AddShort("zTile", (Int16)Arrow->GetBlockHit().z); m_Writer.AddByte("pickup", Arrow->GetPickupState()); m_Writer.AddDouble("damage", Arrow->GetDamageCoeff()); break; diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 7a9490cd4..092b9514c 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1752,7 +1752,7 @@ void cWSSAnvil::LoadArrowFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ // Load pickup state: int PickupIdx = a_NBT.FindChildByName(a_TagIdx, "pickup"); - if (PickupIdx > 0) + if ((PickupIdx > 0) && (a_NBT.GetType(PickupIdx) == TAG_Byte)) { Arrow->SetPickupState((cArrowEntity::ePickupState)a_NBT.GetByte(PickupIdx)); } @@ -1760,7 +1760,7 @@ void cWSSAnvil::LoadArrowFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { // Try the older "player" tag: int PlayerIdx = a_NBT.FindChildByName(a_TagIdx, "player"); - if (PlayerIdx > 0) + if ((PlayerIdx > 0) && (a_NBT.GetType(PlayerIdx) == TAG_Byte)) { Arrow->SetPickupState((a_NBT.GetByte(PlayerIdx) == 0) ? cArrowEntity::psNoPickup : cArrowEntity::psInSurvivalOrCreative); } @@ -1768,7 +1768,7 @@ void cWSSAnvil::LoadArrowFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ // Load damage: int DamageIdx = a_NBT.FindChildByName(a_TagIdx, "damage"); - if (DamageIdx > 0) + if ((DamageIdx > 0) && (a_NBT.GetType(DamageIdx) == TAG_Double)) { Arrow->SetDamageCoeff(a_NBT.GetDouble(DamageIdx)); } @@ -1779,7 +1779,24 @@ void cWSSAnvil::LoadArrowFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ int InBlockZIdx = a_NBT.FindChildByName(a_TagIdx, "zTile"); if ((InBlockXIdx > 0) && (InBlockYIdx > 0) && (InBlockZIdx > 0)) { - Arrow->SetBlockHit(Vector3i(a_NBT.GetInt(InBlockXIdx), a_NBT.GetInt(InBlockYIdx), a_NBT.GetInt(InBlockZIdx))); + if (a_NBT.GetType(InBlockXIdx) == a_NBT.GetType(InBlockYIdx) == a_NBT.GetType(InBlockZIdx)) + { + switch (a_NBT.GetType(InBlockXIdx)) + { + case TAG_Int: + { + // Old MCS code used this, keep reading it for compatibility reasons: + Arrow->SetBlockHit(Vector3i(a_NBT.GetInt(InBlockXIdx), a_NBT.GetInt(InBlockYIdx), a_NBT.GetInt(InBlockZIdx))); + break; + } + case TAG_Short: + { + // Vanilla uses this + Arrow->SetBlockHit(Vector3i((int)a_NBT.GetShort(InBlockXIdx), (int)a_NBT.GetShort(InBlockYIdx), (int)a_NBT.GetShort(InBlockZIdx))); + break; + } + } + } } // Store the new arrow in the entities list: -- cgit v1.2.3 From 060ac500fcd369814d43100549e3d8b0ab51304d Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 25 Sep 2014 19:19:30 +0200 Subject: Fixed wrong Surrounding size --- src/Mobs/Villager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index 1cdac7c74..0efd5501e 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -109,11 +109,11 @@ void cVillager::HandleFarmerPrepareFarmCrops() Surrounding.Read( m_World, (int) GetPosX() - 5, - (int) GetPosX() + 5, + (int) GetPosX() + 6, (int) GetPosY() - 3, - (int) GetPosY() + 3, + (int) GetPosY() + 4, (int) GetPosZ() - 5, - (int) GetPosZ() + 5 + (int) GetPosZ() + 6 ); for (int I = 0; I < 5; I++) -- cgit v1.2.3 From 050b28741bbc503170679d5d3e91000f06f4d6ea Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 25 Sep 2014 19:28:11 +0200 Subject: Comment style --- src/Entities/HangingEntity.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Entities/HangingEntity.h b/src/Entities/HangingEntity.h index 455f2f23f..1cc0034e1 100644 --- a/src/Entities/HangingEntity.h +++ b/src/Entities/HangingEntity.h @@ -24,7 +24,7 @@ public: eBlockFace GetDirection() const { return m_BlockFace; } // tolua_export /** Set the orientation from the hanging entity */ - void SetDirection(eBlockFace a_BlockFace); // tolua_export + void SetDirection(eBlockFace a_BlockFace); // tolua_export /** Returns the X coord. */ int GetTileX() const { return POSX_TOINT; } // tolua_export -- cgit v1.2.3