From 8bbc7fffdb0ba6407f46839bc93fb2f39a131b9f Mon Sep 17 00:00:00 2001 From: ishland Date: Wed, 9 Oct 2024 16:22:39 +0800 Subject: [PATCH] build: 1.21.2-pre1 --- gradle.properties | 4 +- .../access/IEntityPositionS2CPacket.java | 31 --- .../commands/MixinTeleportCommand.java | 193 ------------------ .../MixinServerWorld.java | 51 ----- src/main/resources/vmp.accesswidener | 1 - src/main/resources/vmp.mixins.json | 2 - 6 files changed, 2 insertions(+), 280 deletions(-) delete mode 100644 src/main/java/com/ishland/vmp/mixins/access/IEntityPositionS2CPacket.java delete mode 100644 src/main/java/com/ishland/vmp/mixins/chunk/loading/commands/MixinTeleportCommand.java diff --git a/gradle.properties b/gradle.properties index 78311d9..717eb2a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,8 +3,8 @@ org.gradle.jvmargs=-Xmx2G # Fabric Properties # check these on https://fabricmc.net/versions.html -minecraft_version=24w38a -yarn_mappings=24w38a+build.5 +minecraft_version=1.21.2-pre1 +yarn_mappings=1.21.2-pre1+build.3 loader_version=0.16.5 # Mod Properties diff --git a/src/main/java/com/ishland/vmp/mixins/access/IEntityPositionS2CPacket.java b/src/main/java/com/ishland/vmp/mixins/access/IEntityPositionS2CPacket.java deleted file mode 100644 index 9900839..0000000 --- a/src/main/java/com/ishland/vmp/mixins/access/IEntityPositionS2CPacket.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.ishland.vmp.mixins.access; - -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 IEntityPositionS2CPacket { - - @Accessor("x") - @Mutable - void setX(double x); - - @Accessor("y") - @Mutable - void setY(double y); - - @Accessor("z") - @Mutable - void setZ(double z); - - @Accessor("yaw") - @Mutable - void setYaw(byte yaw); - - @Accessor("pitch") - @Mutable - void setPitch(byte pitch); - -} diff --git a/src/main/java/com/ishland/vmp/mixins/chunk/loading/commands/MixinTeleportCommand.java b/src/main/java/com/ishland/vmp/mixins/chunk/loading/commands/MixinTeleportCommand.java deleted file mode 100644 index ee82b1a..0000000 --- a/src/main/java/com/ishland/vmp/mixins/chunk/loading/commands/MixinTeleportCommand.java +++ /dev/null @@ -1,193 +0,0 @@ -package com.ishland.vmp.mixins.chunk.loading.commands; - -import com.ishland.vmp.common.chunk.loading.async_chunks_on_player_login.AsyncChunkLoadUtil; -import com.ishland.vmp.mixins.access.IServerCommandSource; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.command.argument.PosArgument; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket; -import net.minecraft.network.packet.s2c.play.PositionFlag; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.command.CommandOutput; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.command.TeleportCommand; -import net.minecraft.server.rcon.RconCommandOutput; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.Text; -import net.minecraft.text.Texts; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.util.math.Vec2f; -import net.minecraft.util.math.Vec3d; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -import java.util.Collection; -import java.util.EnumSet; -import java.util.Set; - -@Mixin(TeleportCommand.class) -public abstract class MixinTeleportCommand { - - @Shadow - protected static String formatFloat(double d) { - throw new AbstractMethodError(); - } - - @Shadow - protected static void teleport(ServerCommandSource source, Entity target, ServerWorld world, double x, double y, double z, Set movementFlags, float yaw, float pitch, TeleportCommand.@Nullable LookTarget facingLocation) throws CommandSyntaxException { - } - - /** - * @author ishland - * @reason async teleport - */ - @Overwrite - private static int execute(ServerCommandSource source, Collection targets, Entity destination) { - final Runnable action = () -> { - int successCount = 0; - Entity last = null; - for (Entity entity : targets) { - if (!entity.isAlive()) continue; - try { - teleport( - source, - entity, - (ServerWorld) destination.getWorld(), - destination.getX(), - destination.getY(), - destination.getZ(), - EnumSet.noneOf(PositionFlag.class), - destination.getYaw(), - destination.getPitch(), - null - ); - successCount++; - last = entity; - } catch (CommandSyntaxException e) { - source.sendError(Texts.toText(e.getRawMessage())); - } catch (Throwable t) { - t.printStackTrace(); - source.sendError(Text.literal("Error occurred while teleporting entity")); - } - } - if (successCount == 1) { - Entity finalLast = last; - source.sendFeedback( - () -> Text.translatable("commands.teleport.success.entity.single", finalLast.getDisplayName(), destination.getDisplayName()), true - ); - } else { - int finalSuccessCount = successCount; - source.sendFeedback(() -> Text.translatable("commands.teleport.success.entity.multiple", finalSuccessCount, destination.getDisplayName()), true); - } - }; - - final CommandOutput output = ((IServerCommandSource) source).getOutput(); - if (output instanceof PlayerEntity || output instanceof MinecraftServer || output instanceof RconCommandOutput) { - AsyncChunkLoadUtil.scheduleChunkLoad((ServerWorld) destination.getWorld(), destination.getChunkPos()) - .thenRunAsync(action, destination.getServer()); - } else { - action.run(); - } - - return targets.size(); - } - - /** - * @author ishland - * @reason async teleport - */ - @Overwrite - private static int execute( - ServerCommandSource source, - Collection targets, - ServerWorld world, - PosArgument location, - @Nullable PosArgument rotation, - @Nullable TeleportCommand.LookTarget facingLocation - ) throws CommandSyntaxException { - Vec3d vec3d = location.getPos(source); - Vec2f vec2f = rotation == null ? null : rotation.getRotation(source); - Set set = EnumSet.noneOf(PositionFlag.class); - if (location.isXRelative()) { - set.add(PositionFlag.X); - } - - if (location.isYRelative()) { - set.add(PositionFlag.Y); - } - - if (location.isZRelative()) { - set.add(PositionFlag.Z); - } - - if (rotation == null) { - set.add(PositionFlag.X_ROT); - set.add(PositionFlag.Y_ROT); - } else { - if (rotation.isXRelative()) { - set.add(PositionFlag.X_ROT); - } - - if (rotation.isYRelative()) { - set.add(PositionFlag.Y_ROT); - } - } - - final Runnable action = () -> { - int successCount = 0; - Entity last = null; - - for (Entity entity : targets) { - if (!entity.isAlive()) continue; - try { - if (rotation == null) { - teleport(source, entity, world, vec3d.x, vec3d.y, vec3d.z, set, entity.getYaw(), entity.getPitch(), facingLocation); - } else { - teleport(source, entity, world, vec3d.x, vec3d.y, vec3d.z, set, vec2f.y, vec2f.x, facingLocation); - } - successCount++; - last = entity; - } catch (CommandSyntaxException e) { - source.sendError(Texts.toText(e.getRawMessage())); - } catch (Throwable t) { - t.printStackTrace(); - source.sendError(Text.literal("Error occurred while teleporting entity")); - } - } - - if (successCount == 1) { - Entity finalLast = last; - source.sendFeedback( - () -> Text.translatable( - "commands.teleport.success.location.single", - finalLast.getDisplayName(), - formatFloat(vec3d.x), - formatFloat(vec3d.y), - formatFloat(vec3d.z) - ), - true - ); - } else { - int finalSuccessCount = successCount; - source.sendFeedback( - () -> Text.translatable("commands.teleport.success.location.multiple", finalSuccessCount, formatFloat(vec3d.x), formatFloat(vec3d.y), formatFloat(vec3d.z)), true - ); - } - }; - - final CommandOutput output = ((IServerCommandSource) source).getOutput(); - if (output instanceof PlayerEntity || output instanceof MinecraftServer || output instanceof RconCommandOutput) { - AsyncChunkLoadUtil.scheduleChunkLoad(world, new ChunkPos(BlockPos.ofFloored(vec3d.x, vec3d.y, vec3d.z))) - .thenRunAsync(action, world.getServer()); - } else { - action.run(); - } - - return targets.size(); - } - -} diff --git a/src/main/java/com/ishland/vmp/mixins/playerwatching/optimize_nearby_player_lookups/MixinServerWorld.java b/src/main/java/com/ishland/vmp/mixins/playerwatching/optimize_nearby_player_lookups/MixinServerWorld.java index f5aeeb9..56ac164 100644 --- a/src/main/java/com/ishland/vmp/mixins/playerwatching/optimize_nearby_player_lookups/MixinServerWorld.java +++ b/src/main/java/com/ishland/vmp/mixins/playerwatching/optimize_nearby_player_lookups/MixinServerWorld.java @@ -2,7 +2,6 @@ import com.ishland.vmp.common.chunkwatching.AreaPlayerChunkWatchingManager; import com.ishland.vmp.common.playerwatching.TACSExtension; -import com.ishland.vmp.mixins.access.IThreadedAnvilChunkStorage; import io.papermc.paper.util.MCUtil; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; @@ -16,7 +15,6 @@ import net.minecraft.server.world.ServerChunkManager; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.ChunkSectionPos; -import net.minecraft.util.profiler.Profiler; import net.minecraft.world.MutableWorldProperties; import net.minecraft.world.StructureWorldAccess; import net.minecraft.world.World; @@ -25,9 +23,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import java.util.Set; import java.util.function.Predicate; -import java.util.function.Supplier; @Mixin(ServerWorld.class) public abstract class MixinServerWorld extends World implements StructureWorldAccess { @@ -68,53 +64,6 @@ public PlayerEntity getClosestPlayer(double x, double y, double z, double maxDis return nearestPlayer; } - @Nullable - @Override - public PlayerEntity getClosestPlayer(TargetPredicate targetPredicate, LivingEntity entity) { - return this.getClosestPlayer(targetPredicate, entity, entity.getX(), entity.getY(), entity.getZ()); - } - - @Nullable - @Override - public PlayerEntity getClosestPlayer(TargetPredicate targetPredicate, LivingEntity entity, double x, double y, double z) { - final Object[] playersWatchingChunkArray = getPlayersWatchingChunkArray(x, z); - - ServerPlayerEntity nearestPlayer = null; - double nearestDistance = Double.MAX_VALUE; - for (Object __player : playersWatchingChunkArray) { - if (__player instanceof ServerPlayerEntity player) { - if (targetPredicate == null || targetPredicate.test(entity, player)) { - final double distance = player.squaredDistanceTo(x, y, z); - if (distance < nearestDistance) { - nearestDistance = distance; - nearestPlayer = player; - } - } - } - } - - return nearestPlayer; - } - - private Object[] getPlayersWatchingChunkArray(double x, double z) { - final ServerChunkLoadingManager threadedAnvilChunkStorage = this.getChunkManager().chunkLoadingManager; - final AreaPlayerChunkWatchingManager playerChunkWatchingManager = ((TACSExtension) threadedAnvilChunkStorage).getAreaPlayerChunkWatchingManager(); - final int chunkX = ChunkSectionPos.getSectionCoord(x); - final int chunkZ = ChunkSectionPos.getSectionCoord(z); - - // no maxDistance here so just search within the range, - // and hopefully it works - - final Object[] playersWatchingChunkArray = playerChunkWatchingManager.getPlayersInGeneralAreaMap(MCUtil.getCoordinateKey(chunkX, chunkZ)); - return playersWatchingChunkArray; - } - - @Nullable - @Override - public PlayerEntity getClosestPlayer(TargetPredicate targetPredicate, double x, double y, double z) { - return this.getClosestPlayer(targetPredicate, null, x, y, z); - } - @Override public boolean isPlayerInRange(double x, double y, double z, double range) { final ServerChunkLoadingManager threadedAnvilChunkStorage = this.getChunkManager().chunkLoadingManager; diff --git a/src/main/resources/vmp.accesswidener b/src/main/resources/vmp.accesswidener index c3651fc..0f4e7f9 100644 --- a/src/main/resources/vmp.accesswidener +++ b/src/main/resources/vmp.accesswidener @@ -7,7 +7,6 @@ accessible class net/minecraft/server/world/ServerChunkLoadingManager$Enti accessible class net/minecraft/server/world/ServerChunkLoadingManager$TicketManager accessible class net/minecraft/world/SpawnDensityCapper$DensityCap accessible class net/minecraft/server/command/SpreadPlayersCommand$Pile -accessible class net/minecraft/server/command/TeleportCommand$LookTarget extendable class net/minecraft/server/world/ChunkTicket extendable class net/minecraft/server/world/PlayerChunkWatchingManager diff --git a/src/main/resources/vmp.mixins.json b/src/main/resources/vmp.mixins.json index 59efa30..507dc8e 100644 --- a/src/main/resources/vmp.mixins.json +++ b/src/main/resources/vmp.mixins.json @@ -10,7 +10,6 @@ "access.IChunkHolder", "access.IChunkTicket", "access.IClientConnection", - "access.IEntityPositionS2CPacket", "access.IEntityTrackerEntry", "access.IPointOfInterestSet", "access.IServerChunkManager", @@ -25,7 +24,6 @@ "chunk.loading.MixinPointOfInterestStorage", "chunk.loading.commands.MixinCommandFunctionManager", "chunk.loading.commands.MixinSpreadPlayersCommand", - "chunk.loading.commands.MixinTeleportCommand", "chunk.ticking.MixinServerWorld", "entity.move_zero_velocity.MixinEntity", "entitytracker.MixinThreadedAnvilChunkStorage",