From de74e140d7e8e418576960cb37cc11ba4028a631 Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Mon, 4 Mar 2024 13:33:30 +0100 Subject: [PATCH] Moved armor durability fix injection --- .../injection/access/IArmorMaterials.java | 28 ----------------- .../minecraft/item/MixinArmorMaterials.java | 30 +++++++++++++------ .../mixin/fixes/minecraft/item/MixinItem.java | 15 +--------- 3 files changed, 22 insertions(+), 51 deletions(-) delete mode 100644 src/main/java/de/florianmichael/viafabricplus/injection/access/IArmorMaterials.java diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/access/IArmorMaterials.java b/src/main/java/de/florianmichael/viafabricplus/injection/access/IArmorMaterials.java deleted file mode 100644 index 678d3693..00000000 --- a/src/main/java/de/florianmichael/viafabricplus/injection/access/IArmorMaterials.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus - * Copyright (C) 2021-2024 FlorianMichael/EnZaXD and RK_01/RaphiMC - * Copyright (C) 2023-2024 contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package de.florianmichael.viafabricplus.injection.access; - -import net.minecraft.item.ArmorItem; - -public interface IArmorMaterials { - - int viaFabricPlus$getBaseMultiplier(final ArmorItem.Type type); - -} diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinArmorMaterials.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinArmorMaterials.java index 4c733fd5..86b9f9e8 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinArmorMaterials.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinArmorMaterials.java @@ -19,25 +19,37 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.item; -import de.florianmichael.viafabricplus.injection.access.IArmorMaterials; -import net.minecraft.item.ArmorItem; +import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator; import net.minecraft.item.ArmorMaterials; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; - -import java.util.EnumMap; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(ArmorMaterials.class) -public abstract class MixinArmorMaterials implements IArmorMaterials { +public abstract class MixinArmorMaterials { @Shadow @Final - private static EnumMap BASE_DURABILITY; + private int durabilityMultiplier; - @Override - public int viaFabricPlus$getBaseMultiplier(ArmorItem.Type type) { - return BASE_DURABILITY.get(type); + @Redirect(method = "getDurability", at = @At(value = "FIELD", target = "Lnet/minecraft/item/ArmorMaterials;durabilityMultiplier:I")) + private int changeDurabilityMultiplier(ArmorMaterials instance) { + if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.b1_8tob1_8_1)) { + if (instance == ArmorMaterials.LEATHER) { + return 3; + } else if (instance == ArmorMaterials.CHAIN || instance == ArmorMaterials.GOLD) { + return 6; + } else if (instance == ArmorMaterials.IRON) { + return 12; + } else if (instance == ArmorMaterials.DIAMOND) { + return 24; + } + } + + return this.durabilityMultiplier; } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinItem.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinItem.java index 9eecb58a..a5018fbb 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinItem.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinItem.java @@ -21,10 +21,8 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.item; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; -import de.florianmichael.viafabricplus.injection.access.IArmorMaterials; import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator; import net.minecraft.item.ArmorItem; -import net.minecraft.item.ArmorMaterials; import net.minecraft.item.CrossbowItem; import net.minecraft.item.Item; import net.raphimc.vialegacy.api.LegacyProtocolVersion; @@ -49,18 +47,7 @@ public abstract class MixinItem { @Redirect(method = {"getMaxDamage", "isDamageable", "getItemBarStep", "getItemBarColor"}, at = @At(value = "FIELD", target = "Lnet/minecraft/item/Item;maxDamage:I")) private int changeCrossbowDamage(Item instance) { if (instance instanceof ArmorItem armor && ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.b1_8tob1_8_1)) { - final int baseMultiplier = ((IArmorMaterials) armor.getMaterial()).viaFabricPlus$getBaseMultiplier(armor.getType()); - if (armor.getMaterial() == ArmorMaterials.LEATHER) { - return baseMultiplier * 3; - } else if (armor.getMaterial() == ArmorMaterials.CHAIN || armor.getMaterial() == ArmorMaterials.GOLD) { - return baseMultiplier * 6; - } else if (armor.getMaterial() == ArmorMaterials.IRON) { - return baseMultiplier * 12; - } else if (armor.getMaterial() == ArmorMaterials.DIAMOND) { - return baseMultiplier * 24; - } else { - return maxDamage; - } + return armor.getMaterial().getDurability(armor.getType()); // Other part of fix in MixinArmorMaterials } else if (instance instanceof CrossbowItem && ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_17_1)) { return 326; } else {