diff options
author | Alexander Harkness <me@bearbin.net> | 2018-01-05 12:28:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-05 12:28:06 +0100 |
commit | b4aa19f329b06e42eb2591fc488b70dc0df41940 (patch) | |
tree | 5b18f7bde0b3129310d273f63b68151850c43ea7 /src/Items | |
parent | Add the fmt library (#4065) (diff) | |
download | cuberite-b4aa19f329b06e42eb2591fc488b70dc0df41940.tar cuberite-b4aa19f329b06e42eb2591fc488b70dc0df41940.tar.gz cuberite-b4aa19f329b06e42eb2591fc488b70dc0df41940.tar.bz2 cuberite-b4aa19f329b06e42eb2591fc488b70dc0df41940.tar.lz cuberite-b4aa19f329b06e42eb2591fc488b70dc0df41940.tar.xz cuberite-b4aa19f329b06e42eb2591fc488b70dc0df41940.tar.zst cuberite-b4aa19f329b06e42eb2591fc488b70dc0df41940.zip |
Diffstat (limited to 'src/Items')
-rw-r--r-- | src/Items/ItemAxe.h | 19 | ||||
-rw-r--r-- | src/Items/ItemBigFlower.h | 12 | ||||
-rw-r--r-- | src/Items/ItemBoat.h | 11 | ||||
-rw-r--r-- | src/Items/ItemBow.h | 14 | ||||
-rw-r--r-- | src/Items/ItemChest.h | 12 | ||||
-rw-r--r-- | src/Items/ItemEmptyMap.h | 10 | ||||
-rw-r--r-- | src/Items/ItemFishingRod.h | 12 | ||||
-rw-r--r-- | src/Items/ItemGoldenApple.h | 5 | ||||
-rw-r--r-- | src/Items/ItemHandler.cpp | 17 | ||||
-rw-r--r-- | src/Items/ItemHandler.h | 10 | ||||
-rw-r--r-- | src/Items/ItemHoe.h | 10 | ||||
-rw-r--r-- | src/Items/ItemLighter.h | 4 | ||||
-rw-r--r-- | src/Items/ItemLilypad.h | 5 | ||||
-rw-r--r-- | src/Items/ItemMap.h | 6 | ||||
-rw-r--r-- | src/Items/ItemMilk.h | 4 | ||||
-rw-r--r-- | src/Items/ItemMinecart.h | 11 | ||||
-rw-r--r-- | src/Items/ItemPickaxe.h | 18 | ||||
-rw-r--r-- | src/Items/ItemPumpkin.h | 12 | ||||
-rw-r--r-- | src/Items/ItemShears.h | 11 | ||||
-rw-r--r-- | src/Items/ItemShovel.h | 16 | ||||
-rw-r--r-- | src/Items/ItemSlab.h | 12 | ||||
-rw-r--r-- | src/Items/ItemSword.h | 13 | ||||
-rw-r--r-- | src/Items/ItemThrowable.h | 10 |
23 files changed, 77 insertions, 177 deletions
diff --git a/src/Items/ItemAxe.h b/src/Items/ItemAxe.h index 1f9c44f1e..aeba22cf4 100644 --- a/src/Items/ItemAxe.h +++ b/src/Items/ItemAxe.h @@ -18,7 +18,20 @@ public: } - virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) + + virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) override + { + switch (a_Action) + { + case dlaAttackEntity: return 2; + case dlaBreakBlock: return 1; + case dlaBreakBlockInstant: return 0; + } + } + + + + virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) override { if (!IsBlockMaterialWood(a_Block) && !IsBlockMaterialPlants(a_Block) && !IsBlockMaterialVine(a_Block)) { @@ -40,7 +53,3 @@ public: } } ; - - - - diff --git a/src/Items/ItemBigFlower.h b/src/Items/ItemBigFlower.h index 81a1d54ce..d433c4b87 100644 --- a/src/Items/ItemBigFlower.h +++ b/src/Items/ItemBigFlower.h @@ -1,12 +1,4 @@ -// ItemBigFlower.h - -// Declares the cItemBigFlower class representing the cItemHandler for big flowers - - - - - #pragma once #include "ItemHandler.h" @@ -61,7 +53,3 @@ public: return true; } }; - - - - diff --git a/src/Items/ItemBoat.h b/src/Items/ItemBoat.h index 09d8b1d2d..f0b0cefd8 100644 --- a/src/Items/ItemBoat.h +++ b/src/Items/ItemBoat.h @@ -1,10 +1,3 @@ -// ItemBoat.h - -// Declares the various boat ItemHandlers - - - - #pragma once @@ -109,7 +102,3 @@ public: return true; } } ; - - - - diff --git a/src/Items/ItemBow.h b/src/Items/ItemBow.h index 241df0c3c..53a1373b7 100644 --- a/src/Items/ItemBow.h +++ b/src/Items/ItemBow.h @@ -1,15 +1,8 @@ -// ItemBow.h - -// Declares the cItemBowHandler class representing the itemhandler for bows - - - - - #pragma once #include "../Entities/ArrowEntity.h" +#include "ItemHandler.h" @@ -101,8 +94,3 @@ public: } } } ; - - - - - diff --git a/src/Items/ItemChest.h b/src/Items/ItemChest.h index 83f4c4cfa..58f6fbc6e 100644 --- a/src/Items/ItemChest.h +++ b/src/Items/ItemChest.h @@ -1,12 +1,4 @@ -// ItemChest.h - -// Declares the cItemChestHandler class representing the cItemHandler descendant responsible for chests - - - - - #pragma once #include "ItemHandler.h" @@ -164,7 +156,3 @@ public: private: cItemChestHandler(const cItemChestHandler &) = delete; }; - - - - diff --git a/src/Items/ItemEmptyMap.h b/src/Items/ItemEmptyMap.h index 3d77250fa..bb796d892 100644 --- a/src/Items/ItemEmptyMap.h +++ b/src/Items/ItemEmptyMap.h @@ -1,10 +1,4 @@ -// ItemEmptyMap.h - - - - - #pragma once #include "../Item.h" @@ -64,7 +58,3 @@ public: return true; } } ; - - - - diff --git a/src/Items/ItemFishingRod.h b/src/Items/ItemFishingRod.h index 0720cb3e1..ed8dfafef 100644 --- a/src/Items/ItemFishingRod.h +++ b/src/Items/ItemFishingRod.h @@ -1,12 +1,4 @@ -// ItemFishingRod.h - -// Declares the various fishing rod ItemHandlers - - - - - #pragma once #include "../Entities/Floater.h" @@ -240,7 +232,3 @@ public: return true; } } ; - - - - diff --git a/src/Items/ItemGoldenApple.h b/src/Items/ItemGoldenApple.h index a88d3eb54..00f5ac1c0 100644 --- a/src/Items/ItemGoldenApple.h +++ b/src/Items/ItemGoldenApple.h @@ -1,3 +1,4 @@ + #pragma once #include "ItemFood.h" @@ -48,7 +49,3 @@ public: } }; - - - - diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index e10f17db1..976ab959d 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -494,10 +494,8 @@ void cItemHandler::OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const Handler->DropBlock(ChunkInterface, *a_World, PluginInterface, a_Player, a_BlockX, a_BlockY, a_BlockZ, CanHarvestBlock(Block)); } - if (!cBlockInfo::IsOneHitDig(Block)) - { - a_Player->UseEquippedItem(GetDurabilityLossByAction(dlaBreakBlock)); - } + auto Action = (cBlockInfo::IsOneHitDig(Block) ? dlaBreakBlockInstant : dlaBreakBlock); + a_Player->UseEquippedItem(Action); } @@ -507,7 +505,7 @@ void cItemHandler::OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const void cItemHandler::OnEntityAttack(cPlayer * a_Attacker, cEntity * a_AttackedEntity) { UNUSED(a_AttackedEntity); - a_Attacker->UseEquippedItem(GetDurabilityLossByAction(dlaAttackEntity)); + a_Attacker->UseEquippedItem(dlaAttackEntity); } @@ -527,15 +525,9 @@ void cItemHandler::OnFoodEaten(cWorld * a_World, cPlayer * a_Player, cItem * a_I short cItemHandler::GetDurabilityLossByAction(eDurabilityLostAction a_Action) { - switch (a_Action) - { - case dlaAttackEntity: return 2; - case dlaBreakBlock: return 1; - } + UNUSED(a_Action); - #ifndef __clang__ return 0; - #endif } @@ -865,4 +857,3 @@ float cItemHandler::GetBlockBreakingStrength(BLOCKTYPE a_Block) { return 1.0f; } - diff --git a/src/Items/ItemHandler.h b/src/Items/ItemHandler.h index faee5d008..26703f573 100644 --- a/src/Items/ItemHandler.h +++ b/src/Items/ItemHandler.h @@ -21,10 +21,14 @@ class cItemHandler { public: + /** Actions that may cause durability of an item may be lost, where the + magnitude of the loss depends on the specific item used to perform the + action */ enum eDurabilityLostAction { - dlaBreakBlock, dlaAttackEntity, + dlaBreakBlock, + dlaBreakBlockInstant, }; cItemHandler(int a_ItemType); @@ -107,7 +111,9 @@ public: /** Called after the player has eaten this item. */ virtual void OnFoodEaten(cWorld *a_World, cPlayer *a_Player, cItem *a_Item); - /** Get the durability lost which the item will get, when a specified action was performed. */ + /** Get the durability lost which the item will get, when a specified action + was performed. This is only relevant for uses where the damage taken may + depend on the item used. */ virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action); /** Returns the maximum stack size for a given item */ diff --git a/src/Items/ItemHoe.h b/src/Items/ItemHoe.h index 0bf2d4c4b..8fe53c343 100644 --- a/src/Items/ItemHoe.h +++ b/src/Items/ItemHoe.h @@ -69,9 +69,11 @@ public: virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) override { - return 0; + switch (a_Action) + { + case dlaAttackEntity: return 1; + case dlaBreakBlock: return 0; + case dlaBreakBlockInstant: return 0; + } } } ; - - - diff --git a/src/Items/ItemLighter.h b/src/Items/ItemLighter.h index 5acc5551e..5255e17f0 100644 --- a/src/Items/ItemLighter.h +++ b/src/Items/ItemLighter.h @@ -81,7 +81,3 @@ public: return false; } } ; - - - - diff --git a/src/Items/ItemLilypad.h b/src/Items/ItemLilypad.h index 7a0f05135..7f3b85a70 100644 --- a/src/Items/ItemLilypad.h +++ b/src/Items/ItemLilypad.h @@ -1,3 +1,4 @@ + #pragma once #include "ItemHandler.h" @@ -104,7 +105,3 @@ public: return false; } }; - - - - diff --git a/src/Items/ItemMap.h b/src/Items/ItemMap.h index 57ede063c..203e11fbb 100644 --- a/src/Items/ItemMap.h +++ b/src/Items/ItemMap.h @@ -1,10 +1,4 @@ -// ItemMap.h - - - - - #pragma once #include "../Item.h" diff --git a/src/Items/ItemMilk.h b/src/Items/ItemMilk.h index c426c0057..79c44509f 100644 --- a/src/Items/ItemMilk.h +++ b/src/Items/ItemMilk.h @@ -1,6 +1,10 @@ #pragma once + + + + class cItemMilkHandler: public cItemHandler { diff --git a/src/Items/ItemMinecart.h b/src/Items/ItemMinecart.h index 05f375f06..55a39c5ce 100644 --- a/src/Items/ItemMinecart.h +++ b/src/Items/ItemMinecart.h @@ -1,10 +1,3 @@ -// ItemMinecart.h - -// Declares the various minecart ItemHandlers - - - - #pragma once @@ -73,7 +66,3 @@ public: } } ; - - - - diff --git a/src/Items/ItemPickaxe.h b/src/Items/ItemPickaxe.h index 66796012b..84fa655fc 100644 --- a/src/Items/ItemPickaxe.h +++ b/src/Items/ItemPickaxe.h @@ -16,6 +16,20 @@ public: } + + + virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) override + { + switch (a_Action) + { + case dlaAttackEntity: return 2; + case dlaBreakBlock: return 1; + case dlaBreakBlockInstant: return 0; + } + } + + + char PickaxeLevel() { switch (m_ItemType) @@ -173,7 +187,3 @@ public: } } ; - - - - diff --git a/src/Items/ItemPumpkin.h b/src/Items/ItemPumpkin.h index 7a53d522f..d124265c7 100644 --- a/src/Items/ItemPumpkin.h +++ b/src/Items/ItemPumpkin.h @@ -1,12 +1,4 @@ -// ItemPumpkin.h - -// Declares the cItemPumpkinHandler class representing the pumpkin block in its item form - - - - - #pragma once #include "ItemHandler.h" @@ -150,7 +142,3 @@ public: return false; } }; - - - - diff --git a/src/Items/ItemShears.h b/src/Items/ItemShears.h index b9866e068..bebc85c92 100644 --- a/src/Items/ItemShears.h +++ b/src/Items/ItemShears.h @@ -63,7 +63,12 @@ public: virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) override { - return 1; + switch (a_Action) + { + case dlaAttackEntity: return 0; + case dlaBreakBlock: return 0; + case dlaBreakBlockInstant: return 1; + } } @@ -95,7 +100,3 @@ public: } } ; - - - - diff --git a/src/Items/ItemShovel.h b/src/Items/ItemShovel.h index a3ef97684..a39e6ecac 100644 --- a/src/Items/ItemShovel.h +++ b/src/Items/ItemShovel.h @@ -21,6 +21,20 @@ public: { } + + + virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) override + { + switch (a_Action) + { + case dlaAttackEntity: return 2; + case dlaBreakBlock: return 1; + case dlaBreakBlockInstant: return 0; + } + } + + + virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); @@ -31,7 +45,7 @@ public: BlockHandler(Block)->DropBlock(ChunkInterface, *a_World, PluginInterface, a_Player, a_BlockX, a_BlockY, a_BlockZ); a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); - a_Player->UseEquippedItem(); + a_Player->UseEquippedItem(cItemHandler::dlaBreakBlock); return true; } return false; diff --git a/src/Items/ItemSlab.h b/src/Items/ItemSlab.h index 05bd60423..ff83c0367 100644 --- a/src/Items/ItemSlab.h +++ b/src/Items/ItemSlab.h @@ -1,12 +1,4 @@ -// ItemSlab.h - -// Declares the cItemSlabHandler responsible for handling slabs, when in their item form. - - - - - #pragma once #include "ItemHandler.h" @@ -126,7 +118,3 @@ protected: /** The block type to use when the slab combines into a doubleslab block. */ BLOCKTYPE m_DoubleSlabBlockType; }; - - - - diff --git a/src/Items/ItemSword.h b/src/Items/ItemSword.h index 5730691cf..773b84388 100644 --- a/src/Items/ItemSword.h +++ b/src/Items/ItemSword.h @@ -46,13 +46,10 @@ public: { switch (a_Action) { - case dlaAttackEntity: return 1; - case dlaBreakBlock: return 2; + case dlaAttackEntity: return 1; + case dlaBreakBlock: return 2; + case dlaBreakBlockInstant: return 0; } - - #ifndef __clang__ - return 0; - #endif } @@ -83,7 +80,3 @@ public: } } ; - - - - diff --git a/src/Items/ItemThrowable.h b/src/Items/ItemThrowable.h index 18dd9e801..85234088f 100644 --- a/src/Items/ItemThrowable.h +++ b/src/Items/ItemThrowable.h @@ -1,12 +1,6 @@ -// ItemThrowable.h - // Declares the itemhandlers for throwable items: eggs, snowballs and ender pearls - - - - #pragma once @@ -157,7 +151,3 @@ public: } }; - - - - |