From b3b66c052657c2adf97a718593a472f8caa9fb8f Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Sat, 20 Apr 2024 19:31:04 +0200 Subject: [PATCH] Add interaction range and step height fixes --- gradle.properties | 8 +- .../viafabricplus/ViaFabricPlus.java | 1 - .../entity/MixinClientPlayerEntity.java | 8 -- .../MixinEntityPacketRewriter1_20_3.java | 4 +- .../MixinEntityPacketRewriter1_20_5.java | 87 +++++++++++++++++++ src/main/resources/viafabricplus.mixins.json | 1 + 6 files changed, 94 insertions(+), 15 deletions(-) create mode 100644 src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinEntityPacketRewriter1_20_5.java diff --git a/gradle.properties b/gradle.properties index 12858811..329b9383 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,10 +3,10 @@ org.gradle.jvmargs=-Xmx8G org.gradle.parallel=true # Minecraft/Fabric -minecraft_version=1.20.5-rc1 -yarn_mappings=1.20.5-rc1+build.1 +minecraft_version=1.20.5-rc2 +yarn_mappings=1.20.5-rc2+build.1 loader_version=0.15.10 -fabric_api_version=0.97.3+1.20.5 +fabric_api_version=0.97.4+1.20.5 # Project Details mod_version=3.2.0-SNAPSHOT @@ -14,7 +14,7 @@ maven_group=de.florianmichael archives_base_name=ViaFabricPlus # ViaVersion Libraries -viaversion_version=4.10.0-1.20.5-rc1-SNAPSHOT +viaversion_version=4.10.0-1.20.5-rc2-SNAPSHOT viabackwards_version=4.10.0-24w09a-SNAPSHOT vialegacy_version=2.2.22-SNAPSHOT viaaprilfools_version=2.0.11-SNAPSHOT diff --git a/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java b/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java index 08de70c8..78c51a6f 100644 --- a/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java +++ b/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java @@ -55,7 +55,6 @@ import java.util.concurrent.CompletableFuture; * - Readd item fixes on protocol level: MixinAxeItem, MixinHoeItem, MixinPickaxeItem, MixinShearsItem, MixinShovelItem, MixinSwordItem, MixinMiningToolItem, MixinItem * - Readd item fixes: ArmorMaterials, MixinItemStack, MixinDrawContext, MixinPacketByteBuf * - Figure out how to fix 32k enchantments with codecs (MixinEnchantmentHelper) - * - Add range fixes in VV (Range attributes have to be updated) */ public class ViaFabricPlus { diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinClientPlayerEntity.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinClientPlayerEntity.java index 06785fe4..7f329ecf 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinClientPlayerEntity.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinClientPlayerEntity.java @@ -35,7 +35,6 @@ import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; -import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.entity.vehicle.BoatEntity; import net.minecraft.network.packet.Packet; import net.minecraft.util.math.MathHelper; @@ -217,13 +216,6 @@ public abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity } } - @Inject(method = "init", at = @At("RETURN")) - private void set1_7StepHeight(CallbackInfo ci) { - if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_7_6)) { - this.client.player.getAttributeInstance(EntityAttributes.GENERIC_STEP_HEIGHT).setBaseValue(0.5D); - } - } - @Redirect(method = "tick", slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;hasVehicle()Z")), at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;)V", ordinal = 0)) private void modifyPositionPacket(ClientPlayNetworkHandler instance, Packet packet) throws Exception { if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_5_2)) { diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinEntityPacketRewriter1_20_3.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinEntityPacketRewriter1_20_3.java index 58c6f07a..ce9558e6 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinEntityPacketRewriter1_20_3.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinEntityPacketRewriter1_20_3.java @@ -27,10 +27,10 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(value = EntityPacketRewriter1_20_3.class, remap = false) -public class MixinEntityPacketRewriter1_20_3 { +public abstract class MixinEntityPacketRewriter1_20_3 { @Inject(method = "sendChunksSentGameEvent", at = @At("HEAD"), cancellable = true) - public void cancelGameStatePacket(PacketWrapper wrapper, CallbackInfo ci) { + private void cancelGameStatePacket(PacketWrapper wrapper, CallbackInfo ci) { ci.cancel(); // Handled in MixinClientPlayNetworkHandler } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinEntityPacketRewriter1_20_5.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinEntityPacketRewriter1_20_5.java new file mode 100644 index 00000000..5b5e1d6c --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinEntityPacketRewriter1_20_5.java @@ -0,0 +1,87 @@ +/* + * 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.mixin.fixes.viaversion; + +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPacket1_20_3; +import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.Protocol1_20_5To1_20_3; +import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundPackets1_20_5; +import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.rewriter.EntityPacketRewriter1_20_5; +import com.viaversion.viaversion.rewriter.EntityRewriter; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.UUID; + +@Mixin(value = EntityPacketRewriter1_20_5.class, remap = false) +public abstract class MixinEntityPacketRewriter1_20_5 extends EntityRewriter { + + @Shadow + @Final + private static UUID CREATIVE_BLOCK_INTERACTION_RANGE; + + @Shadow + @Final + private static UUID CREATIVE_ENTITY_INTERACTION_RANGE; + + protected MixinEntityPacketRewriter1_20_5(Protocol1_20_5To1_20_3 protocol) { + super(protocol); + } + + @Shadow + protected abstract void writeAttribute(PacketWrapper wrapper, String attributeId, double base, @Nullable UUID modifierId, double amount); + + /** + * @author RK_01 + * @reason Fix interaction range and step height differences + */ + @Overwrite + private void sendRangeAttributes(final UserConnection connection, final boolean creativeMode) throws Exception { + final PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_20_5.ENTITY_PROPERTIES, connection); + wrapper.write(Type.VAR_INT, this.tracker(connection).clientEntityId()); + if (connection.getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(ProtocolVersion.v1_7_6)) { + wrapper.write(Type.VAR_INT, 3); // Number of attributes + this.writeAttribute(wrapper, "generic.step_height", 0.5D, null, 0D); + } else { + wrapper.write(Type.VAR_INT, 2); // Number of attributes + } + if (connection.getProtocolInfo().serverProtocolVersion().olderThan(LegacyProtocolVersion.r1_0_0tor1_0_1)) { + this.writeAttribute(wrapper, "player.block_interaction_range", 4D, creativeMode ? CREATIVE_BLOCK_INTERACTION_RANGE : null, 1D); + } else { + this.writeAttribute(wrapper, "player.block_interaction_range", 4.5D, creativeMode ? CREATIVE_BLOCK_INTERACTION_RANGE : null, 0.5D); + } + if (connection.getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) { + this.writeAttribute(wrapper, "player.entity_interaction_range", 3D, creativeMode ? CREATIVE_ENTITY_INTERACTION_RANGE : null, 3D); + } else if (connection.getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(ProtocolVersion.v1_13_2)) { + this.writeAttribute(wrapper, "player.entity_interaction_range", 3D, creativeMode ? CREATIVE_ENTITY_INTERACTION_RANGE : null, 1D); + } else { + this.writeAttribute(wrapper, "player.entity_interaction_range", 3D, creativeMode ? CREATIVE_ENTITY_INTERACTION_RANGE : null, 2D); + } + wrapper.scheduleSend(Protocol1_20_5To1_20_3.class); + } + +} diff --git a/src/main/resources/viafabricplus.mixins.json b/src/main/resources/viafabricplus.mixins.json index 0e07ba08..b5a19ed1 100644 --- a/src/main/resources/viafabricplus.mixins.json +++ b/src/main/resources/viafabricplus.mixins.json @@ -160,6 +160,7 @@ "fixes.viaversion.MixinCommonBoss", "fixes.viaversion.MixinEntityIdRewriter", "fixes.viaversion.MixinEntityPacketRewriter1_20_3", + "fixes.viaversion.MixinEntityPacketRewriter1_20_5", "fixes.viaversion.MixinEntityPackets1_17", "fixes.viaversion.MixinEntityPackets1_19_4", "fixes.viaversion.MixinEntityTracker1_9",