Skip to content

Commit bd1d9a6

Browse files
committed
Fix toolBreakProtection not always working with insta-mining
1 parent 79d5f91 commit bd1d9a6

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/main/java/net/earthcomputer/clientcommands/TempRulesImpl.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import net.minecraft.client.Minecraft;
44
import net.minecraft.client.resources.I18n;
5+
import net.minecraft.enchantment.EnchantmentHelper;
56
import net.minecraft.entity.player.EntityPlayer;
7+
import net.minecraft.init.Enchantments;
8+
import net.minecraft.inventory.ClickType;
69

710
public class TempRulesImpl {
811

@@ -28,6 +31,20 @@ private static void initToolBreakProtection() {
2831
e.setCanceled(true);
2932
Minecraft.getMinecraft().ingameGUI
3033
.setOverlayMessage(I18n.format("tempRules.toolBreakProtection.protected"), false);
34+
} else {
35+
// Fix client-server desync
36+
e.getItemStack().setItemDamage(e.getItemStack().getItemDamage() + e.getDamageAmount());
37+
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.UNBREAKING, e.getItemStack()) > 0) {
38+
if (e.getEntityPlayer().openContainer == e.getEntityPlayer().inventoryContainer) {
39+
// Pickup the item and put it back again to refresh durability
40+
for (int i = 0; i < 2; i++) {
41+
Minecraft.getMinecraft().playerController.windowClick(
42+
e.getEntityPlayer().openContainer.windowId,
43+
e.getEntityPlayer().inventory.currentItem, 0, ClickType.PICKUP,
44+
e.getEntityPlayer());
45+
}
46+
}
47+
}
3148
}
3249
}
3350
});

0 commit comments

Comments
 (0)