Class InstanceContainer
- All Implemented Interfaces:
Audience
,ForwardingAudience
,Pointered
,PacketGroupingAudience
,EventHandler<InstanceEvent>
,Block.Getter
,Block.Setter
,Snapshotable
,Taggable
,TagReadable
,TagWritable
,Tickable
,Schedulable
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.minestom.server.instance.block.Block.Getter
Block.Getter.Condition
Nested classes/interfaces inherited from interface net.kyori.adventure.audience.ForwardingAudience
ForwardingAudience.Single
-
Field Summary
Fields inherited from class net.minestom.server.instance.Instance
tagHandler, uniqueId
-
Constructor Summary
ConstructorDescriptionInstanceContainer
(@NotNull UUID uniqueId, DynamicRegistry.Key<DimensionType> dimensionType) InstanceContainer
(@NotNull UUID uniqueId, DynamicRegistry.Key<DimensionType> dimensionType, @Nullable IChunkLoader loader) InstanceContainer
(@NotNull UUID uniqueId, DynamicRegistry.Key<DimensionType> dimensionType, @Nullable IChunkLoader loader, @NotNull NamespaceID dimensionName) InstanceContainer
(@NotNull UUID uniqueId, DynamicRegistry.Key<DimensionType> dimensionType, @NotNull NamespaceID dimensionName) InstanceContainer
(@NotNull DynamicRegistry<DimensionType> dimensionTypeRegistry, @NotNull UUID uniqueId, DynamicRegistry.Key<DimensionType> dimensionType, @Nullable IChunkLoader loader, @NotNull NamespaceID dimensionName) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addSharedInstance
(SharedInstance sharedInstance) Assigns aSharedInstance
to this container.boolean
breakBlock
(@NotNull Player player, @NotNull Point blockPosition, @NotNull BlockFace blockFace, boolean doBlockUpdates) Does callPlayerBlockBreakEvent
and send particle packetscopy()
Copies all the chunks of this instance and create a new instance container with all of them.protected @NotNull CompletableFuture
<@NotNull Chunk> createChunk
(int chunkX, int chunkZ) void
enableAutoChunkLoad
(boolean enable) When set to true, chunks will load automatically when requested.@Nullable Generator
Gets the generator associated with the instancegetChunk
(int chunkX, int chunkZ) Gets the loadedChunk
at a position.@NotNull IChunkLoader
Gets theIChunkLoader
of this instance.@NotNull Collection
<@NotNull Chunk> Gets all the instance chunks.Gets the currentChunkSupplier
.long
Gets the last time at which a block changed.Gets all theSharedInstance
linked to this container.@Nullable InstanceContainer
Gets the instance from which this one has been copied.boolean
Gets if the instance should auto load chunks.boolean
Gets if this instance hasSharedInstance
linked to it.boolean
Determines whether a position in the void.@NotNull CompletableFuture
<Chunk> loadChunk
(int chunkX, int chunkZ) @NotNull CompletableFuture
<Chunk> loadOptionalChunk
(int chunkX, int chunkZ) Loads the chunk if the chunk is already loaded or ifInstance.hasEnabledAutoChunkLoad()
returns true.boolean
placeBlock
(BlockHandler.Placement placement, boolean doBlockUpdates) void
Signals the instance that a block changed.protected @NotNull CompletableFuture
<@NotNull Chunk> retrieveChunk
(int chunkX, int chunkZ) @NotNull CompletableFuture
<Void> Saves multiple chunks to permanent storage.@NotNull CompletableFuture
<Void> saveChunkToStorage
(@NotNull Chunk chunk) Saves aChunk
to permanent storage.@NotNull CompletableFuture
<Void> Saves the current instance tags.void
void
setChunkLoader
(@NotNull IChunkLoader chunkLoader) Changes theIChunkLoader
of this instance (to change how chunks are retrieved when not already loaded).void
setChunkSupplier
(@NotNull ChunkSupplier chunkSupplier) Changes which type ofChunk
implementation to use once one needs to be loaded.void
setGenerator
(@Nullable Generator generator) Changes the generator of the instancevoid
tick
(long time) Performs a single tick in the instance, including scheduled tasks fromInstance.scheduleNextTick(Consumer)
.void
unloadChunk
(@NotNull Chunk chunk) Schedules the removal of aChunk
, this method does not promise when it will be done.Methods inherited from class net.minestom.server.instance.Instance
breakBlock, createInitializeWorldBorderPacket, createTimePacket, eventNode, explode, explode, getBlock, getBlockLight, getCachedDimensionType, getChunkAt, getChunkAt, getChunkEntities, getCreatures, getDimensionName, getDimensionType, getEntities, getEntityById, getEntityByUuid, getEntityTracker, getExperienceOrbs, getExplosionSupplier, getNearbyEntities, getPlayerByUuid, getPlayers, getSkyLight, getTime, getTimeRate, getTimeSynchronizationTicks, getUniqueId, getWeather, getWorldAge, getWorldBorder, isChunkLoaded, isChunkLoaded, isRegistered, loadChunk, loadOptionalChunk, placeBlock, playSoundExcept, playSoundExcept, playSoundExcept, pointers, scheduleNextTick, scheduler, sendBlockAction, setBlock, setBlock, setExplosionSupplier, setRegistered, setTime, setTimeRate, setTimeSynchronizationTicks, setWeather, setWeather, setWorldAge, setWorldBorder, setWorldBorder, tagHandler, unloadChunk, updateSnapshot
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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, stopSound
Methods inherited from interface net.minestom.server.instance.block.Block.Getter
getBlock, getBlock, getBlock
Methods inherited from interface net.minestom.server.instance.block.Block.Setter
setBlock
Methods inherited from interface net.kyori.adventure.audience.ForwardingAudience
clearResourcePacks, deleteMessage, filterAudience, forEachAudience, openBook, playSound, removeResourcePacks, removeResourcePacks, sendMessage, sendMessage, sendMessage, sendMessage, sendPlayerListFooter, sendPlayerListHeader, sendResourcePacks
Methods inherited from interface net.minestom.server.adventure.audience.PacketGroupingAudience
audiences, clearTitle, hideBossBar, playSound, playSound, playSound, resetTitle, sendActionBar, sendGroupedPacket, sendMessage, sendPlayerListHeaderAndFooter, sendTitlePart, showBossBar, stopSound
Methods inherited from interface net.kyori.adventure.pointer.Pointered
get, getOrDefault, getOrDefaultFrom
Methods inherited from interface net.minestom.server.tag.Taggable
getAndSetTag, getAndUpdateTag, getTag, hasTag, removeTag, setTag, updateAndGetTag, updateTag
-
Field Details
-
srcInstance
-
-
Constructor Details
-
InstanceContainer
public InstanceContainer(@NotNull @NotNull UUID uniqueId, @NotNull DynamicRegistry.Key<DimensionType> dimensionType) -
InstanceContainer
public InstanceContainer(@NotNull @NotNull UUID uniqueId, @NotNull DynamicRegistry.Key<DimensionType> dimensionType, @NotNull @NotNull NamespaceID dimensionName) -
InstanceContainer
public InstanceContainer(@NotNull @NotNull UUID uniqueId, @NotNull DynamicRegistry.Key<DimensionType> dimensionType, @Nullable @Nullable IChunkLoader loader) -
InstanceContainer
public InstanceContainer(@NotNull @NotNull UUID uniqueId, @NotNull DynamicRegistry.Key<DimensionType> dimensionType, @Nullable @Nullable IChunkLoader loader, @NotNull @NotNull NamespaceID dimensionName) -
InstanceContainer
public InstanceContainer(@NotNull @NotNull DynamicRegistry<DimensionType> dimensionTypeRegistry, @NotNull @NotNull UUID uniqueId, @NotNull DynamicRegistry.Key<DimensionType> dimensionType, @Nullable @Nullable IChunkLoader loader, @NotNull @NotNull NamespaceID dimensionName)
-
-
Method Details
-
setBlock
-
placeBlock
- Specified by:
placeBlock
in classInstance
-
breakBlock
public boolean breakBlock(@NotNull @NotNull Player player, @NotNull @NotNull Point blockPosition, @NotNull @NotNull BlockFace blockFace, boolean doBlockUpdates) Description copied from class:Instance
Does callPlayerBlockBreakEvent
and send particle packets- Specified by:
breakBlock
in classInstance
- Parameters:
player
- thePlayer
who 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
Description copied from class:Instance
- Specified by:
loadChunk
in classInstance
- Parameters:
chunkX
- the chunk XchunkZ
- the chunk Z- Returns:
- a
CompletableFuture
completed once the chunk has been loaded
-
loadOptionalChunk
Description copied from class:Instance
Loads the chunk if the chunk is already loaded or ifInstance.hasEnabledAutoChunkLoad()
returns true.- Specified by:
loadOptionalChunk
in classInstance
- Parameters:
chunkX
- the chunk XchunkZ
- the chunk Z- Returns:
- a
CompletableFuture
completed once the chunk has been processed, can be null if not loaded
-
unloadChunk
Description copied from class:Instance
Schedules the removal of aChunk
, this method does not promise when it will be done.WARNING: during unloading, all entities other than
Player
will be removed.- Specified by:
unloadChunk
in classInstance
- Parameters:
chunk
- the chunk to unload
-
getChunk
Description copied from class:Instance
Gets the loadedChunk
at a position.WARNING: this should only return already-loaded chunk, use
Instance.loadChunk(int, int)
or similar to load one instead. -
saveInstance
Description copied from class:Instance
Saves the current instance tags.Warning: only the global instance data will be saved, not chunks. You would need to call
Instance.saveChunksToStorage()
too.- Specified by:
saveInstance
in classInstance
- Returns:
- the future called once the instance data has been saved
-
saveChunkToStorage
Description copied from class:Instance
Saves aChunk
to permanent storage.- Specified by:
saveChunkToStorage
in classInstance
- Parameters:
chunk
- theChunk
to save- Returns:
- future called when the chunk is done saving
-
saveChunksToStorage
Description copied from class:Instance
Saves multiple chunks to permanent storage.- Specified by:
saveChunksToStorage
in classInstance
- Returns:
- future called when the chunks are done saving
-
retrieveChunk
-
createChunk
-
enableAutoChunkLoad
public void enableAutoChunkLoad(boolean enable) Description copied from class:Instance
When set to true, chunks will load automatically when requested. Otherwise usingInstance.loadChunk(int, int)
will be required to even spawn a player- Specified by:
enableAutoChunkLoad
in classInstance
- Parameters:
enable
- enable the auto chunk load
-
hasEnabledAutoChunkLoad
public boolean hasEnabledAutoChunkLoad()Description copied from class:Instance
Gets if the instance should auto load chunks.- Specified by:
hasEnabledAutoChunkLoad
in classInstance
- Returns:
- true if auto chunk load is enabled, false otherwise
-
isInVoid
Description copied from class:Instance
Determines whether a position in the void. -
setChunkSupplier
Changes which type ofChunk
implementation to use once one needs to be loaded.Uses
DynamicChunk
by default.WARNING: if you need to save this instance's chunks later, the code needs to be predictable for
IChunkLoader.loadChunk(Instance, int, int)
to create the correct type ofChunk
. tl;dr: Need chunk save = no random type.- Specified by:
setChunkSupplier
in classInstance
- Parameters:
chunkSupplier
- the newChunkSupplier
of this instance, chunks need to be non-null- Throws:
NullPointerException
- ifchunkSupplier
is null
-
getChunkSupplier
Gets the currentChunkSupplier
.You shouldn't use it to generate a new chunk, but as a way to view which one is currently in use.
- Specified by:
getChunkSupplier
in classInstance
- Returns:
- the current
ChunkSupplier
-
copy
Copies all the chunks of this instance and create a new instance container with all of them.Chunks are copied with
Chunk.copy(Instance, int, int)
,UUID
is randomized andDimensionType
is passed over.- Returns:
- an
InstanceContainer
with the exact same chunks as 'this' - See Also:
-
getSrcInstance
Gets the instance from which this one has been copied.Only present if this instance has been created with
copy()
.- Returns:
- the instance source, null if not created by a copy
- See Also:
-
getLastBlockChangeTime
public long getLastBlockChangeTime()Gets the last time at which a block changed.- Returns:
- the time at which the last block changed in milliseconds, 0 if never
-
refreshLastBlockChangeTime
public void refreshLastBlockChangeTime()Signals the instance that a block changed.Useful if you change blocks values directly using a
Chunk
object. -
generator
Description copied from class:Instance
Gets the generator associated with the instance -
setGenerator
Description copied from class:Instance
Changes the generator of the instance- Specified by:
setGenerator
in classInstance
- Parameters:
generator
- the new generator, or null to disable generation
-
getChunks
Gets all the instance chunks. -
getChunkLoader
Gets theIChunkLoader
of this instance.- Returns:
- the
IChunkLoader
of this instance
-
setChunkLoader
Changes theIChunkLoader
of this instance (to change how chunks are retrieved when not already loaded).IChunkLoader.noop()
can be used to do nothing.- Parameters:
chunkLoader
- the newIChunkLoader
-
tick
public void tick(long time) Description copied from class:Instance
Performs a single tick in the instance, including scheduled tasks fromInstance.scheduleNextTick(Consumer)
.Warning: this does not update chunks and entities.
-