mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-01 05:58:00 +01:00
Fixed error relating to unloaded chunk in Entity#update
This commit is contained in:
parent
80f9122da1
commit
ab71133b55
@ -258,7 +258,8 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ChunkUtils.isChunkUnloaded(getInstance(), getPosition().getX(), getPosition().getZ())) {
|
||||
boolean chunkUnloaded = ChunkUtils.isChunkUnloaded(instance, position.getX(), position.getZ());
|
||||
if (chunkUnloaded) {
|
||||
// No update for entities in unloaded chunk
|
||||
return;
|
||||
}
|
||||
@ -275,6 +276,10 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
|
||||
|
||||
Position newPosition = new Position(newX, newY, newZ);
|
||||
|
||||
chunkUnloaded = ChunkUtils.isChunkUnloaded(instance, newX, newZ);
|
||||
if (chunkUnloaded)
|
||||
return;
|
||||
|
||||
if (!(this instanceof Player) && !noGravity) { // players handle gravity by themselves
|
||||
velocity.setY(velocity.getY() - gravityDragPerTick * tps);
|
||||
}
|
||||
@ -319,6 +324,9 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
chunkUnloaded = ChunkUtils.isChunkUnloaded(instance, x, z);
|
||||
if (chunkUnloaded)
|
||||
continue;
|
||||
CustomBlock customBlock = instance.getCustomBlock(x, y, z);
|
||||
if (customBlock != null) {
|
||||
tmpPosition.setX(x);
|
||||
|
@ -404,6 +404,7 @@ public class Player extends LivingEntity {
|
||||
viewableChunks.add(chunk);
|
||||
chunk.addViewer(this);
|
||||
instance.sendChunk(this, chunk);
|
||||
updateViewPosition(chunk);
|
||||
}
|
||||
boolean isLast = counter.get() == length - 1;
|
||||
if (isLast) {
|
||||
@ -411,7 +412,6 @@ public class Player extends LivingEntity {
|
||||
super.setInstance(instance);
|
||||
PlayerSpawnEvent spawnEvent = new PlayerSpawnEvent(instance, firstSpawn);
|
||||
callEvent(PlayerSpawnEvent.class, spawnEvent);
|
||||
updateViewPosition(chunk);
|
||||
} else {
|
||||
// Increment the counter of current loaded chunks
|
||||
counter.incrementAndGet();
|
||||
@ -736,15 +736,16 @@ public class Player extends LivingEntity {
|
||||
int index = newChunks[i];
|
||||
int[] chunkPos = ChunkUtils.getChunkCoord(updatedVisibleChunks[index]);
|
||||
instance.loadOptionalChunk(chunkPos[0], chunkPos[1], chunk -> {
|
||||
if (isFar && isLast) {
|
||||
updatePlayerPosition();
|
||||
}
|
||||
|
||||
if (chunk == null) {
|
||||
return; // Cannot load chunk (auto load is not enabled)
|
||||
}
|
||||
this.viewableChunks.add(chunk);
|
||||
chunk.addViewer(this);
|
||||
instance.sendChunk(this, chunk);
|
||||
if (isFar && isLast) {
|
||||
updatePlayerPosition();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -409,6 +409,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
/**
|
||||
* Creates an explosion at the given position with the given strength. The algorithm used to compute damages is provided by {@link #getExplosionSupplier()}.
|
||||
* If no {@link ExplosionSupplier} was supplied, this method will throw an {@link IllegalStateException}
|
||||
*
|
||||
* @param centerX
|
||||
* @param centerY
|
||||
* @param centerZ
|
||||
@ -421,6 +422,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
/**
|
||||
* Creates an explosion at the given position with the given strength. The algorithm used to compute damages is provided by {@link #getExplosionSupplier()}.
|
||||
* If no {@link ExplosionSupplier} was supplied, this method will throw an {@link IllegalStateException}
|
||||
*
|
||||
* @param centerX
|
||||
* @param centerY
|
||||
* @param centerZ
|
||||
@ -429,7 +431,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
*/
|
||||
public void explode(float centerX, float centerY, float centerZ, float strength, Data additionalData) {
|
||||
ExplosionSupplier explosionSupplier = getExplosionSupplier();
|
||||
if(explosionSupplier == null)
|
||||
if (explosionSupplier == null)
|
||||
throw new IllegalStateException("Tried to create an explosion with no explosion supplier");
|
||||
Explosion explosion = explosionSupplier.createExplosion(centerX, centerY, centerZ, strength, additionalData);
|
||||
explosion.apply(this);
|
||||
@ -437,6 +439,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
|
||||
/**
|
||||
* Return the registered explosion supplier, or null if none was provided
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ExplosionSupplier getExplosionSupplier() {
|
||||
@ -445,6 +448,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
|
||||
/**
|
||||
* Registers the explosion supplier to use in this instance
|
||||
*
|
||||
* @param supplier
|
||||
*/
|
||||
public void setExplosionSupplier(ExplosionSupplier supplier) {
|
||||
|
Loading…
Reference in New Issue
Block a user