From 1544364f21a94eeed0bd07cf5731988d88ea1d17 Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Sat, 11 Nov 2023 18:50:51 +0100 Subject: [PATCH] Implemented some more Elytra changes in 1.15 -> 1.14.4 Slightly fixed last commit --- .../entity/MixinClientPlayerEntity.java | 54 ++++++++++++++----- .../minecraft/entity/MixinLivingEntity.java | 2 +- .../mixin/fixes/minecraft/item/MixinItem.java | 2 +- 3 files changed, 43 insertions(+), 15 deletions(-) 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 b30e161f..e4514e23 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 @@ -17,8 +17,12 @@ */ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.entity; +import com.llamalad7.mixinextras.injector.WrapWithCondition; import com.mojang.authlib.GameProfile; import de.florianmichael.viafabricplus.definition.ClientsideFixes; +import net.minecraft.client.network.ClientPlayNetworkHandler; +import net.minecraft.network.packet.Packet; +import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket; import net.minecraft.world.GameMode; import net.raphimc.vialoader.util.VersionEnum; import de.florianmichael.viafabricplus.settings.impl.DebugSettings; @@ -36,10 +40,7 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; 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.Slice; +import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @SuppressWarnings("ConstantValue") @@ -167,14 +168,6 @@ public abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity } } - @Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isClimbing()Z")) - public boolean alwaysSendPacket(ClientPlayerEntity instance) { - if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_15_1)) { - return false; - } - return isClimbing(); - } - @Redirect(method = "autoJump", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;inverseSqrt(F)F")) public float useFastInverse(float x) { if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_3)) { @@ -194,10 +187,45 @@ public abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity return instance.hasVehicle(); } + @Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;checkFallFlying()Z")) + public boolean removeFallFlyingCheck(ClientPlayerEntity instance) { + // Elytra movement was serverside in <= 1.14.4 and got moved to the client in 1.15 + if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_4)) { + return !this.isOnGround() && this.getVelocity().y < 0.0 && !isFallFlying(); + } + return instance.checkFallFlying(); + } + + @Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isClimbing()Z")) + public boolean removeLadderCheck(ClientPlayerEntity instance) { + if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_15_1)) { + return false; + } + return instance.isClimbing(); + } + + @Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;hasVehicle()Z", ordinal = 3)) + public boolean removeVehicleCheck(ClientPlayerEntity instance) { + if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_4)) { + return false; + } + return instance.hasVehicle(); + } + + @ModifyVariable(method = "tickMovement", at = @At(value = "LOAD", ordinal = 4), ordinal = 4) + public boolean removeBl8Boolean(boolean value) { + if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_4)) { + return false; + } + return value; + } + @Override public boolean isCreative() { if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_7_6tor1_7_10)) { - if (client.interactionManager == null) return super.isCreative(); // Fixes https://github.com/ViaVersion/ViaFabricPlus/issues/216 + if (client.interactionManager == null) { + return super.isCreative(); // Fixes https://github.com/ViaVersion/ViaFabricPlus/issues/216 + } return client.interactionManager.getCurrentGameMode() == GameMode.CREATIVE; } return super.isCreative(); diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinLivingEntity.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinLivingEntity.java index f537545c..77b15c9b 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinLivingEntity.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinLivingEntity.java @@ -211,7 +211,7 @@ public abstract class MixinLivingEntity extends Entity { @Inject(method = "getRidingOffset", at = @At("HEAD"), cancellable = true) public void replaceRidingOffset(Entity vehicle, CallbackInfoReturnable cir) { if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) { - cir.setReturnValue((float) EntityHeightOffsetsPre1_20_2.getHeightOffset((Entity) (Object) this)); + cir.setReturnValue((float) EntityHeightOffsetsPre1_20_2.getHeightOffset(this)); } } 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 ebe8ee16..7f425d7b 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 @@ -34,7 +34,7 @@ public class MixinItem { @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)) { + if (instance instanceof CrossbowItem && ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_17_1)) { return 326; }