From 2f65f5b0c0c5cf3e65abef677d2a6545bfff5fdc Mon Sep 17 00:00:00 2001 From: Sollace Date: Mon, 19 Sep 2022 17:35:12 +0200 Subject: [PATCH] Fixed crash at startup due to bad mixins #59 --- .../unicopia/mixin/MixinReachDistanceFix.java | 26 ++++++------------- .../MixinServerPlayerInteractionManager.java | 26 ++++++++++++++++--- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinReachDistanceFix.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinReachDistanceFix.java index 01176cb6..d2014620 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinReachDistanceFix.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinReachDistanceFix.java @@ -5,34 +5,24 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.*; import com.minelittlepony.unicopia.entity.player.Pony; -import net.minecraft.network.packet.c2s.play.*; import net.minecraft.server.network.*; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -@Mixin(value = { - ServerPlayerInteractionManager.class, - ServerPlayNetworkHandler.class -}) +@Mixin(ServerPlayNetworkHandler.class) abstract class MixinReachDistanceFix { @Redirect( - target = { - @Desc(owner = ServerPlayerInteractionManager.class, value = "processBlockBreakingAction", args = { - BlockPos.class, PlayerActionC2SPacket.Action.class, Direction.class, int.class, int.class - }), - @Desc(owner = ServerPlayNetworkHandler.class, value = "onPlayerInteractBlock", args = { PlayerInteractBlockC2SPacket.class }), - @Desc(owner = ServerPlayNetworkHandler.class, value = "onPlayerInteractEntity", args = { PlayerInteractEntityC2SPacket.class }) + method = { + "onPlayerInteractBlock", + "onPlayerInteractEntity" }, at = @At( value = "FIELD", target = "net/minecraft/server/network/ServerPlayNetworkHandler.MAX_BREAK_SQUARED_DISTANCE:D", opcode = Opcodes.GETSTATIC - ) + ), + require = 0 ) - private double getMaxBreakSquaredDistance() { - Object o = this; - ServerPlayerEntity player = o instanceof ServerPlayNetworkHandler s ? s.getPlayer() : ((MixinServerPlayerInteractionManager)o).getPlayer(); - double reach = 6 + Pony.of(player).getExtendedReach(); + private double bgetMaxBreakSquaredDistance() { + double reach = 6 + Pony.of(((ServerPlayNetworkHandler)(Object)this).getPlayer()).getExtendedReach(); return reach * reach; } } diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinServerPlayerInteractionManager.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinServerPlayerInteractionManager.java index 95499335..47b98398 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinServerPlayerInteractionManager.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinServerPlayerInteractionManager.java @@ -1,13 +1,31 @@ package com.minelittlepony.unicopia.mixin; +import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.network.ServerPlayerInteractionManager; +import com.minelittlepony.unicopia.entity.player.Pony; + +import net.minecraft.server.network.*; @Mixin(ServerPlayerInteractionManager.class) -public interface MixinServerPlayerInteractionManager { +abstract class MixinServerPlayerInteractionManager { @Accessor - ServerPlayerEntity getPlayer(); + public abstract ServerPlayerEntity getPlayer(); + + @Redirect( + method = "processBlockBreakingAction", + at = @At( + value = "FIELD", + target = "net/minecraft/server/network/ServerPlayNetworkHandler.MAX_BREAK_SQUARED_DISTANCE:D", + opcode = Opcodes.GETSTATIC + ), + require = 0 + ) + private double bgetMaxBreakSquaredDistance() { + double reach = 6 + Pony.of(getPlayer()).getExtendedReach(); + return reach * reach; + } }