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 -
Constructor Summary
ConstructorsConstructorDescriptionInstanceContainer
(@NotNull UUID uniqueId, @NotNull DimensionType dimensionType) InstanceContainer
(@NotNull UUID uniqueId, @NotNull DimensionType dimensionType, @Nullable IChunkLoader loader) -
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) 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.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) Forces the generation of aChunk
, even if no file andChunkGenerator
are defined.@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) 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
(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
createTimePacket, eventNode, explode, explode, getBlock, getChunkAt, getChunkAt, getChunkEntities, getCreatures, getDimensionType, getEntities, getEntityTracker, getExperienceOrbs, getExplosionSupplier, getInstanceSpace, getNearbyEntities, getPlayers, getTime, getTimeRate, getTimeUpdate, getUniqueId, getWorldAge, getWorldBorder, isChunkLoaded, isChunkLoaded, isRegistered, loadChunk, loadOptionalChunk, pointers, scheduleNextTick, scheduler, sendBlockAction, setChunkGenerator, setExplosionSupplier, setRegistered, setTime, setTimeRate, setTimeUpdate, 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, sendActionBar, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendPlayerListFooter, sendPlayerListHeader, sendPlayerListHeaderAndFooter, 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
deleteMessage, filterAudience, forEachAudience, openBook, playSound, sendMessage, sendMessage, sendMessage, sendMessage, sendPlayerListFooter, sendPlayerListHeader
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
-
Field Details
-
srcInstance
-
-
Constructor Details
-
InstanceContainer
@Experimental public InstanceContainer(@NotNull @NotNull UUID uniqueId, @NotNull @NotNull DimensionType dimensionType, @Nullable @Nullable IChunkLoader loader) -
InstanceContainer
public InstanceContainer(@NotNull @NotNull UUID uniqueId, @NotNull @NotNull DimensionType dimensionType)
-
-
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) 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 block- Returns:
- true if the block has been broken, false if it has been cancelled
-
loadChunk
Description copied from class:Instance
Forces the generation of aChunk
, even if no file andChunkGenerator
are defined.- 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. If true, entities should take damage and die.Always returning false allow entities to survive 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.- 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.
- 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).- 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.
-