Class Instance
- All Implemented Interfaces:
Audience,ForwardingAudience,Pointered,PacketGroupingAudience,EventHandler<InstanceEvent>,Block.Getter,Block.Setter,Snapshotable,Taggable,TagReadable,TagWritable,Tickable,Schedulable
- Direct Known Subclasses:
InstanceContainer,SharedInstance
Entity.setInstance(Instance).
An instance has entities and chunks, each instance contains its own entity list but the
chunk implementation has to be defined, see InstanceContainer.
WARNING: when making your own implementation registering the instance manually is required
with InstanceManager.registerInstance(Instance), and
you need to be sure to signal the ThreadDispatcher of every partition/element changes.
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.minestom.server.instance.block.Block.Getter
Block.Getter.ConditionNested classes/interfaces inherited from interface net.kyori.adventure.audience.ForwardingAudience
ForwardingAudience.Single -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionInstance(@NotNull UUID uniqueId, @NotNull DimensionType dimensionType) Creates a new instance.Instance(@NotNull UUID uniqueId, @NotNull DimensionType dimensionType, @NotNull NamespaceID dimensionName) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbreakBlock(@NotNull Player player, @NotNull Point blockPosition, @NotNull BlockFace blockFace) Does callPlayerBlockBreakEventand send particle packetsabstract booleanbreakBlock(@NotNull Player player, @NotNull Point blockPosition, @NotNull BlockFace blockFace, boolean doBlockUpdates) Does callPlayerBlockBreakEventand send particle packets@NotNull TimeUpdatePacketCreates aTimeUpdatePacketwith the current age and time of this instanceabstract voidenableAutoChunkLoad(boolean enable) When set to true, chunks will load automatically when requested.@NotNull EventNode<InstanceEvent> voidexplode(float centerX, float centerY, float centerZ, float strength) Creates an explosion at the given position with the given strength.voidexplode(float centerX, float centerY, float centerZ, float strength, @Nullable org.jglrxavpok.hephaistos.nbt.NBTCompound additionalData) Creates an explosion at the given position with the given strength.abstract @Nullable GeneratorGets the generator associated with the instance@Nullable BlockgetBlock(int x, int y, int z, @NotNull Block.Getter.Condition condition) intgetBlockLight(int blockX, int blockY, int blockZ) abstract @Nullable ChunkgetChunk(int chunkX, int chunkZ) Gets the loadedChunkat a position.@Nullable ChunkgetChunkAt(double x, double z) Gets theChunkat the given block position, null if not loaded.@Nullable ChunkgetChunkAt(@NotNull Point point) getChunkEntities(Chunk chunk) Gets the entities located in the chunk.abstract @NotNull Collection<@NotNull Chunk> Gets all the instance's loaded chunks.abstract ChunkSupplierGets the chunk supplier of the instance.@NotNull Set<@NotNull EntityCreature> Deprecated.@NotNull StringGets the instance dimension name.Gets the instanceDimensionType.Gets the entities in the instance;@NotNull Set<@NotNull ExperienceOrb> Deprecated.@Nullable ExplosionSupplierGets the registeredExplosionSupplier, or null if none was provided.@NotNull PFInstanceSpaceGets the instance space.@NotNull Collection<Entity> getNearbyEntities(@NotNull Point point, double range) Gets nearby entities to the given position.Gets the players in the instance;intgetSkyLight(int blockX, int blockY, int blockZ) longgetTime()Gets the current time in the instance (sun/moon).intGets the rate of the time passing, it is 1 by default@Nullable DurationGets the rate at which the client is updated with the current instance time@NotNull UUIDGets the instance unique id.@NotNull WeatherGets the weather of this instancelongGets the age of this instance in tick.@NotNull WorldBorderGets the instanceWorldBorder;@NotNull PosGets the spawn position of the instance.abstract booleanGets if the instance should auto load chunks.booleanisChunkLoaded(int chunkX, int chunkZ) booleanisChunkLoaded(Point point) abstract booleanDetermines whether a position in the void.booleanGets if the instance has been registered inInstanceManager.abstract @NotNull CompletableFuture<@NotNull Chunk> loadChunk(int chunkX, int chunkZ) Forces the generation of aChunk, even if no file andChunkGeneratorare defined.@NotNull CompletableFuture<@NotNull Chunk> Loads the chunk at the givenPointwith a callback.abstract @NotNull CompletableFuture<@Nullable Chunk> loadOptionalChunk(int chunkX, int chunkZ) Loads the chunk if the chunk is already loaded or ifhasEnabledAutoChunkLoad()returns true.@NotNull CompletableFuture<@Nullable Chunk> loadOptionalChunk(@NotNull Point point) booleanplaceBlock(BlockHandler.Placement placement) abstract booleanplaceBlock(BlockHandler.Placement placement, boolean doBlockUpdates) @NotNull Pointerspointers()abstract @NotNull CompletableFuture<Void> Saves multiple chunks to permanent storage.abstract @NotNull CompletableFuture<Void> saveChunkToStorage(@NotNull Chunk chunk) Saves aChunkto permanent storage.abstract @NotNull CompletableFuture<Void> Saves the current instance tags.voidscheduleNextTick(@NotNull Consumer<Instance> callback) Schedules a task to be run during the next instance tick.@NotNull SchedulervoidsendBlockAction(@NotNull Point blockPosition, byte actionId, byte actionParam) Sends aBlockActionPacketfor all the viewers of the specific position.voidabstract voidvoidvoidsetChunkGenerator(@Nullable ChunkGenerator chunkGenerator) Deprecated.abstract voidsetChunkSupplier(@NotNull ChunkSupplier chunkSupplier) voidsetExplosionSupplier(@Nullable ExplosionSupplier supplier) Registers theExplosionSupplierto use in this instance.abstract voidsetGenerator(@Nullable Generator generator) Changes the generator of the instanceprotected voidsetRegistered(boolean registered) Changes the registered field.voidsetTime(long time) Changes the current time in the instance, from 0 to 24000.voidsetTimeRate(int timeRate) Changes the time rate of the instancevoidsetTimeUpdate(@Nullable Duration timeUpdate) Changes the rate at which the client is updated about the timevoidsetWeather(@NotNull Weather weather) Sets the weather of this instance with a fixed transitionvoidsetWeather(@NotNull Weather weather, int transitionTicks) Sets the weather on this instance, transitions over timebooleansetWorldSpawnPosition(@NotNull Pos spawnPosition) Updates the spawn position of the instance.booleansetWorldSpawnPosition(@NotNull Pos spawnPosition, boolean sendPacket) Updates the spawn position of the instance.@NotNull TagHandlervoidtick(long time) Performs a single tick in the instance, including scheduled tasks fromscheduleNextTick(Consumer).voidunloadChunk(int chunkX, int chunkZ) Unloads the chunk at the given position.abstract voidunloadChunk(@NotNull Chunk chunk) Schedules the removal of aChunk, this method does not promise when it will be done.@NotNull InstanceSnapshotupdateSnapshot(@NotNull SnapshotUpdater updater) Updates the currently cached snapshot if required.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.kyori.adventure.audience.Audience
deleteMessage, openBook, removeResourcePacks, removeResourcePacks, removeResourcePacks, sendActionBar, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendPlayerListFooter, sendPlayerListHeader, sendPlayerListHeaderAndFooter, sendResourcePacks, sendResourcePacks, showTitle, stopSoundMethods inherited from interface net.minestom.server.instance.block.Block.Getter
getBlock, getBlock, getBlockMethods inherited from interface net.minestom.server.instance.block.Block.Setter
setBlockMethods inherited from interface net.kyori.adventure.audience.ForwardingAudience
clearResourcePacks, deleteMessage, filterAudience, forEachAudience, openBook, playSound, removeResourcePacks, sendMessage, sendMessage, sendMessage, sendMessage, sendPlayerListFooter, sendPlayerListHeader, sendResourcePacksMethods inherited from interface net.minestom.server.adventure.audience.PacketGroupingAudience
audiences, clearTitle, hideBossBar, playSound, playSound, playSound, resetTitle, sendActionBar, sendGroupedPacket, sendMessage, sendPlayerListHeaderAndFooter, sendTitlePart, showBossBar, stopSoundMethods inherited from interface net.kyori.adventure.pointer.Pointered
get, getOrDefault, getOrDefaultFrom
-
Field Details
-
uniqueId
-
tagHandler
-
-
Constructor Details
-
Instance
Creates a new instance.- Parameters:
uniqueId- theUUIDof the instancedimensionType- theDimensionTypeof the instance
-
Instance
public Instance(@NotNull @NotNull UUID uniqueId, @NotNull @NotNull DimensionType dimensionType, @NotNull @NotNull NamespaceID dimensionName) Creates a new instance.- Parameters:
uniqueId- theUUIDof the instancedimensionType- theDimensionTypeof the instance
-
-
Method Details
-
scheduleNextTick
Schedules a task to be run during the next instance tick.- Parameters:
callback- the task to execute during the next instance tick
-
setBlock
- Specified by:
setBlockin interfaceBlock.Setter
-
setBlock
-
setBlock
public abstract void setBlock(int x, int y, int z, @NotNull @NotNull Block block, boolean doBlockUpdates) -
placeBlock
-
placeBlock
@Internal public abstract boolean placeBlock(@NotNull BlockHandler.Placement placement, boolean doBlockUpdates) -
breakBlock
@Internal public boolean breakBlock(@NotNull @NotNull Player player, @NotNull @NotNull Point blockPosition, @NotNull @NotNull BlockFace blockFace) Does callPlayerBlockBreakEventand send particle packets- Parameters:
player- thePlayerwho break the blockblockPosition- the position of the broken block- Returns:
- true if the block has been broken, false if it has been cancelled
-
breakBlock
@Internal public abstract boolean breakBlock(@NotNull @NotNull Player player, @NotNull @NotNull Point blockPosition, @NotNull @NotNull BlockFace blockFace, boolean doBlockUpdates) Does callPlayerBlockBreakEventand send particle packets- Parameters:
player- thePlayerwho break the blockblockPosition- the position of the broken blockdoBlockUpdates- true to do block updates, false otherwise- Returns:
- true if the block has been broken, false if it has been cancelled
-
loadChunk
@NotNull public abstract @NotNull CompletableFuture<@NotNull Chunk> loadChunk(int chunkX, int chunkZ) Forces the generation of aChunk, even if no file andChunkGeneratorare defined.- Parameters:
chunkX- the chunk XchunkZ- the chunk Z- Returns:
- a
CompletableFuturecompleted once the chunk has been loaded
-
loadChunk
Loads the chunk at the givenPointwith a callback.- Parameters:
point- the chunk position
-
loadOptionalChunk
@NotNull public abstract @NotNull CompletableFuture<@Nullable Chunk> loadOptionalChunk(int chunkX, int chunkZ) Loads the chunk if the chunk is already loaded or ifhasEnabledAutoChunkLoad()returns true.- Parameters:
chunkX- the chunk XchunkZ- the chunk Z- Returns:
- a
CompletableFuturecompleted once the chunk has been processed, can be null if not loaded
-
loadOptionalChunk
@NotNull public @NotNull CompletableFuture<@Nullable Chunk> loadOptionalChunk(@NotNull @NotNull Point point) - Parameters:
point- the chunk position- Returns:
- a
CompletableFuturecompleted once the chunk has been processed, null if not loaded
-
unloadChunk
Schedules the removal of aChunk, this method does not promise when it will be done.WARNING: during unloading, all entities other than
Playerwill be removed.- Parameters:
chunk- the chunk to unload
-
unloadChunk
public void unloadChunk(int chunkX, int chunkZ) Unloads the chunk at the given position.- Parameters:
chunkX- the chunk XchunkZ- the chunk Z
-
getChunk
Gets the loadedChunkat a position.WARNING: this should only return already-loaded chunk, use
loadChunk(int, int)or similar to load one instead.- Parameters:
chunkX- the chunk XchunkZ- the chunk Z- Returns:
- the chunk at the specified position, null if not loaded
-
isChunkLoaded
public boolean isChunkLoaded(int chunkX, int chunkZ) - Parameters:
chunkX- the chunk XchunkZ- this chunk Z- Returns:
- true if the chunk is loaded
-
isChunkLoaded
- Parameters:
point- coordinate of a block or other- Returns:
- true if the chunk is loaded
-
saveInstance
Saves the current instance tags.Warning: only the global instance data will be saved, not chunks. You would need to call
saveChunksToStorage()too.- Returns:
- the future called once the instance data has been saved
-
saveChunkToStorage
@NotNull public abstract @NotNull CompletableFuture<Void> saveChunkToStorage(@NotNull @NotNull Chunk chunk) Saves aChunkto permanent storage.- Parameters:
chunk- theChunkto save- Returns:
- future called when the chunk is done saving
-
saveChunksToStorage
Saves multiple chunks to permanent storage.- Returns:
- future called when the chunks are done saving
-
setChunkGenerator
Deprecated.Changes the instanceChunkGenerator.- Parameters:
chunkGenerator- the newChunkGeneratorof the instance
-
setChunkSupplier
-
getChunkSupplier
Gets the chunk supplier of the instance.- Returns:
- the chunk supplier of the instance
-
generator
Gets the generator associated with the instance- Returns:
- the generator if any
-
setGenerator
Changes the generator of the instance- Parameters:
generator- the new generator, or null to disable generation
-
getChunks
Gets all the instance's loaded chunks.- Returns:
- an unmodifiable containing all the instance chunks
-
enableAutoChunkLoad
public abstract void enableAutoChunkLoad(boolean enable) When set to true, chunks will load automatically when requested. Otherwise usingloadChunk(int, int)will be required to even spawn a player- Parameters:
enable- enable the auto chunk load
-
hasEnabledAutoChunkLoad
public abstract boolean hasEnabledAutoChunkLoad()Gets if the instance should auto load chunks.- Returns:
- true if auto chunk load is enabled, false otherwise
-
isInVoid
Determines whether a position in the void.- Parameters:
point- the point in the world- Returns:
- true if the point is inside the void
-
isRegistered
public boolean isRegistered()Gets if the instance has been registered inInstanceManager.- Returns:
- true if the instance has been registered
-
setRegistered
protected void setRegistered(boolean registered) Changes the registered field.WARNING: should only be used by
InstanceManager.- Parameters:
registered- true to mark the instance as registered
-
getDimensionType
Gets the instanceDimensionType.- Returns:
- the dimension of the instance
-
getDimensionName
Gets the instance dimension name.- Returns:
- the dimension name of the instance
-
getWorldAge
public long getWorldAge()Gets the age of this instance in tick.- Returns:
- the age of this instance in tick
-
setWorldSpawnPosition
Updates the spawn position of the instance. This method doesn't send the SpawnPositionPacket to the players.- Parameters:
spawnPosition- the new spawn position
-
setWorldSpawnPosition
Updates the spawn position of the instance. The underlying spawn position will only be updated if the new position is different from the current one. It sends the SpawnPositionPacket when the boolean option is true and the instance has players.- Parameters:
spawnPosition- the new spawn positionsendPacket- if true, the new spawn position will be sent to all players in the instance
-
getWorldSpawnPosition
Gets the spawn position of the instance. If the position is not set, it will returnPos.ZERO- Returns:
- the spawn position of the instance
-
getTime
public long getTime()Gets the current time in the instance (sun/moon).- Returns:
- the time in the instance
-
setTime
public void setTime(long time) Changes the current time in the instance, from 0 to 24000.If the time is negative, the vanilla client will not move the sun.
0 = sunrise 6000 = noon 12000 = sunset 18000 = midnight
This method is unaffected by
getTimeRate()It does send the new time to all players in the instance, unaffected by
getTimeUpdate()- Parameters:
time- the new time of the instance
-
getTimeRate
public int getTimeRate()Gets the rate of the time passing, it is 1 by default- Returns:
- the time rate of the instance
-
setTimeRate
public void setTimeRate(int timeRate) Changes the time rate of the instance1 is the default value and can be set to 0 to be completely disabled (constant time)
- Parameters:
timeRate- the new time rate of the instance- Throws:
IllegalStateException- iftimeRateis lower than 0
-
getTimeUpdate
Gets the rate at which the client is updated with the current instance time- Returns:
- the client update rate for time related packet
-
setTimeUpdate
Changes the rate at which the client is updated about the timeSetting it to null means that the client will never know about time change (but will still change server-side)
- Parameters:
timeUpdate- the new update rate concerning time
-
createTimePacket
Creates aTimeUpdatePacketwith the current age and time of this instance- Returns:
- the
TimeUpdatePacketwith this instance data
-
getWorldBorder
Gets the instanceWorldBorder;- Returns:
- the
WorldBorderlinked to the instance
-
getEntities
Gets the entities in the instance;- Returns:
- an unmodifiable
Setcontaining all the entities in the instance
-
getPlayers
Gets the players in the instance;- Specified by:
getPlayersin interfacePacketGroupingAudience- Returns:
- an unmodifiable
Setcontaining all the players in the instance
-
getCreatures
Deprecated.Gets the creatures in the instance;- Returns:
- an unmodifiable
Setcontaining all the creatures in the instance
-
getExperienceOrbs
Deprecated.Gets the experience orbs in the instance.- Returns:
- an unmodifiable
Setcontaining all the experience orbs in the instance
-
getChunkEntities
Gets the entities located in the chunk. -
getNearbyEntities
@NotNull public @NotNull Collection<Entity> getNearbyEntities(@NotNull @NotNull Point point, double range) Gets nearby entities to the given position.- Parameters:
point- position to look atrange- max range from the given point to collect entities at- Returns:
- entities that are not further than the specified distance from the transmitted position.
-
getBlock
@Nullable public @Nullable Block getBlock(int x, int y, int z, @NotNull @NotNull Block.Getter.Condition condition) - Specified by:
getBlockin interfaceBlock.Getter
-
sendBlockAction
Sends aBlockActionPacketfor all the viewers of the specific position.- Parameters:
blockPosition- the block positionactionId- the action id, depends on the blockactionParam- the action parameter, depends on the block- See Also:
-
getChunkAt
Gets theChunkat the given block position, null if not loaded.- Parameters:
x- the X positionz- the Z position- Returns:
- the chunk at the given position, null if not loaded
-
getChunkAt
- Parameters:
point- the position- Returns:
- the chunk at the given position, null if not loaded
-
getEntityTracker
-
getUniqueId
Gets the instance unique id.- Returns:
- the instance unique id
-
tick
public void tick(long time) Performs a single tick in the instance, including scheduled tasks fromscheduleNextTick(Consumer).Warning: this does not update chunks and entities.
-
getWeather
Gets the weather of this instance- Returns:
- the instance weather
-
setWeather
Sets the weather on this instance, transitions over time- Parameters:
weather- the new weathertransitionTicks- the ticks to transition to new weather
-
setWeather
Sets the weather of this instance with a fixed transition- Parameters:
weather- the new weather
-
tagHandler
- Specified by:
tagHandlerin interfaceTaggable
-
scheduler
- Specified by:
schedulerin interfaceSchedulable
-
eventNode
- Specified by:
eventNodein interfaceEventHandler<InstanceEvent>
-
updateSnapshot
Description copied from interface:SnapshotableUpdates the currently cached snapshot if required. The updater can be used to retrieve references to other snapshots while avoiding circular dependency. Be careful to do not storeupdateranywhere as its data will change when building requested references.This method is not thread-safe, and targeted at internal use since its execution rely on safe-points (e.g. end of ticks)
- Specified by:
updateSnapshotin interfaceSnapshotable- Parameters:
updater- the snapshot updater/context- Returns:
- the updated snapshot
-
explode
public void explode(float centerX, float centerY, float centerZ, float strength) Creates an explosion at the given position with the given strength. The algorithm used to compute damages is provided bygetExplosionSupplier().- Parameters:
centerX- the center XcenterY- the center YcenterZ- the center Zstrength- the strength of the explosion- Throws:
IllegalStateException- If noExplosionSupplierwas supplied
-
explode
public void explode(float centerX, float centerY, float centerZ, float strength, @Nullable @Nullable org.jglrxavpok.hephaistos.nbt.NBTCompound additionalData) Creates an explosion at the given position with the given strength. The algorithm used to compute damages is provided bygetExplosionSupplier().- Parameters:
centerX- center X of the explosioncenterY- center Y of the explosioncenterZ- center Z of the explosionstrength- the strength of the explosionadditionalData- data to pass to the explosion supplier- Throws:
IllegalStateException- If noExplosionSupplierwas supplied
-
getExplosionSupplier
Gets the registeredExplosionSupplier, or null if none was provided.- Returns:
- the instance explosion supplier, null if none was provided
-
setExplosionSupplier
Registers theExplosionSupplierto use in this instance.- Parameters:
supplier- the explosion supplier
-
getInstanceSpace
Gets the instance space.Used by the pathfinder for entities.
- Returns:
- the instance space
-
pointers
- Specified by:
pointersin interfaceForwardingAudience- Specified by:
pointersin interfacePointered
-
getBlockLight
public int getBlockLight(int blockX, int blockY, int blockZ) -
getSkyLight
public int getSkyLight(int blockX, int blockY, int blockZ)
-
setGenerator(Generator)