Class SharedInstance
- All Implemented Interfaces:
DataContainer
,EventHandler
,BlockModifier
public class SharedInstance extends Instance
SharedInstance
is an instance that shares the same chunks as its linked InstanceContainer
,
entities are separated.-
Field Summary
Fields inherited from class net.minestom.server.instance.Instance
BLOCK_MANAGER, chunkEntities, creatures, entities, experienceOrbs, nextTick, objectEntities, players, uniqueId, UPDATE_MANAGER
-
Constructor Summary
Constructors Constructor Description SharedInstance(java.util.UUID uniqueId, InstanceContainer instanceContainer)
-
Method Summary
Modifier and Type Method Description boolean
breakBlock(Player player, BlockPosition blockPosition)
Does callPlayerBlockBreakEvent
and send particle packetsBlockBatch
createBlockBatch()
Creates a newBlockBatch
linked to this instance.protected void
createChunk(int chunkX, int chunkZ, ChunkCallback callback)
Called to generated a newChunk
from scratch.ChunkBatch
createChunkBatch(Chunk chunk)
Creates a newChunk
batch linked to this instance and the specified chunk.void
enableAutoChunkLoad(boolean enable)
When set to true, chunks will load automatically when requested.Chunk
getChunk(int chunkX, int chunkZ)
Gets the loadedChunk
at a position.ChunkGenerator
getChunkGenerator()
Gets the instanceChunkGenerator
.java.util.Collection<Chunk>
getChunks()
Gets all the instance's chunks.InstanceContainer
getInstanceContainer()
Gets theInstanceContainer
from where this instance takes its chunks from.StorageLocation
getStorageLocation()
Gets the instanceStorageLocation
.boolean
hasEnabledAutoChunkLoad()
Gets if the instance should auto load chunks.boolean
isInVoid(Position position)
Determines whether a position in the void.void
loadChunk(int chunkX, int chunkZ, ChunkCallback callback)
Forces the generation of aChunk
, even if no file andChunkGenerator
are defined.void
loadOptionalChunk(int chunkX, int chunkZ, ChunkCallback callback)
Loads the chunk if the chunk is already loaded or ifInstance.hasEnabledAutoChunkLoad()
returns true.void
refreshBlockStateId(BlockPosition blockPosition, short blockStateId)
Used to change the id of the block in a specificBlockPosition
.void
retrieveChunk(int chunkX, int chunkZ, ChunkCallback callback)
Used when aChunk
is not currently loaded in memory and need to be retrieved from somewhere else.void
saveChunksToStorage(java.lang.Runnable callback)
Saves multiple chunks to permanent storage.void
saveChunkToStorage(Chunk chunk, java.lang.Runnable callback)
Saves aChunk
to permanent storage.void
scheduleUpdate(int time, TimeUnit unit, BlockPosition position)
Schedules a block update at a givenBlockPosition
.void
setBlockStateId(int x, int y, int z, short blockStateId, Data data)
Sets a block at a position.void
setChunkGenerator(ChunkGenerator chunkGenerator)
Changes the instanceChunkGenerator
.void
setCustomBlock(int x, int y, int z, short customBlockId, Data data)
Sets aCustomBlock
at a position.void
setSeparateBlocks(int x, int y, int z, short blockStateId, short customBlockId, Data data)
Sets aCustomBlock
at a position with a custom state id.void
setStorageLocation(StorageLocation storageLocation)
Changes the instanceStorageLocation
.void
unloadChunk(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
addEntityToChunk, explode, explode, getBlockData, getBlockData, getBlockStateId, getBlockStateId, getBlockStateId, getChunkAt, getChunkAt, getChunkAt, getChunkEntities, getCreatures, getCustomBlock, getCustomBlock, getData, getDimensionType, getEntities, getEventCallbacksMap, getExperienceOrbs, getExplosionSupplier, getInstanceSpace, getObjectEntities, getPlayers, getTime, getTimeRate, getTimeUpdate, getUniqueId, getWorldAge, getWorldBorder, isChunkLoaded, isRegistered, loadChunk, loadChunk, loadOptionalChunk, refreshBlockId, refreshBlockId, refreshBlockStateId, removeEntityFromChunk, saveChunksToStorage, saveChunkToStorage, scheduleNextTick, sendBlockAction, setBlockData, setBlockData, setData, setExplosionSupplier, setRegistered, setTime, setTimeRate, setTimeUpdate, tick, unloadChunk, UNSAFE_addEntity, UNSAFE_removeEntity
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.minestom.server.instance.BlockModifier
setBlock, setBlock, setBlockStateId, setBlockStateId, setCustomBlock, setCustomBlock, setCustomBlock, setCustomBlock, setSeparateBlocks, setSeparateBlocks
Methods inherited from interface net.minestom.server.event.handler.EventHandler
addEventCallback, callCancellableEvent, callEvent, getEventCallbacks, getEventCallbacks, removeEventCallback
-
Constructor Details
-
SharedInstance
public SharedInstance(@NotNull java.util.UUID uniqueId, @NotNull InstanceContainer instanceContainer)
-
-
Method Details
-
refreshBlockStateId
Description copied from class:Instance
Used to change the id of the block in a specificBlockPosition
.In case of a
CustomBlock
it does not remove it but only refresh its visual.- Specified by:
refreshBlockStateId
in classInstance
- Parameters:
blockPosition
- the block positionblockStateId
- the new block state
-
breakBlock
Description copied from class:Instance
Does callPlayerBlockBreakEvent
and send particle packets- Specified by:
breakBlock
in classInstance
- Parameters:
player
- thePlayer
who break the blockblockPosition
- theBlockPosition
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. -
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 Zcallback
- optional consumer called after the chunk has tried to be loaded, contains a chunk if it is successful, null otherwise
-
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.For
InstanceContainer
it is done during the nextInstanceContainer.tick(long)
.- 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. -
saveChunkToStorage
Description copied from class:Instance
Saves aChunk
to permanent storage.- Specified by:
saveChunkToStorage
in classInstance
- Parameters:
chunk
- theChunk
to savecallback
- optional callback called when theChunk
is done saving
-
saveChunksToStorage
public void saveChunksToStorage(@Nullable java.lang.Runnable callback)Description copied from class:Instance
Saves multiple chunks to permanent storage.- Specified by:
saveChunksToStorage
in classInstance
- Parameters:
callback
- optional callback called when the chunks are done saving
-
createBlockBatch
Description copied from class:Instance
Creates a newBlockBatch
linked to this instance.- Specified by:
createBlockBatch
in classInstance
- Returns:
- a
BlockBatch
linked to the instance
-
createChunkBatch
Description copied from class:Instance
Creates a newChunk
batch linked to this instance and the specified chunk.- Specified by:
createChunkBatch
in classInstance
- Parameters:
chunk
- the chunk to modify- Returns:
- a ChunkBatch linked to
chunk
-
setChunkGenerator
Description copied from class:Instance
Changes the instanceChunkGenerator
.- Specified by:
setChunkGenerator
in classInstance
- Parameters:
chunkGenerator
- the newChunkGenerator
of the instance
-
getChunkGenerator
Description copied from class:Instance
Gets the instanceChunkGenerator
.- Specified by:
getChunkGenerator
in classInstance
- Returns:
- the
ChunkGenerator
of the instance
-
getChunks
Description copied from class:Instance
Gets all the instance's chunks. -
getStorageLocation
Description copied from class:Instance
Gets the instanceStorageLocation
.- Specified by:
getStorageLocation
in classInstance
- Returns:
- the
StorageLocation
of the instance
-
setStorageLocation
Description copied from class:Instance
Changes the instanceStorageLocation
.- Specified by:
setStorageLocation
in classInstance
- Parameters:
storageLocation
- the newStorageLocation
of the instance
-
retrieveChunk
Description copied from class:Instance
Used when aChunk
is not currently loaded in memory and need to be retrieved from somewhere else. Could be read from disk, or generated from scratch.Be sure to signal the chunk using
UpdateManager.signalChunkLoad(Instance, int, int)
and to cache that this chunk has been loaded.WARNING: it has to retrieve a chunk, this is not optional and should execute the callback in all case.
- Specified by:
retrieveChunk
in classInstance
- Parameters:
chunkX
- the chunk XchunkZ
- the chunk Xcallback
- the optional callback executed once theChunk
has been retrieved
-
createChunk
Description copied from class:Instance
Called to generated a newChunk
from scratch.Be sure to signal the chunk using
UpdateManager.signalChunkLoad(Instance, int, int)
and to cache that this chunk has been loaded.This is where you can put your chunk generation code.
- Specified by:
createChunk
in classInstance
- Parameters:
chunkX
- the chunk XchunkZ
- the chunk Zcallback
- the optional callback executed with the newly createdChunk
-
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.
-
setBlockStateId
Description copied from interface:BlockModifier
Sets a block at a position.You can use
BlockModifier.setBlock(int, int, int, Block)
if you want it to be more explicit.- Parameters:
x
- the block Xy
- the block Yz
- the block ZblockStateId
- the block state iddata
- the blockData
, can be null
-
setCustomBlock
Description copied from interface:BlockModifier
Sets aCustomBlock
at a position.The custom block id should be the one returned by
CustomBlock.getCustomBlockId()
.- Parameters:
x
- the block Xy
- the block Yz
- the block ZcustomBlockId
- the custom block iddata
- the blockData
, can be null
-
setSeparateBlocks
public void setSeparateBlocks(int x, int y, int z, short blockStateId, short customBlockId, Data data)Description copied from interface:BlockModifier
Sets aCustomBlock
at a position with a custom state id.The custom block id should be the one returned by
CustomBlock.getCustomBlockId()
, and the block state id can be anything you want, state id can be retrieved usingBlock.getBlockId()
.- Parameters:
x
- the block Xy
- the block Yz
- the block ZblockStateId
- the block state idcustomBlockId
- the custom block iddata
- the blockData
, can be null
-
scheduleUpdate
Description copied from class:Instance
Schedules a block update at a givenBlockPosition
. Does nothing if noCustomBlock
is present atposition
.Cancelled if the block changes between this call and the actual update.
- Specified by:
scheduleUpdate
in classInstance
- Parameters:
time
- in how long this update must be performed?unit
- in what unit is the time expressedposition
- the location of the block to update
-
getInstanceContainer
Gets theInstanceContainer
from where this instance takes its chunks from.- Returns:
- the associated
InstanceContainer
-