From 402d85d896c793644681c4bb2934a7e0abb5ed8c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 4 Apr 2014 09:56:57 +0200 Subject: Fixed Clang warnings in itemhandlers. --- src/Items/ItemEmptyMap.h | 2 +- src/Items/ItemFishingRod.h | 4 ++-- src/Items/ItemHandler.cpp | 6 +++--- src/Items/ItemLilypad.h | 23 ++++++++++++----------- src/Items/ItemMap.h | 2 +- 5 files changed, 19 insertions(+), 18 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemEmptyMap.h b/src/Items/ItemEmptyMap.h index f0b1e1424..953673382 100644 --- a/src/Items/ItemEmptyMap.h +++ b/src/Items/ItemEmptyMap.h @@ -55,7 +55,7 @@ public: return true; } - a_Player->GetInventory().AddItem(cItem(E_ITEM_MAP, 1, NewMap->GetID()), true, true); + a_Player->GetInventory().AddItem(cItem(E_ITEM_MAP, 1, (short)(NewMap->GetID() & 0x7fff)), true, true); return true; } diff --git a/src/Items/ItemFishingRod.h b/src/Items/ItemFishingRod.h index 15acbd9fe..0431b88b7 100644 --- a/src/Items/ItemFishingRod.h +++ b/src/Items/ItemFishingRod.h @@ -123,7 +123,7 @@ public: } case 2: { - Drops.Add(cItem(E_ITEM_FISHING_ROD, 1, a_World->GetTickRandomNumber(50))); // Fishing rod with durability. TODO: Enchantments on it + Drops.Add(cItem(E_ITEM_FISHING_ROD, 1, (short)a_World->GetTickRandomNumber(50))); // Fishing rod with durability. TODO: Enchantments on it break; } case 3: @@ -152,7 +152,7 @@ public: } else if (Junk <= 4) { - Drops.Add(cItem(E_ITEM_BOW, 1, a_World->GetTickRandomNumber(64))); + Drops.Add(cItem(E_ITEM_BOW, 1, (short)a_World->GetTickRandomNumber(64))); } else if (Junk <= 9) { diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 337b3a83c..1e77717e3 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -506,13 +506,13 @@ bool cItemHandler::GetPlacementBlockTypeMeta( { ASSERT(m_ItemType < 256); // Items with IDs above 255 should all be handled by specific handlers - if (m_ItemType > 256) + if (m_ItemType >= 256) { - LOGERROR("%s: Item %d has no valid block!", __FUNCTION__, m_ItemType); + LOGERROR("%s: Item %d is not eligible for direct block placement!", __FUNCTION__, m_ItemType); return false; } - cBlockHandler * BlockH = BlockHandler(m_ItemType); + cBlockHandler * BlockH = BlockHandler((BLOCKTYPE)m_ItemType); cChunkInterface ChunkInterface(a_World->GetChunkMap()); return BlockH->GetPlacementBlockTypeMeta( ChunkInterface, a_Player, diff --git a/src/Items/ItemLilypad.h b/src/Items/ItemLilypad.h index 5a29abe94..8fc1d8543 100644 --- a/src/Items/ItemLilypad.h +++ b/src/Items/ItemLilypad.h @@ -16,17 +16,19 @@ class cItemLilypadHandler : typedef cItemHandler super; public: - cItemLilypadHandler(BLOCKTYPE a_BlockType) - : cItemHandler(a_BlockType) + cItemLilypadHandler(int a_ItemType): + super(a_ItemType) { } + virtual bool IsPlaceable(void) override { return false; // Set as not placeable so OnItemUse is called } + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override { if (a_BlockFace > BLOCK_FACE_NONE) @@ -45,23 +47,22 @@ public: public cBlockTracer::cCallbacks { public: - cCallbacks(cWorld * a_World) : + cCallbacks(cWorld * a_CBWorld) : m_HasHitFluid(false), - m_World(a_World) + m_World(a_CBWorld) { } - virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override + virtual bool OnNextBlock(int a_CBBlockX, int a_CBBlockY, int a_CBBlockZ, BLOCKTYPE a_CBBlockType, NIBBLETYPE a_CBBlockMeta, char a_CBEntryFace) override { - if (IsBlockWater(a_BlockType)) + if (IsBlockWater(a_CBBlockType)) { - if ((a_BlockMeta != 0) || (a_EntryFace == BLOCK_FACE_NONE)) // The hit block should be a source. The FACE_NONE check is clicking whilst submerged + if ((a_CBBlockMeta != 0) || (a_CBEntryFace == BLOCK_FACE_NONE)) // The hit block should be a source. The FACE_NONE check is clicking whilst submerged { return false; } - a_EntryFace = BLOCK_FACE_YP; // Always place pad at top of water block - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, (eBlockFace)a_EntryFace); - BLOCKTYPE Block = m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); + AddFaceDirection(a_CBBlockX, a_CBBlockY, a_CBBlockZ, BLOCK_FACE_YP); // Always place pad at top of water block + BLOCKTYPE Block = m_World->GetBlock(a_CBBlockX, a_CBBlockY, a_CBBlockZ); if ( !IsBlockWater(Block) && cBlockInfo::FullyOccupiesVoxel(Block) @@ -71,7 +72,7 @@ public: return true; } m_HasHitFluid = true; - m_Pos.Set(a_BlockX, a_BlockY, a_BlockZ); + m_Pos.Set(a_CBBlockX, a_CBBlockY, a_CBBlockZ); return true; } return false; diff --git a/src/Items/ItemMap.h b/src/Items/ItemMap.h index e8ff9da88..056fe0fe7 100644 --- a/src/Items/ItemMap.h +++ b/src/Items/ItemMap.h @@ -29,7 +29,7 @@ public: virtual void OnUpdate(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item) { - cMap * Map = a_World->GetMapManager().GetMapData(a_Item.m_ItemDamage); + cMap * Map = a_World->GetMapManager().GetMapData((unsigned)a_Item.m_ItemDamage); if (Map == NULL) { -- cgit v1.2.3 From 013da806ec20b62a742aded9a9d2b8131193f30d Mon Sep 17 00:00:00 2001 From: jfhumann Date: Fri, 18 Apr 2014 21:09:44 +0200 Subject: Did some static analysis, fixed some bugs and optimized a lot of code --- src/Items/ItemHandler.cpp | 1 - src/Items/ItemHandler.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 1e77717e3..5151eac38 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -431,7 +431,6 @@ bool cItemHandler::IsTool() || (m_ItemType >= 267 && m_ItemType <= 279) || (m_ItemType >= 283 && m_ItemType <= 286) || (m_ItemType >= 290 && m_ItemType <= 294) - || (m_ItemType >= 256 && m_ItemType <= 259) || (m_ItemType == 325) || (m_ItemType == 346); } diff --git a/src/Items/ItemHandler.h b/src/Items/ItemHandler.h index 5b6c239cc..686f4b439 100644 --- a/src/Items/ItemHandler.h +++ b/src/Items/ItemHandler.h @@ -58,8 +58,8 @@ public: struct FoodInfo { - int FoodLevel; double Saturation; + int FoodLevel; int PoisonChance; // 0 - 100, in percent. 0 = no chance of poisoning, 100 = sure poisoning FoodInfo(int a_FoodLevel, double a_Saturation, int a_PoisonChance = 0) : -- cgit v1.2.3 From 5bed1c09bc239f0b5c7b31945c4ee3e5b94cdf17 Mon Sep 17 00:00:00 2001 From: jfhumann Date: Fri, 18 Apr 2014 22:47:59 +0200 Subject: Fixed clang compilation errors. Apparently gcc and MSVC do not care about the order of initializer lists, but clang does. --- src/Items/ItemHandler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Items') diff --git a/src/Items/ItemHandler.h b/src/Items/ItemHandler.h index 686f4b439..f3d78335e 100644 --- a/src/Items/ItemHandler.h +++ b/src/Items/ItemHandler.h @@ -63,8 +63,8 @@ public: int PoisonChance; // 0 - 100, in percent. 0 = no chance of poisoning, 100 = sure poisoning FoodInfo(int a_FoodLevel, double a_Saturation, int a_PoisonChance = 0) : - FoodLevel(a_FoodLevel), Saturation(a_Saturation), + FoodLevel(a_FoodLevel), PoisonChance(a_PoisonChance) { } -- cgit v1.2.3 From 9cbb3a339f98f1737ea78af7f40e1ae7d25027e8 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 24 Apr 2014 20:41:25 +0200 Subject: Fix armor in survival mode. --- src/Items/ItemArmor.h | 54 +++++++++++++++++++++++++++++++++++++++++++++++ src/Items/ItemHandler.cpp | 7 ++++++ src/Items/ItemHandler.h | 30 +++++++++++++------------- 3 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 src/Items/ItemArmor.h (limited to 'src/Items') diff --git a/src/Items/ItemArmor.h b/src/Items/ItemArmor.h new file mode 100644 index 000000000..0f40ac443 --- /dev/null +++ b/src/Items/ItemArmor.h @@ -0,0 +1,54 @@ + +#pragma once + +#include "ItemHandler.h" +#include "../World.h" + + + + + +class cItemArmorHandler : + public cItemHandler +{ +public: + cItemArmorHandler(int a_ItemType) : + cItemHandler(a_ItemType) + { + } + + virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override + { + int SlotNum = -1; + if (ItemCategory::IsHelmet(a_Item.m_ItemType)) + { + SlotNum = 0; + } + else if (ItemCategory::IsChestPlate(a_Item.m_ItemType)) + { + SlotNum = 1; + } + else if (ItemCategory::IsLeggings(a_Item.m_ItemType)) + { + SlotNum = 2; + } + else if (ItemCategory::IsBoots(a_Item.m_ItemType)) + { + SlotNum = 3; + } + + if (!a_Player->GetInventory().GetArmorSlot(SlotNum).IsEmpty()) + { + return false; + } + + a_Player->GetInventory().SetArmorSlot(SlotNum, a_Item.CopyOne()); + a_Player->GetInventory().SetHotbarSlot(a_Player->GetInventory().GetEquippedSlotNum(), cItem()); + return true; + } + +} ; + + + + diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 5151eac38..2cb1471aa 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -8,6 +8,7 @@ #include "../BlockInServerPluginInterface.h" // Handlers: +#include "ItemArmor.h" #include "ItemBed.h" #include "ItemBoat.h" #include "ItemBow.h" @@ -90,6 +91,12 @@ cItemHandler * cItemHandler::GetItemHandler(int a_ItemType) cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) { + // Armor + if (ItemCategory::IsArmor(a_ItemType)) + { + return new cItemArmorHandler(a_ItemType); + } + switch(a_ItemType) { default: return new cItemHandler(a_ItemType); diff --git a/src/Items/ItemHandler.h b/src/Items/ItemHandler.h index f3d78335e..4993eac85 100644 --- a/src/Items/ItemHandler.h +++ b/src/Items/ItemHandler.h @@ -21,13 +21,13 @@ class cItemHandler public: cItemHandler(int a_ItemType); - // Force virtual destructor + /** Force virtual destructor */ virtual ~cItemHandler() {} - /// Called when the player tries to use the item (right mouse button). Return false to make the item unusable. DEFAULT: False + /** Called when the player tries to use the item (right mouse button). Return false to make the item unusable. DEFAULT: False */ virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir); - /// Called when the client sends the SHOOT status in the lclk packet + /** Called when the client sends the SHOOT status in the lclk packet */ virtual void OnItemShoot(cPlayer *, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) { UNUSED(a_BlockX); @@ -36,7 +36,7 @@ public: UNUSED(a_BlockFace); } - /// Called every tick while the item is on the player's inventory (Used by maps) - For now, called only for equipped items + /** Called every tick while the item is on the player's inventory (Used by maps) - For now, called only for equipped items */ virtual void OnUpdate(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item) { UNUSED(a_World); @@ -44,16 +44,16 @@ public: UNUSED(a_Item); } - /// Called while the player diggs a block using this item + /** Called while the player diggs a block using this item */ virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_HeldItem, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace); - /// Called when the player destroys a block using this item. This also calls the drop function for the destroyed block + /** Called when the player destroys a block using this item. This also calls the drop function for the destroyed block */ virtual void OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_X, int a_Y, int a_Z); - /// Called after the player has eaten this item. + /** Called after the player has eaten this item. */ virtual void OnFoodEaten(cWorld *a_World, cPlayer *a_Player, cItem *a_Item); - /// Returns the maximum stack size for a given item + /** Returns the maximum stack size for a given item */ virtual char GetMaxStackSize(void); struct FoodInfo @@ -70,22 +70,22 @@ public: } } ; - /// Returns the FoodInfo for this item. (FoodRecovery, Saturation and PoisionChance) + /** Returns the FoodInfo for this item. (FoodRecovery, Saturation and PoisionChance) */ virtual FoodInfo GetFoodInfo(); - /// Lets the player eat a selected item. Returns true if the player ate the item + /** Lets the player eat a selected item. Returns true if the player ate the item */ virtual bool EatItem(cPlayer *a_Player, cItem *a_Item); - /// Indicates if this item is a tool + /** Indicates if this item is a tool */ virtual bool IsTool(void); - /// Indicates if this item is food + /** Indicates if this item is food */ virtual bool IsFood(void); - /// Blocks simply get placed + /** Blocks simply get placed */ virtual bool IsPlaceable(void); - /** Called before a block is placed into a world. + /** Called before a block is placed into a world. The handler should return true to allow placement, false to refuse. Also, the handler should set a_BlockType and a_BlockMeta to correct values for the newly placed block. */ @@ -96,7 +96,7 @@ public: BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ); - /// Returns whether this tool/item can harvest a specific block (e.g. wooden pickaxe can harvest stone, but wood can´t) DEFAULT: False + /** Returns whether this tool/item can harvest a specific block (e.g. wooden pickaxe can harvest stone, but wood can�t) DEFAULT: False */ virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType); static cItemHandler * GetItemHandler(int a_ItemType); -- cgit v1.2.3 From 376dc880b37e1b104c86efebef0f294c34ca3c42 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 24 Apr 2014 23:03:04 +0200 Subject: Add armor to switch() in ItemHandler.cpp --- src/Items/ItemHandler.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 2cb1471aa..ce9593a70 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -91,12 +91,6 @@ cItemHandler * cItemHandler::GetItemHandler(int a_ItemType) cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) { - // Armor - if (ItemCategory::IsArmor(a_ItemType)) - { - return new cItemArmorHandler(a_ItemType); - } - switch(a_ItemType) { default: return new cItemHandler(a_ItemType); @@ -229,6 +223,31 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) { return new cItemFoodHandler(a_ItemType); } + + // Armor: + case E_ITEM_LEATHER_CAP: + case E_ITEM_GOLD_HELMET: + case E_ITEM_CHAIN_HELMET: + case E_ITEM_IRON_HELMET: + case E_ITEM_DIAMOND_HELMET: + case E_ITEM_LEATHER_TUNIC: + case E_ITEM_GOLD_CHESTPLATE: + case E_ITEM_CHAIN_CHESTPLATE: + case E_ITEM_IRON_CHESTPLATE: + case E_ITEM_DIAMOND_CHESTPLATE: + case E_ITEM_LEATHER_PANTS: + case E_ITEM_GOLD_LEGGINGS: + case E_ITEM_CHAIN_LEGGINGS: + case E_ITEM_IRON_LEGGINGS: + case E_ITEM_DIAMOND_LEGGINGS: + case E_ITEM_LEATHER_BOOTS: + case E_ITEM_GOLD_BOOTS: + case E_ITEM_CHAIN_BOOTS: + case E_ITEM_IRON_BOOTS: + case E_ITEM_DIAMOND_BOOTS: + { + return new cItemArmorHandler(a_ItemType); + } } } -- cgit v1.2.3 From cee70390fae9c240337186e50445e50518ccdba8 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 25 Apr 2014 00:09:22 +0200 Subject: Add unkown armor warning and fix armor stacks. --- src/Items/ItemArmor.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemArmor.h b/src/Items/ItemArmor.h index 0f40ac443..a786990fc 100644 --- a/src/Items/ItemArmor.h +++ b/src/Items/ItemArmor.h @@ -19,7 +19,7 @@ public: virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { - int SlotNum = -1; + int SlotNum; if (ItemCategory::IsHelmet(a_Item.m_ItemType)) { SlotNum = 0; @@ -36,6 +36,11 @@ public: { SlotNum = 3; } + else + { + LOGWARNING("Used unknown armor: %i", a_Item.m_ItemType); + return false; + } if (!a_Player->GetInventory().GetArmorSlot(SlotNum).IsEmpty()) { @@ -43,7 +48,14 @@ public: } a_Player->GetInventory().SetArmorSlot(SlotNum, a_Item.CopyOne()); - a_Player->GetInventory().SetHotbarSlot(a_Player->GetInventory().GetEquippedSlotNum(), cItem()); + + cItem Item(a_Item); + Item.m_ItemCount--; + if (Item.m_ItemCount <= 0) + { + Item.Empty(); + } + a_Player->GetInventory().SetHotbarSlot(a_Player->GetInventory().GetEquippedSlotNum(), Item); return true; } -- cgit v1.2.3 From ccd9023202e2a9f97780fd96438c024a83618052 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 25 Apr 2014 00:10:52 +0200 Subject: Add commit what the code is doing. --- src/Items/ItemArmor.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Items') diff --git a/src/Items/ItemArmor.h b/src/Items/ItemArmor.h index a786990fc..08cddb1ad 100644 --- a/src/Items/ItemArmor.h +++ b/src/Items/ItemArmor.h @@ -17,6 +17,7 @@ public: { } + /** Move the armor to the armor slot of the player's inventory */ virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { int SlotNum; -- cgit v1.2.3 From 0e0c9d82483e01840faf7027fc01a998d5cf2f18 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 12:24:09 -0700 Subject: Missed these CMakeLists. --- src/Items/CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/Items') diff --git a/src/Items/CMakeLists.txt b/src/Items/CMakeLists.txt index 44a9f594f..a6fe6ea70 100644 --- a/src/Items/CMakeLists.txt +++ b/src/Items/CMakeLists.txt @@ -4,4 +4,9 @@ project (MCServer) include_directories ("${PROJECT_SOURCE_DIR}/../") -add_library(Items ItemHandler) +file(GLOB SOURCE + "*.cpp" + "*.h" +) + +add_library(Items ${SOURCE}) -- cgit v1.2.3