mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-04 10:41:41 +02:00
Merge branch 'master' of https://github.com/Minestom/Minestom
This commit is contained in:
commit
04fc38a14f
|
@ -693,7 +693,12 @@ public class Player extends LivingEntity implements CommandSender {
|
||||||
// true if the chunks need to be sent to the client, can be false if the instances share the same chunks (eg SharedInstance)
|
// true if the chunks need to be sent to the client, can be false if the instances share the same chunks (eg SharedInstance)
|
||||||
final boolean needWorldRefresh = !InstanceUtils.areLinked(this.instance, instance);
|
final boolean needWorldRefresh = !InstanceUtils.areLinked(this.instance, instance);
|
||||||
|
|
||||||
if (needWorldRefresh && !firstSpawn) {
|
// true if the player needs every chunk around its position
|
||||||
|
final boolean needChunkLoad = !firstSpawn || firstSpawn &&
|
||||||
|
ChunkUtils.getChunkCoordinate((int) getRespawnPoint().getX()) == 0 &&
|
||||||
|
ChunkUtils.getChunkCoordinate((int) getRespawnPoint().getZ()) == 0;
|
||||||
|
|
||||||
|
if (needWorldRefresh && needChunkLoad) {
|
||||||
// Remove all previous viewable chunks (from the previous instance)
|
// Remove all previous viewable chunks (from the previous instance)
|
||||||
for (Chunk viewableChunk : viewableChunks) {
|
for (Chunk viewableChunk : viewableChunks) {
|
||||||
viewableChunk.removeViewer(this);
|
viewableChunk.removeViewer(this);
|
||||||
|
@ -724,7 +729,7 @@ public class Player extends LivingEntity implements CommandSender {
|
||||||
final boolean isLast = counter.get() == length - 1;
|
final boolean isLast = counter.get() == length - 1;
|
||||||
if (isLast) {
|
if (isLast) {
|
||||||
// This is the last chunk to be loaded , spawn player
|
// This is the last chunk to be loaded , spawn player
|
||||||
spawnPlayer(instance, false);
|
spawnPlayer(instance, firstSpawn);
|
||||||
} else {
|
} else {
|
||||||
// Increment the counter of current loaded chunks
|
// Increment the counter of current loaded chunks
|
||||||
counter.incrementAndGet();
|
counter.incrementAndGet();
|
||||||
|
@ -734,7 +739,7 @@ public class Player extends LivingEntity implements CommandSender {
|
||||||
// WARNING: if auto load is disabled and no chunks are loaded beforehand, player will be stuck.
|
// WARNING: if auto load is disabled and no chunks are loaded beforehand, player will be stuck.
|
||||||
instance.loadOptionalChunk(chunkX, chunkZ, callback);
|
instance.loadOptionalChunk(chunkX, chunkZ, callback);
|
||||||
}
|
}
|
||||||
} else if (firstSpawn) {
|
} else if (!needChunkLoad) {
|
||||||
// The player always believe that his position is 0;0 so this is a pretty hacky fix
|
// The player always believe that his position is 0;0 so this is a pretty hacky fix
|
||||||
instance.loadOptionalChunk(0, 0, chunk -> spawnPlayer(instance, true));
|
instance.loadOptionalChunk(0, 0, chunk -> spawnPlayer(instance, true));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -29,14 +29,14 @@ public class MainDemo {
|
||||||
// Add event listeners
|
// Add event listeners
|
||||||
ConnectionManager connectionManager = MinecraftServer.getConnectionManager();
|
ConnectionManager connectionManager = MinecraftServer.getConnectionManager();
|
||||||
connectionManager.addPlayerInitialization(player -> {
|
connectionManager.addPlayerInitialization(player -> {
|
||||||
// Set the spawning instance
|
// Set the spawning instance and spawn position
|
||||||
player.addEventCallback(PlayerLoginEvent.class, event -> {
|
player.addEventCallback(PlayerLoginEvent.class, event -> {
|
||||||
event.setSpawningInstance(instanceContainer);
|
event.setSpawningInstance(instanceContainer);
|
||||||
player.setRespawnPoint(new Position(0, 45, 0));
|
player.setRespawnPoint(new Position(0, 42, 0));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Start the server
|
// Start the server on port 25565
|
||||||
minecraftServer.start("localhost", 25565);
|
minecraftServer.start("localhost", 25565);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public class MainDemo {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillBiomes(Biome[] biomes, int chunkX, int chunkZ) {
|
public void fillBiomes(Biome[] biomes, int chunkX, int chunkZ) {
|
||||||
Arrays.fill(biomes, MinecraftServer.getBiomeManager().getById(0));
|
Arrays.fill(biomes, Biome.PLAINS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue
Block a user