diff --git a/src/main/java/party/_2a03/mc/command/HomeCommand.java b/src/main/java/party/_2a03/mc/command/HomeCommand.java index 1c58d2e..1e79c8b 100644 --- a/src/main/java/party/_2a03/mc/command/HomeCommand.java +++ b/src/main/java/party/_2a03/mc/command/HomeCommand.java @@ -7,7 +7,7 @@ import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.LiteralText; -import net.minecraft.world.dimension.DimensionType; +import net.minecraft.util.registry.RegistryKey; import party._2a03.mc.server.Config; import party._2a03.mc.server.PlayerData; import party._2a03.mc.server.PlayerPosition; @@ -18,11 +18,11 @@ public class HomeCommand { ServerCommandSource source = ctx.getSource(); ServerPlayerEntity sender = source.getPlayer(); PlayerPosition position = Config.getPlayer(sender.getUuid().toString()).getHome(); - if (position.dimensiontype == null) { + if (position.registrykey == null) { source.sendFeedback(new LiteralText("Home not found, do /home set"), false); return -1; } - sender.teleport(sender.getServer().getWorld(position.dimensiontype), position.x, position.y, position.z, position.yaw, position.pitch); + sender.teleport(sender.getServer().getWorld(position.registrykey), position.x, position.y, position.z, position.yaw, position.pitch); source.sendFeedback(new LiteralText("Teleported to home"), true); return 1; }); @@ -36,8 +36,8 @@ public class HomeCommand { double z = sender.getZ(); float yaw = sender.yaw; float pitch = sender.pitch; - DimensionType dimensiontype = sender.getServerWorld().getDimension().getType(); - PlayerPosition location = new PlayerPosition(x, y, z, yaw, pitch, dimensiontype); + RegistryKey registrykey = sender.getServerWorld().getRegistryKey(); + PlayerPosition location = new PlayerPosition(x, y, z, yaw, pitch, registrykey); playerdata.setHome(location); Config.setPlayer(playerdata); source.sendFeedback(new LiteralText("Your home has been updated"), true); @@ -55,8 +55,8 @@ public class HomeCommand { double z = sender.getZ(); float yaw = sender.yaw; float pitch = sender.pitch; - DimensionType dimensiontype = sender.getServerWorld().getDimension().getType(); - PlayerPosition location = new PlayerPosition(x, y, z, yaw, pitch, dimensiontype); + RegistryKey registrykey = sender.getServerWorld().getRegistryKey(); + PlayerPosition location = new PlayerPosition(x, y, z, yaw, pitch, registrykey); playerdata.setHome(location); Config.setPlayer(playerdata); source.sendFeedback(new LiteralText("User's home has been updated (" + StringArgumentType.getString(ctx, "UUID") + ")"), true); diff --git a/src/main/java/party/_2a03/mc/command/SpawnCommand.java b/src/main/java/party/_2a03/mc/command/SpawnCommand.java index 1e6e4b6..4f9e937 100644 --- a/src/main/java/party/_2a03/mc/command/SpawnCommand.java +++ b/src/main/java/party/_2a03/mc/command/SpawnCommand.java @@ -6,7 +6,7 @@ import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.LiteralText; -import net.minecraft.world.dimension.DimensionType; +import net.minecraft.util.registry.RegistryKey; import party._2a03.mc.server.Config; import party._2a03.mc.server.PlayerPosition; @@ -16,7 +16,7 @@ public class SpawnCommand { ServerCommandSource source = ctx.getSource(); ServerPlayerEntity sender = source.getPlayer(); PlayerPosition position = new PlayerPosition(Config.getData("spawn")); - if (position.dimensiontype == null) { + if (position.registrykey == null) { if (source.hasPermissionLevel(2)) { source.sendFeedback(new LiteralText("Spawn not found, do /spawn set"), false); } else { @@ -24,7 +24,7 @@ public class SpawnCommand { } return -1; } - sender.teleport(sender.getServer().getWorld(position.dimensiontype), position.x, position.y, position.z, position.yaw, position.pitch); + sender.teleport(sender.getServer().getWorld(position.registrykey), position.x, position.y, position.z, position.yaw, position.pitch); source.sendFeedback(new LiteralText("Teleported to the spawn point"), true); return 1; }); @@ -39,8 +39,8 @@ public class SpawnCommand { double z = sender.getZ(); float yaw = sender.yaw; float pitch = sender.pitch; - DimensionType dimensiontype = sender.getServerWorld().getDimension().getType(); - PlayerPosition location = new PlayerPosition(x, y, z, yaw, pitch, dimensiontype); + RegistryKey registrykey = sender.getServerWorld().getRegistryKey(); + PlayerPosition location = new PlayerPosition(x, y, z, yaw, pitch, registrykey); Config.setData("spawn", location.getJSON()); source.sendFeedback(new LiteralText("Spawn has been set"), true); return 1; diff --git a/src/main/java/party/_2a03/mc/mixin/MixinPlayerEntity.java b/src/main/java/party/_2a03/mc/mixin/MixinPlayerEntity.java deleted file mode 100644 index 2118ca1..0000000 --- a/src/main/java/party/_2a03/mc/mixin/MixinPlayerEntity.java +++ /dev/null @@ -1,25 +0,0 @@ -package party._2a03.mc.mixin; - -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -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.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.Mixin; -import party._2a03.mc.server.Config; -import party._2a03.mc.server.PlayerPosition; - -@Mixin(PlayerEntity.class) -public abstract class MixinPlayerEntity extends LivingEntity { - public MixinPlayerEntity() { - super(null, null); - } - - @Inject(method = "getSpawnPosition", at = @At("RETURN"), cancellable = true) - public void OnGetSpawnPosition(CallbackInfoReturnable cir) { - PlayerPosition position = new PlayerPosition(Config.getData("spawn")); - if (position.dimensiontype == this.dimension) - cir.setReturnValue(null); // Don't override the world spawn. - } -} diff --git a/src/main/java/party/_2a03/mc/mixin/MixinServerPlayerEntity.java b/src/main/java/party/_2a03/mc/mixin/MixinServerPlayerEntity.java index c04eade..c992a45 100644 --- a/src/main/java/party/_2a03/mc/mixin/MixinServerPlayerEntity.java +++ b/src/main/java/party/_2a03/mc/mixin/MixinServerPlayerEntity.java @@ -2,23 +2,29 @@ package party._2a03.mc.mixin; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.registry.RegistryKey; +import net.minecraft.world.World; 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.Mixin; +import org.spongepowered.asm.mixin.Shadow; import party._2a03.mc.server.Config; import party._2a03.mc.server.PlayerPosition; @Mixin(ServerPlayerEntity.class) public abstract class MixinServerPlayerEntity extends PlayerEntity { + @Shadow + private RegistryKey spawnPointDimension; + public MixinServerPlayerEntity() { - super(null, null); + super(null, null, null); } @Inject(method = "moveToSpawn", at = @At("HEAD"), cancellable = true) private void OnServerPlayerSpawn(CallbackInfo ci) { PlayerPosition position = new PlayerPosition(Config.getData("spawn")); - if (position.dimensiontype == this.dimension) { + if (position.registrykey == this.spawnPointDimension) { this.updatePositionAndAngles(position.x, position.y, position.z, position.yaw, position.pitch); ci.cancel(); } diff --git a/src/main/java/party/_2a03/mc/server/Config.java b/src/main/java/party/_2a03/mc/server/Config.java index 1b04df1..93c315c 100644 --- a/src/main/java/party/_2a03/mc/server/Config.java +++ b/src/main/java/party/_2a03/mc/server/Config.java @@ -33,7 +33,7 @@ public class Config { json = new JSONObject(jsonRaw); } else { LOGGER.info("Config not found, creating one"); - json = new JSONObject("{\"disableTntExplosions\":false,\"spawn\":[0,0,0,0,0,-2],\"members\":[]}"); + json = new JSONObject("{\"disableTntExplosions\":false,\"spawn\":[0,0,0,0,0,\"\"],\"members\":[]}"); saveConfig(); } LOGGER.info("Configuration loaded"); @@ -93,4 +93,4 @@ public class Config { LOGGER.error("Failed to save config file"); } } -} \ No newline at end of file +} diff --git a/src/main/java/party/_2a03/mc/server/PlayerPosition.java b/src/main/java/party/_2a03/mc/server/PlayerPosition.java index 8dee98d..dd5dc0b 100644 --- a/src/main/java/party/_2a03/mc/server/PlayerPosition.java +++ b/src/main/java/party/_2a03/mc/server/PlayerPosition.java @@ -1,7 +1,9 @@ package party._2a03.mc.server; import org.json.JSONArray; -import net.minecraft.world.dimension.DimensionType; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; +import net.minecraft.util.registry.RegistryKey; import party._2a03.mc.server.Config; public class PlayerPosition { @@ -10,49 +12,49 @@ public class PlayerPosition { public double z; public float yaw; public float pitch; - public DimensionType dimensiontype; + public RegistryKey registrykey; public PlayerPosition() { } public PlayerPosition(JSONArray data) { - int dimension_id = data.getInt(5); - if (dimension_id != -2) { + String registry_string = data.getString(5); + if (!registry_string.isEmpty()) { this.x = data.getDouble(0); this.y = data.getDouble(1); this.z = data.getDouble(2); this.yaw = data.getNumber(3).floatValue(); this.pitch = data.getNumber(4).floatValue(); - this.dimensiontype = DimensionType.byRawId(dimension_id); + this.registrykey = RegistryKey.of(Registry.DIMENSION, new Identifier(registry_string)); } } - public PlayerPosition(double p_x, double p_y, double p_z, float p_yaw, float p_pitch, DimensionType p_dimensiontype) { + public PlayerPosition(double p_x, double p_y, double p_z, float p_yaw, float p_pitch, RegistryKey p_registrykey) { this.x = p_x; this.y = p_y; this.z = p_z; this.yaw = p_yaw; this.pitch = p_pitch; - this.dimensiontype = p_dimensiontype; + this.registrykey = p_registrykey; } public JSONArray getJSON() { JSONArray json = new JSONArray(); - if (this.dimensiontype != null) { + if (this.registrykey != null) { json.put(this.x); json.put(this.y); json.put(this.z); json.put(this.yaw); json.put(this.pitch); - json.put(this.dimensiontype.getRawId()); + json.put(this.registrykey.getValue().toString()); } else { json.put(0); json.put(0); json.put(0); json.put(0); json.put(0); - json.put(-2); + json.put(""); } return json; } -} \ No newline at end of file +} diff --git a/src/main/resources/minecraft-tweaks-2a03.mixins.json b/src/main/resources/minecraft-tweaks-2a03.mixins.json index 0773a7c..6db7143 100644 --- a/src/main/resources/minecraft-tweaks-2a03.mixins.json +++ b/src/main/resources/minecraft-tweaks-2a03.mixins.json @@ -4,7 +4,6 @@ "compatibilityLevel": "JAVA_8", "server": [ "MixinGameModeCommand", - "MixinPlayerEntity", "MixinServerPlayerEntity", "MixinTntBlock", "MixinTntEntity"