Class InstanceContainer
- All Implemented Interfaces:
Audience, ForwardingAudience, Identified, Pointered, PacketGroupingAudience, EventHandler<InstanceEvent>, Block.Getter, Block.Setter, Snapshotable, Taggable, TagReadable, TagWritable, Tickable, Schedulable
-
Nested Class Summary
Nested classes/interfaces inherited from interface Block.Getter
Block.Getter.ConditionNested classes/interfaces inherited from interface ForwardingAudience
ForwardingAudience.Single -
Field Summary
FieldsFields inherited from class Instance
chunkViewDistance, INSTANCE_POINTERS_SUPPLIER, tagHandler, uuid -
Constructor Summary
ConstructorsConstructorDescriptionInstanceContainer(UUID uuid, RegistryKey<DimensionType> dimensionType) InstanceContainer(UUID uuid, RegistryKey<DimensionType> dimensionType, Key dimensionName) InstanceContainer(UUID uuid, RegistryKey<DimensionType> dimensionType, @Nullable ChunkLoader loader) InstanceContainer(UUID uuid, RegistryKey<DimensionType> dimensionType, @Nullable ChunkLoader loader, Key dimensionName) InstanceContainer(DynamicRegistry<DimensionType> dimensionTypeRegistry, UUID uuid, RegistryKey<DimensionType> dimensionType, @Nullable ChunkLoader loader, Key dimensionName) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddSharedInstance(SharedInstance sharedInstance) Assigns aSharedInstanceto this container.booleanbreakBlock(Player player, Point blockPosition, 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 ChunkcreateChunk(int chunkX, int chunkZ) voidenableAutoChunkLoad(boolean enable) When set to true, chunks will load automatically when requested.generateChunk(int chunkX, int chunkZ, Generator generator) Runs the providedGeneratorto generate a chunk at the given position.protected voidgenerateChunk(Chunk chunk, Generator generator) Gets the generator associated with the instancegetChunk(int chunkX, int chunkZ) Gets the loadedChunkat a position.Gets theChunkLoaderof this instance.Gets all the instance chunks.Gets the currentChunkSupplier.longGets the last time at which a block changed.Gets all theSharedInstancelinked to this container.Gets 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.loadChunk(int chunkX, int chunkZ) 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 CompletableFuture<Chunk> retrieveChunk(int chunkX, int chunkZ) Saves multiple chunks to permanent storage.saveChunkToStorage(Chunk chunk) Saves aChunkto permanent storage.Saves the current instance tags.voidvoidsetChunkLoader(ChunkLoader chunkLoader) Changes theChunkLoaderof this instance (to change how chunks are retrieved when not already loaded).voidsetChunkSupplier(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(Chunk chunk) Schedules the removal of aChunk, this method does not promise when it will be done.Methods inherited from class Instance
bossBars, 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, getUuid, getWeather, getWorldAge, getWorldBorder, hideBossBar, identity, invalidateSection, 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, showBossBar, tagHandler, unloadChunk, updateSnapshot, viewDistance, viewDistanceMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface 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 Block.Getter
getBlock, getBlock, getBlockMethods inherited from interface Block.Setter
setBlock, setBlockAreaMethods inherited from interface ForwardingAudience
clearResourcePacks, closeDialog, deleteMessage, filterAudience, forEachAudience, openBook, playSound, removeResourcePacks, removeResourcePacks, sendMessage, sendMessage, sendMessage, sendMessage, sendPlayerListFooter, sendPlayerListHeader, sendResourcePacks, showDialogMethods inherited from interface PacketGroupingAudience
audiences, clearTitle, playSound, playSound, playSound, resetTitle, sendActionBar, sendGroupedPacket, sendMessage, sendNotification, sendPlayerListHeaderAndFooter, sendTitlePart, stopSoundMethods inherited from interface Pointered
get, getOrDefault, getOrDefaultFromMethods inherited from interface Taggable
getAndSetTag, getAndUpdateTag, getTag, hasTag, removeTag, setTag, updateAndGetTag, updateTag
-
Field Details
-
srcInstance
-
-
Constructor Details
-
InstanceContainer
-
InstanceContainer
-
InstanceContainer
public InstanceContainer(UUID uuid, RegistryKey<DimensionType> dimensionType, @Nullable @Nullable ChunkLoader loader) -
InstanceContainer
public InstanceContainer(UUID uuid, RegistryKey<DimensionType> dimensionType, @Nullable @Nullable ChunkLoader loader, Key dimensionName) -
InstanceContainer
public InstanceContainer(DynamicRegistry<DimensionType> dimensionTypeRegistry, UUID uuid, RegistryKey<DimensionType> dimensionType, @Nullable @Nullable ChunkLoader loader, Key dimensionName)
-
-
Method Details
-
setBlock
-
placeBlock
- Specified by:
placeBlockin classInstance
-
breakBlock
public boolean breakBlock(Player player, Point blockPosition, 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:Instance- 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
-
generateChunk
-
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
-
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
ChunkLoader.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 nanoseconds. Only use this to calculate delta times
-
refreshLastBlockChangeTime
public void refreshLastBlockChangeTime()Signals the instance that a block changed.Useful if you change blocks values directly using a
Chunkobject. -
generator
-
setGenerator
-
generateChunk
@Experimental public CompletableFuture<Void> generateChunk(int chunkX, int chunkZ, Generator generator) Description copied from class:InstanceRuns the providedGeneratorto generate a chunk at the given position.Loads the chunk if not already loaded.
- Specified by:
generateChunkin classInstance- Parameters:
chunkX- the chunk XchunkZ- the chunk Zgenerator- the generator to use- Returns:
- a future called once the generation is complete
-
getChunks
Gets all the instance chunks. -
getChunkLoader
Gets theChunkLoaderof this instance.- Returns:
- the
ChunkLoaderof this instance
-
setChunkLoader
Changes theChunkLoaderof this instance (to change how chunks are retrieved when not already loaded).ChunkLoader.noop()can be used to do nothing.- Parameters:
chunkLoader- the newChunkLoader
-
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.
-