aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/DigDurabilityEnchantment.cpp
diff options
context:
space:
mode:
authordaoge_cmd <3523206925@qq.com>2026-03-01 12:16:08 +0800
committerdaoge_cmd <3523206925@qq.com>2026-03-01 12:16:08 +0800
commitb691c43c44ff180d10e7d4a9afc83b98551ff586 (patch)
tree3e9849222cbc6ba49f2f1fc6e5fe7179632c7390 /Minecraft.World/DigDurabilityEnchantment.cpp
parentdef8cb415354ac390b7e89052a50605285f1aca9 (diff)
Initial commit
Diffstat (limited to 'Minecraft.World/DigDurabilityEnchantment.cpp')
-rw-r--r--Minecraft.World/DigDurabilityEnchantment.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/Minecraft.World/DigDurabilityEnchantment.cpp b/Minecraft.World/DigDurabilityEnchantment.cpp
new file mode 100644
index 00000000..f2ef1656
--- /dev/null
+++ b/Minecraft.World/DigDurabilityEnchantment.cpp
@@ -0,0 +1,36 @@
+#include "stdafx.h"
+#include "net.minecraft.world.item.h"
+#include "DigDurabilityEnchantment.h"
+
+DigDurabilityEnchantment::DigDurabilityEnchantment(int id, int frequency) : Enchantment(id, frequency, EnchantmentCategory::digger)
+{
+ setDescriptionId(IDS_ENCHANTMENT_DURABILITY);
+}
+
+int DigDurabilityEnchantment::getMinCost(int level)
+{
+ return 5 + (level - 1) * 8;
+}
+
+int DigDurabilityEnchantment::getMaxCost(int level)
+{
+ return Enchantment::getMinCost(level) + 50;
+}
+
+int DigDurabilityEnchantment::getMaxLevel()
+{
+ return 3;
+}
+
+bool DigDurabilityEnchantment::canEnchant(shared_ptr<ItemInstance> item)
+{
+ if (item->isDamageableItem()) return true;
+ return Enchantment::canEnchant(item);
+}
+
+bool DigDurabilityEnchantment::shouldIgnoreDurabilityDrop(shared_ptr<ItemInstance> item, int level, Random *random)
+{
+ ArmorItem *armor = dynamic_cast<ArmorItem *>(item->getItem());
+ if (armor && random->nextFloat() < 0.6f) return false;
+ return random->nextInt(level + 1) > 0;
+} \ No newline at end of file