Class Instance
- All Implemented Interfaces:
Audience, ForwardingAudience, Identified, 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 Block.Getter
Block.Getter.ConditionNested classes/interfaces inherited from interface ForwardingAudience
ForwardingAudience.Single -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected static final PointersSupplier<Instance> protected TagHandlerprotected UUID -
Constructor Summary
ConstructorsConstructorDescriptionInstance(UUID uuid, RegistryKey<DimensionType> dimensionType) Creates a new instance.Instance(UUID uuid, RegistryKey<DimensionType> dimensionType, Key dimensionName) Creates a new instance.Instance(DynamicRegistry<DimensionType> dimensionTypeRegistry, UUID uuid, RegistryKey<DimensionType> dimensionType, Key dimensionName) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionbossBars()booleanbreakBlock(Player player, Point blockPosition, BlockFace blockFace) Does callPlayerBlockBreakEventand send particle packetsabstract booleanbreakBlock(Player player, Point blockPosition, BlockFace blockFace, boolean doBlockUpdates) Does callPlayerBlockBreakEventand send particle packetsCreates theInitializeWorldBorderPacketsent to players who join this instance.Creates aTimeUpdatePacketwith the current age and time of this instanceabstract voidenableAutoChunkLoad(boolean enable) When set to true, chunks will load automatically when requested.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 CompoundBinaryTag additionalData) Creates an explosion at the given position with the given strength.abstract CompletableFuture<Void> generateChunk(int chunkX, int chunkZ, Generator generator) Runs the providedGeneratorto generate a chunk at the given position.Gets the generator associated with the instancegetBlock(int x, int y, int z, Block.Getter.Condition condition) intgetBlockLight(int blockX, int blockY, int blockZ) getChunk(int chunkX, int chunkZ) Gets the loadedChunkat a position.getChunkAt(double x, double z) Gets theChunkat the given block position, null if not loaded.getChunkAt(Point point) getChunkEntities(Chunk chunk) Gets the entities located in the chunk.abstract Collection<Chunk> Gets all the instance's loaded chunks.abstract ChunkSupplierGets the chunk supplier of the instance.Deprecated.Gets the instance dimension name.Gets the instanceDimensionType.Gets the entities in the instance;getEntityById(int id) Gets an entity based on its id (fromEntity.getEntityId()).getEntityByUuid(UUID uuid) Gets an entity based on its UUID (fromEntity.getUuid()).Deprecated.Gets the registeredExplosionSupplier, or null if none was provided.getNearbyEntities(Point point, double range) Gets nearby entities to the given position.getPlayerByUuid(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 timeDeprecated, for removal: This API element is subject to removal in a future version.getUuid()Gets the instance unique id.Gets the weather of this instancelongGets the age of this instance in tick.Gets the current state of the instanceWorldBorder.abstract booleanGets if the instance should auto load chunks.voidhideBossBar(BossBar bar) Hides aBossBarfrom all players in the instance and stops tracking it.identity()voidinvalidateSection(int sectionX, int sectionY, int sectionZ) 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 CompletableFuture<Chunk> loadChunk(int chunkX, int chunkZ) Loads the chunk at the givenPointwith a callback.abstract CompletableFuture<@Nullable Chunk> loadOptionalChunk(int chunkX, int chunkZ) Loads the chunk if the chunk is already loaded or ifhasEnabledAutoChunkLoad()returns true.loadOptionalChunk(Point point) booleanplaceBlock(BlockHandler.Placement placement) abstract booleanplaceBlock(BlockHandler.Placement placement, boolean doBlockUpdates) voidplaySoundExcept(@Nullable Player excludedPlayer, Sound sound, double x, double y, double z) voidplaySoundExcept(@Nullable Player excludedPlayer, Sound sound, Sound.Emitter emitter) voidplaySoundExcept(@Nullable Player excludedPlayer, Sound sound, Point point) Plays aSoundat a given point, except to the excluded playerpointers()abstract CompletableFuture<Void> Saves multiple chunks to permanent storage.abstract CompletableFuture<Void> saveChunkToStorage(Chunk chunk) Saves aChunkto permanent storage.abstract CompletableFuture<Void> Saves the current instance tags.voidscheduleNextTick(Consumer<Instance> callback) Schedules a task to be run during the next instance tick.voidsendBlockAction(Point blockPosition, byte actionId, byte actionParam) Sends aBlockActionPacketfor all the viewers of the specific position.voidabstract voidvoidabstract voidsetChunkSupplier(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(Weather weather) Sets the weather of this instance with a fixed transitionvoidsetWeather(Weather weather, int transitionTicks) Sets the weather on this instance, transitions over timevoidsetWorldAge(long worldAge) Sets the age of this instance in tick.voidsetWorldBorder(WorldBorder worldBorder) Set the instanceWorldBorderwith an instant transition.voidsetWorldBorder(WorldBorder worldBorder, double transitionTime) Set the instanceWorldBorderwith a smooth transition.voidshowBossBar(BossBar bar) Shows aBossBarto all players in the instance and tracks it.voidtick(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(Chunk chunk) Schedules the removal of aChunk, this method does not promise when it will be done.updateSnapshot(SnapshotUpdater updater) Updates the currently cached snapshot if required.intGets the chunk view distance of this instance, which defaults toServerFlag.CHUNK_VIEW_DISTANCE.voidviewDistance(int newViewDistance) Sets the chunk view distance of this instanceMethods 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
-
INSTANCE_POINTERS_SUPPLIER
-
chunkViewDistance
protected int chunkViewDistance -
uuid
-
tagHandler
-
-
Constructor Details
-
Instance
Creates a new instance.- Parameters:
uuid- theUUIDof the instancedimensionType- theDimensionTypeof the instance
-
Instance
Creates a new instance.- Parameters:
uuid- theUUIDof the instancedimensionType- theDimensionTypeof the instance
-
Instance
public Instance(DynamicRegistry<DimensionType> dimensionTypeRegistry, UUID uuid, RegistryKey<DimensionType> dimensionType, Key dimensionName) Creates a new instance.- Parameters:
uuid- theUUIDof the instancedimensionType- theDimensionTypeof the instance
-
-
Method Details
-
scheduleNextTick
-
setBlock
- Specified by:
setBlockin interfaceBlock.Setter
-
setBlock
-
setBlock
-
placeBlock
-
placeBlock
@Internal public abstract boolean placeBlock(BlockHandler.Placement placement, boolean doBlockUpdates) -
breakBlock
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(Player player, Point blockPosition, 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
- 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
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
- Parameters:
point- the chunk position- Returns:
- a
CompletableFuturecompleted once the chunk has been processed, can be null if not loaded
-
unloadChunk
-
unloadChunk
public void unloadChunk(int chunkX, int chunkZ) Unloads the chunk at the given position.- Parameters:
chunkX- the chunk XchunkZ- the chunk Z
-
invalidateSection
public void invalidateSection(int sectionX, int sectionY, int sectionZ) -
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
-
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
-
setGenerator
-
generateChunk
@Experimental public abstract CompletableFuture<Void> generateChunk(int chunkX, int chunkZ, Generator generator) Runs the providedGeneratorto generate a chunk at the given position.Loads the chunk if not already loaded.
- 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'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
-
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
-
getNearbyEntities
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
- 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
-
getChunkAt
-
getEntityTracker
-
getUuid
-
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
-
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
-
viewDistance
public int viewDistance()Gets the chunk view distance of this instance, which defaults toServerFlag.CHUNK_VIEW_DISTANCE.- Returns:
- The chunk view distance of this instance
-
viewDistance
public void viewDistance(int newViewDistance) Sets the chunk view distance of this instance- Parameters:
newViewDistance- the new view distance
-
showBossBar
Shows aBossBarto all players in the instance and tracks it.- Specified by:
showBossBarin interfaceAudience- Specified by:
showBossBarin interfaceForwardingAudience- Specified by:
showBossBarin interfacePacketGroupingAudience- Parameters:
bar- a boss bar
-
hideBossBar
Hides aBossBarfrom all players in the instance and stops tracking it.- Specified by:
hideBossBarin interfaceAudience- Specified by:
hideBossBarin interfaceForwardingAudience- Specified by:
hideBossBarin interfacePacketGroupingAudience- Parameters:
bar- a boss bar
-
bossBars
-
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
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, Sound sound, 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 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
-
identity
- Specified by:
identityin interfaceIdentified
-
getBlockLight
public int getBlockLight(int blockX, int blockY, int blockZ) -
getSkyLight
public int getSkyLight(int blockX, int blockY, int blockZ)
-
getUuid()