From 6ff375273bf757da7c464f6b6a2b0d475a76f370 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 12 Jan 2014 14:33:32 +0100 Subject: Added cWorld::SpawnMinecart. --- src/World.cpp | 24 ++++++++++++++++++++++++ src/World.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/src/World.cpp b/src/World.cpp index 1cf82d641..b5599c660 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -16,6 +16,7 @@ // Entities (except mobs): #include "Entities/ExpOrb.h" #include "Entities/FallingBlock.h" +#include "Entities/Minecart.h" #include "Entities/Pickup.h" #include "Entities/Player.h" #include "Entities/TNTEntity.h" @@ -1647,6 +1648,29 @@ int cWorld::SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward) +int cWorld::SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType) +{ + cMinecart * Minecart; + switch (a_MinecartType) + { + case E_ITEM_MINECART: Minecart = new cEmptyMinecart (a_X, a_Y, a_Z); break; + case E_ITEM_CHEST_MINECART: Minecart = new cMinecartWithChest (a_X, a_Y, a_Z); break; + case E_ITEM_FURNACE_MINECART: Minecart = new cMinecartWithFurnace (a_X, a_Y, a_Z); break; + case E_ITEM_MINECART_WITH_TNT: Minecart = new cMinecartWithTNT (a_X, a_Y, a_Z); break; + case E_ITEM_MINECART_WITH_HOPPER: Minecart = new cMinecartWithHopper (a_X, a_Y, a_Z); break; + default: + { + ASSERT(!"Unhandled minecart item"); + return -1; + } + } // switch (a_MinecartType) + Minecart->Initialize(this); +} + + + + + void cWorld::SpawnPrimedTNT(double a_X, double a_Y, double a_Z, double a_FuseTimeInSec, double a_InitialVelocityCoeff) { UNUSED(a_InitialVelocityCoeff); diff --git a/src/World.h b/src/World.h index b61708d03..89a236b62 100644 --- a/src/World.h +++ b/src/World.h @@ -363,6 +363,9 @@ public: /// Spawns an falling block entity at the given position. It returns the UniqueID of the spawned falling block. int SpawnFallingBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE BlockType, NIBBLETYPE BlockMeta); + /// Spawns an minecart at the given coordinates. + int SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType); + /// Spawns an experience orb at the given location with the given reward. It returns the UniqueID of the spawned experience orb. int SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward); -- cgit v1.2.3 From c5603ce064d7e4e897aa92d6f43d407802ae3687 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 12 Jan 2014 15:27:50 +0100 Subject: EmptyMinecarts should be able to get a block inside of them. --- src/Entities/Minecart.cpp | 6 ++++-- src/Entities/Minecart.h | 8 +++++++- src/Items/ItemMinecart.h | 2 +- src/Protocol/Protocol17x.cpp | 17 ++++++++++++++++- src/World.cpp | 6 +++--- src/World.h | 2 +- src/WorldStorage/WSSAnvil.cpp | 2 +- 7 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index f75e23d8b..5a9217c9e 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -413,8 +413,10 @@ void cMinecart::DoTakeDamage(TakeDamageInfo & TDI) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cEmptyMinecart: -cEmptyMinecart::cEmptyMinecart(double a_X, double a_Y, double a_Z) : - super(mpNone, a_X, a_Y, a_Z) +cEmptyMinecart::cEmptyMinecart(double a_X, double a_Y, double a_Z, const cItem & a_Content, int a_Height) : + super(mpNone, a_X, a_Y, a_Z), + m_Content(a_Content), + m_Height(a_Height) { } diff --git a/src/Entities/Minecart.h b/src/Entities/Minecart.h index b1b48be4e..87d375c68 100644 --- a/src/Entities/Minecart.h +++ b/src/Entities/Minecart.h @@ -77,10 +77,16 @@ class cEmptyMinecart : public: CLASS_PROTODEF(cEmptyMinecart); - cEmptyMinecart(double a_X, double a_Y, double a_Z); + cEmptyMinecart(double a_X, double a_Y, double a_Z, const cItem & a_Content, int a_Height); + cItem GetContent(void) const {return m_Content;} + int GetBlockHeight(void) const {return m_Height;} // cEntity overrides: virtual void OnRightClicked(cPlayer & a_Player) override; +protected: + + const cItem & m_Content; + int m_Height; } ; diff --git a/src/Items/ItemMinecart.h b/src/Items/ItemMinecart.h index f8eb31a49..b82779026 100644 --- a/src/Items/ItemMinecart.h +++ b/src/Items/ItemMinecart.h @@ -60,7 +60,7 @@ public: cMinecart * Minecart = NULL; switch (m_ItemType) { - case E_ITEM_MINECART: Minecart = new cEmptyMinecart (x, y, z); break; + case E_ITEM_MINECART: Minecart = new cEmptyMinecart (x, y, z, cItem(), 1); break; case E_ITEM_CHEST_MINECART: Minecart = new cMinecartWithChest (x, y, z); break; case E_ITEM_FURNACE_MINECART: Minecart = new cMinecartWithFurnace (x, y, z); break; case E_ITEM_MINECART_WITH_TNT: Minecart = new cMinecartWithTNT (x, y, z); break; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 9c46c6843..8e397358f 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1781,7 +1781,22 @@ void cProtocol172::cPacketizer::WriteEntityMetadata(const cEntity & a_Entity) WriteInt(1); // Shaking direction, doesn't seem to affect anything WriteByte(0x73); WriteFloat((float)(((const cMinecart &)a_Entity).LastDamage() + 10)); // Damage taken / shake effect multiplyer - + + if (((cMinecart &)a_Entity).GetPayload() == cMinecart::mpNone) + { + cEmptyMinecart EmptyMinecart = ((cEmptyMinecart &)a_Entity); + if (!EmptyMinecart.GetContent().IsEmpty()) + { + WriteByte(0x54); + int Content = EmptyMinecart.GetContent().m_ItemType; + Content |= EmptyMinecart.GetContent().m_ItemDamage << 8; + WriteInt(Content); + WriteByte(0x55); + WriteInt(EmptyMinecart.GetBlockHeight()); + WriteByte(0x56); + WriteByte(1); + } + } if (((cMinecart &)a_Entity).GetPayload() == cMinecart::mpFurnace) { WriteByte(0x10); diff --git a/src/World.cpp b/src/World.cpp index b5599c660..d7edbe3f8 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1648,23 +1648,23 @@ int cWorld::SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward) -int cWorld::SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType) +int cWorld::SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType, cItem a_Content, int a_BlockHeight) { cMinecart * Minecart; switch (a_MinecartType) { - case E_ITEM_MINECART: Minecart = new cEmptyMinecart (a_X, a_Y, a_Z); break; + case E_ITEM_MINECART: Minecart = new cEmptyMinecart (a_X, a_Y, a_Z, a_Content, a_BlockHeight); break; case E_ITEM_CHEST_MINECART: Minecart = new cMinecartWithChest (a_X, a_Y, a_Z); break; case E_ITEM_FURNACE_MINECART: Minecart = new cMinecartWithFurnace (a_X, a_Y, a_Z); break; case E_ITEM_MINECART_WITH_TNT: Minecart = new cMinecartWithTNT (a_X, a_Y, a_Z); break; case E_ITEM_MINECART_WITH_HOPPER: Minecart = new cMinecartWithHopper (a_X, a_Y, a_Z); break; default: { - ASSERT(!"Unhandled minecart item"); return -1; } } // switch (a_MinecartType) Minecart->Initialize(this); + return Minecart->GetUniqueID(); } diff --git a/src/World.h b/src/World.h index 89a236b62..23b125e67 100644 --- a/src/World.h +++ b/src/World.h @@ -364,7 +364,7 @@ public: int SpawnFallingBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE BlockType, NIBBLETYPE BlockMeta); /// Spawns an minecart at the given coordinates. - int SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType); + int SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType, cItem a_Content = cItem(), int a_BlockHeight = 1); /// Spawns an experience orb at the given location with the given reward. It returns the UniqueID of the spawned experience orb. int SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward); diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 8605930b6..4fac1bd8d 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1150,7 +1150,7 @@ void cWSSAnvil::LoadFallingBlockFromNBT(cEntityList & a_Entities, const cParsedN void cWSSAnvil::LoadMinecartRFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) { - std::auto_ptr Minecart(new cEmptyMinecart(0, 0, 0)); + std::auto_ptr Minecart(new cEmptyMinecart(0, 0, 0, cItem(), 1)); // TODO: Load the block and the height if (!LoadEntityBaseFromNBT(*Minecart.get(), a_NBT, a_TagIdx)) { return; -- cgit v1.2.3 From f11427e8cd5506204958eec68a8ac2a9152df108 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 12 Jan 2014 18:04:41 +0100 Subject: Renamed cEmptyMinecart to cRideableMinecart --- src/Entities/Minecart.cpp | 7 ++++--- src/Entities/Minecart.h | 6 +++--- src/Items/ItemMinecart.h | 2 +- src/Protocol/Protocol17x.cpp | 12 ++++++------ src/World.cpp | 4 ++-- src/World.h | 2 +- src/WorldStorage/WSSAnvil.cpp | 2 +- 7 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 5a9217c9e..19642efba 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -45,6 +45,7 @@ void cMinecart::SpawnOn(cClientHandle & a_ClientHandle) } } a_ClientHandle.SendSpawnVehicle(*this, 10, SubType); // 10 = Minecarts, SubType = What type of Minecart + a_ClientHandle.SendEntityMetadata(*this); } @@ -411,9 +412,9 @@ void cMinecart::DoTakeDamage(TakeDamageInfo & TDI) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cEmptyMinecart: +// cRideableMinecart: -cEmptyMinecart::cEmptyMinecart(double a_X, double a_Y, double a_Z, const cItem & a_Content, int a_Height) : +cRideableMinecart::cRideableMinecart(double a_X, double a_Y, double a_Z, const cItem & a_Content, int a_Height) : super(mpNone, a_X, a_Y, a_Z), m_Content(a_Content), m_Height(a_Height) @@ -424,7 +425,7 @@ cEmptyMinecart::cEmptyMinecart(double a_X, double a_Y, double a_Z, const cItem & -void cEmptyMinecart::OnRightClicked(cPlayer & a_Player) +void cRideableMinecart::OnRightClicked(cPlayer & a_Player) { if (m_Attachee != NULL) { diff --git a/src/Entities/Minecart.h b/src/Entities/Minecart.h index 87d375c68..a646132ab 100644 --- a/src/Entities/Minecart.h +++ b/src/Entities/Minecart.h @@ -69,15 +69,15 @@ protected: -class cEmptyMinecart : +class cRideableMinecart : public cMinecart { typedef cMinecart super; public: - CLASS_PROTODEF(cEmptyMinecart); + CLASS_PROTODEF(cRideableMinecart); - cEmptyMinecart(double a_X, double a_Y, double a_Z, const cItem & a_Content, int a_Height); + cRideableMinecart(double a_X, double a_Y, double a_Z, const cItem & a_Content, int a_Height); cItem GetContent(void) const {return m_Content;} int GetBlockHeight(void) const {return m_Height;} diff --git a/src/Items/ItemMinecart.h b/src/Items/ItemMinecart.h index b82779026..4071f8c60 100644 --- a/src/Items/ItemMinecart.h +++ b/src/Items/ItemMinecart.h @@ -60,7 +60,7 @@ public: cMinecart * Minecart = NULL; switch (m_ItemType) { - case E_ITEM_MINECART: Minecart = new cEmptyMinecart (x, y, z, cItem(), 1); break; + case E_ITEM_MINECART: Minecart = new cRideableMinecart (x, y, z, cItem(), 1); break; case E_ITEM_CHEST_MINECART: Minecart = new cMinecartWithChest (x, y, z); break; case E_ITEM_FURNACE_MINECART: Minecart = new cMinecartWithFurnace (x, y, z); break; case E_ITEM_MINECART_WITH_TNT: Minecart = new cMinecartWithTNT (x, y, z); break; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 8e397358f..a107c4b1f 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1784,20 +1784,20 @@ void cProtocol172::cPacketizer::WriteEntityMetadata(const cEntity & a_Entity) if (((cMinecart &)a_Entity).GetPayload() == cMinecart::mpNone) { - cEmptyMinecart EmptyMinecart = ((cEmptyMinecart &)a_Entity); - if (!EmptyMinecart.GetContent().IsEmpty()) + cRideableMinecart & RideableMinecart = ((cRideableMinecart &)a_Entity); + if (!RideableMinecart.GetContent().IsEmpty()) { WriteByte(0x54); - int Content = EmptyMinecart.GetContent().m_ItemType; - Content |= EmptyMinecart.GetContent().m_ItemDamage << 8; + int Content = RideableMinecart.GetContent().m_ItemType; + Content |= RideableMinecart.GetContent().m_ItemDamage << 8; WriteInt(Content); WriteByte(0x55); - WriteInt(EmptyMinecart.GetBlockHeight()); + WriteInt(RideableMinecart.GetBlockHeight()); WriteByte(0x56); WriteByte(1); } } - if (((cMinecart &)a_Entity).GetPayload() == cMinecart::mpFurnace) + else if (((cMinecart &)a_Entity).GetPayload() == cMinecart::mpFurnace) { WriteByte(0x10); WriteByte(((const cMinecartWithFurnace &)a_Entity).IsFueled() ? 1 : 0); diff --git a/src/World.cpp b/src/World.cpp index d7edbe3f8..d63a16262 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1648,12 +1648,12 @@ int cWorld::SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward) -int cWorld::SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType, cItem a_Content, int a_BlockHeight) +int cWorld::SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType, const cItem & a_Content, int a_BlockHeight) { cMinecart * Minecart; switch (a_MinecartType) { - case E_ITEM_MINECART: Minecart = new cEmptyMinecart (a_X, a_Y, a_Z, a_Content, a_BlockHeight); break; + case E_ITEM_MINECART: Minecart = new cRideableMinecart (a_X, a_Y, a_Z, a_Content, a_BlockHeight); break; case E_ITEM_CHEST_MINECART: Minecart = new cMinecartWithChest (a_X, a_Y, a_Z); break; case E_ITEM_FURNACE_MINECART: Minecart = new cMinecartWithFurnace (a_X, a_Y, a_Z); break; case E_ITEM_MINECART_WITH_TNT: Minecart = new cMinecartWithTNT (a_X, a_Y, a_Z); break; diff --git a/src/World.h b/src/World.h index 23b125e67..5457bd799 100644 --- a/src/World.h +++ b/src/World.h @@ -364,7 +364,7 @@ public: int SpawnFallingBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE BlockType, NIBBLETYPE BlockMeta); /// Spawns an minecart at the given coordinates. - int SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType, cItem a_Content = cItem(), int a_BlockHeight = 1); + int SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType, const cItem & a_Content = cItem(), int a_BlockHeight = 1); /// Spawns an experience orb at the given location with the given reward. It returns the UniqueID of the spawned experience orb. int SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward); diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 4fac1bd8d..28ec4e0af 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1150,7 +1150,7 @@ void cWSSAnvil::LoadFallingBlockFromNBT(cEntityList & a_Entities, const cParsedN void cWSSAnvil::LoadMinecartRFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) { - std::auto_ptr Minecart(new cEmptyMinecart(0, 0, 0, cItem(), 1)); // TODO: Load the block and the height + std::auto_ptr Minecart(new cRideableMinecart(0, 0, 0, cItem(), 1)); // TODO: Load the block and the height if (!LoadEntityBaseFromNBT(*Minecart.get(), a_NBT, a_TagIdx)) { return; -- cgit v1.2.3 From c7d556afafe6163599923266f5832840d3674495 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 12 Jan 2014 18:15:54 +0100 Subject: Fixed server crash. --- src/Entities/Minecart.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Entities/Minecart.h b/src/Entities/Minecart.h index a646132ab..08e22c546 100644 --- a/src/Entities/Minecart.h +++ b/src/Entities/Minecart.h @@ -85,7 +85,7 @@ public: virtual void OnRightClicked(cPlayer & a_Player) override; protected: - const cItem & m_Content; + cItem m_Content; int m_Height; } ; -- cgit v1.2.3 From ca835a05650cb1a722125fa438a05f70f8b3c2b8 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Thu, 16 Jan 2014 16:54:22 +0100 Subject: Changed GetContent function. --- src/Entities/Minecart.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Entities/Minecart.h b/src/Entities/Minecart.h index 08e22c546..6aec8a834 100644 --- a/src/Entities/Minecart.h +++ b/src/Entities/Minecart.h @@ -79,7 +79,7 @@ public: cRideableMinecart(double a_X, double a_Y, double a_Z, const cItem & a_Content, int a_Height); - cItem GetContent(void) const {return m_Content;} + const cItem & GetContent(void) const {return m_Content;} int GetBlockHeight(void) const {return m_Height;} // cEntity overrides: virtual void OnRightClicked(cPlayer & a_Player) override; -- cgit v1.2.3