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.ConditionNested classes/interfaces inherited from interface net.kyori.adventure.audience.ForwardingAudience
ForwardingAudience.Single -
Field Summary
FieldsFields inherited from class net.minestom.server.instance.Instance
tagHandler, uniqueId -
Constructor Summary
ConstructorsConstructorDescriptionInstanceContainer(@NotNull UUID uniqueId, @NotNull DimensionType dimensionType) InstanceContainer(@NotNull UUID uniqueId, @NotNull DimensionType dimensionType, @Nullable IChunkLoader loader) InstanceContainer(@NotNull UUID uniqueId, @NotNull DimensionType dimensionType, @Nullable IChunkLoader loader, @NotNull NamespaceID dimensionName) InstanceContainer(@NotNull UUID uniqueId, @NotNull DimensionType dimensionType, @NotNull NamespaceID dimensionName) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddSharedInstance(SharedInstance sharedInstance) Assigns aSharedInstanceto this container.booleanbreakBlock(@NotNull Player player, @NotNull Point blockPosition, @NotNull BlockFace blockFace, boolean doBlockUpdates) Does callPlayerBlockBreakEventand 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) voidenableAutoChunkLoad(boolean enable) When set to true, chunks will load automatically when requested.@Nullable GeneratorGets the generator associated with the instancegetChunk(int chunkX, int chunkZ) Gets the loadedChunkat a position.Gets theIChunkLoaderof this instance.@NotNull Collection<@NotNull Chunk> Gets all the instance chunks.Gets the currentChunkSupplier.longGets the last time at which a block changed.Gets all theSharedInstancelinked to this container.@Nullable InstanceContainerGets the instance from which this one has been copied.booleanGets if the instance should auto load chunks.booleanGets if this instance hasSharedInstancelinked to it.booleanDetermines whether a position in the void.@NotNull CompletableFuture<Chunk> loadChunk(int chunkX, int chunkZ) Forces the generation of aChunk, even if no file andChunkGeneratorare defined.@NotNull CompletableFuture<Chunk> loadOptionalChunk(int chunkX, int chunkZ) Loads the chunk if the chunk is already loaded or ifInstance.hasEnabledAutoChunkLoad()returns true.booleanplaceBlock(BlockHandler.Placement placement, boolean doBlockUpdates) voidSignals 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 aChunkto permanent storage.@NotNull CompletableFuture<Void> Saves the current instance tags.voidvoidsetChunkLoader(IChunkLoader chunkLoader) Changes theIChunkLoaderof this instance (to change how chunks are retrieved when not already loaded).voidsetChunkSupplier(@NotNull ChunkSupplier chunkSupplier) Changes which type ofChunkimplementation to use once one needs to be loaded.voidsetGenerator(@Nullable Generator generator) Changes the generator of the instancevoidtick(long time) Performs a single tick in the instance, including scheduled tasks fromInstance.scheduleNextTick(Consumer).voidunloadChunk(@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, createTimePacket, eventNode, explode, explode, getBlock, getBlockLight, getChunkAt, getChunkAt, getChunkEntities, getCreatures, getDimensionName, getDimensionType, getEntities, getEntityTracker, getExperienceOrbs, getExplosionSupplier, getInstanceSpace, getNearbyEntities, getPlayers, getSkyLight, getTime, getTimeRate, getTimeUpdate, getUniqueId, getWeather, getWorldAge, getWorldBorder, getWorldSpawnPosition, isChunkLoaded, isChunkLoaded, isRegistered, loadChunk, loadOptionalChunk, placeBlock, pointers, scheduleNextTick, scheduler, sendBlockAction, setBlock, setBlock, setChunkGenerator, setExplosionSupplier, setRegistered, setTime, setTimeRate, setTimeUpdate, setWeather, setWeather, setWorldSpawnPosition, setWorldSpawnPosition, tagHandler, unloadChunk, updateSnapshotMethods 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
-
srcInstance
-
-
Constructor Details
-
InstanceContainer
public InstanceContainer(@NotNull @NotNull UUID uniqueId, @NotNull @NotNull DimensionType dimensionType) -
InstanceContainer
public InstanceContainer(@NotNull @NotNull UUID uniqueId, @NotNull @NotNull DimensionType dimensionType, @NotNull @NotNull NamespaceID dimensionName) -
InstanceContainer
@Experimental public InstanceContainer(@NotNull @NotNull UUID uniqueId, @NotNull @NotNull DimensionType dimensionType, @Nullable @Nullable IChunkLoader loader) -
InstanceContainer
@Experimental public InstanceContainer(@NotNull @NotNull UUID uniqueId, @NotNull @NotNull DimensionType dimensionType, @Nullable @Nullable IChunkLoader loader, @NotNull @NotNull NamespaceID dimensionName)
-
-
Method Details
-
setBlock
-
placeBlock
- Specified by:
placeBlockin classInstance
-
breakBlock
public boolean breakBlock(@NotNull @NotNull Player player, @NotNull @NotNull Point blockPosition, @NotNull @NotNull BlockFace blockFace, boolean doBlockUpdates) Description copied from class:InstanceDoes callPlayerBlockBreakEventand send particle packets- Specified by:
breakBlockin classInstance- 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
Description copied from class:InstanceForces the generation of aChunk, even if no file andChunkGeneratorare defined.- Specified by:
loadChunkin classInstance- Parameters:
chunkX- the chunk XchunkZ- the chunk Z- Returns:
- a
CompletableFuturecompleted once the chunk has been loaded
-
loadOptionalChunk
Description copied from class:InstanceLoads the chunk if the chunk is already loaded or ifInstance.hasEnabledAutoChunkLoad()returns true.- Specified by:
loadOptionalChunkin classInstance- Parameters:
chunkX- the chunk XchunkZ- the chunk Z- Returns:
- a
CompletableFuturecompleted once the chunk has been processed, can be null if not loaded
-
unloadChunk
Description copied from class:InstanceSchedules the removal of aChunk, this method does not promise when it will be done.WARNING: during unloading, all entities other than
Playerwill be removed.- Specified by:
unloadChunkin classInstance- Parameters:
chunk- the chunk to unload
-
getChunk
Description copied from class:InstanceGets the loadedChunkat 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:InstanceSaves 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:
saveInstancein classInstance- Returns:
- the future called once the instance data has been saved
-
saveChunkToStorage
Description copied from class:InstanceSaves aChunkto permanent storage.- Specified by:
saveChunkToStoragein classInstance- Parameters:
chunk- theChunkto save- Returns:
- future called when the chunk is done saving
-
saveChunksToStorage
Description copied from class:InstanceSaves multiple chunks to permanent storage.- Specified by:
saveChunksToStoragein classInstance- Returns:
- future called when the chunks are done saving
-
retrieveChunk
-
createChunk
-
enableAutoChunkLoad
public void enableAutoChunkLoad(boolean enable) Description copied from class:InstanceWhen set to true, chunks will load automatically when requested. Otherwise usingInstance.loadChunk(int, int)will be required to even spawn a player- Specified by:
enableAutoChunkLoadin classInstance- Parameters:
enable- enable the auto chunk load
-
hasEnabledAutoChunkLoad
public boolean hasEnabledAutoChunkLoad()Description copied from class:InstanceGets if the instance should auto load chunks.- Specified by:
hasEnabledAutoChunkLoadin classInstance- Returns:
- true if auto chunk load is enabled, false otherwise
-
isInVoid
Description copied from class:InstanceDetermines whether a position in the void. -
setChunkSupplier
Changes which type ofChunkimplementation to use once one needs to be loaded.Uses
DynamicChunkby 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:
setChunkSupplierin classInstance- Parameters:
chunkSupplier- the newChunkSupplierof this instance, chunks need to be non-null- Throws:
NullPointerException- ifchunkSupplieris 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:
getChunkSupplierin 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),UUIDis randomized andDimensionTypeis passed over.- Returns:
- an
InstanceContainerwith 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
Chunkobject. -
generator
Description copied from class:InstanceGets the generator associated with the instance -
setGenerator
Description copied from class:InstanceChanges the generator of the instance- Specified by:
setGeneratorin classInstance- Parameters:
generator- the new generator, or null to disable generation
-
getChunks
Gets all the instance chunks. -
getChunkLoader
Gets theIChunkLoaderof this instance.- Returns:
- the
IChunkLoaderof this instance
-
setChunkLoader
Changes theIChunkLoaderof this instance (to change how chunks are retrieved when not already loaded).- Parameters:
chunkLoader- the newIChunkLoader
-
tick
public void tick(long time) Description copied from class:InstancePerforms a single tick in the instance, including scheduled tasks fromInstance.scheduleNextTick(Consumer).Warning: this does not update chunks and entities.
-