mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-02 11:21:15 +01:00
Fix dimension not being sent for the first instance & force dimensions to be registered in the manager
This commit is contained in:
parent
cfe6178e46
commit
706a36b30a
@ -679,11 +679,12 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
viewableChunk.removeViewer(this);
|
||||
}
|
||||
|
||||
// Send the new dimension
|
||||
if (this.instance != null) {
|
||||
// Send the new dimension if player isn't in any instance or if the dimension is different
|
||||
{
|
||||
final DimensionType instanceDimensionType = instance.getDimensionType();
|
||||
if (dimensionType != instanceDimensionType)
|
||||
if (this.instance == null || dimensionType != instanceDimensionType) {
|
||||
sendDimension(instanceDimensionType);
|
||||
}
|
||||
}
|
||||
|
||||
// Load all the required chunks
|
||||
|
@ -112,6 +112,8 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
* @param dimensionType the {@link DimensionType} of the instance
|
||||
*/
|
||||
public Instance(@NotNull UUID uniqueId, @NotNull DimensionType dimensionType) {
|
||||
Check.argCondition(!dimensionType.isRegistered(),
|
||||
"The dimension " + dimensionType.getName() + " is not registered! Please use DimensionTypeManager#addDimension");
|
||||
this.uniqueId = uniqueId;
|
||||
this.dimensionType = dimensionType;
|
||||
|
||||
|
@ -12,8 +12,8 @@ import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
public class JoinGamePacket implements ServerPacket {
|
||||
|
||||
public int entityId;
|
||||
public GameMode gameMode = GameMode.SURVIVAL;
|
||||
public DimensionType dimensionType = DimensionType.OVERWORLD;
|
||||
public GameMode gameMode;
|
||||
public DimensionType dimensionType;
|
||||
public long hashedSeed;
|
||||
public int maxPlayers = 0; // Unused
|
||||
public int viewDistance;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.minestom.server.world;
|
||||
|
||||
import net.minestom.server.utils.NamespaceID;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
|
||||
import java.util.Objects;
|
||||
@ -31,6 +32,8 @@ public class DimensionType {
|
||||
|
||||
private final int id = idCounter.getAndIncrement();
|
||||
|
||||
protected volatile boolean registered;
|
||||
|
||||
private final NamespaceID name;
|
||||
private final boolean natural;
|
||||
private final float ambientLight;
|
||||
@ -76,6 +79,7 @@ public class DimensionType {
|
||||
return new DimensionTypeBuilder();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public NBTCompound toIndexedNBT() {
|
||||
NBTCompound nbt = new NBTCompound();
|
||||
NBTCompound element = toNBT();
|
||||
@ -85,6 +89,7 @@ public class DimensionType {
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public NBTCompound toNBT() {
|
||||
NBTCompound nbt = new NBTCompound()
|
||||
.setFloat("ambient_light", ambientLight)
|
||||
@ -114,6 +119,10 @@ public class DimensionType {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public boolean isRegistered() {
|
||||
return registered;
|
||||
}
|
||||
|
||||
public NamespaceID getName() {
|
||||
return this.name;
|
||||
}
|
||||
@ -154,6 +163,10 @@ public class DimensionType {
|
||||
return this.bedSafe;
|
||||
}
|
||||
|
||||
public String getEffects() {
|
||||
return effects;
|
||||
}
|
||||
|
||||
public boolean isPiglinSafe() {
|
||||
return this.piglinSafe;
|
||||
}
|
||||
|
@ -28,7 +28,8 @@ public final class DimensionTypeManager {
|
||||
* @param dimensionType the dimension to add
|
||||
*/
|
||||
public void addDimension(@NotNull DimensionType dimensionType) {
|
||||
dimensionTypes.add(dimensionType);
|
||||
dimensionType.registered = true;
|
||||
this.dimensionTypes.add(dimensionType);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,6 +39,7 @@ public final class DimensionTypeManager {
|
||||
* @return if the dimension type was removed, false if it was not present before
|
||||
*/
|
||||
public boolean removeDimension(@NotNull DimensionType dimensionType) {
|
||||
dimensionType.registered = false;
|
||||
return dimensionTypes.remove(dimensionType);
|
||||
}
|
||||
|
||||
@ -51,6 +53,14 @@ public final class DimensionTypeManager {
|
||||
return Collections.unmodifiableList(dimensionTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the {@link NBTCompound} containing all the registered dimensions.
|
||||
* <p>
|
||||
* Used when a player connects.
|
||||
*
|
||||
* @return an nbt compound containing the registered dimensions
|
||||
*/
|
||||
@NotNull
|
||||
public NBTCompound toNBT() {
|
||||
NBTCompound dimensions = new NBTCompound();
|
||||
dimensions.setString("type", "minecraft:dimension_type");
|
||||
|
Loading…
Reference in New Issue
Block a user