From 751090cdfdd243e547a2cb221efb43581204956f Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Sat, 13 Jan 2024 06:21:28 +0100 Subject: [PATCH] Updated Via* API usages --- .../MixinMetadataRewriter1_15To1_14_4.java | 20 +++++++++---------- .../MixinMetadataRewriter1_9To1_8.java | 9 +++------ .../mixin/viabedrock/MixinJoinPackets.java | 6 +++--- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinMetadataRewriter1_15To1_14_4.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinMetadataRewriter1_15To1_14_4.java index ccc4f25a..3865a423 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinMetadataRewriter1_15To1_14_4.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinMetadataRewriter1_15To1_14_4.java @@ -19,31 +19,29 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.viaversion; -import com.viaversion.viaversion.api.connection.UserConnection; -import com.viaversion.viaversion.api.minecraft.entities.EntityType; -import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.protocols.protocol1_14_4to1_14_3.ClientboundPackets1_14_4; import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4; import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.metadata.MetadataRewriter1_15To1_14_4; import com.viaversion.viaversion.rewriter.EntityRewriter; +import com.viaversion.viaversion.rewriter.meta.MetaFilter; import de.florianmichael.viafabricplus.fixes.tracker.WolfHealthTracker; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.Redirect; -import java.util.List; - -@Mixin(MetadataRewriter1_15To1_14_4.class) +@Mixin(value = MetadataRewriter1_15To1_14_4.class, remap = false) public abstract class MixinMetadataRewriter1_15To1_14_4 extends EntityRewriter { public MixinMetadataRewriter1_15To1_14_4(Protocol1_15To1_14_4 protocol) { super(protocol); } - @Inject(method = "handleMetadata", at = @At(value = "INVOKE", target = "Ljava/util/List;remove(Ljava/lang/Object;)Z", shift = At.Shift.BEFORE), remap = false) - private void trackHealth(int entityId, EntityType type, Metadata metadata, List metadatas, UserConnection connection, CallbackInfo ci) { - WolfHealthTracker.get(connection).setWolfHealth(entityId, metadata.value()); + @Redirect(method = "registerRewrites", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/rewriter/meta/MetaFilter$Builder;removeIndex(I)V")) + private void trackHealth(MetaFilter.Builder instance, int index) { + instance.index(18).handler((event, meta) -> { + WolfHealthTracker.get(event.user()).setWolfHealth(event.entityId(), meta.value()); + event.cancel(); + }); } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinMetadataRewriter1_9To1_8.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinMetadataRewriter1_9To1_8.java index 8e5e7b1a..543cb323 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinMetadataRewriter1_9To1_8.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/MixinMetadataRewriter1_9To1_8.java @@ -19,24 +19,21 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.viaversion; -import com.viaversion.viaversion.api.connection.UserConnection; -import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import com.viaversion.viaversion.protocols.protocol1_9to1_8.metadata.MetadataRewriter1_9To1_8; +import com.viaversion.viaversion.rewriter.meta.MetaHandlerEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.util.List; - @Mixin(value = MetadataRewriter1_9To1_8.class, remap = false) public abstract class MixinMetadataRewriter1_9To1_8 { @Inject(method = "handleMetadata", at = @At(value = "FIELD", target = "Lcom/viaversion/viaversion/protocols/protocol1_9to1_8/metadata/MetaIndex;PLAYER_HAND:Lcom/viaversion/viaversion/protocols/protocol1_9to1_8/metadata/MetaIndex;", ordinal = 0, shift = At.Shift.BEFORE), cancellable = true) - private void preventMetadataForClientPlayer(int entityId, EntityType type, Metadata metadata, List metadatas, UserConnection connection, CallbackInfo ci) { - if (connection.getEntityTracker(Protocol1_9To1_8.class).clientEntityId() == entityId) { + private void preventMetadataForClientPlayer(MetaHandlerEvent event, Metadata metadata, CallbackInfo ci) { + if (event.user().getEntityTracker(Protocol1_9To1_8.class).clientEntityId() == event.entityId()) { ci.cancel(); } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/viabedrock/MixinJoinPackets.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/viabedrock/MixinJoinPackets.java index 98f6cf3b..0b8939b4 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/viabedrock/MixinJoinPackets.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/viabedrock/MixinJoinPackets.java @@ -33,21 +33,21 @@ import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(value = JoinPackets.class, remap = false) public abstract class MixinJoinPackets { - @Redirect(method = "lambda$register$2", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/packet/PacketWrapper;read(Lcom/viaversion/viaversion/api/type/Type;)Ljava/lang/Object;", ordinal = 5)) + @Redirect(method = "lambda$register$8", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/packet/PacketWrapper;read(Lcom/viaversion/viaversion/api/type/Type;)Ljava/lang/Object;", ordinal = 5)) private static Object trackWorldSeed(PacketWrapper instance, Type tType) throws Exception { final Object seed = instance.read(tType); instance.user().get(JoinGameDataTracker.class).setSeed((long) seed); return seed; } - @Redirect(method = "lambda$register$2", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/packet/PacketWrapper;read(Lcom/viaversion/viaversion/api/type/Type;)Ljava/lang/Object;", ordinal = 55)) + @Redirect(method = "lambda$register$8", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/packet/PacketWrapper;read(Lcom/viaversion/viaversion/api/type/Type;)Ljava/lang/Object;", ordinal = 55)) private static Object trackLevelId(PacketWrapper instance, Type tType) throws Exception { final Object levelId = instance.read(tType); instance.user().get(JoinGameDataTracker.class).setLevelId((String) levelId); return levelId; } - @Redirect(method = "lambda$register$2", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/packet/PacketWrapper;read(Lcom/viaversion/viaversion/api/type/Type;)Ljava/lang/Object;", ordinal = 63)) + @Redirect(method = "lambda$register$8", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/packet/PacketWrapper;read(Lcom/viaversion/viaversion/api/type/Type;)Ljava/lang/Object;", ordinal = 63)) private static Object trackEnchantmentSeed(PacketWrapper instance, Type tType) throws Exception { final Object enchantmentSeed = instance.read(tType); instance.user().get(JoinGameDataTracker.class).setEnchantmentSeed((Integer) enchantmentSeed);