summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Harkness <me@bearbin.net>2018-01-05 12:28:06 +0100
committerGitHub <noreply@github.com>2018-01-05 12:28:06 +0100
commitb4aa19f329b06e42eb2591fc488b70dc0df41940 (patch)
tree5b18f7bde0b3129310d273f63b68151850c43ea7
parentAdd the fmt library (#4065) (diff)
downloadcuberite-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
-rw-r--r--src/Blocks/BlockBigFlower.h6
-rw-r--r--src/Entities/Player.cpp43
-rw-r--r--src/Entities/Player.h9
-rw-r--r--src/Item.h4
-rw-r--r--src/Items/ItemAxe.h19
-rw-r--r--src/Items/ItemBigFlower.h12
-rw-r--r--src/Items/ItemBoat.h11
-rw-r--r--src/Items/ItemBow.h14
-rw-r--r--src/Items/ItemChest.h12
-rw-r--r--src/Items/ItemEmptyMap.h10
-rw-r--r--src/Items/ItemFishingRod.h12
-rw-r--r--src/Items/ItemGoldenApple.h5
-rw-r--r--src/Items/ItemHandler.cpp17
-rw-r--r--src/Items/ItemHandler.h10
-rw-r--r--src/Items/ItemHoe.h10
-rw-r--r--src/Items/ItemLighter.h4
-rw-r--r--src/Items/ItemLilypad.h5
-rw-r--r--src/Items/ItemMap.h6
-rw-r--r--src/Items/ItemMilk.h4
-rw-r--r--src/Items/ItemMinecart.h11
-rw-r--r--src/Items/ItemPickaxe.h18
-rw-r--r--src/Items/ItemPumpkin.h12
-rw-r--r--src/Items/ItemShears.h11
-rw-r--r--src/Items/ItemShovel.h16
-rw-r--r--src/Items/ItemSlab.h12
-rw-r--r--src/Items/ItemSword.h13
-rw-r--r--src/Items/ItemThrowable.h10
-rw-r--r--src/Mobs/Creeper.cpp1
-rw-r--r--src/Mobs/Mooshroom.cpp1
-rw-r--r--src/Mobs/Sheep.cpp1
30 files changed, 111 insertions, 208 deletions
diff --git a/src/Blocks/BlockBigFlower.h b/src/Blocks/BlockBigFlower.h
index 45ba5ac02..defe57d99 100644
--- a/src/Blocks/BlockBigFlower.h
+++ b/src/Blocks/BlockBigFlower.h
@@ -3,6 +3,7 @@
#include "BlockHandler.h"
#include "ChunkInterface.h"
+#include "../Items/ItemHandler.h"
@@ -132,6 +133,7 @@ public:
)
{
a_ChunkInterface.SetBlock(BlockPos.x, BlockPos.y, BlockPos.z, 0, 0);
+ a_Player.UseEquippedItem(cItemHandler::dlaBreakBlockInstant);
}
}
@@ -184,7 +186,3 @@ public:
return 7;
}
} ;
-
-
-
-
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 22f0655f2..71f7b582f 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -2330,35 +2330,25 @@ bool cPlayer::SaveToDisk()
-void cPlayer::UseEquippedItem(int a_Amount)
+void cPlayer::UseEquippedItem(short a_Damage)
{
- if (IsGameModeCreative() || IsGameModeSpectator()) // No damage in creative or spectator
+ // No durability loss in creative or spectator modes:
+ if (IsGameModeCreative() || IsGameModeSpectator())
{
return;
}
- // If the item has an unbreaking enchantment, give it a random chance of not breaking:
+ // If the item has an unbreaking enchantment, give it a chance of escaping damage:
+ // Ref: https://minecraft.gamepedia.com/Enchanting#Unbreaking
cItem Item = GetEquippedItem();
int UnbreakingLevel = static_cast<int>(Item.m_Enchantments.GetLevel(cEnchantments::enchUnbreaking));
- if (UnbreakingLevel > 0)
+ double chance = 1 - (1.0 / (UnbreakingLevel + 1));
+ if (GetRandomProvider().RandBool(chance))
{
- double chance = 0.0;
- if (ItemCategory::IsArmor(Item.m_ItemType))
- {
- chance = 0.6 + (0.4 / (UnbreakingLevel + 1));
- }
- else
- {
- chance = 1.0 / (UnbreakingLevel + 1);
- }
-
- if (GetRandomProvider().RandBool(chance))
- {
- return;
- }
+ return;
}
- if (GetInventory().DamageEquippedItem(static_cast<Int16>(a_Amount)))
+ if (GetInventory().DamageEquippedItem(a_Damage))
{
m_World->BroadcastSoundEffect("entity.item.break", GetPosition(), 0.5f, static_cast<float>(0.75 + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64));
}
@@ -2368,6 +2358,21 @@ void cPlayer::UseEquippedItem(int a_Amount)
+void cPlayer::UseEquippedItem(cItemHandler::eDurabilityLostAction a_Action)
+{
+ // Get item being used:
+ cItem Item = GetEquippedItem();
+
+ // Get base damage for action type:
+ short Dmg = cItemHandler::GetItemHandler(Item)->GetDurabilityLossByAction(a_Action);
+
+ UseEquippedItem(Dmg);
+}
+
+
+
+
+
void cPlayer::HandleFood(void)
{
// Ref.: https://minecraft.gamepedia.com/Hunger
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index f56841613..32a4b0348 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -5,6 +5,7 @@
#include "../Inventory.h"
#include "../Defines.h"
#include "../World.h"
+#include "../Items/ItemHandler.h"
#include "../Statistics.h"
@@ -413,7 +414,13 @@ public:
If the player is not riding a horse or if the horse is untamed, does nothing. */
void OpenHorseInventory();
- void UseEquippedItem(int a_Amount = 1);
+ /** Damage the player's equipped item by a_Damage, possibly less if the
+ equipped item is enchanted. */
+ void UseEquippedItem(short a_Damage = 1);
+
+ /** Damage the player's equipped item by the amount of damage such an item
+ is damaged by when used for a_Action */
+ void UseEquippedItem(cItemHandler::eDurabilityLostAction a_Action);
void SendHealth(void);
diff --git a/src/Item.h b/src/Item.h
index 35c4e4582..a94f35176 100644
--- a/src/Item.h
+++ b/src/Item.h
@@ -270,7 +270,3 @@ public:
int m_MaxAmount;
int m_Weight;
} ;
-
-
-
-
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:
}
};
-
-
-
-
diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp
index aaf241dfb..560364b18 100644
--- a/src/Mobs/Creeper.cpp
+++ b/src/Mobs/Creeper.cpp
@@ -156,4 +156,3 @@ void cCreeper::OnRightClicked(cPlayer & a_Player)
m_BurnedWithFlintAndSteel = true;
}
}
-
diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp
index fc901e627..a468a7282 100644
--- a/src/Mobs/Mooshroom.cpp
+++ b/src/Mobs/Mooshroom.cpp
@@ -77,4 +77,3 @@ void cMooshroom::OnRightClicked(cPlayer & a_Player)
} break;
}
}
-
diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp
index 190fac241..70d991329 100644
--- a/src/Mobs/Sheep.cpp
+++ b/src/Mobs/Sheep.cpp
@@ -208,4 +208,3 @@ NIBBLETYPE cSheep::GenerateNaturalRandomColor(void)
return E_META_WOOL_PINK;
}
}
-