From 4f5ce22d0c5834cd9ef32f509f9dd9ef4865b407 Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Sat, 11 Nov 2023 16:25:33 +0100 Subject: [PATCH] Fixed Crossbow damage offset in 1.18 -> 1.17.1 --- .../mixin/fixes/minecraft/item/MixinItem.java | 43 +++++++++++++++++++ src/main/resources/viafabricplus.mixins.json | 33 +++++++------- 2 files changed, 60 insertions(+), 16 deletions(-) create mode 100644 src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinItem.java 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 new file mode 100644 index 000000000..ebe8ee169 --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinItem.java @@ -0,0 +1,43 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus + * Copyright (C) 2021-2023 FlorianMichael/EnZaXD and 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.mixin.fixes.minecraft.item; + +import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; +import net.minecraft.item.CrossbowItem; +import net.minecraft.item.Item; +import net.raphimc.vialoader.util.VersionEnum; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(Item.class) +public class MixinItem { + + @Shadow @Final private int maxDamage; + + @Redirect(method = { "getMaxDamage", "isDamageable", "getItemBarStep", "getItemBarColor" }, at = @At(value = "FIELD", target = "Lnet/minecraft/item/Item;maxDamage:I")) + public int changeCrossbowDamage(Item instance) { + if (instance instanceof CrossbowItem && ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_18tor1_18_1)) { + return 326; + } + + return maxDamage; + } +} diff --git a/src/main/resources/viafabricplus.mixins.json b/src/main/resources/viafabricplus.mixins.json index 7771a8e61..eb9f91c2f 100644 --- a/src/main/resources/viafabricplus.mixins.json +++ b/src/main/resources/viafabricplus.mixins.json @@ -147,32 +147,33 @@ "fixes.vialegacy.MixinProtocol1_8to1_7_6_10", "fixes.vialegacy.MixinProtocolc0_30toc0_30cpe", "fixes.vialegacy.MixinViaLegacyConfig", + "fixes.viaversion.MixinChatItemRewriter", + "fixes.viaversion.MixinChunkType1_8", + "fixes.viaversion.MixinCommandBlockProvider", "fixes.viaversion.MixinCommonBoss", - "fixes.viaversion.MixinNamedCompoundTagType", - "viaversion.MixinProtocolVersion", "fixes.viaversion.MixinEntityIdRewriter", + "fixes.viaversion.MixinEntityPackets1_17", + "fixes.viaversion.MixinEntityPackets_6_1", + "fixes.viaversion.MixinEntityTracker1_9", + "fixes.viaversion.MixinInventoryAcknowledgements", + "fixes.viaversion.MixinInventoryPackets", + "fixes.viaversion.MixinMetadataRewriter1_15To1_14_4", + "fixes.viaversion.MixinMetadataRewriter1_9To1_8", + "fixes.viaversion.MixinNamedCompoundTagType", "fixes.viaversion.MixinProtocol1_11To1_10", - "fixes.viaversion.MixinChatItemRewriter", - "viaversion.MixinAbstractFenceConnectionHandler", - "viaversion.MixinGlassConnectionHandler", + "fixes.viaversion.MixinProtocol1_12To1_11_1_3", "fixes.viaversion.MixinSkullHandler", "fixes.viaversion.MixinWorldPackets1_13", - "fixes.viaversion.MixinInventoryPackets", - "fixes.viaversion.MixinMetadataRewriter1_15To1_14_4", "fixes.viaversion.MixinWorldPackets1_16_2", - "fixes.viaversion.MixinEntityPackets1_17", - "fixes.viaversion.MixinInventoryAcknowledgements", "fixes.viaversion.MixinWorldPackets1_17", "fixes.viaversion.MixinWorldPackets1_19", - "fixes.viaversion.MixinChunkType1_8", - "fixes.viaversion.MixinCommandBlockProvider", - "fixes.viaversion.MixinEntityPackets_6_1", - "fixes.viaversion.MixinEntityTracker1_9", - "fixes.viaversion.MixinMetadataRewriter1_9To1_8", "jsonwebtoken.MixinClasses", "jsonwebtoken.MixinDefaultJwtParserBuilder", - "fixes.viaversion.MixinProtocol1_12To1_11_1_3", - "viaversion.MixinProtocol1_13To1_12_2" + "viaversion.MixinAbstractFenceConnectionHandler", + "viaversion.MixinGlassConnectionHandler", + "viaversion.MixinProtocol1_13To1_12_2", + "viaversion.MixinProtocolVersion", + "fixes.minecraft.item.MixinItem" ], "injectors": { "defaultRequire": 1