From 4f4ced2b5e713da4b89642d9be94341baa3eab3c Mon Sep 17 00:00:00 2001 From: Peter Svensson Date: Tue, 11 Jun 2024 07:42:36 +0200 Subject: [PATCH] Port to 1.21-pre4 Update dependencies to 1.21-pre4. Note that PlayerAbilityLib requires a not yet accepted PR (https://github.com/Ladysnake/PlayerAbilityLib/pull/24). This was tested using a local build of pal. Adapt to new function signatures for mixins. --- gradle.properties | 10 ++++---- .../ECPlaceholderRegistry.java | 2 +- .../EssentialCommandRegistry.java | 4 +-- .../commands/RulesCommand.java | 2 +- .../config/EssentialCommandsConfig.java | 6 ++--- .../mixin/PlayerManagerMixin.java | 25 ++++++++----------- .../mixin/ServerPlayerEntityMixin.java | 15 ++++++++--- .../mixin/WorldSaveHandlerMixin.java | 4 +-- .../util/NicknameTextUtil.java | 2 +- 9 files changed, 36 insertions(+), 34 deletions(-) diff --git a/gradle.properties b/gradle.properties index 10787b6c..46607467 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx2048M # Fabric Properties # check these on https://fabricmc.net/develup -minecraft_version=1.20.5 -yarn_mappings=1.20.5+build.1 -loader_version=0.15.10 +minecraft_version=1.21-pre4 +yarn_mappings=1.21-pre4+build.3 +loader_version=0.15.11 #Fabric api -fabric_version=0.97.5+1.20.5 +fabric_version=0.100.0+1.21 # Mod Properties mod_name = Essential Commands @@ -20,7 +20,7 @@ archives_base_name = essential_commands # Dependencies permissions_api_version=0.3.1 -placeholder_api_version=2.4.0-pre.1+1.20.5 +placeholder_api_version=2.4.0-pre.2+1.21 pal_version=1.9.0 vanish_version=1.5.3+1.20.4 diff --git a/src/main/java/com/fibermc/essentialcommands/ECPlaceholderRegistry.java b/src/main/java/com/fibermc/essentialcommands/ECPlaceholderRegistry.java index 2bbae4f6..03765d44 100644 --- a/src/main/java/com/fibermc/essentialcommands/ECPlaceholderRegistry.java +++ b/src/main/java/com/fibermc/essentialcommands/ECPlaceholderRegistry.java @@ -12,7 +12,7 @@ private ECPlaceholderRegistry() {} public static void register() { var namespace = EssentialCommands.MOD_ID; Placeholders.register( - new Identifier(namespace, "nickname"), + Identifier.of(namespace, "nickname"), (ctx, arg) -> { if (ctx.hasPlayer()) { return PlaceholderResult.value( diff --git a/src/main/java/com/fibermc/essentialcommands/EssentialCommandRegistry.java b/src/main/java/com/fibermc/essentialcommands/EssentialCommandRegistry.java index 1470adbb..9bfebfb8 100644 --- a/src/main/java/com/fibermc/essentialcommands/EssentialCommandRegistry.java +++ b/src/main/java/com/fibermc/essentialcommands/EssentialCommandRegistry.java @@ -631,7 +631,7 @@ public static void register( essentialCommandsRootNode.addChild(CommandManager.literal("convertEssentialsXPlayerHomes") .requires(source -> source.hasPermissionLevel(4)) .executes((source) -> { - Path mcDir = source.getSource().getServer().getRunDirectory().toPath(); + Path mcDir = source.getSource().getServer().getRunDirectory(); try { EssentialsXParser.convertPlayerDataDir( mcDir.resolve("plugins/Essentials/userdata").toFile(), @@ -648,7 +648,7 @@ public static void register( essentialCommandsRootNode.addChild(CommandManager.literal("convertEssentialsXWarps") .requires(source -> source.hasPermissionLevel(4)) .executes((source) -> { - Path mcDir = source.getSource().getServer().getRunDirectory().toPath(); + Path mcDir = source.getSource().getServer().getRunDirectory(); EssentialsConvertor.warpConvert( source.getSource().getServer(), mcDir.resolve("plugins/Essentials/warps").toFile() diff --git a/src/main/java/com/fibermc/essentialcommands/commands/RulesCommand.java b/src/main/java/com/fibermc/essentialcommands/commands/RulesCommand.java index 6538945b..e1eb72c8 100644 --- a/src/main/java/com/fibermc/essentialcommands/commands/RulesCommand.java +++ b/src/main/java/com/fibermc/essentialcommands/commands/RulesCommand.java @@ -42,7 +42,7 @@ public static int reloadCommand(CommandContext context) thr @SuppressWarnings("ResultOfMethodCallIgnored") public static void reload(MinecraftServer server) throws IOException { - Path mcDir = server.getRunDirectory().toPath(); + Path mcDir = server.getRunDirectory(); var rulesFile = mcDir.resolve("config/essentialcommands/rules.txt").toFile(); rulesFile.getParentFile().mkdirs(); if (rulesFile.createNewFile()) { diff --git a/src/main/java/com/fibermc/essentialcommands/config/EssentialCommandsConfig.java b/src/main/java/com/fibermc/essentialcommands/config/EssentialCommandsConfig.java index 1c375f0d..bf99a82c 100644 --- a/src/main/java/com/fibermc/essentialcommands/config/EssentialCommandsConfig.java +++ b/src/main/java/com/fibermc/essentialcommands/config/EssentialCommandsConfig.java @@ -136,17 +136,17 @@ public EssentialCommandsConfig(Path savePath, String displayName, String documen EssentialCommands.LOGGER.info("Possible world ids: {}", String.join(",", worldIds.stream().map(Identifier::toString).toList())); var configuredWorldIds = configuredWorldIdStrings.stream() - .map(Identifier::new) + .map(Identifier::of) .toList(); EssentialCommands.LOGGER.info("Configured `rtp_enabled_worlds` world ids: {}", String.join(",", configuredWorldIds.stream().map(Identifier::toString).toList())); var validConfiguredWorldIds = configuredWorldIdStrings.stream() - .map(Identifier::new) + .map(Identifier::of) .filter(worldIds::contains) .collect(Collectors.toSet()); var invalidConfiguredWorldIds = configuredWorldIdStrings.stream() - .map(Identifier::new) + .map(Identifier::of) .filter(v -> !worldIds.contains(v)) .toList(); diff --git a/src/main/java/com/fibermc/essentialcommands/mixin/PlayerManagerMixin.java b/src/main/java/com/fibermc/essentialcommands/mixin/PlayerManagerMixin.java index 25f77497..03d1a127 100644 --- a/src/main/java/com/fibermc/essentialcommands/mixin/PlayerManagerMixin.java +++ b/src/main/java/com/fibermc/essentialcommands/mixin/PlayerManagerMixin.java @@ -1,7 +1,5 @@ package com.fibermc.essentialcommands.mixin; -import java.util.Optional; - import com.fibermc.essentialcommands.ECAbilitySources; import com.fibermc.essentialcommands.events.PlayerConnectCallback; import com.fibermc.essentialcommands.events.PlayerLeaveCallback; @@ -16,12 +14,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; +import net.minecraft.entity.Entity; import net.minecraft.network.ClientConnection; import net.minecraft.server.PlayerManager; import net.minecraft.server.network.ConnectedClientData; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; +import net.minecraft.world.TeleportTarget; @Mixin(PlayerManager.class) public abstract class PlayerManagerMixin { @@ -55,13 +54,10 @@ public void onPlayerLeave(ServerPlayerEntity player, CallbackInfo callbackInfo) target = "Lnet/minecraft/server/network/ServerPlayerEntity;copyFrom(Lnet/minecraft/server/network/ServerPlayerEntity;Z)V" ), locals = LocalCapture.CAPTURE_FAILHARD) public void onRespawnPlayer( - ServerPlayerEntity oldServerPlayerEntity, boolean alive, CallbackInfoReturnable cir - , BlockPos blockPos - , float f - , boolean bl + ServerPlayerEntity oldServerPlayerEntity, boolean alive, Entity.RemovalReason removalReason + , CallbackInfoReturnable cir + , TeleportTarget teleportTarget , ServerWorld serverWorld - , Optional optional - , ServerWorld serverWorld2 , ServerPlayerEntity serverPlayerEntity ) { PlayerDataManager.handlePlayerDataRespawnSync(oldServerPlayerEntity, serverPlayerEntity); @@ -74,14 +70,13 @@ public void onRespawnPlayer( target = "Lnet/minecraft/server/world/ServerWorld;getLevelProperties()Lnet/minecraft/world/WorldProperties;" ), locals = LocalCapture.CAPTURE_FAILHARD) public void onRespawnPlayer_afterSetPosition( - ServerPlayerEntity oldServerPlayerEntity, boolean alive, CallbackInfoReturnable cir - , BlockPos blockPos - , float f - , boolean bl + ServerPlayerEntity oldServerPlayerEntity, boolean alive, Entity.RemovalReason removalReason + , CallbackInfoReturnable cir + , TeleportTarget teleportTarget , ServerWorld serverWorld - , Optional optional - , ServerWorld serverWorld2 , ServerPlayerEntity serverPlayerEntity + , byte b + , ServerWorld serverWorld2 ) { PlayerDataManager.handleRespawnAtEcSpawn(oldServerPlayerEntity, serverPlayerEntity); PlayerRespawnCallback.EVENT.invoker().onPlayerRespawn(oldServerPlayerEntity, serverPlayerEntity); diff --git a/src/main/java/com/fibermc/essentialcommands/mixin/ServerPlayerEntityMixin.java b/src/main/java/com/fibermc/essentialcommands/mixin/ServerPlayerEntityMixin.java index be32c39b..8822f815 100644 --- a/src/main/java/com/fibermc/essentialcommands/mixin/ServerPlayerEntityMixin.java +++ b/src/main/java/com/fibermc/essentialcommands/mixin/ServerPlayerEntityMixin.java @@ -18,12 +18,15 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; +import net.minecraft.entity.Entity; import net.minecraft.entity.damage.DamageSource; import net.minecraft.registry.RegistryKey; +import net.minecraft.server.PlayerManager; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.text.Text; import net.minecraft.world.GameMode; +import net.minecraft.world.TeleportTarget; import net.minecraft.world.World; import net.minecraft.world.WorldProperties; @@ -60,14 +63,18 @@ public void onChangeGameMode(GameMode gameMode, CallbackInfoReturnable // ((ServerPlayerEntityAccess) this).getEcPlayerData().updatePlayer(((ServerPlayerEntity) (Object) this)); } - @Inject(method = "teleport(Lnet/minecraft/server/world/ServerWorld;DDDFF)V", at = @At( + @Inject(method = "teleportTo(Lnet/minecraft/world/TeleportTarget;)Lnet/minecraft/entity/Entity;", at = @At( value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;sendPlayerStatus(Lnet/minecraft/server/network/ServerPlayerEntity;)V" ), locals = LocalCapture.CAPTURE_FAILSOFT) public void onTeleportBetweenWorlds( - ServerWorld targetWorld, double x, double y, double z, float yaw, float pitch, - CallbackInfo ci, - ServerWorld serverWorld, WorldProperties worldProperties) + TeleportTarget teleportTarget, + CallbackInfoReturnable cir, + ServerWorld serverWorld, + ServerWorld serverWorld2, + RegistryKey registryKey, + WorldProperties worldProperties, + PlayerManager playerManager) { var playerData = ((ServerPlayerEntityAccess) this).ec$getPlayerData(); playerData.updatePlayerEntity((ServerPlayerEntity) (Object) this); diff --git a/src/main/java/com/fibermc/essentialcommands/mixin/WorldSaveHandlerMixin.java b/src/main/java/com/fibermc/essentialcommands/mixin/WorldSaveHandlerMixin.java index e133b3e2..19e9ef71 100644 --- a/src/main/java/com/fibermc/essentialcommands/mixin/WorldSaveHandlerMixin.java +++ b/src/main/java/com/fibermc/essentialcommands/mixin/WorldSaveHandlerMixin.java @@ -9,9 +9,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.world.WorldSaveHandler; +import net.minecraft.world.PlayerSaveHandler; -@Mixin(WorldSaveHandler.class) +@Mixin(PlayerSaveHandler.class) public class WorldSaveHandlerMixin { @Inject(method = "savePlayerData", at = @At("RETURN")) diff --git a/src/main/java/com/fibermc/essentialcommands/util/NicknameTextUtil.java b/src/main/java/com/fibermc/essentialcommands/util/NicknameTextUtil.java index a26c1161..d36378dd 100644 --- a/src/main/java/com/fibermc/essentialcommands/util/NicknameTextUtil.java +++ b/src/main/java/com/fibermc/essentialcommands/util/NicknameTextUtil.java @@ -42,7 +42,7 @@ private static boolean hasPermissionForTextFragment(Text text, NickPerms sourceP || style.isObfuscated() || style.isStrikethrough() || style.isUnderlined()) - || !style.getFont().equals(new Identifier("minecraft:default"))), + || !style.getFont().equals(Identifier.of("minecraft:default"))), (sourcePerms.click || (style.getClickEvent() == null)), (sourcePerms.hover || (style.getHoverEvent() == null)) );