diff --git a/src/main/java/net/raphimc/viaproxy/injection/mixins/MixinBlockItemPacketRewriter1_20_5.java b/src/main/java/net/raphimc/viaproxy/injection/mixins/MixinBlockItemPacketRewriter1_20_5.java index 519a21a..df86d32 100644 --- a/src/main/java/net/raphimc/viaproxy/injection/mixins/MixinBlockItemPacketRewriter1_20_5.java +++ b/src/main/java/net/raphimc/viaproxy/injection/mixins/MixinBlockItemPacketRewriter1_20_5.java @@ -23,8 +23,6 @@ import com.viaversion.viaversion.api.minecraft.HolderSet; import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer; import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey; import com.viaversion.viaversion.api.minecraft.item.Item; -import com.viaversion.viaversion.api.minecraft.item.data.FoodEffect; -import com.viaversion.viaversion.api.minecraft.item.data.FoodProperties; import com.viaversion.viaversion.api.minecraft.item.data.ToolProperties; import com.viaversion.viaversion.api.minecraft.item.data.ToolRule; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; @@ -46,8 +44,8 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.*; @@ -60,9 +58,6 @@ public abstract class MixinBlockItemPacketRewriter1_20_5 extends ItemRewriter armorMaxDamage_b1_8_1 = new HashMap<>(); - @Unique - private final Set swordItems1_8 = new HashSet<>(); - @Unique private final Map> toolDataChanges = new LinkedHashMap<>(); @@ -84,17 +79,9 @@ public abstract class MixinBlockItemPacketRewriter1_20_5 extends ItemRewriter entry : armorMaxDamages.entrySet()) { - final String item = entry.getKey(); - final int maxDamage = entry.getValue().getAsInt(); - this.armorMaxDamage_b1_8_1.put(item, maxDamage); + this.armorMaxDamage_b1_8_1.put(entry.getKey(), entry.getValue().getAsInt()); } - this.swordItems1_8.add("minecraft:wooden_sword"); - this.swordItems1_8.add("minecraft:stone_sword"); - this.swordItems1_8.add("minecraft:iron_sword"); - this.swordItems1_8.add("minecraft:golden_sword"); - this.swordItems1_8.add("minecraft:diamond_sword"); - ViaProxy.EVENT_MANAGER.registerRunnable(() -> { final JsonObject itemToolComponents = ViaProxyMappingDataLoader.INSTANCE.loadData("item-tool-components.json"); for (Map.Entry entry : itemToolComponents.entrySet()) { @@ -128,25 +115,26 @@ public abstract class MixinBlockItemPacketRewriter1_20_5 extends ItemRewriter cir) { - final StructuredDataContainer data = cir.getReturnValue().dataContainer(); - final String identifier = this.protocol.getMappingData().getFullItemMappings().identifier(cir.getReturnValue().identifier()); - if (user.getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(ProtocolVersion.v1_17_1)) { - if (identifier.equals("minecraft:crossbow")) { - data.set(StructuredDataKey.MAX_DAMAGE, 326); - } - } - if (user.getProtocolInfo().serverProtocolVersion().betweenInclusive(LegacyProtocolVersion.b1_8tob1_8_1, ProtocolVersion.v1_8)) { - if (this.swordItems1_8.contains(identifier)) { - data.set(StructuredDataKey.FOOD1_20_5, new FoodProperties(0, 0F, true, 3600, null, new FoodEffect[0])); - } + @Redirect(method = "appendItemDataFixComponents", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/version/ProtocolVersion;olderThanOrEqualTo(Lcom/viaversion/viaversion/api/protocol/version/ProtocolVersion;)Z")) + private boolean changeSwordFixVersionRange(ProtocolVersion instance, ProtocolVersion other) { + if (other == ProtocolVersion.v1_8) { + return instance.betweenInclusive(LegacyProtocolVersion.b1_8tob1_8_1, ProtocolVersion.v1_8); + } else { + return instance.olderThanOrEqualTo(other); } + } + + @Inject(method = "appendItemDataFixComponents", at = @At("RETURN")) + private void appendItemDataFixComponents(UserConnection user, Item item, CallbackInfo ci) { + final StructuredDataContainer data = item.dataContainer(); + final String identifier = this.protocol.getMappingData().getFullItemMappings().identifier(item.identifier()); + if (user.getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.b1_8tob1_8_1)) { if (this.armorMaxDamage_b1_8_1.containsKey(identifier)) { data.set(StructuredDataKey.MAX_DAMAGE, this.armorMaxDamage_b1_8_1.get(identifier)); } } + if (user.getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.b1_7tob1_7_3)) { if (this.foodItems_b1_7_3.contains(identifier)) { data.set(StructuredDataKey.MAX_STACK_SIZE, 1);