Beginnings of custom dimension support

This commit is contained in:
jglrxavpok 2020-07-07 20:31:59 +02:00
parent 109afe7a54
commit f12ab40a6e
5 changed files with 121 additions and 33 deletions

View File

@ -62,6 +62,10 @@ public class PlayerInit {
netherTest.enableAutoChunkLoad(true); netherTest.enableAutoChunkLoad(true);
netherTest.setChunkGenerator(noiseTestGenerator); netherTest.setChunkGenerator(noiseTestGenerator);
InstanceContainer end = MinecraftServer.getInstanceManager().createInstanceContainer(Dimension.END);
end.enableAutoChunkLoad(true);
end.setChunkGenerator(noiseTestGenerator);
// Load some chunks beforehand // Load some chunks beforehand
int loopStart = -2; int loopStart = -2;
int loopEnd = 10; int loopEnd = 10;
@ -69,6 +73,7 @@ public class PlayerInit {
for (int z = loopStart; z < loopEnd; z++) { for (int z = loopStart; z < loopEnd; z++) {
instanceContainer.loadChunk(x, z); instanceContainer.loadChunk(x, z);
//netherTest.loadChunk(x, z); //netherTest.loadChunk(x, z);
end.loadChunk(x, z);
} }

View File

@ -30,7 +30,7 @@ public class DimensionCommand implements CommandProcessor {
Instance instance = player.getInstance(); Instance instance = player.getInstance();
Dimension targetDimension = Dimension.NETHER; Dimension targetDimension = Dimension.NETHER;
if (instance.getDimension() == Dimension.NETHER) { if (instance.getDimension() == targetDimension) {
targetDimension = Dimension.OVERWORLD; targetDimension = Dimension.OVERWORLD;
} }

View File

@ -38,31 +38,17 @@ public class JoinGamePacket implements ServerPacket {
//array of worlds //array of worlds
writer.writeVarInt(1); writer.writeVarInt(1);
writer.writeSizedString(identifier); writer.writeSizedString("test:spawn_name");
// TODO: modifiable
NBTCompound dimension = new NBTCompound()
.setString("name", "test:normal")
.setFloat("ambient_light", 1F)
.setString("infiniburn", "")
.setByte("natural", (byte) 0x01)
.setByte("has_ceiling", (byte) 0x01)
.setByte("has_skylight", (byte) 0x01)
.setByte("shrunk", (byte) 0x00)
.setByte("ultrawarm", (byte) 0x00)
.setByte("has_raids", (byte) 0x00)
.setByte("respawn_anchor_works", (byte) 0x00)
.setByte("bed_works", (byte) 0x01)
.setByte("piglin_safe", (byte) 0x01)
.setInt("logical_height", 255)
;
NBTList<NBTCompound> dimensionList = new NBTList<>(NBTTypes.TAG_Compound); NBTList<NBTCompound> dimensionList = new NBTList<>(NBTTypes.TAG_Compound);
dimensionList.add(dimension); // TODO: custom list
dimensionList.add(Dimension.OVERWORLD.toNBT());
dimensionList.add(Dimension.NETHER.toNBT());
dimensionList.add(Dimension.END.toNBT());
writer.writeNBT("", new NBTCompound().set("dimension", dimensionList)); writer.writeNBT("", new NBTCompound().set("dimension", dimensionList));
writer.writeSizedString(dimension.getName().toString());
//writer.writeInt(dimension.getId()); writer.writeSizedString(identifier+"_"+dimension.getName().getPath());
writer.writeSizedString("test:normal");
writer.writeSizedString(identifier);
writer.writeLong(hashedSeed); writer.writeLong(hashedSeed);
writer.writeByte(maxPlayers); writer.writeByte(maxPlayers);
writer.writeVarInt(viewDistance); writer.writeVarInt(viewDistance);
@ -71,7 +57,7 @@ public class JoinGamePacket implements ServerPacket {
//debug //debug
writer.writeBoolean(false); writer.writeBoolean(false);
//is flat //is flat
writer.writeBoolean(true); writer.writeBoolean(levelType == LevelType.FLAT);
} }
@Override @Override

View File

@ -17,8 +17,11 @@ public class RespawnPacket implements ServerPacket {
@Override @Override
public void write(PacketWriter writer) { public void write(PacketWriter writer) {
//TODO add api //TODO add api
writer.writeSizedString("test:normal"); writer.writeSizedString(dimension.getName().toString());
writer.writeSizedString("test:spawn");
// Warning: must be different for each dimension type! Otherwise the client seems to cache the world name
writer.writeSizedString("test:spawn_"+dimension.getName().getPath()); // TODO: replace by instance name?
writer.writeLong(hashedSeed); writer.writeLong(hashedSeed);
writer.writeByte(gameMode.getId()); writer.writeByte(gameMode.getId());
writer.writeByte(gameMode.getId()); // Hardcore flag not included writer.writeByte(gameMode.getId()); // Hardcore flag not included

View File

@ -1,16 +1,110 @@
package net.minestom.server.world; package net.minestom.server.world;
public enum Dimension { import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
import net.minestom.server.utils.NamespaceID;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
NETHER(-1), OVERWORLD(0), END(1); import java.util.Optional;
private int id; /**
* https://minecraft.gamepedia.com/Custom_dimension
*/
@Data
@Builder(builderMethodName = "hiddenBuilder", access = AccessLevel.PRIVATE)
public class Dimension {
Dimension(int id) { public static final Dimension OVERWORLD = Dimension.builder(NamespaceID.from("minecraft:overworld"))
this.id = id; .ultrawarm(false)
.natural(true)
.shrunk(false)
.piglinSafe(false)
.respawnAnchorSafe(false)
.bedSafe(true)
.raidCapable(true)
.skylightEnabled(true)
.ceilingEnabled(false)
.fixedTime(Optional.empty())
.ambientLight(0.0f)
.logicalHeight(256)
.infiniburn(NamespaceID.from("minecraft:infiniburn_overworld"))
.build();
public static final Dimension NETHER = Dimension.builder(NamespaceID.from("minecraft:the_nether"))
.ultrawarm(true)
.natural(false)
.shrunk(true)
.piglinSafe(true)
.respawnAnchorSafe(true)
.bedSafe(false)
.raidCapable(false)
.skylightEnabled(false)
.ceilingEnabled(true)
.fixedTime(Optional.of(18000L))
.ambientLight(0.1f)
.logicalHeight(128)
.infiniburn(NamespaceID.from("minecraft:infiniburn_nether"))
.build();
public static final Dimension END = Dimension.builder(NamespaceID.from("minecraft:the_end"))
.ultrawarm(false)
.natural(false)
.shrunk(false)
.piglinSafe(false)
.respawnAnchorSafe(false)
.bedSafe(false)
.raidCapable(true)
.skylightEnabled(false)
.ceilingEnabled(false)
.fixedTime(Optional.of(6000L))
.ambientLight(0.0f)
.logicalHeight(256)
.infiniburn(NamespaceID.from("minecraft:infiniburn_end"))
.build();
private final NamespaceID name;
private final boolean natural;
private final float ambientLight;
private final boolean ceilingEnabled;
private final boolean skylightEnabled;
@Builder.Default private final Optional<Long> fixedTime = Optional.empty();
private final boolean shrunk;
private final boolean raidCapable;
private final boolean respawnAnchorSafe;
private final boolean ultrawarm;
@Builder.Default private final boolean bedSafe = true;
private final boolean piglinSafe;
@Builder.Default private final int logicalHeight = 256;
@Builder.Default private final NamespaceID infiniburn = NamespaceID.from("minecraft:infiniburn_overworld");
public NBTCompound toNBT() {
NBTCompound nbt = new NBTCompound()
.setString("name", name.toString())
.setFloat("ambient_light", ambientLight)
.setString("infiniburn", infiniburn.toString())
.setByte("natural", (byte) (natural ? 0x01 : 0x00))
.setByte("has_ceiling", (byte) (ceilingEnabled ? 0x01 : 0x00))
.setByte("has_skylight", (byte) (skylightEnabled ? 0x01 : 0x00))
.setByte("shrunk", (byte) (shrunk ? 0x01 : 0x00))
.setByte("ultrawarm", (byte) (ultrawarm ? 0x01 : 0x00))
.setByte("has_raids", (byte) (raidCapable ? 0x01 : 0x00))
.setByte("respawn_anchor_works", (byte) (respawnAnchorSafe ? 0x01 : 0x00))
.setByte("bed_works", (byte) (bedSafe ? 0x01 : 0x00))
.setByte("piglin_safe", (byte) (piglinSafe ? 0x01 : 0x00))
.setInt("logical_height", logicalHeight)
;
fixedTime.ifPresent(time -> nbt.setLong("fixed_time", time));
return nbt;
} }
public int getId() { @Override
return id; public String toString() {
return name.toString();
} }
public static DimensionBuilder builder(NamespaceID name) {
return hiddenBuilder().name(name);
}
} }