diff --git a/gradle.properties b/gradle.properties index 41f4dbf..73d5361 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ org.gradle.jvmargs = -Xmx1G minecraft_version = 1.16.2 curseforge_id = 401707 simple_minecraft_version = 1.16.2 - yarn_build = 1 + yarn_build = 12 fabric_loader_version = 0.9.0+build.204 # Mod Properties diff --git a/src/main/java/com/thebrokenrail/gestus/entity/FakePlayerEntity.java b/src/main/java/com/thebrokenrail/gestus/entity/FakePlayerEntity.java index f8e96af..350b71e 100644 --- a/src/main/java/com/thebrokenrail/gestus/entity/FakePlayerEntity.java +++ b/src/main/java/com/thebrokenrail/gestus/entity/FakePlayerEntity.java @@ -180,16 +180,16 @@ public class FakePlayerEntity extends ArmorStandEntity { if (emote != null) { layers[AIM_LAYER].play(emote, (hand == Hand.OFF_HAND) != isLeftHanded()); - return true; - } else { return false; + } else { + return true; } } private void updateAim() { Hand hand = player.getActiveHand(); - if (!updateAim(hand, true)) { - updateAim(hand == Hand.MAIN_HAND ? Hand.OFF_HAND : Hand.MAIN_HAND, false); + if (updateAim(hand, true) && updateAim(hand == Hand.MAIN_HAND ? Hand.OFF_HAND : Hand.MAIN_HAND, false)) { + layers[AIM_LAYER].play(null, false); } } diff --git a/src/main/java/com/thebrokenrail/gestus/mixin/EntityEquipmentUpdateS2CPacketAccessor.java b/src/main/java/com/thebrokenrail/gestus/mixin/EntityEquipmentUpdateS2CPacketAccessor.java new file mode 100644 index 0000000..7f4cf4d --- /dev/null +++ b/src/main/java/com/thebrokenrail/gestus/mixin/EntityEquipmentUpdateS2CPacketAccessor.java @@ -0,0 +1,24 @@ +package com.thebrokenrail.gestus.mixin; + +import com.mojang.datafixers.util.Pair; +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.network.packet.s2c.play.EntityEquipmentUpdateS2CPacket; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.List; + +@Mixin(EntityEquipmentUpdateS2CPacket.class) +public interface EntityEquipmentUpdateS2CPacketAccessor { + @Accessor + int getId(); + + @Accessor + List> getEquipmentList(); + + @Mutable + @Accessor + void setEquipmentList(List> equipmentList); +} diff --git a/src/main/java/com/thebrokenrail/gestus/mixin/MixinEntityTrackerEntry.java b/src/main/java/com/thebrokenrail/gestus/mixin/MixinEntityTrackerEntry.java deleted file mode 100644 index 6110ee6..0000000 --- a/src/main/java/com/thebrokenrail/gestus/mixin/MixinEntityTrackerEntry.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.thebrokenrail.gestus.mixin; - -import com.mojang.datafixers.util.Pair; -import com.thebrokenrail.gestus.util.Util; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.item.ItemStack; -import net.minecraft.server.network.EntityTrackerEntry; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArg; - -import java.util.List; - -@Mixin(EntityTrackerEntry.class) -public class MixinEntityTrackerEntry { - @Shadow - @Final - private Entity entity; - - @ModifyArg(at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/play/EntityEquipmentUpdateS2CPacket;(ILjava/util/List;)V"), method = "*", index = 1) - public List> modifyEquipment(List> list) { - return Util.modifyEquipment(entity, list); - } -} diff --git a/src/main/java/com/thebrokenrail/gestus/mixin/MixinLivingEntity.java b/src/main/java/com/thebrokenrail/gestus/mixin/MixinLivingEntity.java deleted file mode 100644 index f00fb6d..0000000 --- a/src/main/java/com/thebrokenrail/gestus/mixin/MixinLivingEntity.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.thebrokenrail.gestus.mixin; - -import com.mojang.datafixers.util.Pair; -import com.thebrokenrail.gestus.util.Util; -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.ItemStack; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArg; - -import java.util.List; - -@Mixin(LivingEntity.class) -public class MixinLivingEntity { - @ModifyArg(at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/play/EntityEquipmentUpdateS2CPacket;(ILjava/util/List;)V"), method = "*", index = 1) - public List> modifyEquipment(List> list) { - return Util.modifyEquipment((LivingEntity) (Object) this, list); - } -} diff --git a/src/main/java/com/thebrokenrail/gestus/mixin/MixinServerPlayNetworkHandler.java b/src/main/java/com/thebrokenrail/gestus/mixin/MixinServerPlayNetworkHandler.java index a2e9992..60dee27 100644 --- a/src/main/java/com/thebrokenrail/gestus/mixin/MixinServerPlayNetworkHandler.java +++ b/src/main/java/com/thebrokenrail/gestus/mixin/MixinServerPlayNetworkHandler.java @@ -5,7 +5,9 @@ import com.thebrokenrail.gestus.util.Util; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GenericFutureListener; import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.Packet; +import net.minecraft.network.packet.s2c.play.EntityEquipmentUpdateS2CPacket; import net.minecraft.network.packet.s2c.play.EntityTrackerUpdateS2CPacket; import net.minecraft.network.packet.s2c.play.MobSpawnS2CPacket; import net.minecraft.server.network.ServerPlayNetworkHandler; @@ -24,19 +26,25 @@ public class MixinServerPlayNetworkHandler { @Inject(at = @At("HEAD"), method = "sendPacket(Lnet/minecraft/network/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V", cancellable = true) public void sendPacket(Packet packet, GenericFutureListener> listener, CallbackInfo info) { - if (packet instanceof MobSpawnS2CPacket) { - MobSpawnS2CPacketAccessor packetData = (MobSpawnS2CPacketAccessor) packet; - Entity entity = player.getEntityWorld().getEntityById(packetData.getId()); - if (entity instanceof FakePlayerEntity && ((FakePlayerEntity) entity).player.getUuid().equals(player.getUuid())) { - info.cancel(); - } + if (packet == null) { + info.cancel(); } } @ModifyVariable(at = @At("HEAD"), method = "sendPacket(Lnet/minecraft/network/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V", argsOnly = true) public Packet modifyPacket(Packet packet) { - if (packet instanceof EntityTrackerUpdateS2CPacket && ((EntityTrackerUpdateS2CPacketAccessor) packet).getId() == player.getEntityId()) { + if (packet instanceof MobSpawnS2CPacket) { + MobSpawnS2CPacketAccessor packetData = (MobSpawnS2CPacketAccessor) packet; + Entity entity = player.getEntityWorld().getEntityById(packetData.getId()); + if (entity instanceof FakePlayerEntity && ((FakePlayerEntity) entity).player.getUuid().equals(player.getUuid())) { + return null; + } else { + return packet; + } + } else if (packet instanceof EntityTrackerUpdateS2CPacket && ((EntityTrackerUpdateS2CPacketAccessor) packet).getId() == player.getEntityId()) { return Util.modifyTracker(player, (EntityTrackerUpdateS2CPacket) packet); + } else if (packet instanceof EntityEquipmentUpdateS2CPacket && player.getEntityWorld().getEntityById(((EntityEquipmentUpdateS2CPacketAccessor) packet).getId()) instanceof PlayerEntity) { + return Util.modifyEquipment((EntityEquipmentUpdateS2CPacket) packet); } else { return packet; } diff --git a/src/main/java/com/thebrokenrail/gestus/mixin/MixinServerPlayerEntity.java b/src/main/java/com/thebrokenrail/gestus/mixin/MixinServerPlayerEntity.java index 9044e76..5d649e0 100644 --- a/src/main/java/com/thebrokenrail/gestus/mixin/MixinServerPlayerEntity.java +++ b/src/main/java/com/thebrokenrail/gestus/mixin/MixinServerPlayerEntity.java @@ -18,6 +18,8 @@ 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.Objects; + @Mixin(ServerPlayerEntity.class) public abstract class MixinServerPlayerEntity extends PlayerEntity implements ServerPlayerEntityExtension { @Unique @@ -50,7 +52,14 @@ public abstract class MixinServerPlayerEntity extends PlayerEntity implements Se shadow.refreshPositionAndAngles(getX(), getY(), getZ(), yaw, pitch); shadow.setHeadRotation(new EulerAngle(pitch, getHeadYaw() - yaw, 0f)); - shadow.setVelocity(getVelocity()); + + Vec3d olVVelocity = shadow.getVelocity(); + Vec3d velocity = getVelocity(); + if (!Objects.equals(olVVelocity, velocity)) { + shadow.setVelocity(velocity); + shadow.velocityDirty = true; + shadow.velocityModified = true; + } shadow.setCustomNameVisible(!invisible && !isSneaking()); diff --git a/src/main/java/com/thebrokenrail/gestus/util/Util.java b/src/main/java/com/thebrokenrail/gestus/util/Util.java index 06c91fa..c39ed65 100644 --- a/src/main/java/com/thebrokenrail/gestus/util/Util.java +++ b/src/main/java/com/thebrokenrail/gestus/util/Util.java @@ -2,30 +2,27 @@ package com.thebrokenrail.gestus.util; import com.mojang.datafixers.util.Pair; import com.thebrokenrail.gestus.mixin.EntityAccessor; +import com.thebrokenrail.gestus.mixin.EntityEquipmentUpdateS2CPacketAccessor; import com.thebrokenrail.gestus.mixin.EntityTrackerUpdateS2CPacketAccessor; -import net.minecraft.entity.Entity; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.network.packet.s2c.play.EntityEquipmentUpdateS2CPacket; import net.minecraft.network.packet.s2c.play.EntityTrackerUpdateS2CPacket; import java.util.ArrayList; import java.util.List; public class Util { - public static List> modifyEquipment(Entity entity, List> list) { - if (entity instanceof PlayerEntity) { - List> newList = new ArrayList<>(); - for (EquipmentSlot slot : EquipmentSlot.values()) { - newList.add(Pair.of(slot, ItemStack.EMPTY)); - } - return newList; - } else { - return list; + public static EntityEquipmentUpdateS2CPacket modifyEquipment(EntityEquipmentUpdateS2CPacket packet) { + List> newList = new ArrayList<>(); + for (EquipmentSlot slot : EquipmentSlot.values()) { + newList.add(Pair.of(slot, ItemStack.EMPTY)); } + return new EntityEquipmentUpdateS2CPacket(((EntityEquipmentUpdateS2CPacketAccessor) packet).getId(), newList); } private static final int INVISIBILITY_FLAG = 5; diff --git a/src/main/resources/gestus.mixins.json b/src/main/resources/gestus.mixins.json index 1e8d900..f8d6c05 100644 --- a/src/main/resources/gestus.mixins.json +++ b/src/main/resources/gestus.mixins.json @@ -6,9 +6,8 @@ "ArmorStandEntityAccessor", "DataTrackerAccessor", "EntityAccessor", + "EntityEquipmentUpdateS2CPacketAccessor", "EntityTrackerUpdateS2CPacketAccessor", - "MixinEntityTrackerEntry", - "MixinLivingEntity", "MixinMobSpawnS2CPacket", "MixinServerPlayerEntity", "MixinServerPlayNetworkHandler",