From c03f521c8a3e24e1055237e6d79b88226af11d22 Mon Sep 17 00:00:00 2001 From: Patbox Date: Thu, 5 Dec 2024 23:39:05 +0100 Subject: [PATCH] Update to 1.21.4 --- .github/workflows/build.yml | 11 +-- .github/workflows/release.yml | 4 +- build.gradle | 7 +- gradle.properties | 10 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../disguiselib/impl/DisguiseCommand.java | 8 +- .../impl/mixin/EntityMixin_Disguise.java | 42 +++++---- ...erCommonNetworkHandlerMixin_Disguiser.java | 6 +- ...rverPlayNetworkHandlerMixin_Disguiser.java | 35 +++---- .../EntityPositionS2CPacketAccessor.java | 13 --- .../EntitySetHeadYawS2CPacketAccessor.java | 2 +- .../EntitySpawnS2CPacketAccessor.java | 4 +- .../accessor/EntityTrackerEntryAccessor.java | 2 +- ...=> ServerChunkLoadingManagerAccessor.java} | 7 +- .../impl/packets/ExtendedHandler.java | 2 +- .../disguiselib/impl/packets/FakePackets.java | 92 ++++--------------- src/main/resources/disguiselib.mixins.json | 3 +- 17 files changed, 92 insertions(+), 158 deletions(-) delete mode 100644 src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/EntityPositionS2CPacketAccessor.java rename src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/{ThreadedAnvilChunkStorageAccessor.java => ServerChunkLoadingManagerAccessor.java} (60%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index aabc5b7..0240dc1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,12 +8,7 @@ on: [pull_request, push] jobs: build: - strategy: - matrix: - # Use these Java versions - java: [17] - os: [ubuntu-20.04] - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest steps: - name: checkout repository uses: actions/checkout@v2 @@ -22,14 +17,14 @@ jobs: - name: setup jdk ${{ matrix.java }} uses: actions/setup-java@v1 with: - java-version: ${{ matrix.java }} + java-version: 21 - name: make gradle wrapper executable if: ${{ runner.os != 'Windows' }} run: chmod +x ./gradlew - name: build run: ./gradlew build - name: capture build artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: Artifacts path: build/libs/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6830604..c474aeb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -25,7 +25,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v1 with: - java-version: 17 + java-version: 21 - name: Grant execute permission for gradlew run: chmod +x gradlew @@ -38,7 +38,7 @@ jobs: MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} - name: Upload GitHub release - uses: AButler/upload-release-assets@v2.0 + uses: AButler/upload-release-assets@v3.0 with: files: 'build/libs/*.jar' repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/build.gradle b/build.gradle index d4af0ac..8dfba0b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,12 @@ plugins { id "java" id "maven-publish" - id 'fabric-loom' version '1.4.+' + id 'fabric-loom' version '1.7.+' } apply plugin: 'fabric-loom' -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 +sourceCompatibility = JavaVersion.VERSION_21 +targetCompatibility = JavaVersion.VERSION_21 archivesBaseName = rootProject.archives_base_name version = rootProject.mod_version @@ -25,7 +25,6 @@ tasks.withType(JavaCompile).configureEach { // If Javadoc is generated, this must be specified in that task too. it.options.encoding = "UTF-8" - it.options.release = 17 } processResources { diff --git a/gradle.properties b/gradle.properties index 6b68731..c42d673 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,12 +1,12 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx2G # Fabric Properties -minecraft_version=1.20.4 -yarn_mappings=1.20.4+build.1 -loader_version=0.15.3 +minecraft_version=1.21.4 +yarn_mappings=1.21.4+build.1 +loader_version=0.16.9 #Fabric api -fabric_version=0.91.1+1.20.4 +fabric_version=0.110.2+1.21.4 # Mod Properties -mod_version=1.3.5 +mod_version=1.3.6 maven_group=xyz.nucleoid archives_base_name = disguiselib \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e411586..19cfad9 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/xyz/nucleoid/disguiselib/impl/DisguiseCommand.java b/src/main/java/xyz/nucleoid/disguiselib/impl/DisguiseCommand.java index e088bbc..300fe02 100644 --- a/src/main/java/xyz/nucleoid/disguiselib/impl/DisguiseCommand.java +++ b/src/main/java/xyz/nucleoid/disguiselib/impl/DisguiseCommand.java @@ -10,8 +10,10 @@ import net.minecraft.command.argument.EntityArgumentType; import net.minecraft.command.argument.NbtCompoundArgumentType; import net.minecraft.command.argument.RegistryEntryArgumentType; +import net.minecraft.command.argument.RegistryEntryReferenceArgumentType; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; +import net.minecraft.entity.SpawnReason; import net.minecraft.nbt.NbtCompound; import net.minecraft.registry.Registries; import net.minecraft.registry.RegistryKeys; @@ -41,7 +43,7 @@ public static void register(CommandDispatcher dispatcher, C .requires(src -> src.hasPermissionLevel(2)) .then(argument("target", entities()) .then(literal("as") - .then(argument("disguise", RegistryEntryArgumentType.registryEntry(commandRegistryAccess, RegistryKeys.ENTITY_TYPE)) + .then(argument("disguise", new RegistryEntryReferenceArgumentType<>(commandRegistryAccess, RegistryKeys.ENTITY_TYPE)) .suggests(SUMMONABLE_ENTITIES) .executes(DisguiseCommand::setDisguise) .then(argument("nbt", NbtCompoundArgumentType.nbtCompound()) @@ -130,7 +132,7 @@ private static int clearDisguise(CommandContext ctx) throws private static int setDisguise(CommandContext ctx) throws CommandSyntaxException { Collection entities = EntityArgumentType.getEntities(ctx, "target"); ServerCommandSource src = ctx.getSource(); - var type = RegistryEntryArgumentType.getRegistryEntry(ctx, "disguise", RegistryKeys.ENTITY_TYPE); + var type = RegistryEntryReferenceArgumentType.getRegistryEntry(ctx, "disguise", RegistryKeys.ENTITY_TYPE); var disguise = Registries.ENTITY_TYPE.getId(type.value()); NbtCompound nbt; @@ -142,7 +144,7 @@ private static int setDisguise(CommandContext ctx) throws C nbt.putString("id", disguise.toString()); NbtCompound finalNbt = nbt; - entities.forEach(entity -> EntityType.loadEntityWithPassengers(finalNbt, ctx.getSource().getWorld(), (entityx) -> { + entities.forEach(entity -> EntityType.loadEntityWithPassengers(finalNbt, ctx.getSource().getWorld(), SpawnReason.LOAD, (entityx) -> { if(entity == src.getEntity()) { if(src.hasPermissionLevel(2)) ((EntityDisguise) entity).disguiseAs(entityx); diff --git a/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/EntityMixin_Disguise.java b/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/EntityMixin_Disguise.java index 11fd006..0ed93e2 100644 --- a/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/EntityMixin_Disguise.java +++ b/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/EntityMixin_Disguise.java @@ -9,6 +9,7 @@ import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerPosition; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; import net.minecraft.network.packet.c2s.common.SyncedClientOptions; @@ -19,13 +20,12 @@ import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerChunkManager; import net.minecraft.server.world.ServerWorld; -import net.minecraft.server.world.ThreadedAnvilChunkStorage; +import net.minecraft.server.world.ServerChunkLoadingManager; import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import net.minecraft.world.World; -import net.minecraft.world.biome.source.BiomeAccess; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; @@ -38,7 +38,7 @@ import xyz.nucleoid.disguiselib.api.DisguiseUtils; import xyz.nucleoid.disguiselib.api.EntityDisguise; import xyz.nucleoid.disguiselib.impl.mixin.accessor.EntityTrackerEntryAccessor; -import xyz.nucleoid.disguiselib.impl.mixin.accessor.ThreadedAnvilChunkStorageAccessor; +import xyz.nucleoid.disguiselib.impl.mixin.accessor.ServerChunkLoadingManagerAccessor; import java.util.*; import java.util.stream.Collectors; @@ -115,6 +115,8 @@ public abstract class EntityMixin_Disguise implements EntityDisguise, DisguiseUt @Shadow protected abstract void addPassenger(Entity passenger); + @Shadow private boolean onGround; + /** * Tells you the disguised status. * @@ -147,7 +149,7 @@ public void disguiseAs(EntityType entityType) { } else { // Why null check? Well, if entity was disguised via EntityDisguise#disguiseAs(Entity), this field is already set if (this.disguiselib$disguiseEntity == null || this.disguiselib$disguiseEntity.getType() != entityType) - this.disguiselib$disguiseEntity = entityType.create(world); + this.disguiselib$disguiseEntity = entityType.create(world, SpawnReason.LOAD); if (this.disguiselib$profile != null) { // Previous type was player, we have to send a player remove packet @@ -169,13 +171,13 @@ public void disguiseAs(EntityType entityType) { // Minor datatracker thingies this.updateTrackedData(); - // Updating entity on the client - manager.sendToDimension(new EntitiesDestroyS2CPacket(this.id), worldRegistryKey); - manager.sendToDimension(new EntitySpawnS2CPacket(this.disguiselib$entity), worldRegistryKey); // will be replaced by network handler + //noinspection ReferenceToMixin + var tracker = ((ServerChunkLoadingManagerAccessor) ((ServerWorld) this.world).getChunkManager().chunkLoadingManager).getEntityTrackers().get(this.getId()); - manager.sendToDimension(new EntityTrackerUpdateS2CPacket(this.id, this.getDataTracker().getChangedEntries()), worldRegistryKey); - manager.sendToDimension(new EntityEquipmentUpdateS2CPacket(this.id, this.disguiselib$getEquipment()), worldRegistryKey); // Reload equipment - manager.sendToDimension(new EntitySetHeadYawS2CPacket(this.disguiselib$entity, (byte) ((int) (this.getHeadYaw() * 256.0F / 360.0F))), worldRegistryKey); // Head correction + for (var listener : tracker.getListeners()) { + tracker.getEntry().stopTracking(listener.getPlayer()); + tracker.getEntry().startTracking(listener.getPlayer()); + } } /** @@ -364,8 +366,8 @@ public void setGameProfile(@Nullable GameProfile gameProfile) { playerManager.sendToAll(addPacket); ServerChunkManager manager = (ServerChunkManager) this.world.getChunkManager(); - ThreadedAnvilChunkStorage storage = manager.threadedAnvilChunkStorage; - EntityTrackerEntryAccessor trackerEntry = ((ThreadedAnvilChunkStorageAccessor) storage).getEntityTrackers().get(this.getId()); + var storage = manager.chunkLoadingManager; + EntityTrackerEntryAccessor trackerEntry = ((ServerChunkLoadingManagerAccessor) storage).getEntityTrackers().get(this.getId()); if (trackerEntry != null) trackerEntry.getListeners().forEach(tracking -> trackerEntry.getEntry().startTracking(tracking.getPlayer())); @@ -382,7 +384,7 @@ public void setGameProfile(@Nullable GameProfile gameProfile) { player.networkHandler.sendPacket(new HealthUpdateS2CPacket(player.getHealth(), player.getHungerManager().getFoodLevel(), player.getHungerManager().getSaturationLevel())); for (StatusEffectInstance statusEffect : player.getStatusEffects()) { - player.networkHandler.sendPacket(new EntityStatusEffectS2CPacket(player.getId(), statusEffect)); + player.networkHandler.sendPacket(new EntityStatusEffectS2CPacket(player.getId(), statusEffect, false)); } player.sendAbilitiesUpdate(); @@ -423,7 +425,15 @@ private void postTick(CallbackInfo ci) { // more than once per second -> movement isn't as "blocky" if(this.isDisguised()) { if(this.world.getServer() != null && !(this.disguiselib$disguiseEntity instanceof LivingEntity) && !(this.disguiselib$entity instanceof PlayerEntity)) - this.world.getServer().getPlayerManager().sendToDimension(new EntityPositionS2CPacket(this.disguiselib$entity), this.world.getRegistryKey()); + this.world.getServer().getPlayerManager().sendToDimension( + new EntityPositionS2CPacket( + this.disguiselib$entity.getId(), + new PlayerPosition( + this.disguiselib$entity.getSyncedPos(), + this.disguiselib$entity.getVelocity(), + this.disguiselib$entity.getYaw(), + this.disguiselib$entity.getPitch() + ), Set.of(), this.onGround), this.world.getRegistryKey()); else if(this.disguiselib$entity instanceof ServerPlayerEntity && ++this.disguiselib$ticks % 40 == 0 && this.disguiselib$disguiseEntity != null) { // "Disguised as" message MutableText msg = Text.literal("You are disguised as ") @@ -468,7 +478,7 @@ private void fromTag(NbtCompound tag, CallbackInfo ci) { NbtCompound disguiseTag = (NbtCompound) tag.get("DisguiseLib"); if(disguiseTag != null) { - Identifier disguiseTypeId = new Identifier(disguiseTag.getString("DisguiseType")); + Identifier disguiseTypeId = Identifier.tryParse(disguiseTag.getString("DisguiseType")); this.disguiselib$disguiseType = Registries.ENTITY_TYPE.get(disguiseTypeId); if(this.disguiselib$disguiseType == PLAYER) { @@ -477,7 +487,7 @@ private void fromTag(NbtCompound tag, CallbackInfo ci) { } else { NbtCompound disguiseEntityTag = disguiseTag.getCompound("DisguiseEntity"); if(!disguiseEntityTag.isEmpty()) - this.disguiselib$disguiseEntity = EntityType.loadEntityWithPassengers(disguiseEntityTag, this.world, (entityx) -> entityx); + this.disguiselib$disguiseEntity = EntityType.loadEntityWithPassengers(disguiseEntityTag, this.world, SpawnReason.LOAD, (entityx) -> entityx); } } } diff --git a/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/ServerCommonNetworkHandlerMixin_Disguiser.java b/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/ServerCommonNetworkHandlerMixin_Disguiser.java index e063282..186c899 100644 --- a/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/ServerCommonNetworkHandlerMixin_Disguiser.java +++ b/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/ServerCommonNetworkHandlerMixin_Disguiser.java @@ -66,9 +66,9 @@ private void disguiseEntity(Packet packet, PacketCallb return; } if (packet instanceof BundleS2CPacket bundleS2CPacket) { - if (bundleS2CPacket.getPackets() instanceof ArrayList> list) { - var list2 = new ArrayList>(); - var adder = new ArrayList>(); + if (bundleS2CPacket.getPackets() instanceof ArrayList> list) { + var list2 = new ArrayList>(); + var adder = new ArrayList>(); var atomic = new AtomicBoolean(true); for (var packet2 : list) { atomic.set(true); diff --git a/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/ServerPlayNetworkHandlerMixin_Disguiser.java b/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/ServerPlayNetworkHandlerMixin_Disguiser.java index dcf84de..94bc962 100644 --- a/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/ServerPlayNetworkHandlerMixin_Disguiser.java +++ b/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/ServerPlayNetworkHandlerMixin_Disguiser.java @@ -5,16 +5,16 @@ import net.minecraft.entity.EntityType; import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerPosition; import net.minecraft.network.ClientConnection; import net.minecraft.network.listener.ClientPlayPacketListener; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; import net.minecraft.network.packet.s2c.play.*; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.network.ConnectedClientData; -import net.minecraft.server.network.ServerCommonNetworkHandler; -import net.minecraft.server.network.ServerPlayNetworkHandler; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.network.*; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -48,11 +48,14 @@ public ServerPlayNetworkHandlerMixin_Disguiser(MinecraftServer server, ClientCon super(server, connection, clientData); } - public void disguiselib$transformPacket(Packet packet, Runnable remove, Consumer> add) { + public void disguiselib$transformPacket(Packet packet, Runnable remove, Consumer> add) { World world = this.player.getEntityWorld(); - Entity entity = null; if (packet instanceof EntitySpawnS2CPacket) { - entity = world.getEntityById(((EntitySpawnS2CPacketAccessor) packet).getEntityId()); + var entity = world.getEntityById(((EntitySpawnS2CPacketAccessor) packet).getEntityId()); + + if(entity != null) { + disguiselib$sendFakePacket(entity, remove, add); + } } else if (packet instanceof EntitiesDestroyS2CPacket && !((EntitiesDestroyS2CPacketAccessor) packet).getEntityIds().isEmpty() && ((EntitiesDestroyS2CPacketAccessor) packet).getEntityIds().getInt(0) == this.player.getId()) { remove.run(); return; @@ -99,7 +102,7 @@ public ServerPlayNetworkHandlerMixin_Disguiser(MinecraftServer server, ClientCon return; } } else if(packet instanceof EntityVelocityUpdateS2CPacket velocityPacket) { - int id = velocityPacket.getId(); + int id = velocityPacket.getEntityId(); if(id != this.player.getId()) { Entity entity1 = world.getEntityById(id); @@ -109,10 +112,6 @@ public ServerPlayNetworkHandlerMixin_Disguiser(MinecraftServer server, ClientCon } } } - - if(entity != null) { - disguiselib$sendFakePacket(entity, remove, add); - } } /** @@ -125,12 +124,16 @@ public ServerPlayNetworkHandlerMixin_Disguiser(MinecraftServer server, ClientCon EntityDisguise disguise = (EntityDisguise) entity; GameProfile profile = disguise.getGameProfile(); Entity disguiseEntity = disguise.getDisguiseEntity(); + if (disguiseEntity == null) { + return; + } Packet spawnPacket; + var entry = new EntityTrackerEntry((ServerWorld) entity.getWorld(), entity, 1, true, (c) -> {}); if(((EntityDisguise) this.player).hasTrueSight() || !disguise.isDisguised()) - spawnPacket = entity.createSpawnPacket(); + spawnPacket = entity.createSpawnPacket(entry); else - spawnPacket = FakePackets.universalSpawnPacket(entity); + spawnPacket = FakePackets.universalSpawnPacket(entity, entry, entity.getId() != this.player.getId()); if (disguise.getDisguiseType() == EntityType.PLAYER) { PlayerListS2CPacket packet = new PlayerListS2CPacket(PlayerListS2CPacket.Action.ADD_PLAYER, (ServerPlayerEntity) disguiseEntity); @@ -182,11 +185,9 @@ public ServerPlayNetworkHandlerMixin_Disguiser(MinecraftServer server, ClientCon private void disguiselib$moveDisguiseEntity(PlayerMoveC2SPacket packet, CallbackInfo ci) { if(((EntityDisguise) this.player).isDisguised() && ((EntityDisguise) this.player).getDisguiseType() != EntityType.PLAYER) { // Moving disguise for the disguised player - EntityPositionS2CPacket s2CPacket = new EntityPositionS2CPacket(this.player); + EntityPositionS2CPacket s2CPacket = new EntityPositionS2CPacket(((EntityDisguise) this.player).getDisguiseEntity().getId(), new PlayerPosition(player.getSyncedPos(), Vec3d.ZERO, player.getYaw(), player.getPitch()), Set.of(), false); EntitySetHeadYawS2CPacket headYawS2CPacket = new EntitySetHeadYawS2CPacket(this.player, (byte)((int)(this.player.getHeadYaw() * 256.0F / 360.0F))); - //noinspection ConstantConditions - ((EntityPositionS2CPacketAccessor) s2CPacket).setEntityId(((EntityDisguise) this.player).getDisguiseEntity().getId()); //noinspection ConstantConditions ((EntitySetHeadYawS2CPacketAccessor) headYawS2CPacket).setEntityId(((EntityDisguise) this.player).getDisguiseEntity().getId()); this.sendPacket(s2CPacket); diff --git a/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/EntityPositionS2CPacketAccessor.java b/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/EntityPositionS2CPacketAccessor.java deleted file mode 100644 index 328958e..0000000 --- a/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/EntityPositionS2CPacketAccessor.java +++ /dev/null @@ -1,13 +0,0 @@ -package xyz.nucleoid.disguiselib.impl.mixin.accessor; - -import net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(EntityPositionS2CPacket.class) -public interface EntityPositionS2CPacketAccessor { - @Mutable - @Accessor("id") - void setEntityId(int id); -} diff --git a/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/EntitySetHeadYawS2CPacketAccessor.java b/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/EntitySetHeadYawS2CPacketAccessor.java index 8f41e1d..7b5a0b6 100644 --- a/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/EntitySetHeadYawS2CPacketAccessor.java +++ b/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/EntitySetHeadYawS2CPacketAccessor.java @@ -8,6 +8,6 @@ @Mixin(EntitySetHeadYawS2CPacket.class) public interface EntitySetHeadYawS2CPacketAccessor { @Mutable - @Accessor("entity") + @Accessor("entityId") void setEntityId(int id); } diff --git a/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/EntitySpawnS2CPacketAccessor.java b/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/EntitySpawnS2CPacketAccessor.java index b76d867..31cab7e 100644 --- a/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/EntitySpawnS2CPacketAccessor.java +++ b/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/EntitySpawnS2CPacketAccessor.java @@ -17,11 +17,11 @@ public interface EntitySpawnS2CPacketAccessor { @Accessor("entityData") void setEntityData(int entityData); - @Accessor("id") + @Accessor("entityId") int getEntityId(); @Mutable - @Accessor("id") + @Accessor("entityId") void setEntityId(int id); @Mutable diff --git a/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/EntityTrackerEntryAccessor.java b/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/EntityTrackerEntryAccessor.java index e7be2ba..8cec789 100644 --- a/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/EntityTrackerEntryAccessor.java +++ b/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/EntityTrackerEntryAccessor.java @@ -7,7 +7,7 @@ import java.util.Set; -@Mixin(targets = "net.minecraft.server.world.ThreadedAnvilChunkStorage$EntityTracker") +@Mixin(targets = "net.minecraft.server.world.ServerChunkLoadingManager$EntityTracker") public interface EntityTrackerEntryAccessor { @Accessor("entry") EntityTrackerEntry getEntry(); diff --git a/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/ThreadedAnvilChunkStorageAccessor.java b/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/ServerChunkLoadingManagerAccessor.java similarity index 60% rename from src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/ThreadedAnvilChunkStorageAccessor.java rename to src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/ServerChunkLoadingManagerAccessor.java index ab6fcaf..ec6cbac 100644 --- a/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/ThreadedAnvilChunkStorageAccessor.java +++ b/src/main/java/xyz/nucleoid/disguiselib/impl/mixin/accessor/ServerChunkLoadingManagerAccessor.java @@ -1,12 +1,13 @@ package xyz.nucleoid.disguiselib.impl.mixin.accessor; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import net.minecraft.server.world.ThreadedAnvilChunkStorage; +import net.minecraft.server.world.ServerChunkLoadingManager; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; -@Mixin(ThreadedAnvilChunkStorage.class) -public interface ThreadedAnvilChunkStorageAccessor { +@Mixin(ServerChunkLoadingManager.class) +public interface ServerChunkLoadingManagerAccessor { + @SuppressWarnings("ReferenceToMixin") @Accessor("entityTrackers") Int2ObjectMap getEntityTrackers(); } diff --git a/src/main/java/xyz/nucleoid/disguiselib/impl/packets/ExtendedHandler.java b/src/main/java/xyz/nucleoid/disguiselib/impl/packets/ExtendedHandler.java index e51bc40..26da903 100644 --- a/src/main/java/xyz/nucleoid/disguiselib/impl/packets/ExtendedHandler.java +++ b/src/main/java/xyz/nucleoid/disguiselib/impl/packets/ExtendedHandler.java @@ -6,6 +6,6 @@ import java.util.function.Consumer; public interface ExtendedHandler { - void disguiselib$transformPacket(Packet packet, Runnable remove, Consumer> add); + void disguiselib$transformPacket(Packet packet, Runnable remove, Consumer> add); void disguiselib$onClientBrand(); } diff --git a/src/main/java/xyz/nucleoid/disguiselib/impl/packets/FakePackets.java b/src/main/java/xyz/nucleoid/disguiselib/impl/packets/FakePackets.java index 193ffe8..9400f8a 100644 --- a/src/main/java/xyz/nucleoid/disguiselib/impl/packets/FakePackets.java +++ b/src/main/java/xyz/nucleoid/disguiselib/impl/packets/FakePackets.java @@ -1,16 +1,9 @@ package xyz.nucleoid.disguiselib.impl.packets; -import net.minecraft.block.Block; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.FallingBlockEntity; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.packet.Packet; -import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.Vec3d; +import net.minecraft.server.network.EntityTrackerEntry; import xyz.nucleoid.disguiselib.api.EntityDisguise; -import xyz.nucleoid.disguiselib.impl.mixin.accessor.EntitySpawnS2CPacketAccessor; public class FakePackets { /** @@ -18,9 +11,11 @@ public class FakePackets { * Make sure entity is disguised, otherwise packet will stay the same. * * @param entity entity that requires fake spawn packet + * @param entry + * @param b * @return fake entity spawn packet (Either player) */ - public static Packet universalSpawnPacket(Entity entity) { + public static Packet universalSpawnPacket(Entity entity, EntityTrackerEntry entry, boolean replace) { // fixme - disguising non-living kicks you (just upon disguise) Entity disguise = ((EntityDisguise) entity).getDisguiseEntity(); if(disguise == null) { @@ -28,75 +23,20 @@ public static Packet universalSpawnPacket(Entity entity) { } try { - Packet packet = disguise.createSpawnPacket(); - - if(packet instanceof EntitySpawnS2CPacket) { - packet = fakeMobSpawnS2CPacket(entity); + if (replace) { + var x = disguise.getId(); + var y = disguise.getUuid(); + disguise.setId(entity.getId()); + disguise.setUuid(entity.getUuid()); + Packet packet = disguise.createSpawnPacket(entry); + disguise.setId(x); + disguise.setUuid(y); + return packet; + } else { + return disguise.createSpawnPacket(entry); } - - return packet; } catch (Throwable e) { - return entity.createSpawnPacket(); - } - } - - /** - * Constructs a fake {@link EntitySpawnS2CPacket} for the given entity. - * - * @param entity entity that requires fake packet - * - * @return fake {@link EntitySpawnS2CPacket} - */ - public static EntitySpawnS2CPacket fakeMobSpawnS2CPacket(Entity entity) { - EntityDisguise disguise = (EntityDisguise) entity; - EntitySpawnS2CPacket packet = new EntitySpawnS2CPacket(disguise.getDisguiseEntity()); - - EntitySpawnS2CPacketAccessor accessor = (EntitySpawnS2CPacketAccessor) packet; - accessor.setEntityId(entity.getId()); - accessor.setUuid(entity.getUuid()); - - var type = disguise.getDisguiseType(); - - accessor.setEntityType(type != EntityType.MARKER ? type : EntityType.PIG); - accessor.setX(entity.getX()); - accessor.setY(entity.getY()); - accessor.setZ(entity.getZ()); - - accessor.setYaw((byte) ((int) (entity.getY() * 256.0F / 360.0F))); - accessor.setHeadYaw((byte) ((int) (entity.getHeadYaw() * 256.0F / 360.0F))); - accessor.setPitch((byte) ((int) (entity.getPitch() * 256.0F / 360.0F))); - - double max = 3.9D; - Vec3d vec3d = entity.getVelocity(); - double e = MathHelper.clamp(vec3d.x, -max, max); - double f = MathHelper.clamp(vec3d.y, -max, max); - double g = MathHelper.clamp(vec3d.z, -max, max); - accessor.setVelocityX((int) (e * 8000.0D)); - accessor.setVelocityY((int) (f * 8000.0D)); - accessor.setVelocityZ((int) (g * 8000.0D)); - - return packet; - } - - /** - * Constructs a fake {@link EntitySpawnS2CPacket} for the given entity. - * - * @param entity entity that requires fake packet - * - * @return fake {@link EntitySpawnS2CPacket} - */ - public static EntitySpawnS2CPacket fakeEntitySpawnS2CPacket(Entity entity) { - EntitySpawnS2CPacket packet = new EntitySpawnS2CPacket(entity); - EntityDisguise fake = (EntityDisguise) entity; - ((EntitySpawnS2CPacketAccessor) packet).setEntityType(fake.getDisguiseType()); - if(fake.getDisguiseType() == EntityType.FALLING_BLOCK && fake.getDisguiseEntity() instanceof FallingBlockEntity) { - ((EntitySpawnS2CPacketAccessor) packet).setEntityData( - Block.getRawIdFromState( - ((FallingBlockEntity) fake.getDisguiseEntity()).getBlockState() - ) - ); + return entity.createSpawnPacket(entry); } - - return packet; } } diff --git a/src/main/resources/disguiselib.mixins.json b/src/main/resources/disguiselib.mixins.json index cce9495..58f7d92 100644 --- a/src/main/resources/disguiselib.mixins.json +++ b/src/main/resources/disguiselib.mixins.json @@ -11,14 +11,13 @@ "accessor.EntitiesDestroyS2CPacketAccessor", "accessor.EntityAccessor", "accessor.EntityAttributesS2CPacketAccessor", - "accessor.EntityPositionS2CPacketAccessor", "accessor.EntitySetHeadYawS2CPacketAccessor", "accessor.EntitySpawnS2CPacketAccessor", "accessor.EntityTrackerEntryAccessor", "accessor.EntityTrackerUpdateS2CPacketAccessor", "accessor.PlayerEntityAccessor", "accessor.PlayerListS2CPacketAccessor", - "accessor.ThreadedAnvilChunkStorageAccessor" + "accessor.ServerChunkLoadingManagerAccessor" ], "injectors": { "defaultRequire": 1