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 uuid, @NotNull RegistryKey<DimensionType> dimensionType) Creates a new instance.Instance(@NotNull UUID uuid, @NotNull RegistryKey<DimensionType> dimensionType, @NotNull net.kyori.adventure.key.Key dimensionName) Creates a new instance.Instance(@NotNull DynamicRegistry<DimensionType> dimensionTypeRegistry, @NotNull UUID uuid, @NotNull RegistryKey<DimensionType> dimensionType, @NotNull net.kyori.adventure.key.Key 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 InitializeWorldBorderPacketCreates theInitializeWorldBorderPacketsent to players who join this instance.@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 net.kyori.adventure.nbt.CompoundBinaryTag 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) @NotNull DimensionTypeabstract @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;@Nullable EntitygetEntityById(int id) Gets an entity based on its id (fromEntity.getEntityId()).@Nullable EntitygetEntityByUuid(UUID uuid) Gets an entity based on its UUID (fromEntity.getUuid()).@NotNull Set<@NotNull ExperienceOrb> Deprecated.@Nullable ExplosionSupplierGets the registeredExplosionSupplier, or null if none was provided.@NotNull Collection<Entity> getNearbyEntities(@NotNull Point point, double range) Gets nearby entities to the given position.@Nullable PlayergetPlayerByUuid(UUID uuid) Gets a player based on its UUID (fromEntity.getUuid()).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 defaultintGets the rate at which the client is updated with the current instance time@NotNull UUIDDeprecated, for removal: This API element is subject to removal in a future version.@NotNull UUIDgetUuid()Gets the instance unique id.@NotNull WeatherGets the weather of this instancelongGets the age of this instance in tick.@NotNull WorldBorderGets the current state of the instanceWorldBorder.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) @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) voidplaySoundExcept(@Nullable Player excludedPlayer, @NotNull Sound sound, double x, double y, double z) voidplaySoundExcept(@Nullable Player excludedPlayer, @NotNull Sound sound, @NotNull Sound.Emitter emitter) voidplaySoundExcept(@Nullable Player excludedPlayer, @NotNull Sound sound, @NotNull Point point) Plays aSoundat a given point, except to the excluded player@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 voidvoidabstract 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 instancevoidsetTimeSynchronizationTicks(int timeSynchronizationTicks) Changes the natural client time packet synchronization period, defaults toServerFlag.SERVER_TICKS_PER_SECOND.voidsetWeather(@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 timevoidsetWorldAge(long worldAge) Sets the age of this instance in tick.voidsetWorldBorder(@NotNull WorldBorder worldBorder) Set the instanceWorldBorderwith an instant transition.voidsetWorldBorder(@NotNull WorldBorder worldBorder, double transitionTime) Set the instanceWorldBorderwith a smooth transition.@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, removeResourcePacks, sendMessage, sendMessage, sendMessage, sendMessage, sendPlayerListFooter, sendPlayerListHeader, sendResourcePacks, showDialogMethods inherited from interface net.minestom.server.adventure.audience.PacketGroupingAudience
audiences, clearTitle, hideBossBar, playSound, playSound, playSound, resetTitle, sendActionBar, sendGroupedPacket, sendMessage, sendNotification, sendPlayerListHeaderAndFooter, sendTitlePart, showBossBar, stopSoundMethods inherited from interface net.kyori.adventure.pointer.Pointered
get, getOrDefault, getOrDefaultFromMethods inherited from interface net.minestom.server.tag.Taggable
getAndSetTag, getAndUpdateTag, getTag, hasTag, removeTag, setTag, updateAndGetTag, updateTag
-
Field Details
-
uuid
-
tagHandler
-
-
Constructor Details
-
Instance
public Instance(@NotNull @NotNull UUID uuid, @NotNull @NotNull RegistryKey<DimensionType> dimensionType) Creates a new instance.- Parameters:
uuid- theUUIDof the instancedimensionType- theDimensionTypeof the instance
-
Instance
public Instance(@NotNull @NotNull UUID uuid, @NotNull @NotNull RegistryKey<DimensionType> dimensionType, @NotNull @NotNull net.kyori.adventure.key.Key dimensionName) Creates a new instance.- Parameters:
uuid- theUUIDof the instancedimensionType- theDimensionTypeof the instance
-
Instance
public Instance(@NotNull @NotNull DynamicRegistry<DimensionType> dimensionTypeRegistry, @NotNull @NotNull UUID uuid, @NotNull @NotNull RegistryKey<DimensionType> dimensionType, @NotNull @NotNull net.kyori.adventure.key.Key dimensionName) Creates a new instance.- Parameters:
uuid- 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) - 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
-
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
-
getCachedDimensionType
-
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
-
setWorldAge
public void setWorldAge(long worldAge) Sets the age of this instance in tick. It will send the age to all players. Will send new age to all players in the instance, unaffected bygetTimeSynchronizationTicks()- Parameters:
worldAge- the age of this instance in tick
-
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
getTimeSynchronizationTicks()- 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
-
getTimeSynchronizationTicks
public int getTimeSynchronizationTicks()Gets the rate at which the client is updated with the current instance time- Returns:
- the client update rate for time related packet
-
setTimeSynchronizationTicks
public void setTimeSynchronizationTicks(int timeSynchronizationTicks) Changes the natural client time packet synchronization period, defaults toServerFlag.SERVER_TICKS_PER_SECOND.Supplying 0 means that the client will never be synchronized with the current natural instance time (time will still change server-side)
- Parameters:
timeSynchronizationTicks- the rate to update time in ticks
-
createTimePacket
Creates aTimeUpdatePacketwith the current age and time of this instance- Returns:
- the
TimeUpdatePacketwith this instance data
-
getWorldBorder
Gets the current state of the instanceWorldBorder.- Returns:
- the
WorldBorderfor the instance of the current tick
-
setWorldBorder
Set the instanceWorldBorderwith a smooth transition.- Parameters:
worldBorder- the desired final state of the world bordertransitionTime- the time in seconds this world border's diameter will transition for (0 makes this instant)
-
setWorldBorder
Set the instanceWorldBorderwith an instant transition. seesetWorldBorder(WorldBorder, double). -
createInitializeWorldBorderPacket
Creates theInitializeWorldBorderPacketsent to players who join this instance. -
getEntities
Gets the entities in the instance;- Returns:
- an unmodifiable
Setcontaining all the entities in the instance
-
getEntityById
Gets an entity based on its id (fromEntity.getEntityId()).- Parameters:
id- the entity id- Returns:
- the entity having the specified id, null if not found
-
getEntityByUuid
Gets an entity based on its UUID (fromEntity.getUuid()).- Parameters:
uuid- the entity UUID- Returns:
- the entity having the specified uuid, null if not found
-
getPlayerByUuid
Gets a player based on its UUID (fromEntity.getUuid()).- Parameters:
uuid- the player UUID- Returns:
- the player having the specified uuid, null if not found or not a player
-
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
-
getUuid
Gets the instance unique id.- Returns:
- the instance unique id
-
getUniqueId
Deprecated, for removal: This API element is subject to removal in a future version.Replace withgetUuid()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
-
playSoundExcept
public void playSoundExcept(@Nullable @Nullable Player excludedPlayer, @NotNull @NotNull Sound sound, @NotNull @NotNull Point point) Plays aSoundat a given point, except to the excluded player- Parameters:
excludedPlayer- The player in the instance who won't receive the soundsound- The sound to playpoint- The point in this instance at which to play the sound
-
playSoundExcept
-
playSoundExcept
public void playSoundExcept(@Nullable @Nullable Player excludedPlayer, @NotNull @NotNull Sound sound, @NotNull Sound.Emitter emitter) -
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 net.kyori.adventure.nbt.CompoundBinaryTag 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
-
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)
-
getUuid()