mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-05 18:32:28 +01:00
Chunk-related improvements
This commit is contained in:
parent
4b7adae382
commit
6c4eda3bb7
@ -1,6 +1,7 @@
|
||||
package net.minestom.server.event.instance;
|
||||
|
||||
import net.minestom.server.event.trait.InstanceEvent;
|
||||
import net.minestom.server.instance.Chunk;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -10,12 +11,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class InstanceChunkLoadEvent implements InstanceEvent {
|
||||
|
||||
private final Instance instance;
|
||||
private final int chunkX, chunkZ;
|
||||
private final Chunk chunk;
|
||||
|
||||
public InstanceChunkLoadEvent(@NotNull Instance instance, int chunkX, int chunkZ) {
|
||||
public InstanceChunkLoadEvent(@NotNull Instance instance, @NotNull Chunk chunk) {
|
||||
this.instance = instance;
|
||||
this.chunkX = chunkX;
|
||||
this.chunkZ = chunkZ;
|
||||
this.chunk = chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -29,7 +29,7 @@ public class InstanceChunkLoadEvent implements InstanceEvent {
|
||||
* @return the chunk X
|
||||
*/
|
||||
public int getChunkX() {
|
||||
return chunkX;
|
||||
return chunk.getChunkX();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,6 +38,15 @@ public class InstanceChunkLoadEvent implements InstanceEvent {
|
||||
* @return the chunk Z
|
||||
*/
|
||||
public int getChunkZ() {
|
||||
return chunkZ;
|
||||
return chunk.getChunkZ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the chunk.
|
||||
*
|
||||
* @return the chunk.
|
||||
*/
|
||||
public @NotNull Chunk getChunk() {
|
||||
return chunk;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.minestom.server.event.instance;
|
||||
|
||||
import net.minestom.server.event.trait.InstanceEvent;
|
||||
import net.minestom.server.instance.Chunk;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -10,12 +11,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class InstanceChunkUnloadEvent implements InstanceEvent {
|
||||
|
||||
private final Instance instance;
|
||||
private final int chunkX, chunkZ;
|
||||
private final Chunk chunk;
|
||||
|
||||
public InstanceChunkUnloadEvent(@NotNull Instance instance, int chunkX, int chunkZ) {
|
||||
public InstanceChunkUnloadEvent(@NotNull Instance instance, @NotNull Chunk chunk) {
|
||||
this.instance = instance;
|
||||
this.chunkX = chunkX;
|
||||
this.chunkZ = chunkZ;
|
||||
this.chunk = chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -29,7 +29,7 @@ public class InstanceChunkUnloadEvent implements InstanceEvent {
|
||||
* @return the chunk X
|
||||
*/
|
||||
public int getChunkX() {
|
||||
return chunkX;
|
||||
return chunk.getChunkX();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,6 +38,15 @@ public class InstanceChunkUnloadEvent implements InstanceEvent {
|
||||
* @return the chunk Z
|
||||
*/
|
||||
public int getChunkZ() {
|
||||
return chunkZ;
|
||||
return chunk.getChunkZ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the chunk.
|
||||
*
|
||||
* @return the chunk.
|
||||
*/
|
||||
public @NotNull Chunk getChunk() {
|
||||
return chunk;
|
||||
}
|
||||
}
|
||||
|
@ -550,7 +550,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
|
||||
/**
|
||||
* Gets the {@link Chunk} at the given {@link Point}, null if not loaded.
|
||||
*
|
||||
* @param point the chunk position
|
||||
* @param point the position
|
||||
* @return the chunk at the given position, null if not loaded
|
||||
*/
|
||||
public @Nullable Chunk getChunkAt(@NotNull Point point) {
|
||||
|
@ -217,7 +217,7 @@ public class InstanceContainer extends Instance {
|
||||
chunk.removeViewer(viewer);
|
||||
}
|
||||
|
||||
EventDispatcher.call(new InstanceChunkUnloadEvent(this, chunkX, chunkZ));
|
||||
EventDispatcher.call(new InstanceChunkUnloadEvent(this, chunk));
|
||||
// Remove all entities in chunk
|
||||
getChunkEntities(chunk).forEach(entity -> {
|
||||
if (!(entity instanceof Player)) entity.remove();
|
||||
@ -272,7 +272,7 @@ public class InstanceContainer extends Instance {
|
||||
.whenComplete((chunk, throwable) -> {
|
||||
// TODO run in the instance thread?
|
||||
cacheChunk(chunk);
|
||||
GlobalHandles.INSTANCE_CHUNK_LOAD.call(new InstanceChunkLoadEvent(this, chunkX, chunkZ));
|
||||
GlobalHandles.INSTANCE_CHUNK_LOAD.call(new InstanceChunkLoadEvent(this, chunk));
|
||||
synchronized (loadingChunks) {
|
||||
this.loadingChunks.remove(ChunkUtils.getChunkIndex(chunk));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user