diff --git a/src/main/java/fr/themode/demo/Main.java b/src/main/java/fr/themode/demo/Main.java index e45a7a654..973d3b357 100644 --- a/src/main/java/fr/themode/demo/Main.java +++ b/src/main/java/fr/themode/demo/Main.java @@ -3,6 +3,7 @@ package fr.themode.demo; import fr.themode.demo.blocks.BurningTorchBlock; import fr.themode.demo.blocks.StoneBlock; import fr.themode.demo.blocks.UpdatableBlockDemo; +import fr.themode.demo.commands.DimensionCommand; import fr.themode.demo.commands.GamemodeCommand; import fr.themode.demo.commands.HealthCommand; import fr.themode.demo.commands.SimpleCommand; @@ -39,6 +40,7 @@ public class Main { commandManager.register(new HealthCommand()); commandManager.register(new SimpleCommand()); commandManager.register(new GamemodeCommand()); + commandManager.register(new DimensionCommand()); RecipeManager recipeManager = MinecraftServer.getRecipeManager(); ShapelessRecipe shapelessRecipe = new ShapelessRecipe("test", "groupname") { diff --git a/src/main/java/fr/themode/demo/PlayerInit.java b/src/main/java/fr/themode/demo/PlayerInit.java index 992bde30f..fb9c7bce8 100644 --- a/src/main/java/fr/themode/demo/PlayerInit.java +++ b/src/main/java/fr/themode/demo/PlayerInit.java @@ -26,6 +26,7 @@ import net.minestom.server.utils.Position; import net.minestom.server.utils.Vector; import net.minestom.server.utils.time.TimeUnit; import net.minestom.server.utils.time.UpdateOption; +import net.minestom.server.world.Dimension; import java.util.Map; import java.util.UUID; @@ -33,22 +34,28 @@ import java.util.UUID; public class PlayerInit { private static volatile InstanceContainer instanceContainer; + private static volatile InstanceContainer netherTest; static { //StorageFolder storageFolder = MinecraftServer.getStorageManager().getFolder("chunk_data"); ChunkGeneratorDemo chunkGeneratorDemo = new ChunkGeneratorDemo(); NoiseTestGenerator noiseTestGenerator = new NoiseTestGenerator(); //instanceContainer = MinecraftServer.getInstanceManager().createInstanceContainer(storageFolder); - instanceContainer = MinecraftServer.getInstanceManager().createInstanceContainer(); + instanceContainer = MinecraftServer.getInstanceManager().createInstanceContainer(Dimension.OVERWORLD); instanceContainer.enableAutoChunkLoad(true); instanceContainer.setChunkGenerator(noiseTestGenerator); + netherTest = MinecraftServer.getInstanceManager().createInstanceContainer(Dimension.NETHER); + netherTest.enableAutoChunkLoad(true); + netherTest.setChunkGenerator(noiseTestGenerator); + // Load some chunks beforehand int loopStart = -2; int loopEnd = 2; for (int x = loopStart; x < loopEnd; x++) for (int z = loopStart; z < loopEnd; z++) { instanceContainer.loadChunk(x, z); + netherTest.loadChunk(x, z); } } diff --git a/src/main/java/fr/themode/demo/commands/DimensionCommand.java b/src/main/java/fr/themode/demo/commands/DimensionCommand.java new file mode 100644 index 000000000..a8f625fd0 --- /dev/null +++ b/src/main/java/fr/themode/demo/commands/DimensionCommand.java @@ -0,0 +1,51 @@ +package fr.themode.demo.commands; + +import net.minestom.server.MinecraftServer; +import net.minestom.server.command.CommandProcessor; +import net.minestom.server.entity.EntityCreature; +import net.minestom.server.entity.Player; +import net.minestom.server.instance.Instance; +import net.minestom.server.utils.MathUtils; +import net.minestom.server.utils.time.TimeUnit; +import net.minestom.server.world.Dimension; + +import java.util.Optional; + +public class DimensionCommand implements CommandProcessor { + @Override + public String getCommandName() { + return "dimensiontest"; + } + + @Override + public String[] getAliases() { + return new String[0]; + } + + @Override + public boolean process(Player player, String command, String[] args) { + Instance instance = player.getInstance(); + + Dimension targetDimension = Dimension.NETHER; + if(instance.getDimension() == Dimension.NETHER) { + targetDimension = Dimension.OVERWORLD; + } + + Dimension finalTargetDimension = targetDimension; + Optional targetInstance = MinecraftServer.getInstanceManager().getInstances().stream().filter(in -> in.getDimension() == finalTargetDimension).findFirst(); + if(targetInstance.isPresent()) { + player.sendMessage("You were in "+instance.getDimension()); + player.setInstance(targetInstance.get()); + player.sendMessage("You are now in "+targetDimension); + } else { + player.sendMessage("Could not find instance with dimension "+targetDimension); + } + + return true; + } + + @Override + public boolean hasAccess(Player player) { + return true; + } +} diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 51b5132e6..1545d9561 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -744,6 +744,7 @@ public class Player extends LivingEntity { if (dimension.equals(getDimension())) throw new IllegalArgumentException("The dimension need to be different than the current one!"); + refreshDimension(dimension); RespawnPacket respawnPacket = new RespawnPacket(); respawnPacket.dimension = dimension; respawnPacket.gameMode = gameMode;