mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +01:00
Merge pull request #450 from RinesThaix/chunks
Chunk-related improvements
This commit is contained in:
commit
e522ba7e81
@ -1,6 +1,7 @@
|
|||||||
package net.minestom.server.event.instance;
|
package net.minestom.server.event.instance;
|
||||||
|
|
||||||
import net.minestom.server.event.trait.InstanceEvent;
|
import net.minestom.server.event.trait.InstanceEvent;
|
||||||
|
import net.minestom.server.instance.Chunk;
|
||||||
import net.minestom.server.instance.Instance;
|
import net.minestom.server.instance.Instance;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -10,12 +11,11 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
public class InstanceChunkLoadEvent implements InstanceEvent {
|
public class InstanceChunkLoadEvent implements InstanceEvent {
|
||||||
|
|
||||||
private final Instance instance;
|
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.instance = instance;
|
||||||
this.chunkX = chunkX;
|
this.chunk = chunk;
|
||||||
this.chunkZ = chunkZ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -29,7 +29,7 @@ public class InstanceChunkLoadEvent implements InstanceEvent {
|
|||||||
* @return the chunk X
|
* @return the chunk X
|
||||||
*/
|
*/
|
||||||
public int getChunkX() {
|
public int getChunkX() {
|
||||||
return chunkX;
|
return chunk.getChunkX();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,6 +38,15 @@ public class InstanceChunkLoadEvent implements InstanceEvent {
|
|||||||
* @return the chunk Z
|
* @return the chunk Z
|
||||||
*/
|
*/
|
||||||
public int getChunkZ() {
|
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;
|
package net.minestom.server.event.instance;
|
||||||
|
|
||||||
import net.minestom.server.event.trait.InstanceEvent;
|
import net.minestom.server.event.trait.InstanceEvent;
|
||||||
|
import net.minestom.server.instance.Chunk;
|
||||||
import net.minestom.server.instance.Instance;
|
import net.minestom.server.instance.Instance;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -10,12 +11,11 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
public class InstanceChunkUnloadEvent implements InstanceEvent {
|
public class InstanceChunkUnloadEvent implements InstanceEvent {
|
||||||
|
|
||||||
private final Instance instance;
|
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.instance = instance;
|
||||||
this.chunkX = chunkX;
|
this.chunk = chunk;
|
||||||
this.chunkZ = chunkZ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -29,7 +29,7 @@ public class InstanceChunkUnloadEvent implements InstanceEvent {
|
|||||||
* @return the chunk X
|
* @return the chunk X
|
||||||
*/
|
*/
|
||||||
public int getChunkX() {
|
public int getChunkX() {
|
||||||
return chunkX;
|
return chunk.getChunkX();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,6 +38,15 @@ public class InstanceChunkUnloadEvent implements InstanceEvent {
|
|||||||
* @return the chunk Z
|
* @return the chunk Z
|
||||||
*/
|
*/
|
||||||
public int getChunkZ() {
|
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.
|
* 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
|
* @return the chunk at the given position, null if not loaded
|
||||||
*/
|
*/
|
||||||
public @Nullable Chunk getChunkAt(@NotNull Point point) {
|
public @Nullable Chunk getChunkAt(@NotNull Point point) {
|
||||||
|
@ -217,7 +217,7 @@ public class InstanceContainer extends Instance {
|
|||||||
chunk.removeViewer(viewer);
|
chunk.removeViewer(viewer);
|
||||||
}
|
}
|
||||||
|
|
||||||
EventDispatcher.call(new InstanceChunkUnloadEvent(this, chunkX, chunkZ));
|
EventDispatcher.call(new InstanceChunkUnloadEvent(this, chunk));
|
||||||
// Remove all entities in chunk
|
// Remove all entities in chunk
|
||||||
getChunkEntities(chunk).forEach(entity -> {
|
getChunkEntities(chunk).forEach(entity -> {
|
||||||
if (!(entity instanceof Player)) entity.remove();
|
if (!(entity instanceof Player)) entity.remove();
|
||||||
@ -272,7 +272,7 @@ public class InstanceContainer extends Instance {
|
|||||||
.whenComplete((chunk, throwable) -> {
|
.whenComplete((chunk, throwable) -> {
|
||||||
// TODO run in the instance thread?
|
// TODO run in the instance thread?
|
||||||
cacheChunk(chunk);
|
cacheChunk(chunk);
|
||||||
GlobalHandles.INSTANCE_CHUNK_LOAD.call(new InstanceChunkLoadEvent(this, chunkX, chunkZ));
|
GlobalHandles.INSTANCE_CHUNK_LOAD.call(new InstanceChunkLoadEvent(this, chunk));
|
||||||
synchronized (loadingChunks) {
|
synchronized (loadingChunks) {
|
||||||
this.loadingChunks.remove(ChunkUtils.getChunkIndex(chunk));
|
this.loadingChunks.remove(ChunkUtils.getChunkIndex(chunk));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user