1
0
Fork 0

Compare commits

...

4 Commits

Author SHA1 Message Date
Ryan Fox 3cbc868b51
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.
2020-06-24 20:09:28 +00:00
Ryan Fox 3604a9027f
Add mcsrc to .gitignore
I usually symlink the generated Minecraft source code to a folder inside
my project so that I can view them easier. It comes in handy.
2020-06-24 20:09:28 +00:00
Ryan Fox 2f8927356c
1.16 2020-06-24 20:09:28 +00:00
Ryan Fox efeaa6d111
Bump fabric loom 2020-06-23 21:18:14 +00:00
11 changed files with 42 additions and 59 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.gradle/
build/
mcsrc/
run/

View File

@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.2.7-SNAPSHOT'
id 'fabric-loom' version '0.4-SNAPSHOT'
}
repositories {

View File

@ -1,8 +1,8 @@
org.gradle.jvmargs=-Xmx1G
minecraft_version=1.15.2
yarn_mappings=1.15.2+build.15
loader_version=0.8.2+build.194
minecraft_version=1.16
yarn_mappings=1.16+build.1
loader_version=0.8.8+build.202
mod_version = 1.0.0
maven_group = party.2a03.mc
archives_base_name = minecraft-tweaks-2a03
fabric_version=0.5.1+build.294-1.15
fabric_version=0.13.1+build.370-1.16

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

@ -25,6 +25,6 @@
"depends": {
"fabricloader": ">=0.8.2",
"fabric": "*",
"minecraft": "1.15.x"
"minecraft": "1.16.x"
}
}

View File

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