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 f763242e5c5d8e6469685c4be95d3dc264ed6a67 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 23 Apr 2014 21:06:07 +0100 Subject: Small changes --- src/Items/ItemLilypad.h | 14 ++++++-------- src/Items/ItemThrowable.h | 5 ++++- 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemLilypad.h b/src/Items/ItemLilypad.h index 8fc1d8543..bc650cdbd 100644 --- a/src/Items/ItemLilypad.h +++ b/src/Items/ItemLilypad.h @@ -47,9 +47,9 @@ public: public cBlockTracer::cCallbacks { public: - cCallbacks(cWorld * a_CBWorld) : - m_HasHitFluid(false), - m_World(a_CBWorld) + + cCallbacks(void) : + m_HasHitFluid(false) { } @@ -62,10 +62,9 @@ public: return false; } 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) + !IsBlockWater(a_CBBlockType) && + cBlockInfo::FullyOccupiesVoxel(a_CBBlockType) ) { // Can't place lilypad on air/in another block! @@ -80,11 +79,10 @@ public: Vector3i m_Pos; bool m_HasHitFluid; - cWorld * m_World; }; - cCallbacks Callbacks(a_World); + cCallbacks Callbacks; cLineBlockTracer Tracer(*a_Player->GetWorld(), Callbacks); Vector3d Start(a_Player->GetEyePosition() + a_Player->GetLookVector()); Vector3d End(a_Player->GetEyePosition() + a_Player->GetLookVector() * 5); diff --git a/src/Items/ItemThrowable.h b/src/Items/ItemThrowable.h index c6a4e714e..f90caf037 100644 --- a/src/Items/ItemThrowable.h +++ b/src/Items/ItemThrowable.h @@ -127,7 +127,10 @@ public: return false; } - a_World->CreateProjectile(a_BlockX + 0.5, a_BlockY + 1, a_BlockZ + 0.5, m_ProjectileKind, a_Player, a_Player->GetEquippedItem()); + if (a_World->CreateProjectile(a_BlockX + 0.5, a_BlockY + 1, a_BlockZ + 0.5, m_ProjectileKind, a_Player, a_Player->GetEquippedItem()) == -1) + { + return false; + } if (!a_Player->IsGameModeCreative()) { -- 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 From 477b3e7861ca03aec5c46b4c192f5cc1b5f07c4d Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 26 Apr 2014 16:45:39 -0700 Subject: Moved cArrowEntity out of ProjectileEntity.h --- src/Items/ItemBow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Items') diff --git a/src/Items/ItemBow.h b/src/Items/ItemBow.h index 410c5f512..a53d59b58 100644 --- a/src/Items/ItemBow.h +++ b/src/Items/ItemBow.h @@ -9,7 +9,7 @@ #pragma once -#include "../Entities/ProjectileEntity.h" +#include "../Entities/ProjectileArrow.h" -- cgit v1.2.3 From 9b0cb3fd97701370915a9a5b3d5b237fa7f90e06 Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 27 Apr 2014 17:03:06 -0700 Subject: Fixed projectile source filenames, indentations --- src/Items/ItemBow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Items') diff --git a/src/Items/ItemBow.h b/src/Items/ItemBow.h index a53d59b58..8c0b3a0a3 100644 --- a/src/Items/ItemBow.h +++ b/src/Items/ItemBow.h @@ -9,7 +9,7 @@ #pragma once -#include "../Entities/ProjectileArrow.h" +#include "../Entities/ArrowEntity.h" -- cgit v1.2.3 From 5c7876c2dd6aa966fbab6dc0df95ed8d2a17c5c8 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 2 May 2014 19:13:57 +0200 Subject: Added a sanitizer for Spawn egg damage value. This disallows spawning unknown mobs from unknown spawn eggs. Ref.: #928. --- src/Items/ItemSpawnEgg.h | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'src/Items') diff --git a/src/Items/ItemSpawnEgg.h b/src/Items/ItemSpawnEgg.h index 0d6019398..bba97afa1 100644 --- a/src/Items/ItemSpawnEgg.h +++ b/src/Items/ItemSpawnEgg.h @@ -33,7 +33,10 @@ public: a_BlockY--; } - if (a_World->SpawnMob(a_BlockX + 0.5, a_BlockY, a_BlockZ + 0.5, (cMonster::eType)(a_Item.m_ItemDamage)) >= 0) + cMonster::eType MonsterType = ItemDamageToMonsterType(a_Item.m_ItemDamage); + if ( + (MonsterType != cMonster::mtInvalidType) && // Valid monster type + (a_World->SpawnMob(a_BlockX + 0.5, a_BlockY, a_BlockZ + 0.5, MonsterType) >= 0)) // Spawning succeeded { if (!a_Player->IsGameModeCreative()) { @@ -45,6 +48,41 @@ public: return false; } + + + /** Converts the Spawn egg item damage to the monster type to spawn. + Returns mtInvalidType for invalid damage values. */ + static cMonster::eType ItemDamageToMonsterType(short a_ItemDamage) + { + switch (a_ItemDamage) + { + case E_META_SPAWN_EGG_BAT: return cMonster::mtBat; + case E_META_SPAWN_EGG_BLAZE: return cMonster::mtBlaze; + case E_META_SPAWN_EGG_CAVE_SPIDER: return cMonster::mtCaveSpider; + case E_META_SPAWN_EGG_CHICKEN: return cMonster::mtChicken; + case E_META_SPAWN_EGG_COW: return cMonster::mtCow; + case E_META_SPAWN_EGG_CREEPER: return cMonster::mtCreeper; + case E_META_SPAWN_EGG_ENDERMAN: return cMonster::mtEnderman; + case E_META_SPAWN_EGG_GHAST: return cMonster::mtGhast; + case E_META_SPAWN_EGG_HORSE: return cMonster::mtHorse; + case E_META_SPAWN_EGG_MAGMA_CUBE: return cMonster::mtMagmaCube; + case E_META_SPAWN_EGG_MOOSHROOM: return cMonster::mtMooshroom; + case E_META_SPAWN_EGG_OCELOT: return cMonster::mtOcelot; + case E_META_SPAWN_EGG_PIG: return cMonster::mtPig; + case E_META_SPAWN_EGG_SHEEP: return cMonster::mtSheep; + case E_META_SPAWN_EGG_SILVERFISH: return cMonster::mtSilverfish; + case E_META_SPAWN_EGG_SKELETON: return cMonster::mtSkeleton; + case E_META_SPAWN_EGG_SLIME: return cMonster::mtSlime; + case E_META_SPAWN_EGG_SPIDER: return cMonster::mtSpider; + case E_META_SPAWN_EGG_SQUID: return cMonster::mtSquid; + case E_META_SPAWN_EGG_VILLAGER: return cMonster::mtVillager; + case E_META_SPAWN_EGG_WITCH: return cMonster::mtWitch; + case E_META_SPAWN_EGG_WOLF: return cMonster::mtWolf; + case E_META_SPAWN_EGG_ZOMBIE: return cMonster::mtZombie; + case E_META_SPAWN_EGG_ZOMBIE_PIGMAN: return cMonster::mtZombiePigman; + } + return cMonster::mtInvalidType; + } } ; -- cgit v1.2.3 From 3c102870f600178b7cabf6714f83e06fc05b42fd Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 1 May 2014 00:47:57 +0200 Subject: Add anvil window and slot area. --- src/Items/ItemArmor.h | 43 +++++++++++++++++++++++++++++++++++++++++++ src/Items/ItemHandler.cpp | 19 +++++++++++++++++++ src/Items/ItemHandler.h | 6 ++++++ src/Items/ItemPickaxe.h | 13 +++++++++++++ src/Items/ItemShovel.h | 14 ++++++++++++++ src/Items/ItemSword.h | 13 +++++++++++++ 6 files changed, 108 insertions(+) (limited to 'src/Items') diff --git a/src/Items/ItemArmor.h b/src/Items/ItemArmor.h index 08cddb1ad..f53100bb1 100644 --- a/src/Items/ItemArmor.h +++ b/src/Items/ItemArmor.h @@ -60,6 +60,49 @@ public: return true; } + virtual bool CanRepairWithItem(const cItem & a_Item) override + { + switch (m_ItemType) + { + case E_ITEM_CHAIN_BOOTS: + case E_ITEM_CHAIN_CHESTPLATE: + case E_ITEM_CHAIN_HELMET: + case E_ITEM_CHAIN_LEGGINGS: + { + return (a_Item.m_ItemType == E_ITEM_IRON); + } + case E_ITEM_DIAMOND_BOOTS: + case E_ITEM_DIAMOND_CHESTPLATE: + case E_ITEM_DIAMOND_HELMET: + case E_ITEM_DIAMOND_LEGGINGS: + { + return (a_Item.m_ItemType == E_ITEM_DIAMOND); + } + case E_ITEM_IRON_BOOTS: + case E_ITEM_IRON_CHESTPLATE: + case E_ITEM_IRON_HELMET: + case E_ITEM_IRON_LEGGINGS: + { + return (a_Item.m_ItemType == E_ITEM_IRON); + } + case E_ITEM_GOLD_BOOTS: + case E_ITEM_GOLD_CHESTPLATE: + case E_ITEM_GOLD_HELMET: + case E_ITEM_GOLD_LEGGINGS: + { + return (a_Item.m_ItemType == E_ITEM_GOLD); + } + case E_ITEM_LEATHER_BOOTS: + case E_ITEM_LEATHER_CAP: + case E_ITEM_LEATHER_PANTS: + case E_ITEM_LEATHER_TUNIC: + { + return (a_Item.m_ItemType == E_ITEM_LEATHER); + } + } + return false; + } + } ; diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index ce9593a70..105def2ce 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -511,6 +511,25 @@ bool cItemHandler::IsPlaceable(void) + +bool cItemHandler::CanRepairWithItem(const cItem & a_Item) +{ + return false; +} + + + + + +int cItemHandler::GetRepairCost(void) +{ + return 0; +} + + + + + bool cItemHandler::CanHarvestBlock(BLOCKTYPE a_BlockType) { UNUSED(a_BlockType); diff --git a/src/Items/ItemHandler.h b/src/Items/ItemHandler.h index 4993eac85..420eefcf1 100644 --- a/src/Items/ItemHandler.h +++ b/src/Items/ItemHandler.h @@ -85,6 +85,12 @@ public: /** Blocks simply get placed */ virtual bool IsPlaceable(void); + /** Can the anvil repair this item, when a_Item is the second input? */ + virtual bool CanRepairWithItem(const cItem & a_Item); + + /** Get the repair cost from the item, or 0 if the item hasn't repair cost. */ + virtual int GetRepairCost(void); + /** 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. diff --git a/src/Items/ItemPickaxe.h b/src/Items/ItemPickaxe.h index 2a8e40daa..46e68ec70 100644 --- a/src/Items/ItemPickaxe.h +++ b/src/Items/ItemPickaxe.h @@ -85,6 +85,19 @@ public: } return false; } + + virtual bool CanRepairWithItem(const cItem & a_Item) override + { + switch (m_ItemType) + { + case E_ITEM_WOODEN_PICKAXE: return (a_Item.m_ItemType == E_BLOCK_PLANKS); + case E_ITEM_STONE_PICKAXE: return (a_Item.m_ItemType == E_BLOCK_COBBLESTONE); + case E_ITEM_IRON_PICKAXE: return (a_Item.m_ItemType == E_ITEM_IRON); + case E_ITEM_GOLD_PICKAXE: return (a_Item.m_ItemType == E_ITEM_GOLD); + case E_ITEM_DIAMOND_PICKAXE: return (a_Item.m_ItemType == E_ITEM_DIAMOND); + } + return false; + } } ; diff --git a/src/Items/ItemShovel.h b/src/Items/ItemShovel.h index 873d5ae25..7659ccc54 100644 --- a/src/Items/ItemShovel.h +++ b/src/Items/ItemShovel.h @@ -41,4 +41,18 @@ public: { return (a_BlockType == E_BLOCK_SNOW); } + + virtual bool CanRepairWithItem(const cItem & a_Item) override + { + switch (m_ItemType) + { + case E_ITEM_WOODEN_SHOVEL: return (a_Item.m_ItemType == E_BLOCK_PLANKS); + case E_ITEM_STONE_SHOVEL: return (a_Item.m_ItemType == E_BLOCK_COBBLESTONE); + case E_ITEM_IRON_SHOVEL: return (a_Item.m_ItemType == E_ITEM_IRON); + case E_ITEM_GOLD_SHOVEL: return (a_Item.m_ItemType == E_ITEM_GOLD); + case E_ITEM_DIAMOND_SHOVEL: return (a_Item.m_ItemType == E_ITEM_DIAMOND); + } + return false; + } + }; diff --git a/src/Items/ItemSword.h b/src/Items/ItemSword.h index a7c1d2432..34656ff99 100644 --- a/src/Items/ItemSword.h +++ b/src/Items/ItemSword.h @@ -23,6 +23,19 @@ public: { return (a_BlockType == E_BLOCK_COBWEB); } + + virtual bool CanRepairWithItem(const cItem & a_Item) override + { + switch (m_ItemType) + { + case E_ITEM_WOODEN_SWORD: return (a_Item.m_ItemType == E_BLOCK_PLANKS); + case E_ITEM_STONE_SWORD: return (a_Item.m_ItemType == E_BLOCK_COBBLESTONE); + case E_ITEM_IRON_SWORD: return (a_Item.m_ItemType == E_ITEM_IRON); + case E_ITEM_GOLD_SWORD: return (a_Item.m_ItemType == E_ITEM_GOLD); + case E_ITEM_DIAMOND_SWORD: return (a_Item.m_ItemType == E_ITEM_DIAMOND); + } + return false; + } } ; -- cgit v1.2.3 From 1df7dbe7c91953c2413908b846649e884b7ac53c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 5 May 2014 23:45:35 +0100 Subject: Suggestions'd --- src/Items/ItemThrowable.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemThrowable.h b/src/Items/ItemThrowable.h index f90caf037..35c2b8731 100644 --- a/src/Items/ItemThrowable.h +++ b/src/Items/ItemThrowable.h @@ -28,15 +28,19 @@ 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 { + Vector3d Pos = a_Player->GetThrowStartPos(); + Vector3d Speed = a_Player->GetLookVector() * m_SpeedCoeff; + + if (a_World->CreateProjectile(Pos.x, Pos.y, Pos.z, m_ProjectileKind, a_Player, a_Player->GetEquippedItem(), &Speed) < 0) + { + return false; + } + if (!a_Player->IsGameModeCreative()) { a_Player->GetInventory().RemoveOneEquippedItem(); } - Vector3d Pos = a_Player->GetThrowStartPos(); - Vector3d Speed = a_Player->GetLookVector() * m_SpeedCoeff; - a_World->CreateProjectile(Pos.x, Pos.y, Pos.z, m_ProjectileKind, a_Player, a_Player->GetEquippedItem(), &Speed); - return true; } @@ -127,7 +131,7 @@ public: return false; } - if (a_World->CreateProjectile(a_BlockX + 0.5, a_BlockY + 1, a_BlockZ + 0.5, m_ProjectileKind, a_Player, a_Player->GetEquippedItem()) == -1) + if (a_World->CreateProjectile(a_BlockX + 0.5, a_BlockY + 1, a_BlockZ + 0.5, m_ProjectileKind, a_Player, a_Player->GetEquippedItem()) < 0) { return false; } -- cgit v1.2.3 From 954b59d6f460106e93efab39c8666d4692db25b6 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 6 May 2014 19:38:09 +0200 Subject: Rename CanRepairWithItem to CanRepairWithRawMaterial and rename Size() to Count() --- src/Items/ItemArmor.h | 12 ++++++------ src/Items/ItemHandler.cpp | 2 +- src/Items/ItemHandler.h | 2 +- src/Items/ItemPickaxe.h | 12 ++++++------ src/Items/ItemShovel.h | 12 ++++++------ src/Items/ItemSword.h | 12 ++++++------ 6 files changed, 26 insertions(+), 26 deletions(-) (limited to 'src/Items') diff --git a/src/Items/ItemArmor.h b/src/Items/ItemArmor.h index f53100bb1..2436df5bd 100644 --- a/src/Items/ItemArmor.h +++ b/src/Items/ItemArmor.h @@ -60,7 +60,7 @@ public: return true; } - virtual bool CanRepairWithItem(const cItem & a_Item) override + virtual bool CanRepairWithRawMaterial(short a_ItemType) override { switch (m_ItemType) { @@ -69,35 +69,35 @@ public: case E_ITEM_CHAIN_HELMET: case E_ITEM_CHAIN_LEGGINGS: { - return (a_Item.m_ItemType == E_ITEM_IRON); + return (a_ItemType == E_ITEM_IRON); } case E_ITEM_DIAMOND_BOOTS: case E_ITEM_DIAMOND_CHESTPLATE: case E_ITEM_DIAMOND_HELMET: case E_ITEM_DIAMOND_LEGGINGS: { - return (a_Item.m_ItemType == E_ITEM_DIAMOND); + return (a_ItemType == E_ITEM_DIAMOND); } case E_ITEM_IRON_BOOTS: case E_ITEM_IRON_CHESTPLATE: case E_ITEM_IRON_HELMET: case E_ITEM_IRON_LEGGINGS: { - return (a_Item.m_ItemType == E_ITEM_IRON); + return (a_ItemType == E_ITEM_IRON); } case E_ITEM_GOLD_BOOTS: case E_ITEM_GOLD_CHESTPLATE: case E_ITEM_GOLD_HELMET: case E_ITEM_GOLD_LEGGINGS: { - return (a_Item.m_ItemType == E_ITEM_GOLD); + return (a_ItemType == E_ITEM_GOLD); } case E_ITEM_LEATHER_BOOTS: case E_ITEM_LEATHER_CAP: case E_ITEM_LEATHER_PANTS: case E_ITEM_LEATHER_TUNIC: { - return (a_Item.m_ItemType == E_ITEM_LEATHER); + return (a_ItemType == E_ITEM_LEATHER); } } return false; diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index 105def2ce..5cc5b66a0 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -512,7 +512,7 @@ bool cItemHandler::IsPlaceable(void) -bool cItemHandler::CanRepairWithItem(const cItem & a_Item) +bool cItemHandler::CanRepairWithRawMaterial(short a_ItemType) { return false; } diff --git a/src/Items/ItemHandler.h b/src/Items/ItemHandler.h index 420eefcf1..ca090eb29 100644 --- a/src/Items/ItemHandler.h +++ b/src/Items/ItemHandler.h @@ -86,7 +86,7 @@ public: virtual bool IsPlaceable(void); /** Can the anvil repair this item, when a_Item is the second input? */ - virtual bool CanRepairWithItem(const cItem & a_Item); + virtual bool CanRepairWithRawMaterial(short a_ItemType); /** Get the repair cost from the item, or 0 if the item hasn't repair cost. */ virtual int GetRepairCost(void); diff --git a/src/Items/ItemPickaxe.h b/src/Items/ItemPickaxe.h index 46e68ec70..ff2c2069b 100644 --- a/src/Items/ItemPickaxe.h +++ b/src/Items/ItemPickaxe.h @@ -86,15 +86,15 @@ public: return false; } - virtual bool CanRepairWithItem(const cItem & a_Item) override + virtual bool CanRepairWithRawMaterial(short a_ItemType) override { switch (m_ItemType) { - case E_ITEM_WOODEN_PICKAXE: return (a_Item.m_ItemType == E_BLOCK_PLANKS); - case E_ITEM_STONE_PICKAXE: return (a_Item.m_ItemType == E_BLOCK_COBBLESTONE); - case E_ITEM_IRON_PICKAXE: return (a_Item.m_ItemType == E_ITEM_IRON); - case E_ITEM_GOLD_PICKAXE: return (a_Item.m_ItemType == E_ITEM_GOLD); - case E_ITEM_DIAMOND_PICKAXE: return (a_Item.m_ItemType == E_ITEM_DIAMOND); + case E_ITEM_WOODEN_PICKAXE: return (a_ItemType == E_BLOCK_PLANKS); + case E_ITEM_STONE_PICKAXE: return (a_ItemType == E_BLOCK_COBBLESTONE); + case E_ITEM_IRON_PICKAXE: return (a_ItemType == E_ITEM_IRON); + case E_ITEM_GOLD_PICKAXE: return (a_ItemType == E_ITEM_GOLD); + case E_ITEM_DIAMOND_PICKAXE: return (a_ItemType == E_ITEM_DIAMOND); } return false; } diff --git a/src/Items/ItemShovel.h b/src/Items/ItemShovel.h index 7659ccc54..333ba46e8 100644 --- a/src/Items/ItemShovel.h +++ b/src/Items/ItemShovel.h @@ -42,15 +42,15 @@ public: return (a_BlockType == E_BLOCK_SNOW); } - virtual bool CanRepairWithItem(const cItem & a_Item) override + virtual bool CanRepairWithRawMaterial(short a_ItemType) override { switch (m_ItemType) { - case E_ITEM_WOODEN_SHOVEL: return (a_Item.m_ItemType == E_BLOCK_PLANKS); - case E_ITEM_STONE_SHOVEL: return (a_Item.m_ItemType == E_BLOCK_COBBLESTONE); - case E_ITEM_IRON_SHOVEL: return (a_Item.m_ItemType == E_ITEM_IRON); - case E_ITEM_GOLD_SHOVEL: return (a_Item.m_ItemType == E_ITEM_GOLD); - case E_ITEM_DIAMOND_SHOVEL: return (a_Item.m_ItemType == E_ITEM_DIAMOND); + case E_ITEM_WOODEN_SHOVEL: return (a_ItemType == E_BLOCK_PLANKS); + case E_ITEM_STONE_SHOVEL: return (a_ItemType == E_BLOCK_COBBLESTONE); + case E_ITEM_IRON_SHOVEL: return (a_ItemType == E_ITEM_IRON); + case E_ITEM_GOLD_SHOVEL: return (a_ItemType == E_ITEM_GOLD); + case E_ITEM_DIAMOND_SHOVEL: return (a_ItemType == E_ITEM_DIAMOND); } return false; } diff --git a/src/Items/ItemSword.h b/src/Items/ItemSword.h index 34656ff99..44feb2d83 100644 --- a/src/Items/ItemSword.h +++ b/src/Items/ItemSword.h @@ -24,15 +24,15 @@ public: return (a_BlockType == E_BLOCK_COBWEB); } - virtual bool CanRepairWithItem(const cItem & a_Item) override + virtual bool CanRepairWithRawMaterial(short a_ItemType) override { switch (m_ItemType) { - case E_ITEM_WOODEN_SWORD: return (a_Item.m_ItemType == E_BLOCK_PLANKS); - case E_ITEM_STONE_SWORD: return (a_Item.m_ItemType == E_BLOCK_COBBLESTONE); - case E_ITEM_IRON_SWORD: return (a_Item.m_ItemType == E_ITEM_IRON); - case E_ITEM_GOLD_SWORD: return (a_Item.m_ItemType == E_ITEM_GOLD); - case E_ITEM_DIAMOND_SWORD: return (a_Item.m_ItemType == E_ITEM_DIAMOND); + case E_ITEM_WOODEN_SWORD: return (a_ItemType == E_BLOCK_PLANKS); + case E_ITEM_STONE_SWORD: return (a_ItemType == E_BLOCK_COBBLESTONE); + case E_ITEM_IRON_SWORD: return (a_ItemType == E_ITEM_IRON); + case E_ITEM_GOLD_SWORD: return (a_ItemType == E_ITEM_GOLD); + case E_ITEM_DIAMOND_SWORD: return (a_ItemType == E_ITEM_DIAMOND); } return false; } -- cgit v1.2.3