1
0
Fork 0

Use the World registry instead of dimension IDs

In 1.16, they got rid of dimension IDs and started using a registry. I
personally love this decision, but I need to update the mod for it.
This commit is contained in:
Ryan Fox 2020-06-24 20:07:12 +00:00
parent 3604a9027f
commit 3cbc868b51
Signed by: flewkey
GPG Key ID: 94F56ADFD848851E
7 changed files with 35 additions and 53 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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.
}
}

View File

@ -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<World> 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();
}

View File

@ -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");
}
}
}
}

View File

@ -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;
}
}
}

View File

@ -4,7 +4,6 @@
"compatibilityLevel": "JAVA_8",
"server": [
"MixinGameModeCommand",
"MixinPlayerEntity",
"MixinServerPlayerEntity",
"MixinTntBlock",
"MixinTntEntity"