From 777041806fb5085e94838fa9bb0b1c3fe0b61696 Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 17 Feb 2014 20:14:08 +0100 Subject: [PATCH 01/22] Add Skulls/Heads --- src/BlockEntities/BlockEntity.cpp | 2 + src/BlockEntities/SkullEntity.cpp | 110 ++++++++++++++++++++++++ src/BlockEntities/SkullEntity.h | 79 +++++++++++++++++ src/CMakeLists.txt | 1 + src/Chunk.cpp | 2 + src/Defines.h | 37 ++++++++ src/Items/ItemHandler.cpp | 2 + src/Items/ItemSkull.h | 43 +++++++++ src/Protocol/Protocol17x.cpp | 14 +++ src/WorldStorage/NBTChunkSerializer.cpp | 26 ++++-- src/WorldStorage/NBTChunkSerializer.h | 2 + src/WorldStorage/WSSAnvil.cpp | 40 +++++++++ src/WorldStorage/WSSAnvil.h | 1 + 13 files changed, 354 insertions(+), 5 deletions(-) create mode 100644 src/BlockEntities/SkullEntity.cpp create mode 100644 src/BlockEntities/SkullEntity.h create mode 100644 src/Items/ItemSkull.h diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp index 97b5c1a66..441f54a26 100644 --- a/src/BlockEntities/BlockEntity.cpp +++ b/src/BlockEntities/BlockEntity.cpp @@ -15,6 +15,7 @@ #include "JukeboxEntity.h" #include "NoteEntity.h" #include "SignEntity.h" +#include "SkullEntity.h" @@ -31,6 +32,7 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE case E_BLOCK_ENDER_CHEST: return new cEnderChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); case E_BLOCK_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); + case E_BLOCK_HEAD: return new cSkullEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta, a_World); case E_BLOCK_HOPPER: return new cHopperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_SIGN_POST: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_WALLSIGN: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); diff --git a/src/BlockEntities/SkullEntity.cpp b/src/BlockEntities/SkullEntity.cpp new file mode 100644 index 000000000..3f3bc00ed --- /dev/null +++ b/src/BlockEntities/SkullEntity.cpp @@ -0,0 +1,110 @@ + +// SkullEntity.cpp + +// Implements the cSkullEntity class representing a single skull/head in the world + +#include "Globals.h" +#include "json/json.h" +#include "SkullEntity.h" +#include "../Entities/Player.h" + + + + + +cSkullEntity::cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockMeta, cWorld * a_World) : + super(E_BLOCK_HEAD, a_BlockX, a_BlockY, a_BlockZ, a_World), + //m_SkullType(static_cast(a_BlockMeta)), + m_Owner("") +{ + +} + + + + + +void cSkullEntity::UsedBy(cPlayer * a_Player) +{ + UNUSED(a_Player); +} + + + + + +void cSkullEntity::SetSkullType(const eSkullType & a_SkullType) +{ + if ((!m_Owner.empty()) && (a_SkullType != SKULL_TYPE_PLAYER)) + { + m_Owner = ""; + } + m_SkullType = a_SkullType; +} + + + + + +void cSkullEntity::SetRotation(eSkullRotation a_Rotation) +{ + m_Rotation = a_Rotation; +} + + + + + +void cSkullEntity::SetOwner(const AString & a_Owner) +{ + if ((a_Owner.length() > 16) || (m_SkullType != SKULL_TYPE_PLAYER)) + { + return; + } + m_Owner = a_Owner; +} + + + + + +void cSkullEntity::SendTo(cClientHandle & a_Client) +{ + a_Client.SendUpdateBlockEntity(*this); +} + + + + + +bool cSkullEntity::LoadFromJson(const Json::Value & a_Value) +{ + m_PosX = a_Value.get("x", 0).asInt(); + m_PosY = a_Value.get("y", 0).asInt(); + m_PosZ = a_Value.get("z", 0).asInt(); + + m_SkullType = static_cast(a_Value.get("SkullType", 0).asInt()); + m_Rotation = static_cast(a_Value.get("Rotation", 0).asInt()); + m_Owner = a_Value.get("Owner", "").asString(); + + return true; +} + + + + + +void cSkullEntity::SaveToJson(Json::Value & a_Value) +{ + a_Value["x"] = m_PosX; + a_Value["y"] = m_PosY; + a_Value["z"] = m_PosZ; + + a_Value["SkullType"] = m_SkullType; + a_Value["Rotation"] = m_Rotation; + a_Value["Owner"] = m_Owner; +} + + + + diff --git a/src/BlockEntities/SkullEntity.h b/src/BlockEntities/SkullEntity.h new file mode 100644 index 000000000..6f47c7d30 --- /dev/null +++ b/src/BlockEntities/SkullEntity.h @@ -0,0 +1,79 @@ +// SkullEntity.h + +// Declares the cSkullEntity class representing a single skull/head in the world + + + + + +#pragma once + +#include "BlockEntity.h" + + + + + +namespace Json +{ + class Value; +} + + + + + +// tolua_begin + +class cSkullEntity : + public cBlockEntity +{ + typedef cBlockEntity super; + +public: + + // tolua_end + + /// Creates a new skull entity at the specified block coords. a_World may be NULL + cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockMeta, cWorld * a_World); + + bool LoadFromJson( const Json::Value& a_Value ); + virtual void SaveToJson(Json::Value& a_Value ) override; + + // tolua_begin + + /// Set the Skull Type + void SetSkullType(const eSkullType & a_SkullType); + + /// Set the Rotation + void SetRotation(eSkullRotation a_Rotation); + + // Set the Player Name for Player Skulls + void SetOwner(const AString & a_Owner); + + /// Get the Skull Type + eSkullType GetSkullType(void) const { return m_SkullType; } + + /// Get the Rotation + eSkullRotation GetRotation(void) const { return m_Rotation; } + + /// Get the setted Player Name + AString GetOwner(void) const { return m_Owner; } + + // tolua_end + + virtual void UsedBy(cPlayer * a_Player) override; + virtual void SendTo(cClientHandle & a_Client) override; + + static const char * GetClassStatic(void) { return "cSkullEntity"; } + +private: + + eSkullType m_SkullType; + eSkullRotation m_Rotation; + AString m_Owner; +} ; // tolua_export + + + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6ba952f92..e46aa3ee5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,6 +39,7 @@ if (NOT MSVC) BlockEntities/JukeboxEntity.h BlockEntities/NoteEntity.h BlockEntities/SignEntity.h + BlockEntities/SkullEntity.h BlockID.h BoundingBox.h ChatColor.h diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 3028d24d0..c66dae7b4 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -1314,6 +1314,7 @@ void cChunk::CreateBlockEntities(void) case E_BLOCK_HOPPER: case E_BLOCK_SIGN_POST: case E_BLOCK_WALLSIGN: + case E_BLOCK_HEAD: case E_BLOCK_NOTE_BLOCK: case E_BLOCK_JUKEBOX: { @@ -1442,6 +1443,7 @@ void cChunk::SetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, case E_BLOCK_HOPPER: case E_BLOCK_SIGN_POST: case E_BLOCK_WALLSIGN: + case E_BLOCK_HEAD: case E_BLOCK_NOTE_BLOCK: case E_BLOCK_JUKEBOX: { diff --git a/src/Defines.h b/src/Defines.h index f33d1ae56..7e22cbdc5 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -174,6 +174,43 @@ enum eWeather +enum eSkullType +{ + SKULL_TYPE_SKELETON = 0, + SKULL_TYPE_WITHER = 1, + SKULL_TYPE_ZOMBIE = 2, + SKULL_TYPE_PLAYER = 3, + SKULL_TYPE_CREEPER = 4, +} ; + + + + + +enum eSkullRotation +{ + SKULL_ROTATION_NORTH = 0, + SKULL_ROTATION_NORTH_NORTH_EAST = 1, + SKULL_ROTATION_NORTH_EAST = 2, + SKULL_ROTATION_EAST_NORTH_EAST = 3, + SKULL_ROTATION_EAST = 4, + SKULL_ROTATION_EAST_SOUTH_EAST = 5, + SKULL_ROTATION_SOUTH_EAST = 6, + SKULL_ROTATION_SOUTH_SOUTH_EAST = 7, + SKULL_ROTATION_SOUTH = 8, + SKULL_ROTATION_SOUTH_SOUTH_WEST = 9, + SKULL_ROTATION_SOUTH_WEST = 10, + SKULL_ROTATION_WEST_SOUTH_WEST = 11, + SKULL_ROTATION_WEST = 12, + SKULL_ROTATION_WEST_NORTH_WEST = 13, + SKULL_ROTATION_NORTH_WEST = 14, + SKULL_ROTATION_NORTH_NORTH_WEST = 15, +} ; + + + + + inline const char * ClickActionToString(eClickAction a_ClickAction) { switch (a_ClickAction) diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 19913ab24..4ede75cf1 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -35,6 +35,7 @@ #include "ItemShears.h" #include "ItemShovel.h" #include "ItemSign.h" +#include "ItemSkull.h" #include "ItemSpawnEgg.h" #include "ItemSugarcane.h" #include "ItemSword.h" @@ -110,6 +111,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_ITEM_REDSTONE_REPEATER: return new cItemRedstoneRepeaterHandler(a_ItemType); case E_ITEM_SHEARS: return new cItemShearsHandler(a_ItemType); case E_ITEM_SIGN: return new cItemSignHandler(a_ItemType); + case E_ITEM_HEAD: return new cItemSkullHandler(a_ItemType); case E_ITEM_SNOWBALL: return new cItemSnowballHandler(); case E_ITEM_SPAWN_EGG: return new cItemSpawnEggHandler(a_ItemType); case E_ITEM_SUGARCANE: return new cItemSugarcaneHandler(a_ItemType); diff --git a/src/Items/ItemSkull.h b/src/Items/ItemSkull.h new file mode 100644 index 000000000..f511c8c4a --- /dev/null +++ b/src/Items/ItemSkull.h @@ -0,0 +1,43 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" + + + + + +class cItemSkullHandler : + public cItemHandler +{ +public: + cItemSkullHandler(int a_ItemType) : + cItemHandler(a_ItemType) + { + } + + + 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, + BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta + ) override + { + a_BlockType = E_BLOCK_HEAD; + a_BlockMeta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage & 0x0f); + + return true; + } +} ; + + + + diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index f7d13774d..4d55822fb 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -26,6 +26,7 @@ Implements the 1.7.x protocol classes: #include "../Mobs/IncludeAllMonsters.h" #include "../UI/Window.h" #include "../BlockEntities/CommandBlockEntity.h" +#include "../BlockEntities/SkullEntity.h" #include "../CompositeChat.h" @@ -1042,6 +1043,7 @@ void cProtocol172::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) { case E_BLOCK_MOB_SPAWNER: Action = 1; break; // Update mob spawner spinny mob thing case E_BLOCK_COMMAND_BLOCK: Action = 2; break; // Update command block text + case E_BLOCK_HEAD: Action = 4; break; // Update Skull entity default: ASSERT(!"Unhandled or unimplemented BlockEntity update request!"); break; } Pkt.WriteByte(Action); @@ -2269,6 +2271,18 @@ void cProtocol172::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt } break; } + case E_BLOCK_HEAD: + { + cSkullEntity & SkullEntity = (cSkullEntity &)a_BlockEntity; + + Writer.AddInt("x", SkullEntity.GetPosX()); + Writer.AddInt("y", SkullEntity.GetPosY()); + Writer.AddInt("z", SkullEntity.GetPosZ()); + Writer.AddByte("SkullType", SkullEntity.GetSkullType() & 0xFF); + Writer.AddByte("Rot", SkullEntity.GetRotation() & 0xFF); + Writer.AddString("ExtraType", SkullEntity.GetOwner().c_str()); + Writer.AddString("id", "Skull"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though + } default: break; } diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 95b5e66d2..6da141728 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -19,6 +19,7 @@ #include "../BlockEntities/JukeboxEntity.h" #include "../BlockEntities/NoteEntity.h" #include "../BlockEntities/SignEntity.h" +#include "../BlockEntities/SkullEntity.h" #include "../Entities/Entity.h" #include "../Entities/FallingBlock.h" @@ -248,11 +249,25 @@ void cNBTChunkSerializer::AddCommandBlockEntity(cCommandBlockEntity * a_CmdBlock void cNBTChunkSerializer::AddSignEntity(cSignEntity * a_Sign) { m_Writer.BeginCompound(""); - AddBasicTileEntity(a_Sign, "Sign"); - m_Writer.AddString("Text1", a_Sign->GetLine(0)); - m_Writer.AddString("Text2", a_Sign->GetLine(1)); - m_Writer.AddString("Text3", a_Sign->GetLine(2)); - m_Writer.AddString("Text4", a_Sign->GetLine(3)); + AddBasicTileEntity(a_Sign, "Sign"); + m_Writer.AddString("Text1", a_Sign->GetLine(0)); + m_Writer.AddString("Text2", a_Sign->GetLine(1)); + m_Writer.AddString("Text3", a_Sign->GetLine(2)); + m_Writer.AddString("Text4", a_Sign->GetLine(3)); + m_Writer.EndCompound(); +} + + + + + +void cNBTChunkSerializer::AddSkullEntity(cSkullEntity * a_Skull) +{ + m_Writer.BeginCompound(""); + AddBasicTileEntity(a_Skull, "Skull"); + m_Writer.AddByte ("SkullType", a_Skull->GetSkullType() & 0xFF); + m_Writer.AddByte ("Rot", a_Skull->GetRotation() & 0xFF); + m_Writer.AddString("ExtraType", a_Skull->GetOwner()); m_Writer.EndCompound(); } @@ -666,6 +681,7 @@ void cNBTChunkSerializer::BlockEntity(cBlockEntity * a_Entity) case E_BLOCK_HOPPER: AddHopperEntity ((cHopperEntity *) a_Entity); break; case E_BLOCK_SIGN_POST: case E_BLOCK_WALLSIGN: AddSignEntity ((cSignEntity *) a_Entity); break; + case E_BLOCK_HEAD: AddSkullEntity ((cSkullEntity *) a_Entity); break; case E_BLOCK_NOTE_BLOCK: AddNoteEntity ((cNoteEntity *) a_Entity); break; case E_BLOCK_JUKEBOX: AddJukeboxEntity ((cJukeboxEntity *) a_Entity); break; case E_BLOCK_COMMAND_BLOCK: AddCommandBlockEntity((cCommandBlockEntity *) a_Entity); break; diff --git a/src/WorldStorage/NBTChunkSerializer.h b/src/WorldStorage/NBTChunkSerializer.h index 245b68063..fd5601e47 100644 --- a/src/WorldStorage/NBTChunkSerializer.h +++ b/src/WorldStorage/NBTChunkSerializer.h @@ -29,6 +29,7 @@ class cHopperEntity; class cJukeboxEntity; class cNoteEntity; class cSignEntity; +class cSkullEntity; class cFallingBlock; class cMinecart; class cMinecartWithChest; @@ -93,6 +94,7 @@ protected: void AddJukeboxEntity (cJukeboxEntity * a_Jukebox); void AddNoteEntity (cNoteEntity * a_Note); void AddSignEntity (cSignEntity * a_Sign); + void AddSkullEntity (cSkullEntity * a_Skull); void AddCommandBlockEntity(cCommandBlockEntity * a_CmdBlock); // Entities: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index e95813a3c..89a236f07 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -24,6 +24,7 @@ #include "../BlockEntities/JukeboxEntity.h" #include "../BlockEntities/NoteEntity.h" #include "../BlockEntities/SignEntity.h" +#include "../BlockEntities/SkullEntity.h" #include "../Mobs/Monster.h" @@ -597,6 +598,10 @@ void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntities, con { LoadSignFromNBT(a_BlockEntities, a_NBT, Child); } + else if (strncmp(a_NBT.GetData(sID), "Skull", a_NBT.GetDataLength(sID)) == 0) + { + LoadSkullFromNBT(a_BlockEntities, a_NBT, Child); + } else if (strncmp(a_NBT.GetData(sID), "Trap", a_NBT.GetDataLength(sID)) == 0) { LoadDispenserFromNBT(a_BlockEntities, a_NBT, Child); @@ -927,6 +932,41 @@ void cWSSAnvil::LoadSignFromNBT(cBlockEntityList & a_BlockEntities, const cParse +void cWSSAnvil::LoadSkullFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx) +{ + ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound); + int x, y, z; + if (!GetBlockEntityNBTPos(a_NBT, a_TagIdx, x, y, z)) + { + return; + } + std::auto_ptr Skull(new cSkullEntity(E_BLOCK_HEAD, x, y, z, m_World)); + + int currentLine = a_NBT.FindChildByName(a_TagIdx, "SkullType"); + if (currentLine >= 0) + { + Skull->SetSkullType(static_cast(a_NBT.GetByte(currentLine))); + } + + currentLine = a_NBT.FindChildByName(a_TagIdx, "Rot"); + if (currentLine >= 0) + { + Skull->SetRotation(static_cast(a_NBT.GetByte(currentLine))); + } + + currentLine = a_NBT.FindChildByName(a_TagIdx, "ExtraType"); + if (currentLine >= 0) + { + Skull->SetOwner(a_NBT.GetString(currentLine)); + } + + a_BlockEntities.push_back(Skull.release()); +} + + + + + void cWSSAnvil::LoadCommandBlockFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx) { ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound); diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h index 5093ad083..9c9e17258 100644 --- a/src/WorldStorage/WSSAnvil.h +++ b/src/WorldStorage/WSSAnvil.h @@ -139,6 +139,7 @@ protected: void LoadJukeboxFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadNoteFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadSignFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); + void LoadSkullFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadCommandBlockFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_EntityTagIdx, const char * a_IDTag, int a_IDTagLength); From 52c41f886927cf62ed592ba7fec974eee6b16844 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 18 Feb 2014 21:40:02 +0100 Subject: [PATCH 02/22] Add Heads completely --- src/Bindings/ManualBindings.cpp | 2 + src/BlockEntities/BlockEntity.cpp | 2 +- src/BlockEntities/SkullEntity.cpp | 4 +- src/BlockEntities/SkullEntity.h | 2 +- src/Blocks/BlockHandler.cpp | 2 + src/Blocks/BlockSkull.h | 69 +++++++++++++++++++++++++++++++ src/Chunk.cpp | 33 +++++++++++++++ src/Chunk.h | 7 +++- src/ChunkMap.cpp | 18 ++++++++ src/ChunkMap.h | 5 +++ src/Items/ItemSkull.h | 1 + src/World.cpp | 9 ++++ src/World.h | 5 +++ src/WorldStorage/WSSAnvil.cpp | 2 +- 14 files changed, 154 insertions(+), 7 deletions(-) create mode 100644 src/Blocks/BlockSkull.h diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 2a7631120..70f3fbcf2 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -22,6 +22,7 @@ #include "../BlockEntities/FurnaceEntity.h" #include "../BlockEntities/HopperEntity.h" #include "../BlockEntities/NoteEntity.h" +#include "../BlockEntities/SkullEntity.h" #include "md5/md5.h" #include "../LineBlockTracer.h" #include "../WorldStorage/SchematicFileSerializer.h" @@ -2416,6 +2417,7 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "DoWithFurnaceAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithNoteBlockAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithCommandBlockAt", tolua_DoWithXYZ); + tolua_function(tolua_S, "DoWithSkullBlockAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::DoWithPlayer>); tolua_function(tolua_S, "FindAndDoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::FindAndDoWithPlayer>); tolua_function(tolua_S, "ForEachBlockEntityInChunk", tolua_ForEachInChunk); diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp index 441f54a26..f01a139d2 100644 --- a/src/BlockEntities/BlockEntity.cpp +++ b/src/BlockEntities/BlockEntity.cpp @@ -30,9 +30,9 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE case E_BLOCK_DISPENSER: return new cDispenserEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_DROPPER: return new cDropperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_ENDER_CHEST: return new cEnderChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_HEAD: return new cSkullEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); case E_BLOCK_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); - case E_BLOCK_HEAD: return new cSkullEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta, a_World); case E_BLOCK_HOPPER: return new cHopperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_SIGN_POST: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_WALLSIGN: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); diff --git a/src/BlockEntities/SkullEntity.cpp b/src/BlockEntities/SkullEntity.cpp index 3f3bc00ed..43b97b93e 100644 --- a/src/BlockEntities/SkullEntity.cpp +++ b/src/BlockEntities/SkullEntity.cpp @@ -12,12 +12,10 @@ -cSkullEntity::cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockMeta, cWorld * a_World) : +cSkullEntity::cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : super(E_BLOCK_HEAD, a_BlockX, a_BlockY, a_BlockZ, a_World), - //m_SkullType(static_cast(a_BlockMeta)), m_Owner("") { - } diff --git a/src/BlockEntities/SkullEntity.h b/src/BlockEntities/SkullEntity.h index 6f47c7d30..ffd84465f 100644 --- a/src/BlockEntities/SkullEntity.h +++ b/src/BlockEntities/SkullEntity.h @@ -35,7 +35,7 @@ public: // tolua_end /// Creates a new skull entity at the specified block coords. a_World may be NULL - cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockMeta, cWorld * a_World); + cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); bool LoadFromJson( const Json::Value& a_Value ); virtual void SaveToJson(Json::Value& a_Value ) override; diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 6c9bbeb02..870de7a7d 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -34,6 +34,7 @@ #include "BlockGlass.h" #include "BlockGlowstone.h" #include "BlockGravel.h" +#include "BlockSkull.h" #include "BlockHopper.h" #include "BlockIce.h" #include "BlockLadder.h" @@ -146,6 +147,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_GRASS: return new cBlockDirtHandler (a_BlockType); case E_BLOCK_GRAVEL: return new cBlockGravelHandler (a_BlockType); case E_BLOCK_HAY_BALE: return new cBlockSidewaysHandler (a_BlockType); + case E_BLOCK_HEAD: return new cBlockSkullHandler (a_BlockType); case E_BLOCK_HOPPER: return new cBlockHopperHandler (a_BlockType); case E_BLOCK_ICE: return new cBlockIceHandler (a_BlockType); case E_BLOCK_INACTIVE_COMPARATOR: return new cBlockComparatorHandler (a_BlockType); diff --git a/src/Blocks/BlockSkull.h b/src/Blocks/BlockSkull.h new file mode 100644 index 000000000..eea5ac922 --- /dev/null +++ b/src/Blocks/BlockSkull.h @@ -0,0 +1,69 @@ + +#pragma once + +#include "BlockEntity.h" +#include "../BlockEntities/SkullEntity.h" + + + + + +class cBlockSkullHandler : + public cBlockEntityHandler +{ +public: + cBlockSkullHandler(BLOCKTYPE a_BlockType) + : cBlockEntityHandler(a_BlockType) + { + } + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + a_Pickups.push_back(cItem(E_ITEM_HEAD, 1, 0)); + } + + virtual void OnPlacedByPlayer( + cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, 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 + ) override + { + class cCallback : public cSkullBlockCallback + { + cPlayer * m_Player; + NIBBLETYPE m_OldBlockMeta; + NIBBLETYPE m_NewBlockMeta; + + virtual bool Item (cSkullEntity * a_SkullEntity) + { + int Rotation = 0; + if (m_NewBlockMeta == 1) + { + Rotation = (int) floor(m_Player->GetYaw() * 16.0F / 360.0F + 0.5) & 0xF; + } + + a_SkullEntity->SetSkullType(static_cast(m_OldBlockMeta)); + a_SkullEntity->SetRotation(static_cast(Rotation)); + return false; + } + + public: + cCallback (cPlayer * a_Player, NIBBLETYPE a_OldBlockMeta, NIBBLETYPE a_NewBlockMeta) : + m_Player(a_Player), + m_OldBlockMeta(a_OldBlockMeta), + m_NewBlockMeta(a_NewBlockMeta) + {} + }; + cCallback Callback(a_Player, a_BlockMeta, static_cast(a_BlockFace)); + + a_BlockMeta = a_BlockFace; + cWorld * World = (cWorld *) &a_WorldInterface; + World->DoWithSkullBlockAt(a_BlockX, a_BlockY, a_BlockZ, Callback); + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta); + } +} ; + + + + diff --git a/src/Chunk.cpp b/src/Chunk.cpp index c66dae7b4..8b03732f3 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -19,6 +19,7 @@ #include "BlockEntities/JukeboxEntity.h" #include "BlockEntities/NoteEntity.h" #include "BlockEntities/SignEntity.h" +#include "BlockEntities/SkullEntity.h" #include "Entities/Pickup.h" #include "Item.h" #include "Noise.h" @@ -2311,6 +2312,38 @@ bool cChunk::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCom +bool cChunk::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback) +{ + // The blockentity list is locked by the parent chunkmap's CS + for (cBlockEntityList::iterator itr = m_BlockEntities.begin(), itr2 = itr; itr != m_BlockEntities.end(); itr = itr2) + { + ++itr2; + if (((*itr)->GetPosX() != a_BlockX) || ((*itr)->GetPosY() != a_BlockY) || ((*itr)->GetPosZ() != a_BlockZ)) + { + continue; + } + if ((*itr)->GetBlockType() != E_BLOCK_HEAD) + { + // There is a block entity here, but of different type. No other block entity can be here, so we can safely bail out + return false; + } + + // The correct block entity is here, + if (a_Callback.Item((cSkullEntity *)*itr)) + { + return false; + } + return true; + } // for itr - m_BlockEntitites[] + + // Not found: + return false; +} + + + + + bool cChunk::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4) { // The blockentity list is locked by the parent chunkmap's CS diff --git a/src/Chunk.h b/src/Chunk.h index 696690068..27388deb4 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -31,6 +31,7 @@ class cChestEntity; class cDispenserEntity; class cFurnaceEntity; class cNoteEntity; +class cSkullEntity; class cBlockArea; class cPawn; class cPickup; @@ -47,6 +48,7 @@ typedef cItemCallback cDispenserCallback; typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; +typedef cItemCallback cSkullBlockCallback; @@ -241,7 +243,10 @@ public: bool DoWithNoteBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cNoteBlockCallback & a_Callback); /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */ - bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); + bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); + + /** Calls the callback for the skull block at the specified coords; returns false if there's no skull block at those coords or callback returns true, returns true if found */ + bool DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback); /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 0c5a8d9b9..5f1674c03 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -2121,6 +2121,24 @@ bool cChunkMap::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, c +bool cChunkMap::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback) +{ + int ChunkX, ChunkZ; + int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; + cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); + cCSLock Lock(m_CSLayers); + cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); + if ((Chunk == NULL) && !Chunk->IsValid()) + { + return false; + } + return Chunk->DoWithSkullBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); +} + + + + + bool cChunkMap::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4) { int ChunkX, ChunkZ; diff --git a/src/ChunkMap.h b/src/ChunkMap.h index d713d0cf5..02c245dc9 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -25,6 +25,7 @@ class cDropSpenserEntity; class cFurnaceEntity; class cNoteEntity; class cCommandBlockEntity; +class cSkullEntity; class cPawn; class cPickup; class cChunkDataSerializer; @@ -43,6 +44,7 @@ typedef cItemCallback cDropSpenserCallback; typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; +typedef cItemCallback cSkullBlockCallback; typedef cItemCallback cChunkCallback; @@ -245,6 +247,9 @@ public: /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */ bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); // Lua-accessible + /** Calls the callback for the skull block at the specified coords; returns false if there's no skull block at those coords or callback returns true, returns true if found */ + bool DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback); // Lua-accessible + /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible diff --git a/src/Items/ItemSkull.h b/src/Items/ItemSkull.h index f511c8c4a..3648f1436 100644 --- a/src/Items/ItemSkull.h +++ b/src/Items/ItemSkull.h @@ -31,6 +31,7 @@ public: BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override { + a_BlockType = E_BLOCK_HEAD; a_BlockMeta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage & 0x0f); diff --git a/src/World.cpp b/src/World.cpp index d67ad36d1..14d904d72 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1165,6 +1165,15 @@ bool cWorld::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCom +bool cWorld::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback) +{ + return m_ChunkMap->DoWithSkullBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); +} + + + + + bool cWorld::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4) { return m_ChunkMap->GetSignLines(a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4); diff --git a/src/World.h b/src/World.h index 97358b88a..4e83833ed 100644 --- a/src/World.h +++ b/src/World.h @@ -45,6 +45,7 @@ class cChestEntity; class cDispenserEntity; class cFurnaceEntity; class cNoteEntity; +class cSkullEntity; class cMobCensus; class cCompositeChat; @@ -57,6 +58,7 @@ typedef cItemCallback cDispenserCallback; typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; +typedef cItemCallback cSkullBlockCallback; @@ -510,6 +512,9 @@ public: /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */ bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); // Exported in ManualBindings.cpp + /** Calls the callback for the skull block at the specified coords; returns false if there's no skull block at those coords or callback returns true, returns true if found */ + bool DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback); // Exported in ManualBindings.cpp + /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Exported in ManualBindings.cpp diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 89a236f07..58dc2e9e4 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -940,7 +940,7 @@ void cWSSAnvil::LoadSkullFromNBT(cBlockEntityList & a_BlockEntities, const cPars { return; } - std::auto_ptr Skull(new cSkullEntity(E_BLOCK_HEAD, x, y, z, m_World)); + std::auto_ptr Skull(new cSkullEntity(x, y, z, m_World)); int currentLine = a_NBT.FindChildByName(a_TagIdx, "SkullType"); if (currentLine >= 0) From 823ee3a125d1b57880eaa050d25e5bc71180506d Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 19 Feb 2014 14:12:34 +0100 Subject: [PATCH 03/22] Add break to Protocol17x.cpp and use new comment delimiter --- src/BlockEntities/SkullEntity.h | 14 +++++++------- src/Protocol/Protocol17x.cpp | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/BlockEntities/SkullEntity.h b/src/BlockEntities/SkullEntity.h index ffd84465f..3dc355623 100644 --- a/src/BlockEntities/SkullEntity.h +++ b/src/BlockEntities/SkullEntity.h @@ -34,7 +34,7 @@ public: // tolua_end - /// Creates a new skull entity at the specified block coords. a_World may be NULL + /** Creates a new skull entity at the specified block coords. a_World may be NULL */ cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); bool LoadFromJson( const Json::Value& a_Value ); @@ -42,22 +42,22 @@ public: // tolua_begin - /// Set the Skull Type + /** Set the Skull Type */ void SetSkullType(const eSkullType & a_SkullType); - /// Set the Rotation + /** Set the Rotation */ void SetRotation(eSkullRotation a_Rotation); - // Set the Player Name for Player Skulls + /** Set the Player Name for Player Skull */ void SetOwner(const AString & a_Owner); - /// Get the Skull Type + /** Get the Skull Type */ eSkullType GetSkullType(void) const { return m_SkullType; } - /// Get the Rotation + /** Get the Rotation */ eSkullRotation GetRotation(void) const { return m_Rotation; } - /// Get the setted Player Name + /** Get the setted Player Name */ AString GetOwner(void) const { return m_Owner; } // tolua_end diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 4d55822fb..07b23e0ac 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -2282,6 +2282,7 @@ void cProtocol172::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt Writer.AddByte("Rot", SkullEntity.GetRotation() & 0xFF); Writer.AddString("ExtraType", SkullEntity.GetOwner().c_str()); Writer.AddString("id", "Skull"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though + break; } default: break; } From d63ce62f3bbe4b8e89b8c54af4b71d77bcc7e052 Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 19 Feb 2014 14:45:09 +0100 Subject: [PATCH 04/22] Rename SkullEntity to MobHeadEntity --- src/Bindings/ManualBindings.cpp | 4 +- src/BlockEntities/BlockEntity.cpp | 4 +- src/BlockEntities/MobHeadEntity.cpp | 108 ++++++++++++++++++++ src/BlockEntities/MobHeadEntity.h | 79 ++++++++++++++ src/BlockEntities/SkullEntity.cpp | 108 -------------------- src/BlockEntities/SkullEntity.h | 79 -------------- src/Blocks/BlockHandler.cpp | 4 +- src/Blocks/{BlockSkull.h => BlockMobHead.h} | 16 +-- src/CMakeLists.txt | 2 +- src/Chunk.cpp | 6 +- src/Chunk.h | 8 +- src/ChunkMap.cpp | 4 +- src/ChunkMap.h | 8 +- src/Defines.h | 4 +- src/Items/ItemHandler.cpp | 4 +- src/Items/{ItemSkull.h => ItemMobHead.h} | 6 +- src/Protocol/Protocol17x.cpp | 18 ++-- src/World.cpp | 4 +- src/World.h | 8 +- src/WorldStorage/NBTChunkSerializer.cpp | 14 +-- src/WorldStorage/NBTChunkSerializer.h | 4 +- src/WorldStorage/WSSAnvil.cpp | 16 +-- src/WorldStorage/WSSAnvil.h | 2 +- 23 files changed, 254 insertions(+), 256 deletions(-) create mode 100644 src/BlockEntities/MobHeadEntity.cpp create mode 100644 src/BlockEntities/MobHeadEntity.h delete mode 100644 src/BlockEntities/SkullEntity.cpp delete mode 100644 src/BlockEntities/SkullEntity.h rename src/Blocks/{BlockSkull.h => BlockMobHead.h} (74%) rename src/Items/{ItemSkull.h => ItemMobHead.h} (89%) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 70f3fbcf2..41b4cc0f4 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -22,7 +22,7 @@ #include "../BlockEntities/FurnaceEntity.h" #include "../BlockEntities/HopperEntity.h" #include "../BlockEntities/NoteEntity.h" -#include "../BlockEntities/SkullEntity.h" +#include "../BlockEntities/MobHeadEntity.h" #include "md5/md5.h" #include "../LineBlockTracer.h" #include "../WorldStorage/SchematicFileSerializer.h" @@ -2417,7 +2417,7 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "DoWithFurnaceAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithNoteBlockAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithCommandBlockAt", tolua_DoWithXYZ); - tolua_function(tolua_S, "DoWithSkullBlockAt", tolua_DoWithXYZ); + tolua_function(tolua_S, "DoWithMobHeadBlockAt", tolua_DoWithXYZ); tolua_function(tolua_S, "DoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::DoWithPlayer>); tolua_function(tolua_S, "FindAndDoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::FindAndDoWithPlayer>); tolua_function(tolua_S, "ForEachBlockEntityInChunk", tolua_ForEachInChunk); diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp index f01a139d2..57ad83de9 100644 --- a/src/BlockEntities/BlockEntity.cpp +++ b/src/BlockEntities/BlockEntity.cpp @@ -15,7 +15,7 @@ #include "JukeboxEntity.h" #include "NoteEntity.h" #include "SignEntity.h" -#include "SkullEntity.h" +#include "MobHeadEntity.h" @@ -30,7 +30,7 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE case E_BLOCK_DISPENSER: return new cDispenserEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_DROPPER: return new cDropperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_ENDER_CHEST: return new cEnderChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); - case E_BLOCK_HEAD: return new cSkullEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_HEAD: return new cMobHeadEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); case E_BLOCK_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); case E_BLOCK_HOPPER: return new cHopperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); diff --git a/src/BlockEntities/MobHeadEntity.cpp b/src/BlockEntities/MobHeadEntity.cpp new file mode 100644 index 000000000..c0a1781f6 --- /dev/null +++ b/src/BlockEntities/MobHeadEntity.cpp @@ -0,0 +1,108 @@ + +// MobHeadEntity.cpp + +// Implements the cMobHeadEntity class representing a single skull/head in the world + +#include "Globals.h" +#include "json/json.h" +#include "MobHeadEntity.h" +#include "../Entities/Player.h" + + + + + +cMobHeadEntity::cMobHeadEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : + super(E_BLOCK_HEAD, a_BlockX, a_BlockY, a_BlockZ, a_World), + m_Owner("") +{ +} + + + + + +void cMobHeadEntity::UsedBy(cPlayer * a_Player) +{ + UNUSED(a_Player); +} + + + + + +void cMobHeadEntity::SetType(const eMobHeadType & a_Type) +{ + if ((!m_Owner.empty()) && (a_Type != SKULL_TYPE_PLAYER)) + { + m_Owner = ""; + } + m_Type = a_Type; +} + + + + + +void cMobHeadEntity::SetRotation(eMobHeadRotation a_Rotation) +{ + m_Rotation = a_Rotation; +} + + + + + +void cMobHeadEntity::SetOwner(const AString & a_Owner) +{ + if ((a_Owner.length() > 16) || (m_Type != SKULL_TYPE_PLAYER)) + { + return; + } + m_Owner = a_Owner; +} + + + + + +void cMobHeadEntity::SendTo(cClientHandle & a_Client) +{ + a_Client.SendUpdateBlockEntity(*this); +} + + + + + +bool cMobHeadEntity::LoadFromJson(const Json::Value & a_Value) +{ + m_PosX = a_Value.get("x", 0).asInt(); + m_PosY = a_Value.get("y", 0).asInt(); + m_PosZ = a_Value.get("z", 0).asInt(); + + m_Type = static_cast(a_Value.get("Type", 0).asInt()); + m_Rotation = static_cast(a_Value.get("Rotation", 0).asInt()); + m_Owner = a_Value.get("Owner", "").asString(); + + return true; +} + + + + + +void cMobHeadEntity::SaveToJson(Json::Value & a_Value) +{ + a_Value["x"] = m_PosX; + a_Value["y"] = m_PosY; + a_Value["z"] = m_PosZ; + + a_Value["Type"] = m_Type; + a_Value["Rotation"] = m_Rotation; + a_Value["Owner"] = m_Owner; +} + + + + diff --git a/src/BlockEntities/MobHeadEntity.h b/src/BlockEntities/MobHeadEntity.h new file mode 100644 index 000000000..367eb15e7 --- /dev/null +++ b/src/BlockEntities/MobHeadEntity.h @@ -0,0 +1,79 @@ +// MobHeadEntity.h + +// Declares the cMobHeadEntity class representing a single skull/head in the world + + + + + +#pragma once + +#include "BlockEntity.h" + + + + + +namespace Json +{ + class Value; +} + + + + + +// tolua_begin + +class cMobHeadEntity : + public cBlockEntity +{ + typedef cBlockEntity super; + +public: + + // tolua_end + + /** Creates a new mob head entity at the specified block coords. a_World may be NULL */ + cMobHeadEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); + + bool LoadFromJson( const Json::Value& a_Value ); + virtual void SaveToJson(Json::Value& a_Value ) override; + + // tolua_begin + + /** Set the Type */ + void SetType(const eMobHeadType & a_SkullType); + + /** Set the Rotation */ + void SetRotation(eMobHeadRotation a_Rotation); + + /** Set the Player Name for Mobheads with Player type */ + void SetOwner(const AString & a_Owner); + + /** Get the Type */ + eMobHeadType GetType(void) const { return m_Type; } + + /** Get the Rotation */ + eMobHeadRotation GetRotation(void) const { return m_Rotation; } + + /** Get the setted Player Name */ + AString GetOwner(void) const { return m_Owner; } + + // tolua_end + + virtual void UsedBy(cPlayer * a_Player) override; + virtual void SendTo(cClientHandle & a_Client) override; + + static const char * GetClassStatic(void) { return "cMobHeadEntity"; } + +private: + + eMobHeadType m_Type; + eMobHeadRotation m_Rotation; + AString m_Owner; +} ; // tolua_export + + + + diff --git a/src/BlockEntities/SkullEntity.cpp b/src/BlockEntities/SkullEntity.cpp deleted file mode 100644 index 43b97b93e..000000000 --- a/src/BlockEntities/SkullEntity.cpp +++ /dev/null @@ -1,108 +0,0 @@ - -// SkullEntity.cpp - -// Implements the cSkullEntity class representing a single skull/head in the world - -#include "Globals.h" -#include "json/json.h" -#include "SkullEntity.h" -#include "../Entities/Player.h" - - - - - -cSkullEntity::cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : - super(E_BLOCK_HEAD, a_BlockX, a_BlockY, a_BlockZ, a_World), - m_Owner("") -{ -} - - - - - -void cSkullEntity::UsedBy(cPlayer * a_Player) -{ - UNUSED(a_Player); -} - - - - - -void cSkullEntity::SetSkullType(const eSkullType & a_SkullType) -{ - if ((!m_Owner.empty()) && (a_SkullType != SKULL_TYPE_PLAYER)) - { - m_Owner = ""; - } - m_SkullType = a_SkullType; -} - - - - - -void cSkullEntity::SetRotation(eSkullRotation a_Rotation) -{ - m_Rotation = a_Rotation; -} - - - - - -void cSkullEntity::SetOwner(const AString & a_Owner) -{ - if ((a_Owner.length() > 16) || (m_SkullType != SKULL_TYPE_PLAYER)) - { - return; - } - m_Owner = a_Owner; -} - - - - - -void cSkullEntity::SendTo(cClientHandle & a_Client) -{ - a_Client.SendUpdateBlockEntity(*this); -} - - - - - -bool cSkullEntity::LoadFromJson(const Json::Value & a_Value) -{ - m_PosX = a_Value.get("x", 0).asInt(); - m_PosY = a_Value.get("y", 0).asInt(); - m_PosZ = a_Value.get("z", 0).asInt(); - - m_SkullType = static_cast(a_Value.get("SkullType", 0).asInt()); - m_Rotation = static_cast(a_Value.get("Rotation", 0).asInt()); - m_Owner = a_Value.get("Owner", "").asString(); - - return true; -} - - - - - -void cSkullEntity::SaveToJson(Json::Value & a_Value) -{ - a_Value["x"] = m_PosX; - a_Value["y"] = m_PosY; - a_Value["z"] = m_PosZ; - - a_Value["SkullType"] = m_SkullType; - a_Value["Rotation"] = m_Rotation; - a_Value["Owner"] = m_Owner; -} - - - - diff --git a/src/BlockEntities/SkullEntity.h b/src/BlockEntities/SkullEntity.h deleted file mode 100644 index 3dc355623..000000000 --- a/src/BlockEntities/SkullEntity.h +++ /dev/null @@ -1,79 +0,0 @@ -// SkullEntity.h - -// Declares the cSkullEntity class representing a single skull/head in the world - - - - - -#pragma once - -#include "BlockEntity.h" - - - - - -namespace Json -{ - class Value; -} - - - - - -// tolua_begin - -class cSkullEntity : - public cBlockEntity -{ - typedef cBlockEntity super; - -public: - - // tolua_end - - /** Creates a new skull entity at the specified block coords. a_World may be NULL */ - cSkullEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); - - bool LoadFromJson( const Json::Value& a_Value ); - virtual void SaveToJson(Json::Value& a_Value ) override; - - // tolua_begin - - /** Set the Skull Type */ - void SetSkullType(const eSkullType & a_SkullType); - - /** Set the Rotation */ - void SetRotation(eSkullRotation a_Rotation); - - /** Set the Player Name for Player Skull */ - void SetOwner(const AString & a_Owner); - - /** Get the Skull Type */ - eSkullType GetSkullType(void) const { return m_SkullType; } - - /** Get the Rotation */ - eSkullRotation GetRotation(void) const { return m_Rotation; } - - /** Get the setted Player Name */ - AString GetOwner(void) const { return m_Owner; } - - // tolua_end - - virtual void UsedBy(cPlayer * a_Player) override; - virtual void SendTo(cClientHandle & a_Client) override; - - static const char * GetClassStatic(void) { return "cSkullEntity"; } - -private: - - eSkullType m_SkullType; - eSkullRotation m_Rotation; - AString m_Owner; -} ; // tolua_export - - - - diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 870de7a7d..09a1244ea 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -34,7 +34,7 @@ #include "BlockGlass.h" #include "BlockGlowstone.h" #include "BlockGravel.h" -#include "BlockSkull.h" +#include "BlockMobHead.h" #include "BlockHopper.h" #include "BlockIce.h" #include "BlockLadder.h" @@ -147,7 +147,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_GRASS: return new cBlockDirtHandler (a_BlockType); case E_BLOCK_GRAVEL: return new cBlockGravelHandler (a_BlockType); case E_BLOCK_HAY_BALE: return new cBlockSidewaysHandler (a_BlockType); - case E_BLOCK_HEAD: return new cBlockSkullHandler (a_BlockType); + case E_BLOCK_HEAD: return new cBlockMobHeadHandler (a_BlockType); case E_BLOCK_HOPPER: return new cBlockHopperHandler (a_BlockType); case E_BLOCK_ICE: return new cBlockIceHandler (a_BlockType); case E_BLOCK_INACTIVE_COMPARATOR: return new cBlockComparatorHandler (a_BlockType); diff --git a/src/Blocks/BlockSkull.h b/src/Blocks/BlockMobHead.h similarity index 74% rename from src/Blocks/BlockSkull.h rename to src/Blocks/BlockMobHead.h index eea5ac922..6a00c3acd 100644 --- a/src/Blocks/BlockSkull.h +++ b/src/Blocks/BlockMobHead.h @@ -2,17 +2,17 @@ #pragma once #include "BlockEntity.h" -#include "../BlockEntities/SkullEntity.h" +#include "../BlockEntities/MobHeadEntity.h" -class cBlockSkullHandler : +class cBlockMobHeadHandler : public cBlockEntityHandler { public: - cBlockSkullHandler(BLOCKTYPE a_BlockType) + cBlockMobHeadHandler(BLOCKTYPE a_BlockType) : cBlockEntityHandler(a_BlockType) { } @@ -29,13 +29,13 @@ public: BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ) override { - class cCallback : public cSkullBlockCallback + class cCallback : public cMobHeadBlockCallback { cPlayer * m_Player; NIBBLETYPE m_OldBlockMeta; NIBBLETYPE m_NewBlockMeta; - virtual bool Item (cSkullEntity * a_SkullEntity) + virtual bool Item (cMobHeadEntity * a_MobHeadEntity) { int Rotation = 0; if (m_NewBlockMeta == 1) @@ -43,8 +43,8 @@ public: Rotation = (int) floor(m_Player->GetYaw() * 16.0F / 360.0F + 0.5) & 0xF; } - a_SkullEntity->SetSkullType(static_cast(m_OldBlockMeta)); - a_SkullEntity->SetRotation(static_cast(Rotation)); + a_MobHeadEntity->SetType(static_cast(m_OldBlockMeta)); + a_MobHeadEntity->SetRotation(static_cast(Rotation)); return false; } @@ -59,7 +59,7 @@ public: a_BlockMeta = a_BlockFace; cWorld * World = (cWorld *) &a_WorldInterface; - World->DoWithSkullBlockAt(a_BlockX, a_BlockY, a_BlockZ, Callback); + World->DoWithMobHeadBlockAt(a_BlockX, a_BlockY, a_BlockZ, Callback); a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta); } } ; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e46aa3ee5..bfece3312 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,7 +39,7 @@ if (NOT MSVC) BlockEntities/JukeboxEntity.h BlockEntities/NoteEntity.h BlockEntities/SignEntity.h - BlockEntities/SkullEntity.h + BlockEntities/MobHeadEntity.h BlockID.h BoundingBox.h ChatColor.h diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 8b03732f3..0e757be6e 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -19,7 +19,7 @@ #include "BlockEntities/JukeboxEntity.h" #include "BlockEntities/NoteEntity.h" #include "BlockEntities/SignEntity.h" -#include "BlockEntities/SkullEntity.h" +#include "BlockEntities/MobHeadEntity.h" #include "Entities/Pickup.h" #include "Item.h" #include "Noise.h" @@ -2312,7 +2312,7 @@ bool cChunk::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCom -bool cChunk::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback) +bool cChunk::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback) { // The blockentity list is locked by the parent chunkmap's CS for (cBlockEntityList::iterator itr = m_BlockEntities.begin(), itr2 = itr; itr != m_BlockEntities.end(); itr = itr2) @@ -2329,7 +2329,7 @@ bool cChunk::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkull } // The correct block entity is here, - if (a_Callback.Item((cSkullEntity *)*itr)) + if (a_Callback.Item((cMobHeadEntity *)*itr)) { return false; } diff --git a/src/Chunk.h b/src/Chunk.h index 27388deb4..6bec60813 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -31,7 +31,7 @@ class cChestEntity; class cDispenserEntity; class cFurnaceEntity; class cNoteEntity; -class cSkullEntity; +class cMobHeadEntity; class cBlockArea; class cPawn; class cPickup; @@ -48,7 +48,7 @@ typedef cItemCallback cDispenserCallback; typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; -typedef cItemCallback cSkullBlockCallback; +typedef cItemCallback cMobHeadBlockCallback; @@ -245,8 +245,8 @@ public: /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */ bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); - /** Calls the callback for the skull block at the specified coords; returns false if there's no skull block at those coords or callback returns true, returns true if found */ - bool DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback); + /** Calls the callback for the mob head block at the specified coords; returns false if there's no mob header block at those coords or callback returns true, returns true if found */ + bool DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback); /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index 5f1674c03..0d19ecd28 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -2121,7 +2121,7 @@ bool cChunkMap::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, c -bool cChunkMap::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback) +bool cChunkMap::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback) { int ChunkX, ChunkZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; @@ -2132,7 +2132,7 @@ bool cChunkMap::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSk { return false; } - return Chunk->DoWithSkullBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); + return Chunk->DoWithMobHeadBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 02c245dc9..fb587a52e 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -25,7 +25,7 @@ class cDropSpenserEntity; class cFurnaceEntity; class cNoteEntity; class cCommandBlockEntity; -class cSkullEntity; +class cMobHeadEntity; class cPawn; class cPickup; class cChunkDataSerializer; @@ -44,7 +44,7 @@ typedef cItemCallback cDropSpenserCallback; typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; -typedef cItemCallback cSkullBlockCallback; +typedef cItemCallback cMobHeadBlockCallback; typedef cItemCallback cChunkCallback; @@ -247,8 +247,8 @@ public: /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */ bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); // Lua-accessible - /** Calls the callback for the skull block at the specified coords; returns false if there's no skull block at those coords or callback returns true, returns true if found */ - bool DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback); // Lua-accessible + /** Calls the callback for the mob head block at the specified coords; returns false if there's no mob head block at those coords or callback returns true, returns true if found */ + bool DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback); // Lua-accessible /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible diff --git a/src/Defines.h b/src/Defines.h index 7e22cbdc5..ba2866f83 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -174,7 +174,7 @@ enum eWeather -enum eSkullType +enum eMobHeadType { SKULL_TYPE_SKELETON = 0, SKULL_TYPE_WITHER = 1, @@ -187,7 +187,7 @@ enum eSkullType -enum eSkullRotation +enum eMobHeadRotation { SKULL_ROTATION_NORTH = 0, SKULL_ROTATION_NORTH_NORTH_EAST = 1, diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 4ede75cf1..3c3d98858 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -35,7 +35,7 @@ #include "ItemShears.h" #include "ItemShovel.h" #include "ItemSign.h" -#include "ItemSkull.h" +#include "ItemMobHead.h" #include "ItemSpawnEgg.h" #include "ItemSugarcane.h" #include "ItemSword.h" @@ -111,7 +111,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_ITEM_REDSTONE_REPEATER: return new cItemRedstoneRepeaterHandler(a_ItemType); case E_ITEM_SHEARS: return new cItemShearsHandler(a_ItemType); case E_ITEM_SIGN: return new cItemSignHandler(a_ItemType); - case E_ITEM_HEAD: return new cItemSkullHandler(a_ItemType); + case E_ITEM_HEAD: return new cItemMobHeadHandler(a_ItemType); case E_ITEM_SNOWBALL: return new cItemSnowballHandler(); case E_ITEM_SPAWN_EGG: return new cItemSpawnEggHandler(a_ItemType); case E_ITEM_SUGARCANE: return new cItemSugarcaneHandler(a_ItemType); diff --git a/src/Items/ItemSkull.h b/src/Items/ItemMobHead.h similarity index 89% rename from src/Items/ItemSkull.h rename to src/Items/ItemMobHead.h index 3648f1436..5ae040282 100644 --- a/src/Items/ItemSkull.h +++ b/src/Items/ItemMobHead.h @@ -8,11 +8,11 @@ -class cItemSkullHandler : +class cItemMobHeadHandler : public cItemHandler { public: - cItemSkullHandler(int a_ItemType) : + cItemMobHeadHandler(int a_ItemType) : cItemHandler(a_ItemType) { } @@ -31,10 +31,8 @@ public: BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override { - a_BlockType = E_BLOCK_HEAD; a_BlockMeta = (NIBBLETYPE)(a_Player->GetEquippedItem().m_ItemDamage & 0x0f); - return true; } } ; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 07b23e0ac..344dcc676 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -26,7 +26,7 @@ Implements the 1.7.x protocol classes: #include "../Mobs/IncludeAllMonsters.h" #include "../UI/Window.h" #include "../BlockEntities/CommandBlockEntity.h" -#include "../BlockEntities/SkullEntity.h" +#include "../BlockEntities/MobHeadEntity.h" #include "../CompositeChat.h" @@ -1043,7 +1043,7 @@ void cProtocol172::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) { case E_BLOCK_MOB_SPAWNER: Action = 1; break; // Update mob spawner spinny mob thing case E_BLOCK_COMMAND_BLOCK: Action = 2; break; // Update command block text - case E_BLOCK_HEAD: Action = 4; break; // Update Skull entity + case E_BLOCK_HEAD: Action = 4; break; // Update Mobhead entity default: ASSERT(!"Unhandled or unimplemented BlockEntity update request!"); break; } Pkt.WriteByte(Action); @@ -2273,14 +2273,14 @@ void cProtocol172::cPacketizer::WriteBlockEntity(const cBlockEntity & a_BlockEnt } case E_BLOCK_HEAD: { - cSkullEntity & SkullEntity = (cSkullEntity &)a_BlockEntity; + cMobHeadEntity & MobHeadEntity = (cMobHeadEntity &)a_BlockEntity; - Writer.AddInt("x", SkullEntity.GetPosX()); - Writer.AddInt("y", SkullEntity.GetPosY()); - Writer.AddInt("z", SkullEntity.GetPosZ()); - Writer.AddByte("SkullType", SkullEntity.GetSkullType() & 0xFF); - Writer.AddByte("Rot", SkullEntity.GetRotation() & 0xFF); - Writer.AddString("ExtraType", SkullEntity.GetOwner().c_str()); + Writer.AddInt("x", MobHeadEntity.GetPosX()); + Writer.AddInt("y", MobHeadEntity.GetPosY()); + Writer.AddInt("z", MobHeadEntity.GetPosZ()); + Writer.AddByte("SkullType", MobHeadEntity.GetType() & 0xFF); + Writer.AddByte("Rot", MobHeadEntity.GetRotation() & 0xFF); + Writer.AddString("ExtraType", MobHeadEntity.GetOwner().c_str()); Writer.AddString("id", "Skull"); // "Tile Entity ID" - MC wiki; vanilla server always seems to send this though break; } diff --git a/src/World.cpp b/src/World.cpp index 14d904d72..c0a621a2c 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1165,9 +1165,9 @@ bool cWorld::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCom -bool cWorld::DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback) +bool cWorld::DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback) { - return m_ChunkMap->DoWithSkullBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); + return m_ChunkMap->DoWithMobHeadBlockAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } diff --git a/src/World.h b/src/World.h index 4e83833ed..9c7079a92 100644 --- a/src/World.h +++ b/src/World.h @@ -45,7 +45,7 @@ class cChestEntity; class cDispenserEntity; class cFurnaceEntity; class cNoteEntity; -class cSkullEntity; +class cMobHeadEntity; class cMobCensus; class cCompositeChat; @@ -58,7 +58,7 @@ typedef cItemCallback cDispenserCallback; typedef cItemCallback cFurnaceCallback; typedef cItemCallback cNoteBlockCallback; typedef cItemCallback cCommandBlockCallback; -typedef cItemCallback cSkullBlockCallback; +typedef cItemCallback cMobHeadBlockCallback; @@ -512,8 +512,8 @@ public: /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */ bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); // Exported in ManualBindings.cpp - /** Calls the callback for the skull block at the specified coords; returns false if there's no skull block at those coords or callback returns true, returns true if found */ - bool DoWithSkullBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cSkullBlockCallback & a_Callback); // Exported in ManualBindings.cpp + /** Calls the callback for the mob head block at the specified coords; returns false if there's no mob head block at those coords or callback returns true, returns true if found */ + bool DoWithMobHeadBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadBlockCallback & a_Callback); // Exported in ManualBindings.cpp /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */ bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Exported in ManualBindings.cpp diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 6da141728..cf6df114e 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -19,7 +19,7 @@ #include "../BlockEntities/JukeboxEntity.h" #include "../BlockEntities/NoteEntity.h" #include "../BlockEntities/SignEntity.h" -#include "../BlockEntities/SkullEntity.h" +#include "../BlockEntities/MobHeadEntity.h" #include "../Entities/Entity.h" #include "../Entities/FallingBlock.h" @@ -261,13 +261,13 @@ void cNBTChunkSerializer::AddSignEntity(cSignEntity * a_Sign) -void cNBTChunkSerializer::AddSkullEntity(cSkullEntity * a_Skull) +void cNBTChunkSerializer::AddMobHeadEntity(cMobHeadEntity * a_MobHead) { m_Writer.BeginCompound(""); - AddBasicTileEntity(a_Skull, "Skull"); - m_Writer.AddByte ("SkullType", a_Skull->GetSkullType() & 0xFF); - m_Writer.AddByte ("Rot", a_Skull->GetRotation() & 0xFF); - m_Writer.AddString("ExtraType", a_Skull->GetOwner()); + AddBasicTileEntity(a_MobHead, "Skull"); + m_Writer.AddByte ("SkullType", a_MobHead->GetType() & 0xFF); + m_Writer.AddByte ("Rot", a_MobHead->GetRotation() & 0xFF); + m_Writer.AddString("ExtraType", a_MobHead->GetOwner()); m_Writer.EndCompound(); } @@ -681,7 +681,7 @@ void cNBTChunkSerializer::BlockEntity(cBlockEntity * a_Entity) case E_BLOCK_HOPPER: AddHopperEntity ((cHopperEntity *) a_Entity); break; case E_BLOCK_SIGN_POST: case E_BLOCK_WALLSIGN: AddSignEntity ((cSignEntity *) a_Entity); break; - case E_BLOCK_HEAD: AddSkullEntity ((cSkullEntity *) a_Entity); break; + case E_BLOCK_HEAD: AddMobHeadEntity ((cMobHeadEntity *) a_Entity); break; case E_BLOCK_NOTE_BLOCK: AddNoteEntity ((cNoteEntity *) a_Entity); break; case E_BLOCK_JUKEBOX: AddJukeboxEntity ((cJukeboxEntity *) a_Entity); break; case E_BLOCK_COMMAND_BLOCK: AddCommandBlockEntity((cCommandBlockEntity *) a_Entity); break; diff --git a/src/WorldStorage/NBTChunkSerializer.h b/src/WorldStorage/NBTChunkSerializer.h index fd5601e47..5f9e16ed1 100644 --- a/src/WorldStorage/NBTChunkSerializer.h +++ b/src/WorldStorage/NBTChunkSerializer.h @@ -29,7 +29,7 @@ class cHopperEntity; class cJukeboxEntity; class cNoteEntity; class cSignEntity; -class cSkullEntity; +class cMobHeadEntity; class cFallingBlock; class cMinecart; class cMinecartWithChest; @@ -94,7 +94,7 @@ protected: void AddJukeboxEntity (cJukeboxEntity * a_Jukebox); void AddNoteEntity (cNoteEntity * a_Note); void AddSignEntity (cSignEntity * a_Sign); - void AddSkullEntity (cSkullEntity * a_Skull); + void AddMobHeadEntity (cMobHeadEntity * a_MobHead); void AddCommandBlockEntity(cCommandBlockEntity * a_CmdBlock); // Entities: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 58dc2e9e4..d4490c7fe 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -24,7 +24,7 @@ #include "../BlockEntities/JukeboxEntity.h" #include "../BlockEntities/NoteEntity.h" #include "../BlockEntities/SignEntity.h" -#include "../BlockEntities/SkullEntity.h" +#include "../BlockEntities/MobHeadEntity.h" #include "../Mobs/Monster.h" @@ -600,7 +600,7 @@ void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntities, con } else if (strncmp(a_NBT.GetData(sID), "Skull", a_NBT.GetDataLength(sID)) == 0) { - LoadSkullFromNBT(a_BlockEntities, a_NBT, Child); + LoadMobHeadFromNBT(a_BlockEntities, a_NBT, Child); } else if (strncmp(a_NBT.GetData(sID), "Trap", a_NBT.GetDataLength(sID)) == 0) { @@ -932,7 +932,7 @@ void cWSSAnvil::LoadSignFromNBT(cBlockEntityList & a_BlockEntities, const cParse -void cWSSAnvil::LoadSkullFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx) +void cWSSAnvil::LoadMobHeadFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx) { ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound); int x, y, z; @@ -940,27 +940,27 @@ void cWSSAnvil::LoadSkullFromNBT(cBlockEntityList & a_BlockEntities, const cPars { return; } - std::auto_ptr Skull(new cSkullEntity(x, y, z, m_World)); + std::auto_ptr MobHead(new cMobHeadEntity(x, y, z, m_World)); int currentLine = a_NBT.FindChildByName(a_TagIdx, "SkullType"); if (currentLine >= 0) { - Skull->SetSkullType(static_cast(a_NBT.GetByte(currentLine))); + MobHead->SetType(static_cast(a_NBT.GetByte(currentLine))); } currentLine = a_NBT.FindChildByName(a_TagIdx, "Rot"); if (currentLine >= 0) { - Skull->SetRotation(static_cast(a_NBT.GetByte(currentLine))); + MobHead->SetRotation(static_cast(a_NBT.GetByte(currentLine))); } currentLine = a_NBT.FindChildByName(a_TagIdx, "ExtraType"); if (currentLine >= 0) { - Skull->SetOwner(a_NBT.GetString(currentLine)); + MobHead->SetOwner(a_NBT.GetString(currentLine)); } - a_BlockEntities.push_back(Skull.release()); + a_BlockEntities.push_back(MobHead.release()); } diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h index 9c9e17258..541371560 100644 --- a/src/WorldStorage/WSSAnvil.h +++ b/src/WorldStorage/WSSAnvil.h @@ -139,7 +139,7 @@ protected: void LoadJukeboxFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadNoteFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadSignFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); - void LoadSkullFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); + void LoadMobHeadFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadCommandBlockFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx); void LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_EntityTagIdx, const char * a_IDTag, int a_IDTagLength); From a3fa52ec739d6640f7dc4d481de77d633111cf46 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 20 Feb 2014 10:48:29 +0100 Subject: [PATCH 05/22] Fixed bindings for cBlockArea:Get(Rel)BlockTypeMeta(). They no longer require the ghost output params. --- src/Bindings/ManualBindings.cpp | 133 +++++++++++++++++++++++++------- src/BlockArea.h | 6 ++ 2 files changed, 110 insertions(+), 29 deletions(-) diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 41b4cc0f4..c220e5e0a 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -213,7 +213,7 @@ static int tolua_DoWith(lua_State* tolua_S) return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 2 or 3 arguments, got %i", NumArgs); } - Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, 0); + Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, NULL); const char * ItemName = tolua_tocppstring(tolua_S, 2, ""); if ((ItemName == NULL) || (ItemName[0] == 0)) @@ -307,7 +307,7 @@ static int tolua_DoWithID(lua_State* tolua_S) return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 2 or 3 arguments, got %i", NumArgs); } - Ty1 * self = (Ty1 *)tolua_tousertype(tolua_S, 1, 0); + Ty1 * self = (Ty1 *)tolua_tousertype(tolua_S, 1, NULL); int ItemID = (int)tolua_tonumber(tolua_S, 2, 0); if (!lua_isfunction(tolua_S, 3)) @@ -397,7 +397,7 @@ static int tolua_DoWithXYZ(lua_State* tolua_S) return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 4 or 5 arguments, got %i", NumArgs); } - Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, 0); + Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, NULL); if (!lua_isnumber(tolua_S, 2) || !lua_isnumber(tolua_S, 3) || !lua_isnumber(tolua_S, 4)) { return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a number for parameters #1, #2 and #3"); @@ -491,7 +491,7 @@ static int tolua_ForEachInChunk(lua_State* tolua_S) return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 3 or 4 arguments, got %i", NumArgs); } - Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, 0); + Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, NULL); if (!lua_isnumber(tolua_S, 2) || !lua_isnumber(tolua_S, 3)) { return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a number for parameters #1 and #2"); @@ -585,7 +585,7 @@ static int tolua_ForEach(lua_State * tolua_S) return lua_do_error(tolua_S, "Error in function call '#funcname#': Requires 1 or 2 arguments, got %i", NumArgs); } - Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, 0); + Ty1 * self = (Ty1 *) tolua_tousertype(tolua_S, 1, NULL); if (self == NULL) { return lua_do_error(tolua_S, "Error in function call '#funcname#': Not called on an object instance"); @@ -682,7 +682,7 @@ static int tolua_cWorld_GetBlockInfo(lua_State * tolua_S) else #endif { - cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, 0); + cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, NULL); int BlockX = (int) tolua_tonumber (tolua_S, 2, 0); int BlockY = (int) tolua_tonumber (tolua_S, 3, 0); int BlockZ = (int) tolua_tonumber (tolua_S, 4, 0); @@ -737,7 +737,7 @@ static int tolua_cWorld_GetBlockTypeMeta(lua_State * tolua_S) else #endif { - cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, 0); + cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, NULL); int BlockX = (int) tolua_tonumber (tolua_S, 2, 0); int BlockY = (int) tolua_tonumber (tolua_S, 3, 0); int BlockZ = (int) tolua_tonumber (tolua_S, 4, 0); @@ -789,7 +789,7 @@ static int tolua_cWorld_GetSignLines(lua_State * tolua_S) else #endif { - cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, 0); + cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, NULL); int BlockX = (int) tolua_tonumber (tolua_S, 2, 0); int BlockY = (int) tolua_tonumber (tolua_S, 3, 0); int BlockZ = (int) tolua_tonumber (tolua_S, 4, 0); @@ -847,7 +847,7 @@ static int tolua_cWorld_SetSignLines(lua_State * tolua_S) else #endif { - cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, 0); + cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, NULL); int BlockX = (int) tolua_tonumber (tolua_S, 2, 0); int BlockY = (int) tolua_tonumber (tolua_S, 3, 0); int BlockZ = (int) tolua_tonumber (tolua_S, 4, 0); @@ -896,7 +896,7 @@ static int tolua_cWorld_TryGetHeight(lua_State * tolua_S) else #endif { - cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, 0); + cWorld * self = (cWorld *) tolua_tousertype (tolua_S, 1, NULL); int BlockX = (int) tolua_tonumber (tolua_S, 2, 0); int BlockZ = (int) tolua_tonumber (tolua_S, 3, 0); #ifndef TOLUA_RELEASE @@ -968,7 +968,7 @@ static int tolua_cWorld_QueueTask(lua_State * tolua_S) } // Retrieve the args: - cWorld * self = (cWorld *)tolua_tousertype(tolua_S, 1, 0); + cWorld * self = (cWorld *)tolua_tousertype(tolua_S, 1, NULL); if (self == NULL) { return lua_do_error(tolua_S, "Error in function call '#funcname#': Not called on an object instance"); @@ -1066,7 +1066,7 @@ static int tolua_cWorld_ScheduleTask(lua_State * tolua_S) static int tolua_cPluginManager_GetAllPlugins(lua_State * tolua_S) { - cPluginManager * self = (cPluginManager *)tolua_tousertype(tolua_S, 1, 0); + cPluginManager * self = (cPluginManager *)tolua_tousertype(tolua_S, 1, NULL); const cPluginManager::PluginMap & AllPlugins = self->GetAllPlugins(); @@ -1290,7 +1290,7 @@ static int tolua_cPluginManager_ForEachCommand(lua_State * tolua_S) return 0; } - cPluginManager * self = (cPluginManager *)tolua_tousertype(tolua_S, 1, 0); + cPluginManager * self = (cPluginManager *)tolua_tousertype(tolua_S, 1, NULL); if (self == NULL) { LOGWARN("Error in function call 'ForEachCommand': Not called on an object instance"); @@ -1365,7 +1365,7 @@ static int tolua_cPluginManager_ForEachConsoleCommand(lua_State * tolua_S) return 0; } - cPluginManager * self = (cPluginManager *)tolua_tousertype(tolua_S, 1, 0); + cPluginManager * self = (cPluginManager *)tolua_tousertype(tolua_S, 1, NULL); if (self == NULL) { LOGWARN("Error in function call 'ForEachConsoleCommand': Not called on an object instance"); @@ -1687,7 +1687,7 @@ static int tolua_cWorld_ChunkStay(lua_State * tolua_S) static int tolua_cPlayer_GetGroups(lua_State* tolua_S) { - cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0); + cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S, 1, NULL); const cPlayer::GroupList & AllGroups = self->GetGroups(); @@ -1712,7 +1712,7 @@ static int tolua_cPlayer_GetGroups(lua_State* tolua_S) static int tolua_cPlayer_GetResolvedPermissions(lua_State* tolua_S) { - cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0); + cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S, 1, NULL); cPlayer::StringList AllPermissions = self->GetResolvedPermissions(); @@ -1825,7 +1825,7 @@ static int tolua_SetObjectCallback(lua_State * tolua_S) static int tolua_cPluginLua_AddWebTab(lua_State * tolua_S) { - cPluginLua * self = (cPluginLua *)tolua_tousertype(tolua_S,1,0); + cPluginLua * self = (cPluginLua *)tolua_tousertype(tolua_S, 1, NULL); tolua_Error tolua_err; tolua_err.array = 0; @@ -1869,7 +1869,7 @@ static int tolua_cPluginLua_AddWebTab(lua_State * tolua_S) static int tolua_cPluginLua_AddTab(lua_State* tolua_S) { - cPluginLua * self = (cPluginLua *) tolua_tousertype(tolua_S, 1, 0); + cPluginLua * self = (cPluginLua *) tolua_tousertype(tolua_S, 1, NULL); LOGWARN("WARNING: Using deprecated function AddTab()! Use AddWebTab() instead. (plugin \"%s\" in folder \"%s\")", self->GetName().c_str(), self->GetDirectory().c_str() ); @@ -1889,7 +1889,7 @@ static int tolua_cPlugin_Call(lua_State * tolua_S) L.LogStackTrace(); // Retrieve the params: plugin and the function name to call - cPluginLua * TargetPlugin = (cPluginLua *) tolua_tousertype(tolua_S, 1, 0); + cPluginLua * TargetPlugin = (cPluginLua *) tolua_tousertype(tolua_S, 1, NULL); AString FunctionName = tolua_tostring(tolua_S, 2, ""); // Call the function: @@ -1942,7 +1942,7 @@ static int tolua_push_StringStringMap(lua_State* tolua_S, std::map< std::string, static int tolua_get_HTTPRequest_Params(lua_State* tolua_S) { - HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S,1,0); + HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S, 1, NULL); return tolua_push_StringStringMap(tolua_S, self->Params); } @@ -1952,7 +1952,7 @@ static int tolua_get_HTTPRequest_Params(lua_State* tolua_S) static int tolua_get_HTTPRequest_PostParams(lua_State* tolua_S) { - HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S,1,0); + HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S, 1, NULL); return tolua_push_StringStringMap(tolua_S, self->PostParams); } @@ -1962,7 +1962,7 @@ static int tolua_get_HTTPRequest_PostParams(lua_State* tolua_S) static int tolua_get_HTTPRequest_FormData(lua_State* tolua_S) { - HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S,1,0); + HTTPRequest* self = (HTTPRequest*) tolua_tousertype(tolua_S, 1, NULL); std::map< std::string, HTTPFormData >& FormData = self->FormData; lua_newtable(tolua_S); @@ -1985,7 +1985,7 @@ static int tolua_get_HTTPRequest_FormData(lua_State* tolua_S) static int tolua_cWebAdmin_GetPlugins(lua_State * tolua_S) { - cWebAdmin* self = (cWebAdmin*) tolua_tousertype(tolua_S,1,0); + cWebAdmin* self = (cWebAdmin*) tolua_tousertype(tolua_S, 1, NULL); const cWebAdmin::PluginList & AllPlugins = self->GetPlugins(); @@ -2010,7 +2010,7 @@ static int tolua_cWebAdmin_GetPlugins(lua_State * tolua_S) static int tolua_cWebPlugin_GetTabNames(lua_State * tolua_S) { - cWebPlugin* self = (cWebPlugin*) tolua_tousertype(tolua_S,1,0); + cWebPlugin* self = (cWebPlugin*) tolua_tousertype(tolua_S, 1, NULL); const cWebPlugin::TabNameList & TabNames = self->GetTabNames(); @@ -2077,7 +2077,7 @@ static int Lua_ItemGrid_GetSlotCoords(lua_State * L) } { - const cItemGrid * self = (const cItemGrid *)tolua_tousertype(L, 1, 0); + const cItemGrid * self = (const cItemGrid *)tolua_tousertype(L, 1, NULL); int SlotNum = (int)tolua_tonumber(L, 2, 0); if (self == NULL) { @@ -2289,7 +2289,7 @@ static int tolua_cHopperEntity_GetOutputBlockPos(lua_State * tolua_S) { return 0; } - cHopperEntity * self = (cHopperEntity *)tolua_tousertype(tolua_S, 1, 0); + cHopperEntity * self = (cHopperEntity *)tolua_tousertype(tolua_S, 1, NULL); if (self == NULL) { tolua_error(tolua_S, "invalid 'self' in function 'cHopperEntity::GetOutputBlockPos()'", NULL); @@ -2315,6 +2315,76 @@ static int tolua_cHopperEntity_GetOutputBlockPos(lua_State * tolua_S) +static int tolua_cBlockArea_GetBlockTypeMeta(lua_State * tolua_S) +{ + // function cBlockArea::GetBlockTypeMeta() + // Exported manually because tolua generates extra input params for the outputs + + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(1, "cBlockArea") || + !L.CheckParamNumber (2, 4) + ) + { + return 0; + } + + cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, NULL); + if (self == NULL) + { + tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea:GetRelBlockTypeMeta'", NULL); + return 0; + } + int BlockX = (int)tolua_tonumber(tolua_S, 2, 0); + int BlockY = (int)tolua_tonumber(tolua_S, 3, 0); + int BlockZ = (int)tolua_tonumber(tolua_S, 4, 0); + BLOCKTYPE BlockType; + NIBBLETYPE BlockMeta; + self->GetBlockTypeMeta(BlockX, BlockY, BlockZ, BlockType, BlockMeta); + tolua_pushnumber(tolua_S, BlockType); + tolua_pushnumber(tolua_S, BlockMeta); + return 2; +} + + + + + +static int tolua_cBlockArea_GetRelBlockTypeMeta(lua_State * tolua_S) +{ + // function cBlockArea::GetRelBlockTypeMeta() + // Exported manually because tolua generates extra input params for the outputs + + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(1, "cBlockArea") || + !L.CheckParamNumber (2, 4) + ) + { + return 0; + } + + cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, NULL); + if (self == NULL) + { + tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea:GetRelBlockTypeMeta'", NULL); + return 0; + } + int BlockX = (int)tolua_tonumber(tolua_S, 2, 0); + int BlockY = (int)tolua_tonumber(tolua_S, 3, 0); + int BlockZ = (int)tolua_tonumber(tolua_S, 4, 0); + BLOCKTYPE BlockType; + NIBBLETYPE BlockMeta; + self->GetRelBlockTypeMeta(BlockX, BlockY, BlockZ, BlockType, BlockMeta); + tolua_pushnumber(tolua_S, BlockType); + tolua_pushnumber(tolua_S, BlockMeta); + return 2; +} + + + + + static int tolua_cBlockArea_LoadFromSchematicFile(lua_State * tolua_S) { // function cBlockArea::LoadFromSchematicFile @@ -2328,7 +2398,7 @@ static int tolua_cBlockArea_LoadFromSchematicFile(lua_State * tolua_S) { return 0; } - cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, 0); + cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, NULL); if (self == NULL) { tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea::LoadFromSchematicFile'", NULL); @@ -2344,6 +2414,7 @@ static int tolua_cBlockArea_LoadFromSchematicFile(lua_State * tolua_S) + static int tolua_cBlockArea_SaveToSchematicFile(lua_State * tolua_S) { // function cBlockArea::SaveToSchematicFile @@ -2357,7 +2428,7 @@ static int tolua_cBlockArea_SaveToSchematicFile(lua_State * tolua_S) { return 0; } - cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, 0); + cBlockArea * self = (cBlockArea *)tolua_tousertype(tolua_S, 1, NULL); if (self == NULL) { tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea::SaveToSchematicFile'", NULL); @@ -2371,6 +2442,8 @@ static int tolua_cBlockArea_SaveToSchematicFile(lua_State * tolua_S) + + void ManualBindings::Bind(lua_State * tolua_S) { tolua_beginmodule(tolua_S, NULL); @@ -2387,8 +2460,10 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cBlockArea"); + tolua_function(tolua_S, "GetBlockTypeMeta", tolua_cBlockArea_GetBlockTypeMeta); + tolua_function(tolua_S, "GetRelBlockTypeMeta", tolua_cBlockArea_GetRelBlockTypeMeta); tolua_function(tolua_S, "LoadFromSchematicFile", tolua_cBlockArea_LoadFromSchematicFile); - tolua_function(tolua_S, "SaveToSchematicFile", tolua_cBlockArea_SaveToSchematicFile); + tolua_function(tolua_S, "SaveToSchematicFile", tolua_cBlockArea_SaveToSchematicFile); tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cHopperEntity"); diff --git a/src/BlockArea.h b/src/BlockArea.h index 59bc0f241..b4a161f32 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -184,9 +184,15 @@ public: void SetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); void SetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + + // tolua_end + + // These need manual exporting, tolua generates the binding as requiring 2 extra input params void GetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const; void GetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const; + // tolua_begin + int GetSizeX(void) const { return m_SizeX; } int GetSizeY(void) const { return m_SizeY; } int GetSizeZ(void) const { return m_SizeZ; } From 7b8ff7c9868e574f53d4740046db7c686bd978fb Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 20 Feb 2014 11:05:45 +0100 Subject: [PATCH 06/22] APIDump: Fixed cBlockArea:GetRelBlockType() return types. --- MCServer/Plugins/APIDump/APIDesc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index fd4b1d947..73bb5c7fb 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -118,7 +118,7 @@ g_APIDesc = GetRelBlockMeta = { Params = "RelBlockX, RelBlockY, RelBlockZ", Return = "NIBBLETYPE", Notes = "Returns the block meta at the specified relative coords" }, GetRelBlockSkyLight = { Params = "RelBlockX, RelBlockY, RelBlockZ", Return = "NIBBLETYPE", Notes = "Returns the skylight at the specified relative coords" }, GetRelBlockType = { Params = "RelBlockX, RelBlockY, RelBlockZ", Return = "BLOCKTYPE", Notes = "Returns the block type at the specified relative coords" }, - GetRelBlockTypeMeta = { Params = "RelBlockX, RelBlockY, RelBlockZ", Return = "NIBBLETYPE", Notes = "Returns the block type and meta at the specified relative coords" }, + GetRelBlockTypeMeta = { Params = "RelBlockX, RelBlockY, RelBlockZ", Return = "BLOCKTYPE, NIBBLETYPE", Notes = "Returns the block type and meta at the specified relative coords" }, GetSizeX = { Params = "", Return = "number", Notes = "Returns the size of the held data in the x-axis" }, GetSizeY = { Params = "", Return = "number", Notes = "Returns the size of the held data in the y-axis" }, GetSizeZ = { Params = "", Return = "number", Notes = "Returns the size of the held data in the z-axis" }, From c2277c6feeae4551c511588e6da8b05e1bc0c22e Mon Sep 17 00:00:00 2001 From: TheJumper Date: Thu, 20 Feb 2014 16:26:50 +0100 Subject: [PATCH 07/22] BlockBed.cpp: Fixed Multiple people in one bed. OnUse in BlockBed.cpp now checks whether bit flag 0x4 in the Data values of the bed is set before somebody can try to sleep in the bed. --- src/Blocks/BlockBed.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index a6f3c36b6..2fa3a7264 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -63,20 +63,29 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface if (a_WorldInterface.GetTimeOfDay() > 13000) { NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - if (Meta & 0x8) + if(Meta & 0x4) { - // Is pillow - a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); + a_Player->SendMessageFailure("This bed is occupied."); } else { - // Is foot end - Vector3i Direction = MetaDataToDirection( Meta & 0x7 ); - if (a_ChunkInterface.GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping + if (Meta & 0x8) { - a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); + // Is pillow + a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); } + else + { + // Is foot end + Vector3i Direction = MetaDataToDirection( Meta & 0x7 ); + if (a_ChunkInterface.GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) == E_BLOCK_BED) // Must always use pillow location for sleeping + { + a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z); + } + } + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, (Meta | (1 << 2))); } + } else { a_Player->SendMessageFailure("You can only sleep at night"); } @@ -86,3 +95,5 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface + + From 1b081a0fbbc217ed48830368c6e40b24a7af5358 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Thu, 20 Feb 2014 17:31:38 +0100 Subject: [PATCH 08/22] BlockBed.cpp: Fixed space at if statement Added a space after an if statement and before the first bracket to keep up code conventions. --- src/Blocks/BlockBed.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index 2fa3a7264..3dad4feba 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -63,7 +63,7 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface if (a_WorldInterface.GetTimeOfDay() > 13000) { NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - if(Meta & 0x4) + if (Meta & 0x4) { a_Player->SendMessageFailure("This bed is occupied."); } From 1b32b005626e7dd7e466358910d461bf5fb11a64 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Fri, 21 Feb 2014 18:45:00 +0100 Subject: [PATCH 09/22] Fixed Mob Drops, Add Rare and Uncommon Drops, Looting inflicts Drops --- src/Mobs/Blaze.cpp | 6 +++++- src/Mobs/Cavespider.cpp | 8 ++++++-- src/Mobs/Chicken.cpp | 5 +++-- src/Mobs/Cow.cpp | 5 +++-- src/Mobs/Creeper.cpp | 3 ++- src/Mobs/Enderman.cpp | 3 ++- src/Mobs/Ghast.cpp | 5 +++-- src/Mobs/Horse.cpp | 3 ++- src/Mobs/IronGolem.cpp | 1 + src/Mobs/Magmacube.cpp | 5 ++++- src/Mobs/Monster.cpp | 29 +++++++++++++++++++++++++++++ src/Mobs/Monster.h | 3 +++ src/Mobs/Mooshroom.cpp | 5 +++-- src/Mobs/Pig.cpp | 3 ++- src/Mobs/Skeleton.cpp | 24 ++++++++++++++++++++++-- src/Mobs/Slime.cpp | 7 +++++-- src/Mobs/SnowGolem.cpp | 2 +- src/Mobs/Spider.cpp | 8 ++++++-- src/Mobs/Squid.cpp | 3 ++- src/Mobs/Witch.cpp | 27 ++++++++++++++++++++------- src/Mobs/Witch.h | 1 + src/Mobs/Zombie.cpp | 15 ++++++++++++--- src/Mobs/Zombiepigman.cpp | 10 +++++++--- 23 files changed, 144 insertions(+), 37 deletions(-) diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index f9c05b17a..084567708 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -19,7 +19,11 @@ cBlaze::cBlaze(void) : void cBlaze::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_BLAZE_ROD); + if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) + { + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_BLAZE_ROD); + } } diff --git a/src/Mobs/Cavespider.cpp b/src/Mobs/Cavespider.cpp index aba1ff9f5..0554f5c2a 100644 --- a/src/Mobs/Cavespider.cpp +++ b/src/Mobs/Cavespider.cpp @@ -31,8 +31,12 @@ void cCavespider::Tick(float a_Dt, cChunk & a_Chunk) void cCavespider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_STRING); - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_SPIDER_EYE); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); + if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) + { + AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); + } } diff --git a/src/Mobs/Chicken.cpp b/src/Mobs/Chicken.cpp index fab92ce49..4ca016883 100644 --- a/src/Mobs/Chicken.cpp +++ b/src/Mobs/Chicken.cpp @@ -48,8 +48,9 @@ void cChicken::Tick(float a_Dt, cChunk & a_Chunk) void cChicken::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_FEATHER); - a_Drops.push_back(cItem(IsOnFire() ? E_ITEM_COOKED_CHICKEN : E_ITEM_RAW_CHICKEN, 1)); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_FEATHER); + AddRandomDropItem(a_Drops, 1, 1, IsOnFire() ? E_ITEM_COOKED_CHICKEN : E_ITEM_RAW_CHICKEN); } diff --git a/src/Mobs/Cow.cpp b/src/Mobs/Cow.cpp index d8e905217..2740e4e72 100644 --- a/src/Mobs/Cow.cpp +++ b/src/Mobs/Cow.cpp @@ -21,8 +21,9 @@ cCow::cCow(void) : void cCow::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_LEATHER); - AddRandomDropItem(a_Drops, 1, 3, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); + AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); } diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp index ff0abfdca..594878e52 100644 --- a/src/Mobs/Creeper.cpp +++ b/src/Mobs/Creeper.cpp @@ -39,7 +39,8 @@ void cCreeper::Tick(float a_Dt, cChunk & a_Chunk) void cCreeper::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_GUNPOWDER); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); if ((a_Killer != NULL) && (a_Killer->IsProjectile())) { diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp index a784131e4..b79bf20fc 100644 --- a/src/Mobs/Enderman.cpp +++ b/src/Mobs/Enderman.cpp @@ -21,7 +21,8 @@ cEnderman::cEnderman(void) : void cEnderman::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_ENDER_PEARL); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ENDER_PEARL); } diff --git a/src/Mobs/Ghast.cpp b/src/Mobs/Ghast.cpp index 96a29b2d8..b62069d63 100644 --- a/src/Mobs/Ghast.cpp +++ b/src/Mobs/Ghast.cpp @@ -18,8 +18,9 @@ cGhast::cGhast(void) : void cGhast::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_GUNPOWDER); - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_GHAST_TEAR); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); + AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GHAST_TEAR); } diff --git a/src/Mobs/Horse.cpp b/src/Mobs/Horse.cpp index bb9a4e3f6..4220585a1 100644 --- a/src/Mobs/Horse.cpp +++ b/src/Mobs/Horse.cpp @@ -140,7 +140,8 @@ void cHorse::OnRightClicked(cPlayer & a_Player) void cHorse::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_LEATHER); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); if (m_bIsSaddled) { a_Drops.push_back(cItem(E_ITEM_SADDLE, 1)); diff --git a/src/Mobs/IronGolem.cpp b/src/Mobs/IronGolem.cpp index 47c961098..057834afd 100644 --- a/src/Mobs/IronGolem.cpp +++ b/src/Mobs/IronGolem.cpp @@ -19,6 +19,7 @@ cIronGolem::cIronGolem(void) : void cIronGolem::GetDrops(cItems & a_Drops, cEntity * a_Killer) { AddRandomDropItem(a_Drops, 0, 5, E_ITEM_IRON); + AddRandomDropItem(a_Drops, 0, 2, E_BLOCK_FLOWER); } diff --git a/src/Mobs/Magmacube.cpp b/src/Mobs/Magmacube.cpp index 86447ff6b..ec6137ca6 100644 --- a/src/Mobs/Magmacube.cpp +++ b/src/Mobs/Magmacube.cpp @@ -19,7 +19,10 @@ cMagmaCube::cMagmaCube(int a_Size) : void cMagmaCube::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_MAGMA_CREAM); + if (GetSize() > 1) + { + AddRandomUncommonDropItem(a_Drops, 25.0f, E_ITEM_MAGMA_CREAM); + } } diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index b5cf693cb..66629474b 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -880,6 +880,35 @@ void cMonster::AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned +void cMonster::AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short a_Item, short a_ItemHealth) +{ + MTRand r1; + int Count = r1.randInt() % 1000; + if (Count < (a_Chance*10)) + { + a_Drops.push_back(cItem(a_Item, 1, a_ItemHealth)); + } +} + + + + + +void cMonster::AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a_LootingLevel) +{ + MTRand r1; + int Count = r1.randInt() % 200; + if (Count < (5 + a_LootingLevel)) + { + int Rare = r1.randInt() % a_Items.Size(); + a_Drops.push_back(a_Items.at(Rare)); + } +} + + + + + void cMonster::HandleDaylightBurning(cChunk & a_Chunk) { if (!m_BurnsInDaylight) diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 4d2e099c5..909504213 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -224,6 +224,9 @@ protected: bool m_BurnsInDaylight; void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0); + void AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short a_Item, short a_ItemHealth = 0); + void AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a_LootingLevel); + } ; // tolua_export diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index 88101cd83..4c245ea2d 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -23,8 +23,9 @@ cMooshroom::cMooshroom(void) : void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_LEATHER); - AddRandomDropItem(a_Drops, 1, 3, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); + AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); } diff --git a/src/Mobs/Pig.cpp b/src/Mobs/Pig.cpp index d8f3dda37..063e2a5b4 100644 --- a/src/Mobs/Pig.cpp +++ b/src/Mobs/Pig.cpp @@ -21,7 +21,8 @@ cPig::cPig(void) : void cPig::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 1, 3, IsOnFire() ? E_ITEM_COOKED_PORKCHOP : E_ITEM_RAW_PORKCHOP); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_COOKED_PORKCHOP : E_ITEM_RAW_PORKCHOP); if (m_bIsSaddled) { a_Drops.push_back(cItem(E_ITEM_SADDLE, 1)); diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index 4c8e78988..b0a5670cf 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -20,8 +20,28 @@ cSkeleton::cSkeleton(bool IsWither) : void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_ARROW); - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_BONE); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + if (IsWither()) + { + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); + AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_COAL); + cItems RareDrops; + RareDrops.Add(cItem(E_ITEM_HEAD, 1, 1)); + if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); + AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + } + else + { + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ARROW); + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); + cItems RareDrops; + if (!GetEquippedHelmet().IsEmpty()) RareDrops.Add(GetEquippedHelmet()); + if (!GetEquippedChestplate().IsEmpty()) RareDrops.Add(GetEquippedChestplate()); + if (!GetEquippedLeggings().IsEmpty()) RareDrops.Add(GetEquippedLeggings()); + if (!GetEquippedBoots().IsEmpty()) RareDrops.Add(GetEquippedBoots()); + if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); + AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + } } diff --git a/src/Mobs/Slime.cpp b/src/Mobs/Slime.cpp index 19f376c21..f5b2cabc2 100644 --- a/src/Mobs/Slime.cpp +++ b/src/Mobs/Slime.cpp @@ -20,8 +20,11 @@ cSlime::cSlime(int a_Size) : void cSlime::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - // TODO: only when tiny - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_SLIMEBALL); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + if (GetSize() == 1) + { + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SLIMEBALL); + } } diff --git a/src/Mobs/SnowGolem.cpp b/src/Mobs/SnowGolem.cpp index c60103055..b68d18575 100644 --- a/src/Mobs/SnowGolem.cpp +++ b/src/Mobs/SnowGolem.cpp @@ -19,7 +19,7 @@ cSnowGolem::cSnowGolem(void) : void cSnowGolem::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 5, E_ITEM_SNOWBALL); + AddRandomDropItem(a_Drops, 0, 15, E_ITEM_SNOWBALL); } diff --git a/src/Mobs/Spider.cpp b/src/Mobs/Spider.cpp index b19a5dcef..1f41328a2 100644 --- a/src/Mobs/Spider.cpp +++ b/src/Mobs/Spider.cpp @@ -18,8 +18,12 @@ cSpider::cSpider(void) : void cSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_STRING); - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_SPIDER_EYE); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); + if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) + { + AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); + } } diff --git a/src/Mobs/Squid.cpp b/src/Mobs/Squid.cpp index 5a27762ff..9dee69cbb 100644 --- a/src/Mobs/Squid.cpp +++ b/src/Mobs/Squid.cpp @@ -21,7 +21,8 @@ cSquid::cSquid(void) : void cSquid::GetDrops(cItems & a_Drops, cEntity * a_Killer) { // Drops 0-3 Ink Sacs - AddRandomDropItem(a_Drops, 0, 3, E_ITEM_DYE, E_META_DYE_BLACK); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 3 + LootingLevel, E_ITEM_DYE, E_META_DYE_BLACK); } diff --git a/src/Mobs/Witch.cpp b/src/Mobs/Witch.cpp index 25d27041f..88e8f4e50 100644 --- a/src/Mobs/Witch.cpp +++ b/src/Mobs/Witch.cpp @@ -18,13 +18,26 @@ cWitch::cWitch(void) : void cWitch::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 6, E_ITEM_GLASS_BOTTLE); - AddRandomDropItem(a_Drops, 0, 6, E_ITEM_GLOWSTONE_DUST); - AddRandomDropItem(a_Drops, 0, 6, E_ITEM_GUNPOWDER); - AddRandomDropItem(a_Drops, 0, 6, E_ITEM_REDSTONE_DUST); - AddRandomDropItem(a_Drops, 0, 6, E_ITEM_SPIDER_EYE); - AddRandomDropItem(a_Drops, 0, 6, E_ITEM_STICK); - AddRandomDropItem(a_Drops, 0, 6, E_ITEM_SUGAR); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + MTRand r1; + int DropTypeCount = (r1.randInt() % 3) + 1; + for (int i = 0; i < DropTypeCount; i++) + { + int DropType = r1.randInt() % 7; + switch (DropType) + { + case 0: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLASS_BOTTLE); + case 1: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLOWSTONE_DUST); + case 2: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); + case 3: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_REDSTONE_DUST); + case 4: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SPIDER_EYE); + case 5: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STICK); + case 6: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SUGAR); + } + } + cItems RareDrops; + if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); + AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); } diff --git a/src/Mobs/Witch.h b/src/Mobs/Witch.h index 4e637beea..51c63322a 100644 --- a/src/Mobs/Witch.h +++ b/src/Mobs/Witch.h @@ -2,6 +2,7 @@ #pragma once #include "AggressiveMonster.h" +#include "../MersenneTwister.h" diff --git a/src/Mobs/Zombie.cpp b/src/Mobs/Zombie.cpp index 27e8ed5fb..72373266a 100644 --- a/src/Mobs/Zombie.cpp +++ b/src/Mobs/Zombie.cpp @@ -23,9 +23,18 @@ cZombie::cZombie(bool a_IsVillagerZombie) : void cZombie::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 2, E_ITEM_ROTTEN_FLESH); - - // TODO: Rare drops + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ROTTEN_FLESH); + cItems RareDrops; + RareDrops.Add(cItem(E_ITEM_IRON)); + RareDrops.Add(cItem(E_ITEM_CARROT)); + RareDrops.Add(cItem(E_ITEM_POTATO)); + if (!GetEquippedHelmet().IsEmpty()) RareDrops.Add(GetEquippedHelmet()); + if (!GetEquippedChestplate().IsEmpty()) RareDrops.Add(GetEquippedChestplate()); + if (!GetEquippedLeggings().IsEmpty()) RareDrops.Add(GetEquippedLeggings()); + if (!GetEquippedBoots().IsEmpty()) RareDrops.Add(GetEquippedBoots()); + if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); + AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); } diff --git a/src/Mobs/Zombiepigman.cpp b/src/Mobs/Zombiepigman.cpp index 6ac89ed4c..d1eadc2ae 100644 --- a/src/Mobs/Zombiepigman.cpp +++ b/src/Mobs/Zombiepigman.cpp @@ -19,10 +19,14 @@ cZombiePigman::cZombiePigman(void) : void cZombiePigman::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_ROTTEN_FLESH); - AddRandomDropItem(a_Drops, 0, 1, E_ITEM_GOLD_NUGGET); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ROTTEN_FLESH); + AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GOLD_NUGGET); - // TODO: Rare drops + cItems RareDrops; + RareDrops.Add(cItem(E_ITEM_GOLD)); + if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); + AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); } From 7a7b9e88b295bd5e151f84cb4ae78d1749367d4e Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sat, 22 Feb 2014 01:21:49 +0100 Subject: [PATCH 10/22] Added static Enchantment Constants, Replaced cryptic Looting ID --- src/BlockID.h | 32 ++++++++++++++++++++++++++++++++ src/Mobs/Blaze.cpp | 2 +- src/Mobs/Cavespider.cpp | 2 +- src/Mobs/Chicken.cpp | 2 +- src/Mobs/Cow.cpp | 2 +- src/Mobs/Creeper.cpp | 2 +- src/Mobs/Enderman.cpp | 2 +- src/Mobs/Ghast.cpp | 2 +- src/Mobs/Horse.cpp | 2 +- src/Mobs/Mooshroom.cpp | 2 +- src/Mobs/Pig.cpp | 2 +- src/Mobs/Skeleton.cpp | 2 +- src/Mobs/Slime.cpp | 2 +- src/Mobs/Spider.cpp | 2 +- src/Mobs/Squid.cpp | 2 +- src/Mobs/Witch.cpp | 2 +- src/Mobs/Zombie.cpp | 2 +- src/Mobs/Zombiepigman.cpp | 2 +- 18 files changed, 49 insertions(+), 17 deletions(-) diff --git a/src/BlockID.h b/src/BlockID.h index 740c5fc90..e23a0f82a 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -392,6 +392,38 @@ enum ENUM_ITEM_ID +// ENCHANTMENT IDS +enum +{ + E_ENCHANTMENT_PROTECTION = 0, + E_ENCHANTMENT_FIRE_PROTECTION = 1, + E_ENCHANTMENT_FEATHER_FALLING = 2, + E_ENCHANTMENT_BLAST_PROTECTION = 3, + E_ENCHANTMENT_PROJECTILE_PROTECTION= 4, + E_ENCHANTMENT_RESPIRATION = 5, + E_ENCHANTMENT_AQUA_AFFINITY = 6, + E_ENCHANTMENT_THORNS = 7, + E_ENCHANTMENT_SHARPNESS = 16, + E_ENCHANTMENT_SMITE = 17, + E_ENCHANTMENT_BANE_OF_ARTHROPODS = 18, + E_ENCHANTMENT_KNOCKBACK = 19, + E_ENCHANTMENT_FIREASPECT = 20, + E_ENCHANTMENT_LOOTING = 21, + E_ENCHANTMENT_EFFICIENCY = 32, + E_ENCHANTMENT_SILKTOUCH = 33, + E_ENCHANTMENT_UNBREAKING = 34, + E_ENCHANTMENT_FORTUNE = 35, + E_ENCHANTMENT_POWER = 48, + E_ENCHANTMENT_PUNCH = 49, + E_ENCHANTMENT_FLAME = 50, + E_ENCHANTMENT_INFINITY = 51, + E_ENCHANTMENT_LUCKOFTHESEA = 61, + E_ENCHANTMENT_LURE = 62, +}; + + + + enum { diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index 084567708..bd16a36e2 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -21,7 +21,7 @@ void cBlaze::GetDrops(cItems & a_Drops, cEntity * a_Killer) { if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_BLAZE_ROD); } } diff --git a/src/Mobs/Cavespider.cpp b/src/Mobs/Cavespider.cpp index 0554f5c2a..7274820b7 100644 --- a/src/Mobs/Cavespider.cpp +++ b/src/Mobs/Cavespider.cpp @@ -31,7 +31,7 @@ void cCavespider::Tick(float a_Dt, cChunk & a_Chunk) void cCavespider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) { diff --git a/src/Mobs/Chicken.cpp b/src/Mobs/Chicken.cpp index 4ca016883..9388e1097 100644 --- a/src/Mobs/Chicken.cpp +++ b/src/Mobs/Chicken.cpp @@ -48,7 +48,7 @@ void cChicken::Tick(float a_Dt, cChunk & a_Chunk) void cChicken::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_FEATHER); AddRandomDropItem(a_Drops, 1, 1, IsOnFire() ? E_ITEM_COOKED_CHICKEN : E_ITEM_RAW_CHICKEN); } diff --git a/src/Mobs/Cow.cpp b/src/Mobs/Cow.cpp index 2740e4e72..cda067fac 100644 --- a/src/Mobs/Cow.cpp +++ b/src/Mobs/Cow.cpp @@ -21,7 +21,7 @@ cCow::cCow(void) : void cCow::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); } diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp index 594878e52..0ae78eee3 100644 --- a/src/Mobs/Creeper.cpp +++ b/src/Mobs/Creeper.cpp @@ -39,7 +39,7 @@ void cCreeper::Tick(float a_Dt, cChunk & a_Chunk) void cCreeper::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); if ((a_Killer != NULL) && (a_Killer->IsProjectile())) diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp index b79bf20fc..4a5ad25be 100644 --- a/src/Mobs/Enderman.cpp +++ b/src/Mobs/Enderman.cpp @@ -21,7 +21,7 @@ cEnderman::cEnderman(void) : void cEnderman::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ENDER_PEARL); } diff --git a/src/Mobs/Ghast.cpp b/src/Mobs/Ghast.cpp index b62069d63..a73ed0944 100644 --- a/src/Mobs/Ghast.cpp +++ b/src/Mobs/Ghast.cpp @@ -18,7 +18,7 @@ cGhast::cGhast(void) : void cGhast::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GHAST_TEAR); } diff --git a/src/Mobs/Horse.cpp b/src/Mobs/Horse.cpp index 4220585a1..3c29e3682 100644 --- a/src/Mobs/Horse.cpp +++ b/src/Mobs/Horse.cpp @@ -140,7 +140,7 @@ void cHorse::OnRightClicked(cPlayer & a_Player) void cHorse::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); if (m_bIsSaddled) { diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index 4c245ea2d..17995ce91 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -23,7 +23,7 @@ cMooshroom::cMooshroom(void) : void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); } diff --git a/src/Mobs/Pig.cpp b/src/Mobs/Pig.cpp index 063e2a5b4..e4e46dfec 100644 --- a/src/Mobs/Pig.cpp +++ b/src/Mobs/Pig.cpp @@ -21,7 +21,7 @@ cPig::cPig(void) : void cPig::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_COOKED_PORKCHOP : E_ITEM_RAW_PORKCHOP); if (m_bIsSaddled) { diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index b0a5670cf..622cb5ceb 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -20,7 +20,7 @@ cSkeleton::cSkeleton(bool IsWither) : void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); if (IsWither()) { AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); diff --git a/src/Mobs/Slime.cpp b/src/Mobs/Slime.cpp index f5b2cabc2..7941e2452 100644 --- a/src/Mobs/Slime.cpp +++ b/src/Mobs/Slime.cpp @@ -20,7 +20,7 @@ cSlime::cSlime(int a_Size) : void cSlime::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); if (GetSize() == 1) { AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SLIMEBALL); diff --git a/src/Mobs/Spider.cpp b/src/Mobs/Spider.cpp index 1f41328a2..aeb6e1bcc 100644 --- a/src/Mobs/Spider.cpp +++ b/src/Mobs/Spider.cpp @@ -18,7 +18,7 @@ cSpider::cSpider(void) : void cSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) { diff --git a/src/Mobs/Squid.cpp b/src/Mobs/Squid.cpp index 9dee69cbb..4f2abf574 100644 --- a/src/Mobs/Squid.cpp +++ b/src/Mobs/Squid.cpp @@ -21,7 +21,7 @@ cSquid::cSquid(void) : void cSquid::GetDrops(cItems & a_Drops, cEntity * a_Killer) { // Drops 0-3 Ink Sacs - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 3 + LootingLevel, E_ITEM_DYE, E_META_DYE_BLACK); } diff --git a/src/Mobs/Witch.cpp b/src/Mobs/Witch.cpp index 88e8f4e50..6cb103645 100644 --- a/src/Mobs/Witch.cpp +++ b/src/Mobs/Witch.cpp @@ -18,7 +18,7 @@ cWitch::cWitch(void) : void cWitch::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); MTRand r1; int DropTypeCount = (r1.randInt() % 3) + 1; for (int i = 0; i < DropTypeCount; i++) diff --git a/src/Mobs/Zombie.cpp b/src/Mobs/Zombie.cpp index 72373266a..6a007683b 100644 --- a/src/Mobs/Zombie.cpp +++ b/src/Mobs/Zombie.cpp @@ -23,7 +23,7 @@ cZombie::cZombie(bool a_IsVillagerZombie) : void cZombie::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ROTTEN_FLESH); cItems RareDrops; RareDrops.Add(cItem(E_ITEM_IRON)); diff --git a/src/Mobs/Zombiepigman.cpp b/src/Mobs/Zombiepigman.cpp index d1eadc2ae..ca222f9fe 100644 --- a/src/Mobs/Zombiepigman.cpp +++ b/src/Mobs/Zombiepigman.cpp @@ -19,7 +19,7 @@ cZombiePigman::cZombiePigman(void) : void cZombiePigman::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(21); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ROTTEN_FLESH); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GOLD_NUGGET); From 764de9c39939e2184671e52ebab599c4e1c6b47d Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sat, 22 Feb 2014 01:27:32 +0100 Subject: [PATCH 11/22] Changed killer detection by using cEntity methods --- src/Mobs/Blaze.cpp | 2 +- src/Mobs/Cavespider.cpp | 2 +- src/Mobs/Spider.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index bd16a36e2..005bb23a1 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -19,7 +19,7 @@ cBlaze::cBlaze(void) : void cBlaze::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) + if (a_Killer->IsPlayer() || a_Killer->IsA("cWolf")) { int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_BLAZE_ROD); diff --git a/src/Mobs/Cavespider.cpp b/src/Mobs/Cavespider.cpp index 7274820b7..9c88ac5d7 100644 --- a/src/Mobs/Cavespider.cpp +++ b/src/Mobs/Cavespider.cpp @@ -33,7 +33,7 @@ void cCavespider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); - if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) + if (a_Killer->IsPlayer() || a_Killer->IsA("cWolf")) { AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); } diff --git a/src/Mobs/Spider.cpp b/src/Mobs/Spider.cpp index aeb6e1bcc..1eb340075 100644 --- a/src/Mobs/Spider.cpp +++ b/src/Mobs/Spider.cpp @@ -20,7 +20,7 @@ void cSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); - if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) + if (a_Killer->IsPlayer() || a_Killer->IsA("cWolf")) { AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); } From c4bfe670c602ec498cc9ee9f6f7f430a353cdda0 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sat, 22 Feb 2014 01:29:50 +0100 Subject: [PATCH 12/22] Monster.cpp: Fixed Formatting in AddRandomUncommonDropItem --- src/Mobs/Monster.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 66629474b..777b78c63 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -884,7 +884,7 @@ void cMonster::AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short { MTRand r1; int Count = r1.randInt() % 1000; - if (Count < (a_Chance*10)) + if (Count < (a_Chance * 10)) { a_Drops.push_back(cItem(a_Item, 1, a_ItemHealth)); } From f45d7d9769782b5e9a11348c4ef261a2da51091a Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sat, 22 Feb 2014 01:42:49 +0100 Subject: [PATCH 13/22] Monster.h: Added doxy-comments for drop methods --- src/Mobs/Monster.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 909504213..670e899c5 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -223,8 +223,11 @@ protected: void HandleDaylightBurning(cChunk & a_Chunk); bool m_BurnsInDaylight; + /** Adds a random number of a_Item between a_Min and a_Max to itemdrops a_Drops*/ void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0); + /** Adds a item a_Item with the chance of a_Chance to itemdrops a_Drops*/ void AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short a_Item, short a_ItemHealth = 0); + /** Adds one rare item out of the list of rare items a_Items modified by the looting level a_LootingLevel(I-III or custom) to the itemdrop a_Drops*/ void AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a_LootingLevel); From 748a9c60b336f5ffabed9d5f2d86fc757bd3a253 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sat, 22 Feb 2014 02:11:54 +0100 Subject: [PATCH 14/22] Mooshroom.cpp: Added right click interaction --- src/Mobs/Mooshroom.cpp | 38 +++++++++++++++++++++++++++++++++++++- src/Mobs/Mooshroom.h | 1 + 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index 17995ce91..4787c6096 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -2,11 +2,12 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Mooshroom.h" +#include "../Entities/Player.h" + -// TODO: Milk Cow @@ -30,3 +31,38 @@ void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer) + + +void cMooshroom::OnRightClicked(cPlayer & a_Player) +{ + if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_BUCKET)) + { + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + a_Player.GetInventory().AddItem(E_ITEM_MILK); + } + } + + if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_BOWL)) + { + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + a_Player.GetInventory().AddItem(E_ITEM_MUSHROOM_SOUP); + } + } + + if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_SHEARS) + { + if (!a_Player.IsGameModeCreative()) + { + a_Player.UseEquippedItem(); + } + + cItems Drops; + Drops.push_back(cItem(E_BLOCK_RED_MUSHROOM, 5, 0)); + m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); + } +} + diff --git a/src/Mobs/Mooshroom.h b/src/Mobs/Mooshroom.h index c94301098..16f6c8248 100644 --- a/src/Mobs/Mooshroom.h +++ b/src/Mobs/Mooshroom.h @@ -18,6 +18,7 @@ public: CLASS_PROTODEF(cMooshroom); virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; + virtual void OnRightClicked(cPlayer & a_Player) override; virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); } } ; From b15ca0055b922f39b968b051efd921897d61276c Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sat, 22 Feb 2014 12:58:32 +0100 Subject: [PATCH 15/22] Fixed Looting segment fault - a_Killer can be NULL --- src/Mobs/Blaze.cpp | 2 +- src/Mobs/Cavespider.cpp | 8 ++++++-- src/Mobs/Chicken.cpp | 6 +++++- src/Mobs/Cow.cpp | 6 +++++- src/Mobs/Creeper.cpp | 6 +++++- src/Mobs/Enderman.cpp | 6 +++++- src/Mobs/Ghast.cpp | 6 +++++- src/Mobs/Horse.cpp | 6 +++++- src/Mobs/Mooshroom.cpp | 6 +++++- src/Mobs/Pig.cpp | 6 +++++- src/Mobs/Skeleton.cpp | 6 +++++- src/Mobs/Slime.cpp | 6 +++++- src/Mobs/Spider.cpp | 8 ++++++-- src/Mobs/Squid.cpp | 6 +++++- src/Mobs/Witch.cpp | 6 +++++- src/Mobs/Zombie.cpp | 6 +++++- src/Mobs/Zombiepigman.cpp | 6 +++++- 17 files changed, 83 insertions(+), 19 deletions(-) diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index 005bb23a1..fb97ea3c4 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -19,7 +19,7 @@ cBlaze::cBlaze(void) : void cBlaze::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - if (a_Killer->IsPlayer() || a_Killer->IsA("cWolf")) + if (a_Killer != NULL && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_BLAZE_ROD); diff --git a/src/Mobs/Cavespider.cpp b/src/Mobs/Cavespider.cpp index 9c88ac5d7..a2678744b 100644 --- a/src/Mobs/Cavespider.cpp +++ b/src/Mobs/Cavespider.cpp @@ -31,9 +31,13 @@ void cCavespider::Tick(float a_Dt, cChunk & a_Chunk) void cCavespider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); - if (a_Killer->IsPlayer() || a_Killer->IsA("cWolf")) + if (a_Killer != NULL && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); } diff --git a/src/Mobs/Chicken.cpp b/src/Mobs/Chicken.cpp index 9388e1097..b58eedbf7 100644 --- a/src/Mobs/Chicken.cpp +++ b/src/Mobs/Chicken.cpp @@ -48,7 +48,11 @@ void cChicken::Tick(float a_Dt, cChunk & a_Chunk) void cChicken::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_FEATHER); AddRandomDropItem(a_Drops, 1, 1, IsOnFire() ? E_ITEM_COOKED_CHICKEN : E_ITEM_RAW_CHICKEN); } diff --git a/src/Mobs/Cow.cpp b/src/Mobs/Cow.cpp index cda067fac..49eac5cf5 100644 --- a/src/Mobs/Cow.cpp +++ b/src/Mobs/Cow.cpp @@ -21,7 +21,11 @@ cCow::cCow(void) : void cCow::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); } diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp index 0ae78eee3..3dd978088 100644 --- a/src/Mobs/Creeper.cpp +++ b/src/Mobs/Creeper.cpp @@ -39,7 +39,11 @@ void cCreeper::Tick(float a_Dt, cChunk & a_Chunk) void cCreeper::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); if ((a_Killer != NULL) && (a_Killer->IsProjectile())) diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp index 4a5ad25be..f0a3b5f5d 100644 --- a/src/Mobs/Enderman.cpp +++ b/src/Mobs/Enderman.cpp @@ -21,7 +21,11 @@ cEnderman::cEnderman(void) : void cEnderman::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ENDER_PEARL); } diff --git a/src/Mobs/Ghast.cpp b/src/Mobs/Ghast.cpp index a73ed0944..300435557 100644 --- a/src/Mobs/Ghast.cpp +++ b/src/Mobs/Ghast.cpp @@ -18,7 +18,11 @@ cGhast::cGhast(void) : void cGhast::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GHAST_TEAR); } diff --git a/src/Mobs/Horse.cpp b/src/Mobs/Horse.cpp index 3c29e3682..73cc532bf 100644 --- a/src/Mobs/Horse.cpp +++ b/src/Mobs/Horse.cpp @@ -140,7 +140,11 @@ void cHorse::OnRightClicked(cPlayer & a_Player) void cHorse::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); if (m_bIsSaddled) { diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index 4787c6096..bc1b9cac7 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -24,7 +24,11 @@ cMooshroom::cMooshroom(void) : void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); } diff --git a/src/Mobs/Pig.cpp b/src/Mobs/Pig.cpp index e4e46dfec..aa127a590 100644 --- a/src/Mobs/Pig.cpp +++ b/src/Mobs/Pig.cpp @@ -21,7 +21,11 @@ cPig::cPig(void) : void cPig::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_COOKED_PORKCHOP : E_ITEM_RAW_PORKCHOP); if (m_bIsSaddled) { diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index 622cb5ceb..7c62de9cf 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -20,7 +20,11 @@ cSkeleton::cSkeleton(bool IsWither) : void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } if (IsWither()) { AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); diff --git a/src/Mobs/Slime.cpp b/src/Mobs/Slime.cpp index 7941e2452..2001fdcb4 100644 --- a/src/Mobs/Slime.cpp +++ b/src/Mobs/Slime.cpp @@ -20,7 +20,11 @@ cSlime::cSlime(int a_Size) : void cSlime::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } if (GetSize() == 1) { AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SLIMEBALL); diff --git a/src/Mobs/Spider.cpp b/src/Mobs/Spider.cpp index 1eb340075..d20f4997c 100644 --- a/src/Mobs/Spider.cpp +++ b/src/Mobs/Spider.cpp @@ -18,9 +18,13 @@ cSpider::cSpider(void) : void cSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); - if (a_Killer->IsPlayer() || a_Killer->IsA("cWolf")) + if (a_Killer != NULL && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); } diff --git a/src/Mobs/Squid.cpp b/src/Mobs/Squid.cpp index 4f2abf574..24818222b 100644 --- a/src/Mobs/Squid.cpp +++ b/src/Mobs/Squid.cpp @@ -21,7 +21,11 @@ cSquid::cSquid(void) : void cSquid::GetDrops(cItems & a_Drops, cEntity * a_Killer) { // Drops 0-3 Ink Sacs - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 3 + LootingLevel, E_ITEM_DYE, E_META_DYE_BLACK); } diff --git a/src/Mobs/Witch.cpp b/src/Mobs/Witch.cpp index 6cb103645..f9025afe3 100644 --- a/src/Mobs/Witch.cpp +++ b/src/Mobs/Witch.cpp @@ -18,7 +18,11 @@ cWitch::cWitch(void) : void cWitch::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } MTRand r1; int DropTypeCount = (r1.randInt() % 3) + 1; for (int i = 0; i < DropTypeCount; i++) diff --git a/src/Mobs/Zombie.cpp b/src/Mobs/Zombie.cpp index 6a007683b..61cf49c14 100644 --- a/src/Mobs/Zombie.cpp +++ b/src/Mobs/Zombie.cpp @@ -23,7 +23,11 @@ cZombie::cZombie(bool a_IsVillagerZombie) : void cZombie::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ROTTEN_FLESH); cItems RareDrops; RareDrops.Add(cItem(E_ITEM_IRON)); diff --git a/src/Mobs/Zombiepigman.cpp b/src/Mobs/Zombiepigman.cpp index ca222f9fe..5492068c9 100644 --- a/src/Mobs/Zombiepigman.cpp +++ b/src/Mobs/Zombiepigman.cpp @@ -19,7 +19,11 @@ cZombiePigman::cZombiePigman(void) : void cZombiePigman::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + } AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ROTTEN_FLESH); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GOLD_NUGGET); From 90574d083da08ccd6699bdad403601e282d73b89 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sat, 22 Feb 2014 22:57:40 +0100 Subject: [PATCH 16/22] Changed formatting, encapsuled armor drop, introduced better static Enchantment IDs --- src/BlockID.h | 32 -------------------------------- src/Enchantments.h | 32 ++++++++++++++++++++++++++++++++ src/Mobs/Blaze.cpp | 2 +- src/Mobs/Cavespider.cpp | 2 +- src/Mobs/Monster.cpp | 28 ++++++++++++++++++++++++++++ src/Mobs/Monster.h | 8 +++++++- src/Mobs/Skeleton.cpp | 10 ++-------- src/Mobs/Witch.cpp | 14 +++++++------- src/Mobs/Zombie.cpp | 6 +----- src/Mobs/Zombiepigman.cpp | 2 +- 10 files changed, 80 insertions(+), 56 deletions(-) diff --git a/src/BlockID.h b/src/BlockID.h index e23a0f82a..740c5fc90 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -392,38 +392,6 @@ enum ENUM_ITEM_ID -// ENCHANTMENT IDS -enum -{ - E_ENCHANTMENT_PROTECTION = 0, - E_ENCHANTMENT_FIRE_PROTECTION = 1, - E_ENCHANTMENT_FEATHER_FALLING = 2, - E_ENCHANTMENT_BLAST_PROTECTION = 3, - E_ENCHANTMENT_PROJECTILE_PROTECTION= 4, - E_ENCHANTMENT_RESPIRATION = 5, - E_ENCHANTMENT_AQUA_AFFINITY = 6, - E_ENCHANTMENT_THORNS = 7, - E_ENCHANTMENT_SHARPNESS = 16, - E_ENCHANTMENT_SMITE = 17, - E_ENCHANTMENT_BANE_OF_ARTHROPODS = 18, - E_ENCHANTMENT_KNOCKBACK = 19, - E_ENCHANTMENT_FIREASPECT = 20, - E_ENCHANTMENT_LOOTING = 21, - E_ENCHANTMENT_EFFICIENCY = 32, - E_ENCHANTMENT_SILKTOUCH = 33, - E_ENCHANTMENT_UNBREAKING = 34, - E_ENCHANTMENT_FORTUNE = 35, - E_ENCHANTMENT_POWER = 48, - E_ENCHANTMENT_PUNCH = 49, - E_ENCHANTMENT_FLAME = 50, - E_ENCHANTMENT_INFINITY = 51, - E_ENCHANTMENT_LUCKOFTHESEA = 61, - E_ENCHANTMENT_LURE = 62, -}; - - - - enum { diff --git a/src/Enchantments.h b/src/Enchantments.h index e984df92e..14a900e19 100644 --- a/src/Enchantments.h +++ b/src/Enchantments.h @@ -21,6 +21,38 @@ class cParsedNBT; +// ENCHANTMENT IDS +enum +{ + E_ENCHANTMENT_PROTECTION = 0, + E_ENCHANTMENT_FIRE_PROTECTION = 1, + E_ENCHANTMENT_FEATHER_FALLING = 2, + E_ENCHANTMENT_BLAST_PROTECTION = 3, + E_ENCHANTMENT_PROJECTILE_PROTECTION= 4, + E_ENCHANTMENT_RESPIRATION = 5, + E_ENCHANTMENT_AQUA_AFFINITY = 6, + E_ENCHANTMENT_THORNS = 7, + E_ENCHANTMENT_SHARPNESS = 16, + E_ENCHANTMENT_SMITE = 17, + E_ENCHANTMENT_BANE_OF_ARTHROPODS = 18, + E_ENCHANTMENT_KNOCKBACK = 19, + E_ENCHANTMENT_FIREASPECT = 20, + E_ENCHANTMENT_LOOTING = 21, + E_ENCHANTMENT_EFFICIENCY = 32, + E_ENCHANTMENT_SILKTOUCH = 33, + E_ENCHANTMENT_UNBREAKING = 34, + E_ENCHANTMENT_FORTUNE = 35, + E_ENCHANTMENT_POWER = 48, + E_ENCHANTMENT_PUNCH = 49, + E_ENCHANTMENT_FLAME = 50, + E_ENCHANTMENT_INFINITY = 51, + E_ENCHANTMENT_LUCKOFTHESEA = 61, + E_ENCHANTMENT_LURE = 62, +}; + + + + /** Class that stores item enchantments or stored-enchantments The enchantments may be serialized to a stringspec and read back from such stringspec. diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index fb97ea3c4..cd5437d97 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -19,7 +19,7 @@ cBlaze::cBlaze(void) : void cBlaze::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - if (a_Killer != NULL && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) + if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_BLAZE_ROD); diff --git a/src/Mobs/Cavespider.cpp b/src/Mobs/Cavespider.cpp index a2678744b..4ef80e5f0 100644 --- a/src/Mobs/Cavespider.cpp +++ b/src/Mobs/Cavespider.cpp @@ -37,7 +37,7 @@ void cCavespider::GetDrops(cItems & a_Drops, cEntity * a_Killer) LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); - if (a_Killer != NULL && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) + if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); } diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 777b78c63..c81f46d6a 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -909,6 +909,34 @@ void cMonster::AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a +void cMonster::AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel) +{ + MTRand r1; + if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2))) + { + if (!GetEquippedHelmet().IsEmpty()) a_Drops.push_back(GetEquippedHelmet()); + } + + if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2))) + { + if (!GetEquippedChestplate().IsEmpty()) a_Drops.push_back(GetEquippedChestplate()); + } + + if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2))) + { + if (!GetEquippedLeggings().IsEmpty()) a_Drops.push_back(GetEquippedLeggings()); + } + + if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2))) + { + if (!GetEquippedBoots().IsEmpty()) a_Drops.push_back(GetEquippedBoots()); + } +} + + + + + void cMonster::HandleDaylightBurning(cChunk & a_Chunk) { if (!m_BurnsInDaylight) diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 670e899c5..6f7352b52 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -5,6 +5,7 @@ #include "../Defines.h" #include "../BlockID.h" #include "../Item.h" +#include "../Enchantments.h" @@ -225,11 +226,16 @@ protected: /** Adds a random number of a_Item between a_Min and a_Max to itemdrops a_Drops*/ void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0); - /** Adds a item a_Item with the chance of a_Chance to itemdrops a_Drops*/ + + /** Adds a item a_Item with the chance of a_Chance (in percent) to itemdrops a_Drops*/ void AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short a_Item, short a_ItemHealth = 0); + /** Adds one rare item out of the list of rare items a_Items modified by the looting level a_LootingLevel(I-III or custom) to the itemdrop a_Drops*/ void AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a_LootingLevel); + /** Adds armor that is equipped with the chance of 8,5% (Looting 3: 11,5%) to the drop*/ + void AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel); + } ; // tolua_export diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index 7c62de9cf..c941ae521 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -31,20 +31,14 @@ void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer) AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_COAL); cItems RareDrops; RareDrops.Add(cItem(E_ITEM_HEAD, 1, 1)); - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomArmorDropItem(a_Drops, LootingLevel); } else { AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ARROW); AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); - cItems RareDrops; - if (!GetEquippedHelmet().IsEmpty()) RareDrops.Add(GetEquippedHelmet()); - if (!GetEquippedChestplate().IsEmpty()) RareDrops.Add(GetEquippedChestplate()); - if (!GetEquippedLeggings().IsEmpty()) RareDrops.Add(GetEquippedLeggings()); - if (!GetEquippedBoots().IsEmpty()) RareDrops.Add(GetEquippedBoots()); - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); - AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomArmorDropItem(a_Drops, LootingLevel); } } diff --git a/src/Mobs/Witch.cpp b/src/Mobs/Witch.cpp index f9025afe3..a278a1964 100644 --- a/src/Mobs/Witch.cpp +++ b/src/Mobs/Witch.cpp @@ -30,13 +30,13 @@ void cWitch::GetDrops(cItems & a_Drops, cEntity * a_Killer) int DropType = r1.randInt() % 7; switch (DropType) { - case 0: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLASS_BOTTLE); - case 1: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLOWSTONE_DUST); - case 2: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); - case 3: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_REDSTONE_DUST); - case 4: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SPIDER_EYE); - case 5: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STICK); - case 6: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SUGAR); + case 0: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLASS_BOTTLE); break; + case 1: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLOWSTONE_DUST); break; + case 2: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); break; + case 3: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_REDSTONE_DUST); break; + case 4: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SPIDER_EYE); break; + case 5: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STICK); break; + case 6: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SUGAR); break; } } cItems RareDrops; diff --git a/src/Mobs/Zombie.cpp b/src/Mobs/Zombie.cpp index 61cf49c14..5facf085e 100644 --- a/src/Mobs/Zombie.cpp +++ b/src/Mobs/Zombie.cpp @@ -33,12 +33,8 @@ void cZombie::GetDrops(cItems & a_Drops, cEntity * a_Killer) RareDrops.Add(cItem(E_ITEM_IRON)); RareDrops.Add(cItem(E_ITEM_CARROT)); RareDrops.Add(cItem(E_ITEM_POTATO)); - if (!GetEquippedHelmet().IsEmpty()) RareDrops.Add(GetEquippedHelmet()); - if (!GetEquippedChestplate().IsEmpty()) RareDrops.Add(GetEquippedChestplate()); - if (!GetEquippedLeggings().IsEmpty()) RareDrops.Add(GetEquippedLeggings()); - if (!GetEquippedBoots().IsEmpty()) RareDrops.Add(GetEquippedBoots()); - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomArmorDropItem(a_Drops, LootingLevel); } diff --git a/src/Mobs/Zombiepigman.cpp b/src/Mobs/Zombiepigman.cpp index 5492068c9..3ecc65fed 100644 --- a/src/Mobs/Zombiepigman.cpp +++ b/src/Mobs/Zombiepigman.cpp @@ -29,8 +29,8 @@ void cZombiePigman::GetDrops(cItems & a_Drops, cEntity * a_Killer) cItems RareDrops; RareDrops.Add(cItem(E_ITEM_GOLD)); - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomArmorDropItem(a_Drops, LootingLevel); } From 43b2370bac14578247f87fff7eec50f574b588e0 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sat, 22 Feb 2014 22:59:12 +0100 Subject: [PATCH 17/22] Changed formatting again --- src/Mobs/Spider.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mobs/Spider.cpp b/src/Mobs/Spider.cpp index d20f4997c..4a6f09aa4 100644 --- a/src/Mobs/Spider.cpp +++ b/src/Mobs/Spider.cpp @@ -24,7 +24,7 @@ void cSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer) LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); - if (a_Killer != NULL && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) + if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); } From beba3e55d73280cb7edfe315f1beaf20dd21e556 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sun, 23 Feb 2014 14:03:01 +0100 Subject: [PATCH 18/22] Finally corrected the Enchantment constants. --- src/Enchantments.h | 33 --------------------------------- src/Mobs/Blaze.cpp | 2 +- src/Mobs/Cavespider.cpp | 2 +- src/Mobs/Chicken.cpp | 2 +- src/Mobs/Cow.cpp | 2 +- src/Mobs/Creeper.cpp | 2 +- src/Mobs/Enderman.cpp | 2 +- src/Mobs/Ghast.cpp | 2 +- src/Mobs/Horse.cpp | 2 +- src/Mobs/Mooshroom.cpp | 2 +- src/Mobs/Pig.cpp | 2 +- src/Mobs/Skeleton.cpp | 2 +- src/Mobs/Slime.cpp | 2 +- src/Mobs/Spider.cpp | 2 +- src/Mobs/Squid.cpp | 2 +- src/Mobs/Witch.cpp | 2 +- src/Mobs/Zombie.cpp | 2 +- src/Mobs/Zombiepigman.cpp | 2 +- 18 files changed, 17 insertions(+), 50 deletions(-) diff --git a/src/Enchantments.h b/src/Enchantments.h index 14a900e19..f77b535d8 100644 --- a/src/Enchantments.h +++ b/src/Enchantments.h @@ -21,39 +21,6 @@ class cParsedNBT; -// ENCHANTMENT IDS -enum -{ - E_ENCHANTMENT_PROTECTION = 0, - E_ENCHANTMENT_FIRE_PROTECTION = 1, - E_ENCHANTMENT_FEATHER_FALLING = 2, - E_ENCHANTMENT_BLAST_PROTECTION = 3, - E_ENCHANTMENT_PROJECTILE_PROTECTION= 4, - E_ENCHANTMENT_RESPIRATION = 5, - E_ENCHANTMENT_AQUA_AFFINITY = 6, - E_ENCHANTMENT_THORNS = 7, - E_ENCHANTMENT_SHARPNESS = 16, - E_ENCHANTMENT_SMITE = 17, - E_ENCHANTMENT_BANE_OF_ARTHROPODS = 18, - E_ENCHANTMENT_KNOCKBACK = 19, - E_ENCHANTMENT_FIREASPECT = 20, - E_ENCHANTMENT_LOOTING = 21, - E_ENCHANTMENT_EFFICIENCY = 32, - E_ENCHANTMENT_SILKTOUCH = 33, - E_ENCHANTMENT_UNBREAKING = 34, - E_ENCHANTMENT_FORTUNE = 35, - E_ENCHANTMENT_POWER = 48, - E_ENCHANTMENT_PUNCH = 49, - E_ENCHANTMENT_FLAME = 50, - E_ENCHANTMENT_INFINITY = 51, - E_ENCHANTMENT_LUCKOFTHESEA = 61, - E_ENCHANTMENT_LURE = 62, -}; - - - - - /** Class that stores item enchantments or stored-enchantments The enchantments may be serialized to a stringspec and read back from such stringspec. The format for the stringspec is "id=lvl;id=lvl;id=lvl...", with an optional semicolon at the end, diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index cd5437d97..ac42cf40b 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -21,7 +21,7 @@ void cBlaze::GetDrops(cItems & a_Drops, cEntity * a_Killer) { if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_BLAZE_ROD); } } diff --git a/src/Mobs/Cavespider.cpp b/src/Mobs/Cavespider.cpp index 4ef80e5f0..94e93283d 100644 --- a/src/Mobs/Cavespider.cpp +++ b/src/Mobs/Cavespider.cpp @@ -34,7 +34,7 @@ void cCavespider::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) diff --git a/src/Mobs/Chicken.cpp b/src/Mobs/Chicken.cpp index b58eedbf7..f7e44238f 100644 --- a/src/Mobs/Chicken.cpp +++ b/src/Mobs/Chicken.cpp @@ -51,7 +51,7 @@ void cChicken::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_FEATHER); AddRandomDropItem(a_Drops, 1, 1, IsOnFire() ? E_ITEM_COOKED_CHICKEN : E_ITEM_RAW_CHICKEN); diff --git a/src/Mobs/Cow.cpp b/src/Mobs/Cow.cpp index 49eac5cf5..9914df6b5 100644 --- a/src/Mobs/Cow.cpp +++ b/src/Mobs/Cow.cpp @@ -24,7 +24,7 @@ void cCow::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp index 3dd978088..40ee20e44 100644 --- a/src/Mobs/Creeper.cpp +++ b/src/Mobs/Creeper.cpp @@ -42,7 +42,7 @@ void cCreeper::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp index f0a3b5f5d..becc99a86 100644 --- a/src/Mobs/Enderman.cpp +++ b/src/Mobs/Enderman.cpp @@ -24,7 +24,7 @@ void cEnderman::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ENDER_PEARL); } diff --git a/src/Mobs/Ghast.cpp b/src/Mobs/Ghast.cpp index 300435557..fe18f5e76 100644 --- a/src/Mobs/Ghast.cpp +++ b/src/Mobs/Ghast.cpp @@ -21,7 +21,7 @@ void cGhast::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GHAST_TEAR); diff --git a/src/Mobs/Horse.cpp b/src/Mobs/Horse.cpp index 73cc532bf..9d130301f 100644 --- a/src/Mobs/Horse.cpp +++ b/src/Mobs/Horse.cpp @@ -143,7 +143,7 @@ void cHorse::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); if (m_bIsSaddled) diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index bc1b9cac7..5873ec63f 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -27,7 +27,7 @@ void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); diff --git a/src/Mobs/Pig.cpp b/src/Mobs/Pig.cpp index aa127a590..e862f5aaa 100644 --- a/src/Mobs/Pig.cpp +++ b/src/Mobs/Pig.cpp @@ -24,7 +24,7 @@ void cPig::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_COOKED_PORKCHOP : E_ITEM_RAW_PORKCHOP); if (m_bIsSaddled) diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index c941ae521..661f0712c 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -23,7 +23,7 @@ void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } if (IsWither()) { diff --git a/src/Mobs/Slime.cpp b/src/Mobs/Slime.cpp index 2001fdcb4..52a52bb39 100644 --- a/src/Mobs/Slime.cpp +++ b/src/Mobs/Slime.cpp @@ -23,7 +23,7 @@ void cSlime::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } if (GetSize() == 1) { diff --git a/src/Mobs/Spider.cpp b/src/Mobs/Spider.cpp index 4a6f09aa4..8b978ff6b 100644 --- a/src/Mobs/Spider.cpp +++ b/src/Mobs/Spider.cpp @@ -21,7 +21,7 @@ void cSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) diff --git a/src/Mobs/Squid.cpp b/src/Mobs/Squid.cpp index 24818222b..ba9171b39 100644 --- a/src/Mobs/Squid.cpp +++ b/src/Mobs/Squid.cpp @@ -24,7 +24,7 @@ void cSquid::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 3 + LootingLevel, E_ITEM_DYE, E_META_DYE_BLACK); } diff --git a/src/Mobs/Witch.cpp b/src/Mobs/Witch.cpp index a278a1964..bdc9e11de 100644 --- a/src/Mobs/Witch.cpp +++ b/src/Mobs/Witch.cpp @@ -21,7 +21,7 @@ void cWitch::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } MTRand r1; int DropTypeCount = (r1.randInt() % 3) + 1; diff --git a/src/Mobs/Zombie.cpp b/src/Mobs/Zombie.cpp index 5facf085e..999cd4a35 100644 --- a/src/Mobs/Zombie.cpp +++ b/src/Mobs/Zombie.cpp @@ -26,7 +26,7 @@ void cZombie::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ROTTEN_FLESH); cItems RareDrops; diff --git a/src/Mobs/Zombiepigman.cpp b/src/Mobs/Zombiepigman.cpp index 3ecc65fed..a967d5066 100644 --- a/src/Mobs/Zombiepigman.cpp +++ b/src/Mobs/Zombiepigman.cpp @@ -22,7 +22,7 @@ void cZombiePigman::GetDrops(cItems & a_Drops, cEntity * a_Killer) int LootingLevel = 0; if (a_Killer != NULL) { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); } AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ROTTEN_FLESH); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GOLD_NUGGET); From 1afcc255bfe7153dc397970e0ece41d6d48e63be Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sun, 23 Feb 2014 18:13:49 +0100 Subject: [PATCH 19/22] Fixed Formatting, Added DropChance attributes to Monsters --- src/Mobs/Monster.cpp | 26 +++- src/Mobs/Monster.h | 20 +++ src/Mobs/Mooshroom.cpp | 47 +++---- src/Mobs/Skeleton.cpp | 8 +- src/Mobs/Witch.cpp | 4 +- src/Mobs/Zombie.cpp | 1 + src/Mobs/Zombiepigman.cpp | 1 + src/WorldStorage/NBTChunkSerializer.cpp | 8 ++ src/WorldStorage/WSSAnvil.cpp | 163 ++++++++++++++++++++++++ src/WorldStorage/WSSAnvil.h | 3 + 10 files changed, 247 insertions(+), 34 deletions(-) diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index c81f46d6a..23e4219e8 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -81,6 +81,11 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString , m_AttackDamage(1) , m_AttackRange(2) , m_AttackInterval(0) + , m_DropChanceWeapon(0.085) + , m_DropChanceHelmet(0.085) + , m_DropChanceChestplate(0.085) + , m_DropChanceLeggings(0.085) + , m_DropChanceBoots(0.085) , m_SightDistance(25) , m_BurnsInDaylight(false) { @@ -912,22 +917,22 @@ void cMonster::AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a void cMonster::AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel) { MTRand r1; - if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2))) + if (r1.randInt() % 200 < ((m_DropChanceHelmet * 200) + (a_LootingLevel * 2))) { if (!GetEquippedHelmet().IsEmpty()) a_Drops.push_back(GetEquippedHelmet()); } - if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2))) + if (r1.randInt() % 200 < ((m_DropChanceChestplate * 200) + (a_LootingLevel * 2))) { if (!GetEquippedChestplate().IsEmpty()) a_Drops.push_back(GetEquippedChestplate()); } - if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2))) + if (r1.randInt() % 200 < ((m_DropChanceLeggings * 200) + (a_LootingLevel * 2))) { if (!GetEquippedLeggings().IsEmpty()) a_Drops.push_back(GetEquippedLeggings()); } - if (r1.randInt() % 200 < (17 + (a_LootingLevel * 2))) + if (r1.randInt() % 200 < ((m_DropChanceBoots * 200) + (a_LootingLevel * 2))) { if (!GetEquippedBoots().IsEmpty()) a_Drops.push_back(GetEquippedBoots()); } @@ -937,6 +942,19 @@ void cMonster::AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel) +void cMonster::AddRandomWeaponDropItem(cItems & a_Drops, short a_LootingLevel) +{ + MTRand r1; + if (r1.randInt() % 200 < ((m_DropChanceWeapon * 200) + (a_LootingLevel * 2))) + { + if (!GetEquippedWeapon().IsEmpty()) a_Drops.push_back(GetEquippedWeapon()); + } +} + + + + + void cMonster::HandleDaylightBurning(cChunk & a_Chunk) { if (!m_BurnsInDaylight) diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 6f7352b52..b75ac444f 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -119,6 +119,17 @@ public: void SetAttackDamage(int a_AttackDamage) { m_AttackDamage = a_AttackDamage; } void SetSightDistance(int a_SightDistance) { m_SightDistance = a_SightDistance; } + float GetDropChanceWeapon() { return m_DropChanceWeapon; }; + float GetDropChanceHelmet() { return m_DropChanceHelmet; }; + float GetDropChanceChestplate() { return m_DropChanceChestplate; }; + float GetDropChanceLeggings() { return m_DropChanceLeggings; }; + float GetDropChanceBoots() { return m_DropChanceBoots; }; + void SetDropChanceWeapon(float a_DropChanceWeapon) { m_DropChanceWeapon = a_DropChanceWeapon; }; + void SetDropChanceHelmet(float a_DropChanceHelmet) { m_DropChanceHelmet = a_DropChanceHelmet; }; + void SetDropChanceChestplate(float a_DropChanceChestplate) { m_DropChanceChestplate = a_DropChanceChestplate; }; + void SetDropChanceLeggings(float a_DropChanceLeggings) { m_DropChanceLeggings = a_DropChanceLeggings; }; + void SetDropChanceBoots(float a_DropChanceBoots) { m_DropChanceBoots = a_DropChanceBoots; }; + /// Sets whether the mob burns in daylight. Only evaluated at next burn-decision tick void SetBurnsInDaylight(bool a_BurnsInDaylight) { m_BurnsInDaylight = a_BurnsInDaylight; } @@ -221,6 +232,12 @@ protected: float m_AttackInterval; int m_SightDistance; + float m_DropChanceWeapon; + float m_DropChanceHelmet; + float m_DropChanceChestplate; + float m_DropChanceLeggings; + float m_DropChanceBoots; + void HandleDaylightBurning(cChunk & a_Chunk); bool m_BurnsInDaylight; @@ -236,6 +253,9 @@ protected: /** Adds armor that is equipped with the chance of 8,5% (Looting 3: 11,5%) to the drop*/ void AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel); + /** Adds weapon that is equipped with the chance of 8,5% (Looting 3: 11,5%) to the drop*/ + void AddRandomWeaponDropItem(cItems & a_Drops, short a_LootingLevel); + } ; // tolua_export diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index 5873ec63f..8e4c52ae6 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -39,34 +39,35 @@ void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer) void cMooshroom::OnRightClicked(cPlayer & a_Player) { - if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_BUCKET)) + switch (a_Player.GetEquippedItem().m_ItemType) { - if (!a_Player.IsGameModeCreative()) + case E_ITEM_BUCKET: { - a_Player.GetInventory().RemoveOneEquippedItem(); - a_Player.GetInventory().AddItem(E_ITEM_MILK); - } - } - - if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_BOWL)) - { - if (!a_Player.IsGameModeCreative()) + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + a_Player.GetInventory().AddItem(E_ITEM_MILK); + } + } break; + case E_ITEM_BOWL: { - a_Player.GetInventory().RemoveOneEquippedItem(); - a_Player.GetInventory().AddItem(E_ITEM_MUSHROOM_SOUP); - } - } - - if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_SHEARS) - { - if (!a_Player.IsGameModeCreative()) + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + a_Player.GetInventory().AddItem(E_ITEM_MUSHROOM_SOUP); + } + } break; + case E_ITEM_SHEARS: { - a_Player.UseEquippedItem(); - } + if (!a_Player.IsGameModeCreative()) + { + a_Player.UseEquippedItem(); + } - cItems Drops; - Drops.push_back(cItem(E_BLOCK_RED_MUSHROOM, 5, 0)); - m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); + cItems Drops; + Drops.push_back(cItem(E_BLOCK_RED_MUSHROOM, 5, 0)); + m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); + } break; } } diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index 661f0712c..47fcdbb26 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -27,19 +27,19 @@ void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer) } if (IsWither()) { - AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_COAL); cItems RareDrops; RareDrops.Add(cItem(E_ITEM_HEAD, 1, 1)); AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); - AddRandomArmorDropItem(a_Drops, LootingLevel); } else { AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ARROW); - AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); - AddRandomArmorDropItem(a_Drops, LootingLevel); + } + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); + AddRandomArmorDropItem(a_Drops, LootingLevel); + AddRandomWeaponDropItem(a_Drops, LootingLevel); } diff --git a/src/Mobs/Witch.cpp b/src/Mobs/Witch.cpp index bdc9e11de..6956f7b7a 100644 --- a/src/Mobs/Witch.cpp +++ b/src/Mobs/Witch.cpp @@ -39,9 +39,7 @@ void cWitch::GetDrops(cItems & a_Drops, cEntity * a_Killer) case 6: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SUGAR); break; } } - cItems RareDrops; - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); - AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomWeaponDropItem(a_Drops, LootingLevel); } diff --git a/src/Mobs/Zombie.cpp b/src/Mobs/Zombie.cpp index 999cd4a35..f19e096ee 100644 --- a/src/Mobs/Zombie.cpp +++ b/src/Mobs/Zombie.cpp @@ -35,6 +35,7 @@ void cZombie::GetDrops(cItems & a_Drops, cEntity * a_Killer) RareDrops.Add(cItem(E_ITEM_POTATO)); AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); AddRandomArmorDropItem(a_Drops, LootingLevel); + AddRandomWeaponDropItem(a_Drops, LootingLevel); } diff --git a/src/Mobs/Zombiepigman.cpp b/src/Mobs/Zombiepigman.cpp index a967d5066..a0142b566 100644 --- a/src/Mobs/Zombiepigman.cpp +++ b/src/Mobs/Zombiepigman.cpp @@ -31,6 +31,7 @@ void cZombiePigman::GetDrops(cItems & a_Drops, cEntity * a_Killer) RareDrops.Add(cItem(E_ITEM_GOLD)); AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); AddRandomArmorDropItem(a_Drops, LootingLevel); + AddRandomWeaponDropItem(a_Drops, LootingLevel); } diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 2a1eda523..5bcaf06bd 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -407,6 +407,14 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) } } // switch (payload) + m_Writer.BeginList("DropChances", TAG_Float); + m_Writer.AddFloat("", a_Monster->GetDropChanceWeapon()); + m_Writer.AddFloat("", a_Monster->GetDropChanceHelmet()); + m_Writer.AddFloat("", a_Monster->GetDropChanceChestplate()); + m_Writer.AddFloat("", a_Monster->GetDropChanceLeggings()); + m_Writer.AddFloat("", a_Monster->GetDropChanceBoots()); + m_Writer.EndList(); + m_Writer.BeginCompound(""); AddBasicEntity(a_Monster, EntityClass); switch (a_Monster->GetMobType()) diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index d4490c7fe..a5f4e1b25 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1485,6 +1485,11 @@ void cWSSAnvil::LoadBatFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1500,6 +1505,11 @@ void cWSSAnvil::LoadBlazeFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1515,6 +1525,11 @@ void cWSSAnvil::LoadCaveSpiderFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1530,6 +1545,11 @@ void cWSSAnvil::LoadChickenFromNBT(cEntityList & a_Entities, const cParsedNBT & { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1545,6 +1565,11 @@ void cWSSAnvil::LoadCowFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1560,6 +1585,11 @@ void cWSSAnvil::LoadCreeperFromNBT(cEntityList & a_Entities, const cParsedNBT & { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1575,6 +1605,11 @@ void cWSSAnvil::LoadEnderDragonFromNBT(cEntityList & a_Entities, const cParsedNB { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1591,6 +1626,11 @@ void cWSSAnvil::LoadEndermanFromNBT(cEntityList & a_Entities, const cParsedNBT & return; } + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } + a_Entities.push_back(Monster.release()); } @@ -1606,6 +1646,11 @@ void cWSSAnvil::LoadGhastFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ return; } + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } + a_Entities.push_back(Monster.release()); } @@ -1620,6 +1665,11 @@ void cWSSAnvil::LoadGiantFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1646,6 +1696,11 @@ void cWSSAnvil::LoadHorseFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1661,6 +1716,11 @@ void cWSSAnvil::LoadIronGolemFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1682,6 +1742,11 @@ void cWSSAnvil::LoadMagmaCubeFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1697,6 +1762,11 @@ void cWSSAnvil::LoadMooshroomFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1712,6 +1782,11 @@ void cWSSAnvil::LoadOcelotFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1727,6 +1802,11 @@ void cWSSAnvil::LoadPigFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1748,6 +1828,11 @@ void cWSSAnvil::LoadSheepFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1763,6 +1848,11 @@ void cWSSAnvil::LoadSilverfishFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1784,6 +1874,11 @@ void cWSSAnvil::LoadSkeletonFromNBT(cEntityList & a_Entities, const cParsedNBT & { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1805,6 +1900,11 @@ void cWSSAnvil::LoadSlimeFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1820,6 +1920,11 @@ void cWSSAnvil::LoadSnowGolemFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1835,6 +1940,11 @@ void cWSSAnvil::LoadSpiderFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1850,6 +1960,11 @@ void cWSSAnvil::LoadSquidFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1871,6 +1986,11 @@ void cWSSAnvil::LoadVillagerFromNBT(cEntityList & a_Entities, const cParsedNBT & { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1886,6 +2006,11 @@ void cWSSAnvil::LoadWitchFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1901,6 +2026,11 @@ void cWSSAnvil::LoadWitherFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1916,6 +2046,10 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N { return; } + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } int OwnerIdx = a_NBT.FindChildByName(a_TagIdx, "Owner"); if (OwnerIdx > 0) { @@ -1964,6 +2098,11 @@ void cWSSAnvil::LoadZombieFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1980,6 +2119,11 @@ void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT return; } + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } + a_Entities.push_back(Monster.release()); } @@ -2023,6 +2167,25 @@ bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_N +bool LoadMonsterBaseFromNBT(cMonster & a_Monster, const cParsedNBT & a_NBT, int a_TagIdx) +{ + float DropChance[5]; + if (!LoadDoublesListFromNBT(DropChance, 5, a_NBT, a_NBT.FindChildByName(a_TagIdx, "DropChance"))) + { + return false; + } + a_Monster.SetDropChanceWeapon(DropChance[0]); + a_Monster.SetDropChanceHelmet(DropChance[1]); + a_Monster.SetDropChanceChestplate(DropChance[2]); + a_Monster.SetDropChanceLeggings(DropChance[3]); + a_Monster.SetDropChanceBoots(DropChance[4]); + return true; +} + + + + + bool cWSSAnvil::LoadProjectileBaseFromNBT(cProjectileEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx) { if (!LoadEntityBaseFromNBT(a_Entity, a_NBT, a_TagIdx)) diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h index 541371560..6c6444dae 100644 --- a/src/WorldStorage/WSSAnvil.h +++ b/src/WorldStorage/WSSAnvil.h @@ -194,6 +194,9 @@ protected: /// Loads entity common data from the NBT compound; returns true if successful bool LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx); + /// Loads monster common data from the NBT compound; returns true if successful + bool LoadMonsterBaseFromNBT(cMonster & a_Monster, const cParsedNBT & a_NBT, int a_TagIdx); + /// Loads projectile common data from the NBT compound; returns true if successful bool LoadProjectileBaseFromNBT(cProjectileEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIx); From 72dd48f7e741217077f82d9c8ec7e55618102bd6 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sun, 23 Feb 2014 18:43:47 +0100 Subject: [PATCH 20/22] Fixed Compiling Issues --- src/WorldStorage/NBTChunkSerializer.cpp | 15 +++++++-------- src/WorldStorage/WSSAnvil.cpp | 22 ++++++++++++++++++++-- src/WorldStorage/WSSAnvil.h | 4 ++++ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 5bcaf06bd..b9d92d2df 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -407,16 +407,15 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) } } // switch (payload) - m_Writer.BeginList("DropChances", TAG_Float); - m_Writer.AddFloat("", a_Monster->GetDropChanceWeapon()); - m_Writer.AddFloat("", a_Monster->GetDropChanceHelmet()); - m_Writer.AddFloat("", a_Monster->GetDropChanceChestplate()); - m_Writer.AddFloat("", a_Monster->GetDropChanceLeggings()); - m_Writer.AddFloat("", a_Monster->GetDropChanceBoots()); - m_Writer.EndList(); - m_Writer.BeginCompound(""); AddBasicEntity(a_Monster, EntityClass); + m_Writer.BeginList("DropChances", TAG_Float); + m_Writer.AddFloat("", a_Monster->GetDropChanceWeapon()); + m_Writer.AddFloat("", a_Monster->GetDropChanceHelmet()); + m_Writer.AddFloat("", a_Monster->GetDropChanceChestplate()); + m_Writer.AddFloat("", a_Monster->GetDropChanceLeggings()); + m_Writer.AddFloat("", a_Monster->GetDropChanceBoots()); + m_Writer.EndList(); switch (a_Monster->GetMobType()) { case cMonster::mtBat: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index a5f4e1b25..10c8d1f51 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -2167,10 +2167,10 @@ bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_N -bool LoadMonsterBaseFromNBT(cMonster & a_Monster, const cParsedNBT & a_NBT, int a_TagIdx) +bool cWSSAnvil::LoadMonsterBaseFromNBT(cMonster & a_Monster, const cParsedNBT & a_NBT, int a_TagIdx) { float DropChance[5]; - if (!LoadDoublesListFromNBT(DropChance, 5, a_NBT, a_NBT.FindChildByName(a_TagIdx, "DropChance"))) + if (!LoadFloatsListFromNBT(DropChance, 5, a_NBT, a_NBT.FindChildByName(a_TagIdx, "DropChance"))) { return false; } @@ -2228,6 +2228,24 @@ bool cWSSAnvil::LoadDoublesListFromNBT(double * a_Doubles, int a_NumDoubles, con +bool cWSSAnvil::LoadFloatsListFromNBT(float * a_Floats, int a_NumFloats, const cParsedNBT & a_NBT, int a_TagIdx) +{ + if ((a_TagIdx < 0) || (a_NBT.GetType(a_TagIdx) != TAG_List) || (a_NBT.GetChildrenType(a_TagIdx) != TAG_Float)) + { + return false; + } + int idx = 0; + for (int Tag = a_NBT.GetFirstChild(a_TagIdx); (Tag > 0) && (idx < a_NumFloats); Tag = a_NBT.GetNextSibling(Tag), ++idx) + { + a_Floats[idx] = a_NBT.GetFloat(Tag); + } // for Tag - PosTag[] + return (idx == a_NumFloats); // Did we read enough doubles? +} + + + + + bool cWSSAnvil::GetBlockEntityNBTPos(const cParsedNBT & a_NBT, int a_TagIdx, int & a_X, int & a_Y, int & a_Z) { int x = a_NBT.FindChildByName(a_TagIdx, "x"); diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h index 6c6444dae..4acf3f2a1 100644 --- a/src/WorldStorage/WSSAnvil.h +++ b/src/WorldStorage/WSSAnvil.h @@ -10,6 +10,7 @@ #include "WorldStorage.h" #include "FastNBT.h" +#include "../Mobs/Monster.h" @@ -203,6 +204,9 @@ protected: /// Loads an array of doubles of the specified length from the specified NBT list tag a_TagIdx; returns true if successful bool LoadDoublesListFromNBT(double * a_Doubles, int a_NumDoubles, const cParsedNBT & a_NBT, int a_TagIdx); + /// Loads an array of floats of the specified length from the specified NBT list tag a_TagIdx; returns true if successful + bool LoadFloatsListFromNBT(float * a_Floats, int a_NumFloats, const cParsedNBT & a_NBT, int a_TagIdx); + /// Helper function for extracting the X, Y, and Z int subtags of a NBT compound; returns true if successful bool GetBlockEntityNBTPos(const cParsedNBT & a_NBT, int a_TagIdx, int & a_X, int & a_Y, int & a_Z); From 847aef898de868dd88354adfb763e48fad22d6b2 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sun, 23 Feb 2014 19:12:34 +0100 Subject: [PATCH 21/22] Fixed Formatting, Added DropChances and CanPickUpLoot attributes to Monsters --- src/Mobs/Monster.cpp | 1 + src/Mobs/Monster.h | 23 +++++++++++++---------- src/WorldStorage/NBTChunkSerializer.cpp | 1 + src/WorldStorage/WSSAnvil.cpp | 2 ++ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 23e4219e8..4ab485321 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -86,6 +86,7 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString , m_DropChanceChestplate(0.085) , m_DropChanceLeggings(0.085) , m_DropChanceBoots(0.085) + , m_CanPickUpLoot(true) , m_SightDistance(25) , m_BurnsInDaylight(false) { diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index b75ac444f..49d0cf9ef 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -119,16 +119,18 @@ public: void SetAttackDamage(int a_AttackDamage) { m_AttackDamage = a_AttackDamage; } void SetSightDistance(int a_SightDistance) { m_SightDistance = a_SightDistance; } - float GetDropChanceWeapon() { return m_DropChanceWeapon; }; - float GetDropChanceHelmet() { return m_DropChanceHelmet; }; - float GetDropChanceChestplate() { return m_DropChanceChestplate; }; - float GetDropChanceLeggings() { return m_DropChanceLeggings; }; - float GetDropChanceBoots() { return m_DropChanceBoots; }; - void SetDropChanceWeapon(float a_DropChanceWeapon) { m_DropChanceWeapon = a_DropChanceWeapon; }; - void SetDropChanceHelmet(float a_DropChanceHelmet) { m_DropChanceHelmet = a_DropChanceHelmet; }; - void SetDropChanceChestplate(float a_DropChanceChestplate) { m_DropChanceChestplate = a_DropChanceChestplate; }; - void SetDropChanceLeggings(float a_DropChanceLeggings) { m_DropChanceLeggings = a_DropChanceLeggings; }; - void SetDropChanceBoots(float a_DropChanceBoots) { m_DropChanceBoots = a_DropChanceBoots; }; + float GetDropChanceWeapon() { return m_DropChanceWeapon; } + float GetDropChanceHelmet() { return m_DropChanceHelmet; } + float GetDropChanceChestplate() { return m_DropChanceChestplate; } + float GetDropChanceLeggings() { return m_DropChanceLeggings; } + float GetDropChanceBoots() { return m_DropChanceBoots; } + bool CanPickUpLoot() { return m_CanPickUpLoot; } + void SetDropChanceWeapon(float a_DropChanceWeapon) { m_DropChanceWeapon = a_DropChanceWeapon; } + void SetDropChanceHelmet(float a_DropChanceHelmet) { m_DropChanceHelmet = a_DropChanceHelmet; } + void SetDropChanceChestplate(float a_DropChanceChestplate) { m_DropChanceChestplate = a_DropChanceChestplate; } + void SetDropChanceLeggings(float a_DropChanceLeggings) { m_DropChanceLeggings = a_DropChanceLeggings; } + void SetDropChanceBoots(float a_DropChanceBoots) { m_DropChanceBoots = a_DropChanceBoots; } + void SetCanPickUpLoot(bool a_CanPickUpLoot) { m_CanPickUpLoot = a_CanPickUpLoot; } /// Sets whether the mob burns in daylight. Only evaluated at next burn-decision tick void SetBurnsInDaylight(bool a_BurnsInDaylight) { m_BurnsInDaylight = a_BurnsInDaylight; } @@ -237,6 +239,7 @@ protected: float m_DropChanceChestplate; float m_DropChanceLeggings; float m_DropChanceBoots; + bool m_CanPickUpLoot; void HandleDaylightBurning(cChunk & a_Chunk); bool m_BurnsInDaylight; diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index b9d92d2df..c1c659b36 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -416,6 +416,7 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) m_Writer.AddFloat("", a_Monster->GetDropChanceLeggings()); m_Writer.AddFloat("", a_Monster->GetDropChanceBoots()); m_Writer.EndList(); + m_Writer.AddByte("CanPickUpLoot", (char)a_Monster->CanPickUpLoot()); switch (a_Monster->GetMobType()) { case cMonster::mtBat: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 10c8d1f51..05332d23d 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -2179,6 +2179,8 @@ bool cWSSAnvil::LoadMonsterBaseFromNBT(cMonster & a_Monster, const cParsedNBT & a_Monster.SetDropChanceChestplate(DropChance[2]); a_Monster.SetDropChanceLeggings(DropChance[3]); a_Monster.SetDropChanceBoots(DropChance[4]); + bool CanPickUpLoot = (a_NBT.GetByte(a_NBT.FindChildByName(a_TagIdx, "CanPickUpLoot")) == 1); + a_Monster.SetCanPickUpLoot(CanPickUpLoot); return true; } From 2f59517023765e8f5d5555adacafd146729ab071 Mon Sep 17 00:00:00 2001 From: TheJumper Date: Sun, 23 Feb 2014 19:35:56 +0100 Subject: [PATCH 22/22] Fixed Formatting, Added DropChances and CanPickUpLoot attributes to Monsters --- src/BlockID.h | 32 ----- src/Enchantments.h | 1 - src/Mobs/Blaze.cpp | 4 +- src/Mobs/Cavespider.cpp | 8 +- src/Mobs/Chicken.cpp | 6 +- src/Mobs/Cow.cpp | 6 +- src/Mobs/Creeper.cpp | 6 +- src/Mobs/Enderman.cpp | 6 +- src/Mobs/Ghast.cpp | 6 +- src/Mobs/Horse.cpp | 6 +- src/Mobs/Monster.cpp | 49 ++++++- src/Mobs/Monster.h | 32 +++++ src/Mobs/Mooshroom.cpp | 45 +++++- src/Mobs/Mooshroom.h | 1 + src/Mobs/Pig.cpp | 6 +- src/Mobs/Skeleton.cpp | 20 ++- src/Mobs/Slime.cpp | 6 +- src/Mobs/Spider.cpp | 8 +- src/Mobs/Squid.cpp | 6 +- src/Mobs/Witch.cpp | 24 ++-- src/Mobs/Zombie.cpp | 13 +- src/Mobs/Zombiepigman.cpp | 9 +- src/WorldStorage/NBTChunkSerializer.cpp | 8 ++ src/WorldStorage/WSSAnvil.cpp | 183 ++++++++++++++++++++++++ src/WorldStorage/WSSAnvil.h | 7 + 25 files changed, 417 insertions(+), 81 deletions(-) diff --git a/src/BlockID.h b/src/BlockID.h index e23a0f82a..740c5fc90 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -392,38 +392,6 @@ enum ENUM_ITEM_ID -// ENCHANTMENT IDS -enum -{ - E_ENCHANTMENT_PROTECTION = 0, - E_ENCHANTMENT_FIRE_PROTECTION = 1, - E_ENCHANTMENT_FEATHER_FALLING = 2, - E_ENCHANTMENT_BLAST_PROTECTION = 3, - E_ENCHANTMENT_PROJECTILE_PROTECTION= 4, - E_ENCHANTMENT_RESPIRATION = 5, - E_ENCHANTMENT_AQUA_AFFINITY = 6, - E_ENCHANTMENT_THORNS = 7, - E_ENCHANTMENT_SHARPNESS = 16, - E_ENCHANTMENT_SMITE = 17, - E_ENCHANTMENT_BANE_OF_ARTHROPODS = 18, - E_ENCHANTMENT_KNOCKBACK = 19, - E_ENCHANTMENT_FIREASPECT = 20, - E_ENCHANTMENT_LOOTING = 21, - E_ENCHANTMENT_EFFICIENCY = 32, - E_ENCHANTMENT_SILKTOUCH = 33, - E_ENCHANTMENT_UNBREAKING = 34, - E_ENCHANTMENT_FORTUNE = 35, - E_ENCHANTMENT_POWER = 48, - E_ENCHANTMENT_PUNCH = 49, - E_ENCHANTMENT_FLAME = 50, - E_ENCHANTMENT_INFINITY = 51, - E_ENCHANTMENT_LUCKOFTHESEA = 61, - E_ENCHANTMENT_LURE = 62, -}; - - - - enum { diff --git a/src/Enchantments.h b/src/Enchantments.h index e984df92e..f77b535d8 100644 --- a/src/Enchantments.h +++ b/src/Enchantments.h @@ -21,7 +21,6 @@ class cParsedNBT; - /** Class that stores item enchantments or stored-enchantments The enchantments may be serialized to a stringspec and read back from such stringspec. The format for the stringspec is "id=lvl;id=lvl;id=lvl...", with an optional semicolon at the end, diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index bd16a36e2..ac42cf40b 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -19,9 +19,9 @@ cBlaze::cBlaze(void) : void cBlaze::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) + if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_BLAZE_ROD); } } diff --git a/src/Mobs/Cavespider.cpp b/src/Mobs/Cavespider.cpp index 7274820b7..94e93283d 100644 --- a/src/Mobs/Cavespider.cpp +++ b/src/Mobs/Cavespider.cpp @@ -31,9 +31,13 @@ void cCavespider::Tick(float a_Dt, cChunk & a_Chunk) void cCavespider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); - if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) + if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); } diff --git a/src/Mobs/Chicken.cpp b/src/Mobs/Chicken.cpp index 9388e1097..f7e44238f 100644 --- a/src/Mobs/Chicken.cpp +++ b/src/Mobs/Chicken.cpp @@ -48,7 +48,11 @@ void cChicken::Tick(float a_Dt, cChunk & a_Chunk) void cChicken::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_FEATHER); AddRandomDropItem(a_Drops, 1, 1, IsOnFire() ? E_ITEM_COOKED_CHICKEN : E_ITEM_RAW_CHICKEN); } diff --git a/src/Mobs/Cow.cpp b/src/Mobs/Cow.cpp index cda067fac..9914df6b5 100644 --- a/src/Mobs/Cow.cpp +++ b/src/Mobs/Cow.cpp @@ -21,7 +21,11 @@ cCow::cCow(void) : void cCow::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); } diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp index 0ae78eee3..40ee20e44 100644 --- a/src/Mobs/Creeper.cpp +++ b/src/Mobs/Creeper.cpp @@ -39,7 +39,11 @@ void cCreeper::Tick(float a_Dt, cChunk & a_Chunk) void cCreeper::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); if ((a_Killer != NULL) && (a_Killer->IsProjectile())) diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp index 4a5ad25be..becc99a86 100644 --- a/src/Mobs/Enderman.cpp +++ b/src/Mobs/Enderman.cpp @@ -21,7 +21,11 @@ cEnderman::cEnderman(void) : void cEnderman::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ENDER_PEARL); } diff --git a/src/Mobs/Ghast.cpp b/src/Mobs/Ghast.cpp index a73ed0944..fe18f5e76 100644 --- a/src/Mobs/Ghast.cpp +++ b/src/Mobs/Ghast.cpp @@ -18,7 +18,11 @@ cGhast::cGhast(void) : void cGhast::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GHAST_TEAR); } diff --git a/src/Mobs/Horse.cpp b/src/Mobs/Horse.cpp index 3c29e3682..9d130301f 100644 --- a/src/Mobs/Horse.cpp +++ b/src/Mobs/Horse.cpp @@ -140,7 +140,11 @@ void cHorse::OnRightClicked(cPlayer & a_Player) void cHorse::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); if (m_bIsSaddled) { diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 66629474b..4ab485321 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -81,6 +81,12 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString , m_AttackDamage(1) , m_AttackRange(2) , m_AttackInterval(0) + , m_DropChanceWeapon(0.085) + , m_DropChanceHelmet(0.085) + , m_DropChanceChestplate(0.085) + , m_DropChanceLeggings(0.085) + , m_DropChanceBoots(0.085) + , m_CanPickUpLoot(true) , m_SightDistance(25) , m_BurnsInDaylight(false) { @@ -884,7 +890,7 @@ void cMonster::AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short { MTRand r1; int Count = r1.randInt() % 1000; - if (Count < (a_Chance*10)) + if (Count < (a_Chance * 10)) { a_Drops.push_back(cItem(a_Item, 1, a_ItemHealth)); } @@ -909,6 +915,47 @@ void cMonster::AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a +void cMonster::AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel) +{ + MTRand r1; + if (r1.randInt() % 200 < ((m_DropChanceHelmet * 200) + (a_LootingLevel * 2))) + { + if (!GetEquippedHelmet().IsEmpty()) a_Drops.push_back(GetEquippedHelmet()); + } + + if (r1.randInt() % 200 < ((m_DropChanceChestplate * 200) + (a_LootingLevel * 2))) + { + if (!GetEquippedChestplate().IsEmpty()) a_Drops.push_back(GetEquippedChestplate()); + } + + if (r1.randInt() % 200 < ((m_DropChanceLeggings * 200) + (a_LootingLevel * 2))) + { + if (!GetEquippedLeggings().IsEmpty()) a_Drops.push_back(GetEquippedLeggings()); + } + + if (r1.randInt() % 200 < ((m_DropChanceBoots * 200) + (a_LootingLevel * 2))) + { + if (!GetEquippedBoots().IsEmpty()) a_Drops.push_back(GetEquippedBoots()); + } +} + + + + + +void cMonster::AddRandomWeaponDropItem(cItems & a_Drops, short a_LootingLevel) +{ + MTRand r1; + if (r1.randInt() % 200 < ((m_DropChanceWeapon * 200) + (a_LootingLevel * 2))) + { + if (!GetEquippedWeapon().IsEmpty()) a_Drops.push_back(GetEquippedWeapon()); + } +} + + + + + void cMonster::HandleDaylightBurning(cChunk & a_Chunk) { if (!m_BurnsInDaylight) diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 909504213..49d0cf9ef 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -5,6 +5,7 @@ #include "../Defines.h" #include "../BlockID.h" #include "../Item.h" +#include "../Enchantments.h" @@ -118,6 +119,19 @@ public: void SetAttackDamage(int a_AttackDamage) { m_AttackDamage = a_AttackDamage; } void SetSightDistance(int a_SightDistance) { m_SightDistance = a_SightDistance; } + float GetDropChanceWeapon() { return m_DropChanceWeapon; } + float GetDropChanceHelmet() { return m_DropChanceHelmet; } + float GetDropChanceChestplate() { return m_DropChanceChestplate; } + float GetDropChanceLeggings() { return m_DropChanceLeggings; } + float GetDropChanceBoots() { return m_DropChanceBoots; } + bool CanPickUpLoot() { return m_CanPickUpLoot; } + void SetDropChanceWeapon(float a_DropChanceWeapon) { m_DropChanceWeapon = a_DropChanceWeapon; } + void SetDropChanceHelmet(float a_DropChanceHelmet) { m_DropChanceHelmet = a_DropChanceHelmet; } + void SetDropChanceChestplate(float a_DropChanceChestplate) { m_DropChanceChestplate = a_DropChanceChestplate; } + void SetDropChanceLeggings(float a_DropChanceLeggings) { m_DropChanceLeggings = a_DropChanceLeggings; } + void SetDropChanceBoots(float a_DropChanceBoots) { m_DropChanceBoots = a_DropChanceBoots; } + void SetCanPickUpLoot(bool a_CanPickUpLoot) { m_CanPickUpLoot = a_CanPickUpLoot; } + /// Sets whether the mob burns in daylight. Only evaluated at next burn-decision tick void SetBurnsInDaylight(bool a_BurnsInDaylight) { m_BurnsInDaylight = a_BurnsInDaylight; } @@ -220,13 +234,31 @@ protected: float m_AttackInterval; int m_SightDistance; + float m_DropChanceWeapon; + float m_DropChanceHelmet; + float m_DropChanceChestplate; + float m_DropChanceLeggings; + float m_DropChanceBoots; + bool m_CanPickUpLoot; + void HandleDaylightBurning(cChunk & a_Chunk); bool m_BurnsInDaylight; + /** Adds a random number of a_Item between a_Min and a_Max to itemdrops a_Drops*/ void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0); + + /** Adds a item a_Item with the chance of a_Chance (in percent) to itemdrops a_Drops*/ void AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short a_Item, short a_ItemHealth = 0); + + /** Adds one rare item out of the list of rare items a_Items modified by the looting level a_LootingLevel(I-III or custom) to the itemdrop a_Drops*/ void AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a_LootingLevel); + /** Adds armor that is equipped with the chance of 8,5% (Looting 3: 11,5%) to the drop*/ + void AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel); + + /** Adds weapon that is equipped with the chance of 8,5% (Looting 3: 11,5%) to the drop*/ + void AddRandomWeaponDropItem(cItems & a_Drops, short a_LootingLevel); + } ; // tolua_export diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index 17995ce91..8e4c52ae6 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -2,11 +2,12 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Mooshroom.h" +#include "../Entities/Player.h" + -// TODO: Milk Cow @@ -23,10 +24,50 @@ cMooshroom::cMooshroom(void) : void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER); AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); } + + +void cMooshroom::OnRightClicked(cPlayer & a_Player) +{ + switch (a_Player.GetEquippedItem().m_ItemType) + { + case E_ITEM_BUCKET: + { + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + a_Player.GetInventory().AddItem(E_ITEM_MILK); + } + } break; + case E_ITEM_BOWL: + { + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + a_Player.GetInventory().AddItem(E_ITEM_MUSHROOM_SOUP); + } + } break; + case E_ITEM_SHEARS: + { + if (!a_Player.IsGameModeCreative()) + { + a_Player.UseEquippedItem(); + } + + cItems Drops; + Drops.push_back(cItem(E_BLOCK_RED_MUSHROOM, 5, 0)); + m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); + } break; + } +} + diff --git a/src/Mobs/Mooshroom.h b/src/Mobs/Mooshroom.h index c94301098..16f6c8248 100644 --- a/src/Mobs/Mooshroom.h +++ b/src/Mobs/Mooshroom.h @@ -18,6 +18,7 @@ public: CLASS_PROTODEF(cMooshroom); virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; + virtual void OnRightClicked(cPlayer & a_Player) override; virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); } } ; diff --git a/src/Mobs/Pig.cpp b/src/Mobs/Pig.cpp index e4e46dfec..e862f5aaa 100644 --- a/src/Mobs/Pig.cpp +++ b/src/Mobs/Pig.cpp @@ -21,7 +21,11 @@ cPig::cPig(void) : void cPig::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_COOKED_PORKCHOP : E_ITEM_RAW_PORKCHOP); if (m_bIsSaddled) { diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index 622cb5ceb..47fcdbb26 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -20,28 +20,26 @@ cSkeleton::cSkeleton(bool IsWither) : void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } if (IsWither()) { - AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_COAL); cItems RareDrops; RareDrops.Add(cItem(E_ITEM_HEAD, 1, 1)); - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); } else { AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ARROW); - AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); - cItems RareDrops; - if (!GetEquippedHelmet().IsEmpty()) RareDrops.Add(GetEquippedHelmet()); - if (!GetEquippedChestplate().IsEmpty()) RareDrops.Add(GetEquippedChestplate()); - if (!GetEquippedLeggings().IsEmpty()) RareDrops.Add(GetEquippedLeggings()); - if (!GetEquippedBoots().IsEmpty()) RareDrops.Add(GetEquippedBoots()); - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); - AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + } + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_BONE); + AddRandomArmorDropItem(a_Drops, LootingLevel); + AddRandomWeaponDropItem(a_Drops, LootingLevel); } diff --git a/src/Mobs/Slime.cpp b/src/Mobs/Slime.cpp index 7941e2452..52a52bb39 100644 --- a/src/Mobs/Slime.cpp +++ b/src/Mobs/Slime.cpp @@ -20,7 +20,11 @@ cSlime::cSlime(int a_Size) : void cSlime::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } if (GetSize() == 1) { AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SLIMEBALL); diff --git a/src/Mobs/Spider.cpp b/src/Mobs/Spider.cpp index aeb6e1bcc..8b978ff6b 100644 --- a/src/Mobs/Spider.cpp +++ b/src/Mobs/Spider.cpp @@ -18,9 +18,13 @@ cSpider::cSpider(void) : void cSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STRING); - if (a_Killer->IsA("cPlayer") || a_Killer->IsA("cWolf")) + if ((a_Killer != NULL) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { AddRandomUncommonDropItem(a_Drops, 33.0f, E_ITEM_SPIDER_EYE); } diff --git a/src/Mobs/Squid.cpp b/src/Mobs/Squid.cpp index 4f2abf574..ba9171b39 100644 --- a/src/Mobs/Squid.cpp +++ b/src/Mobs/Squid.cpp @@ -21,7 +21,11 @@ cSquid::cSquid(void) : void cSquid::GetDrops(cItems & a_Drops, cEntity * a_Killer) { // Drops 0-3 Ink Sacs - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 3 + LootingLevel, E_ITEM_DYE, E_META_DYE_BLACK); } diff --git a/src/Mobs/Witch.cpp b/src/Mobs/Witch.cpp index 6cb103645..6956f7b7a 100644 --- a/src/Mobs/Witch.cpp +++ b/src/Mobs/Witch.cpp @@ -18,7 +18,11 @@ cWitch::cWitch(void) : void cWitch::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } MTRand r1; int DropTypeCount = (r1.randInt() % 3) + 1; for (int i = 0; i < DropTypeCount; i++) @@ -26,18 +30,16 @@ void cWitch::GetDrops(cItems & a_Drops, cEntity * a_Killer) int DropType = r1.randInt() % 7; switch (DropType) { - case 0: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLASS_BOTTLE); - case 1: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLOWSTONE_DUST); - case 2: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); - case 3: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_REDSTONE_DUST); - case 4: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SPIDER_EYE); - case 5: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STICK); - case 6: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SUGAR); + case 0: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLASS_BOTTLE); break; + case 1: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GLOWSTONE_DUST); break; + case 2: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); break; + case 3: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_REDSTONE_DUST); break; + case 4: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SPIDER_EYE); break; + case 5: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_STICK); break; + case 6: AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SUGAR); break; } } - cItems RareDrops; - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); - AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomWeaponDropItem(a_Drops, LootingLevel); } diff --git a/src/Mobs/Zombie.cpp b/src/Mobs/Zombie.cpp index 6a007683b..f19e096ee 100644 --- a/src/Mobs/Zombie.cpp +++ b/src/Mobs/Zombie.cpp @@ -23,18 +23,19 @@ cZombie::cZombie(bool a_IsVillagerZombie) : void cZombie::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_ROTTEN_FLESH); cItems RareDrops; RareDrops.Add(cItem(E_ITEM_IRON)); RareDrops.Add(cItem(E_ITEM_CARROT)); RareDrops.Add(cItem(E_ITEM_POTATO)); - if (!GetEquippedHelmet().IsEmpty()) RareDrops.Add(GetEquippedHelmet()); - if (!GetEquippedChestplate().IsEmpty()) RareDrops.Add(GetEquippedChestplate()); - if (!GetEquippedLeggings().IsEmpty()) RareDrops.Add(GetEquippedLeggings()); - if (!GetEquippedBoots().IsEmpty()) RareDrops.Add(GetEquippedBoots()); - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomArmorDropItem(a_Drops, LootingLevel); + AddRandomWeaponDropItem(a_Drops, LootingLevel); } diff --git a/src/Mobs/Zombiepigman.cpp b/src/Mobs/Zombiepigman.cpp index ca222f9fe..a0142b566 100644 --- a/src/Mobs/Zombiepigman.cpp +++ b/src/Mobs/Zombiepigman.cpp @@ -19,14 +19,19 @@ cZombiePigman::cZombiePigman(void) : void cZombiePigman::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(E_ENCHANTMENT_LOOTING); + int LootingLevel = 0; + if (a_Killer != NULL) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ROTTEN_FLESH); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GOLD_NUGGET); cItems RareDrops; RareDrops.Add(cItem(E_ITEM_GOLD)); - if (!GetEquippedWeapon().IsEmpty()) RareDrops.Add(GetEquippedWeapon()); AddRandomRareDropItem(a_Drops, RareDrops, LootingLevel); + AddRandomArmorDropItem(a_Drops, LootingLevel); + AddRandomWeaponDropItem(a_Drops, LootingLevel); } diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 2a1eda523..c1c659b36 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -409,6 +409,14 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) m_Writer.BeginCompound(""); AddBasicEntity(a_Monster, EntityClass); + m_Writer.BeginList("DropChances", TAG_Float); + m_Writer.AddFloat("", a_Monster->GetDropChanceWeapon()); + m_Writer.AddFloat("", a_Monster->GetDropChanceHelmet()); + m_Writer.AddFloat("", a_Monster->GetDropChanceChestplate()); + m_Writer.AddFloat("", a_Monster->GetDropChanceLeggings()); + m_Writer.AddFloat("", a_Monster->GetDropChanceBoots()); + m_Writer.EndList(); + m_Writer.AddByte("CanPickUpLoot", (char)a_Monster->CanPickUpLoot()); switch (a_Monster->GetMobType()) { case cMonster::mtBat: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index d4490c7fe..05332d23d 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1485,6 +1485,11 @@ void cWSSAnvil::LoadBatFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1500,6 +1505,11 @@ void cWSSAnvil::LoadBlazeFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1515,6 +1525,11 @@ void cWSSAnvil::LoadCaveSpiderFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1530,6 +1545,11 @@ void cWSSAnvil::LoadChickenFromNBT(cEntityList & a_Entities, const cParsedNBT & { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1545,6 +1565,11 @@ void cWSSAnvil::LoadCowFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1560,6 +1585,11 @@ void cWSSAnvil::LoadCreeperFromNBT(cEntityList & a_Entities, const cParsedNBT & { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1575,6 +1605,11 @@ void cWSSAnvil::LoadEnderDragonFromNBT(cEntityList & a_Entities, const cParsedNB { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1591,6 +1626,11 @@ void cWSSAnvil::LoadEndermanFromNBT(cEntityList & a_Entities, const cParsedNBT & return; } + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } + a_Entities.push_back(Monster.release()); } @@ -1606,6 +1646,11 @@ void cWSSAnvil::LoadGhastFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ return; } + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } + a_Entities.push_back(Monster.release()); } @@ -1620,6 +1665,11 @@ void cWSSAnvil::LoadGiantFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1646,6 +1696,11 @@ void cWSSAnvil::LoadHorseFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1661,6 +1716,11 @@ void cWSSAnvil::LoadIronGolemFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1682,6 +1742,11 @@ void cWSSAnvil::LoadMagmaCubeFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1697,6 +1762,11 @@ void cWSSAnvil::LoadMooshroomFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1712,6 +1782,11 @@ void cWSSAnvil::LoadOcelotFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1727,6 +1802,11 @@ void cWSSAnvil::LoadPigFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1748,6 +1828,11 @@ void cWSSAnvil::LoadSheepFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1763,6 +1848,11 @@ void cWSSAnvil::LoadSilverfishFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1784,6 +1874,11 @@ void cWSSAnvil::LoadSkeletonFromNBT(cEntityList & a_Entities, const cParsedNBT & { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1805,6 +1900,11 @@ void cWSSAnvil::LoadSlimeFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1820,6 +1920,11 @@ void cWSSAnvil::LoadSnowGolemFromNBT(cEntityList & a_Entities, const cParsedNBT { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1835,6 +1940,11 @@ void cWSSAnvil::LoadSpiderFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1850,6 +1960,11 @@ void cWSSAnvil::LoadSquidFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1871,6 +1986,11 @@ void cWSSAnvil::LoadVillagerFromNBT(cEntityList & a_Entities, const cParsedNBT & { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1886,6 +2006,11 @@ void cWSSAnvil::LoadWitchFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1901,6 +2026,11 @@ void cWSSAnvil::LoadWitherFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1916,6 +2046,10 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N { return; } + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } int OwnerIdx = a_NBT.FindChildByName(a_TagIdx, "Owner"); if (OwnerIdx > 0) { @@ -1964,6 +2098,11 @@ void cWSSAnvil::LoadZombieFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } a_Entities.push_back(Monster.release()); } @@ -1980,6 +2119,11 @@ void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT return; } + if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx)) + { + return; + } + a_Entities.push_back(Monster.release()); } @@ -2023,6 +2167,27 @@ bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_N +bool cWSSAnvil::LoadMonsterBaseFromNBT(cMonster & a_Monster, const cParsedNBT & a_NBT, int a_TagIdx) +{ + float DropChance[5]; + if (!LoadFloatsListFromNBT(DropChance, 5, a_NBT, a_NBT.FindChildByName(a_TagIdx, "DropChance"))) + { + return false; + } + a_Monster.SetDropChanceWeapon(DropChance[0]); + a_Monster.SetDropChanceHelmet(DropChance[1]); + a_Monster.SetDropChanceChestplate(DropChance[2]); + a_Monster.SetDropChanceLeggings(DropChance[3]); + a_Monster.SetDropChanceBoots(DropChance[4]); + bool CanPickUpLoot = (a_NBT.GetByte(a_NBT.FindChildByName(a_TagIdx, "CanPickUpLoot")) == 1); + a_Monster.SetCanPickUpLoot(CanPickUpLoot); + return true; +} + + + + + bool cWSSAnvil::LoadProjectileBaseFromNBT(cProjectileEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx) { if (!LoadEntityBaseFromNBT(a_Entity, a_NBT, a_TagIdx)) @@ -2065,6 +2230,24 @@ bool cWSSAnvil::LoadDoublesListFromNBT(double * a_Doubles, int a_NumDoubles, con +bool cWSSAnvil::LoadFloatsListFromNBT(float * a_Floats, int a_NumFloats, const cParsedNBT & a_NBT, int a_TagIdx) +{ + if ((a_TagIdx < 0) || (a_NBT.GetType(a_TagIdx) != TAG_List) || (a_NBT.GetChildrenType(a_TagIdx) != TAG_Float)) + { + return false; + } + int idx = 0; + for (int Tag = a_NBT.GetFirstChild(a_TagIdx); (Tag > 0) && (idx < a_NumFloats); Tag = a_NBT.GetNextSibling(Tag), ++idx) + { + a_Floats[idx] = a_NBT.GetFloat(Tag); + } // for Tag - PosTag[] + return (idx == a_NumFloats); // Did we read enough doubles? +} + + + + + bool cWSSAnvil::GetBlockEntityNBTPos(const cParsedNBT & a_NBT, int a_TagIdx, int & a_X, int & a_Y, int & a_Z) { int x = a_NBT.FindChildByName(a_TagIdx, "x"); diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h index 541371560..4acf3f2a1 100644 --- a/src/WorldStorage/WSSAnvil.h +++ b/src/WorldStorage/WSSAnvil.h @@ -10,6 +10,7 @@ #include "WorldStorage.h" #include "FastNBT.h" +#include "../Mobs/Monster.h" @@ -194,12 +195,18 @@ protected: /// Loads entity common data from the NBT compound; returns true if successful bool LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx); + /// Loads monster common data from the NBT compound; returns true if successful + bool LoadMonsterBaseFromNBT(cMonster & a_Monster, const cParsedNBT & a_NBT, int a_TagIdx); + /// Loads projectile common data from the NBT compound; returns true if successful bool LoadProjectileBaseFromNBT(cProjectileEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIx); /// Loads an array of doubles of the specified length from the specified NBT list tag a_TagIdx; returns true if successful bool LoadDoublesListFromNBT(double * a_Doubles, int a_NumDoubles, const cParsedNBT & a_NBT, int a_TagIdx); + /// Loads an array of floats of the specified length from the specified NBT list tag a_TagIdx; returns true if successful + bool LoadFloatsListFromNBT(float * a_Floats, int a_NumFloats, const cParsedNBT & a_NBT, int a_TagIdx); + /// Helper function for extracting the X, Y, and Z int subtags of a NBT compound; returns true if successful bool GetBlockEntityNBTPos(const cParsedNBT & a_NBT, int a_TagIdx, int & a_X, int & a_Y, int & a_Z);