mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2025-01-08 19:38:57 +01:00
Moved armor durability fix injection
This commit is contained in:
parent
e0ec0e3c13
commit
de74e140d7
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
|
||||
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.florianmichael.viafabricplus.injection.access;
|
||||
|
||||
import net.minecraft.item.ArmorItem;
|
||||
|
||||
public interface IArmorMaterials {
|
||||
|
||||
int viaFabricPlus$getBaseMultiplier(final ArmorItem.Type type);
|
||||
|
||||
}
|
@ -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<ArmorItem.Type, Integer> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user