Hytale Server API - World and Chunk System

World

Location: com/hypixel/hytale/server/core/universe/world/World.java

public class World extends TickingThread implements Executor, ChunkAccessor<WorldChunk>, IWorldChunks, IMessageReceiver

Fields:

FieldTypeDescription
nameStringWorld identifier
savePathPathDisk storage path
worldConfigWorldConfigWorld configuration
chunkStoreChunkStoreChunk storage manager
entityStoreEntityStoreEntity storage manager
chunkLightingChunkLightingManagerLighting system
worldMapManagerWorldMapManagerWorld map manager
worldPathConfigWorldPathConfigPath configuration
taskQueueDequeTask execution queue
aliveAtomicBooleanWorld alive state
eventRegistryEventRegistryEvent system
isTickingbooleanWhether world updates
isPausedbooleanWhether world is paused
ticklongCurrent tick counter
randomRandomRandom generator
entitySeedAtomicIntegerEntity RNG seed
playersMap<UUID, PlayerRef>Connected players

Constants:

  • SAVE_INTERVAL = 10.0f
  • DEFAULT = "default"

Key Methods:

CompletableFuture<World> init()
CompletableFuture<PlayerRef> addPlayer(PlayerRef, Transform, Boolean, Boolean)
CompletableFuture<Void> drainPlayersTo(World)
WorldChunk loadChunkIfInMemory(long index)
WorldChunk getChunkIfLoaded(long index)
WorldChunk getChunkIfInMemory(long index)
WorldChunk getChunkIfNonTicking(long index)
CompletableFuture<WorldChunk> getChunkAsync(long index)
void sendMessage(Message)
void consumeTaskQueue()
void setPaused(boolean)
void setTicking(boolean)
GameplayConfig getGameplayConfig()
DeathConfig getDeathConfig()
int getPlayerCount()
Collection<PlayerRef> getPlayerRefs()

Universe

Location: com/hypixel/hytale/server/core/universe/Universe.java

public class Universe extends JavaPlugin implements IMessageReceiver, MetricProvider

Fields:

FieldTypeDescription
pathPathUniverse root directory
playersMap<UUID, PlayerRef>All connected players
worldsMap<String, World>Worlds by name
worldsByUuidMap<UUID, World>Worlds by UUID
playerStoragePlayerStoragePlayer data storage
worldConfigProviderWorldConfigProviderConfig loader
universeReadyCompletableFutureReady signal

Key Methods:

static Universe get()
CompletableFuture<World> addWorld(String name)
CompletableFuture<World> makeWorld(String name, Path savePath, WorldConfig config, boolean start)
CompletableFuture<World> loadWorld(String name)
World getWorld(String worldName)
World getWorld(UUID uuid)
World getDefaultWorld()
boolean removeWorld(String name)
void removeWorldExceptionally(String name)
List<PlayerRef> getPlayers()
PlayerRef getPlayer(UUID uuid)
PlayerRef getPlayer(String value, NameMatching matching)
CompletableFuture<PlayerRef> addPlayer(Channel, String, ProtocolVersion, UUID, String, PlayerAuthentication, int, PlayerSkin)
void removePlayer(PlayerRef)
CompletableFuture<void> runBackup()

WorldChunk

Location: com/hypixel/hytale/server/core/universe/world/chunk/WorldChunk.java

public class WorldChunk implements BlockAccessor, Component<ChunkStore>

Fields:

FieldTypeDescription
worldWorldParent world
flagsLockStampedLockFlag synchronization
flagsFlagsChunk state flags
referenceRefComponent reference
blockChunkBlockChunkBlock data storage
blockComponentChunkBlockComponentChunkBlock entity storage
entityChunkEntityChunkEntity storage
keepAliveintKeep-alive counter (default 15)
activeTimerintActivity timer (default 15)
needsSavingbooleanNeeds save flag
isSavingbooleanCurrently saving
keepLoadedbooleanForce loaded
lightingUpdatesEnabledbooleanLighting updates
chunkLightTimingAtomicLongLighting metrics

Constants:

  • KEEP_ALIVE_DEFAULT = 15

Key Methods:

boolean is(ChunkFlag flag)
boolean not(ChunkFlag flag)
void setFlag(ChunkFlag flag, boolean value)
boolean toggleFlag(ChunkFlag flag)
void initFlags()
BlockChunk getBlockChunk()
BlockComponentChunk getBlockComponentChunk()
EntityChunk getEntityChunk()
int getBlock(int x, int y, int z)
boolean setBlock(int x, int y, int z, int id, BlockType, int rotation, int filler, int settings)
BlockState getState(int x, int y, int z)
void setState(int x, int y, int z, BlockState state, boolean notify)
int getFiller(int x, int y, int z)
int getRotationIndex(int x, int y, int z)
boolean setTicking(int x, int y, int z, boolean ticking)
boolean isTicking(int x, int y, int z)
short getHeight(int x, int z)
int getTint(int x, int z)
boolean getNeedsSaving()
boolean consumeNeedsSaving()
int getX()
int getZ()
long getIndex()

ChunkFlag

Location: com/hypixel/hytale/server/core/universe/world/chunk/ChunkFlag.java

FlagDescription
START_INITInitialization started
INITFully initialized
NEWLY_GENERATEDProcedurally generated
ON_DISKSaved to disk
TICKINGActively ticking

ChunkStore

Location: com/hypixel/hytale/server/core/universe/world/storage/ChunkStore.java

public class ChunkStore implements WorldProvider

Fields:

FieldTypeDescription
worldWorldParent world
storeStoreComponent store
loaderIChunkLoaderChunk I/O loader
saverIChunkSaverChunk I/O saver
generatorIWorldGenWorld generator
chunksLong2ObjectConcurrentHashMapChunk cache
generatorLoadedCompletableFutureGenerator ready
totalGeneratedChunksCountAtomicIntegerGenerated count
totalLoadedChunksCountAtomicIntegerLoaded count

Constants:

  • MAX_FAILURE_BACKOFF_NANOS - 10 seconds
  • FAILURE_BACKOFF_NANOS - 1 millisecond

Key Methods:

World getWorld()
Store<ChunkStore> getStore()
IChunkLoader getLoader()
IChunkSaver getSaver()
IWorldGen getGenerator()
void setGenerator(IWorldGen)
LongSet getChunkIndexes()
int getLoadedChunksCount()
int getTotalGeneratedChunksCount()
int getTotalLoadedChunksCount()
void start(IResourceStorage)
void shutdown()
Ref<ChunkStore> getChunkReference(long index)
Ref<ChunkStore> getChunkSectionReference(int x, int y, int z)
CompletableFuture<Ref<ChunkStore>> getChunkReferenceAsync(long index)
CompletableFuture<Ref<ChunkStore>> getChunkReferenceAsync(long index, int flags)
boolean isChunkOnBackoff(long index, long maxFailureBackoffNanos)
void waitForLoadingChunks()
void remove(Ref<ChunkStore> reference, RemoveReason)

ChunkLoadState Inner Class:

FieldType
lockStampedLock
flagsint
futureCompletableFuture<Ref>
referenceRef
throwableThrowable
failedWhenlong
failedCounterint

ChunkUtil

Location: com/hypixel/hytale/math/util/ChunkUtil.java

Constants:

ConstantValueDescription
BITS5Bits per coordinate
SIZE32Chunk size
SIZE_21024SIZE^2
SIZE_MINUS_131SIZE - 1
SIZE_MASK31Bitmask
SIZE_COLUMNS1024Blocks per chunk
SIZE_COLUMNS_MASK1023Column mask
SIZE_BLOCKS32768Blocks per chunk (32^3)
BITS2102D encoding bits
HEIGHT_SECTIONS10Vertical sections
HEIGHT320World height
HEIGHT_MINUS_1319HEIGHT - 1
MIN_Y0Minimum block Y
MIN_ENTITY_Y-32Minimum entity Y
NOT_FOUNDindexChunk(INT_MIN, INT_MIN)Invalid marker

Coordinate Methods:

long indexChunk(int x, int z)
int xOfChunkIndex(long index)
int zOfChunkIndex(long index)
long indexChunkFromBlock(int blockX, int blockZ)
long indexChunkFromBlock(double blockX, double blockZ)
int chunkCoordinate(int block)
int chunkCoordinate(double block)
int minBlock(int chunkCoord)
int maxBlock(int chunkCoord)
boolean isWithinLocalChunk(int x, int z)
boolean isSameChunk(int x0, int z0, int x1, int z1)
boolean isSameChunkSection(int x0, int y0, int z0, int x1, int y1, int z1)

Block Indexing:

int indexBlock(int x, int y, int z)
int indexBlockInColumn(int x, int y, int z)
int xFromBlockInColumn(int index)
int yFromBlockInColumn(int index)
int zFromBlockInColumn(int index)
int localCoordinate(long v)

Encoding:

  • Block index: ((y & 31) << 10) | ((z & 31) << 5) | (x & 31)
  • Chunk index: (chunkX << 32) | chunkZ

BlockChunk

Location: com/hypixel/hytale/server/core/universe/world/chunk/BlockChunk.java

public class BlockChunk implements Component<ChunkStore>

Fields:

FieldTypeDescription
indexlongChunk index
xintChunk X
zintChunk Z
heightShortBytePaletteHeightmap (32x32)
tintIntBytePaletteColor tints (32x32)
chunkSectionsBlockSection[]10 vertical sections
environmentsEnvironmentChunkEnvironment data
needsPhysicsbooleanPhysics recalc flag
needsSavingbooleanSave needed flag

Constants:

  • VERSION = 3
  • SEND_LOCAL_LIGHTING_DATA = true
  • SEND_GLOBAL_LIGHTING_DATA = false

Key Methods:

void load(int x, int z)
BlockSection getSectionAtBlockY(int y)
BlockSection getSectionAtIndex(int index)
BlockSection[] getChunkSections()
int getBlock(int x, int y, int z)
boolean setBlock(int x, int y, int z, int blockId, int rotation, int filler)
short getHeight(int x, int z)
short getHeight(int index)
void setHeight(int x, int z, short height)
short updateHeight(int x, int z)
short updateHeight(int x, int z, short startY)
int getTint(int x, int z)
void setTint(int x, int z, int tint)
int getEnvironment(int x, int y, int z)
void setEnvironment(int x, int y, int z, int environment)
byte getSkyLight(int x, int y, int z)
byte getRedBlockLight(int x, int y, int z)
byte getGreenBlockLight(int x, int y, int z)
byte getBlueBlockLight(int x, int y, int z)
short getBlockLight(int x, int y, int z)
boolean setTicking(int x, int y, int z, boolean ticking)
boolean isTicking(int x, int y, int z)
int getTickingBlocksCount()
Int2IntMap blockCounts()
IntSet blocks()
boolean getNeedsSaving()
boolean consumeNeedsSaving()
boolean consumeNeedsPhysics()
void markNeedsSaving()
void markNeedsPhysics()

EntityStore

Location: com/hypixel/hytale/server/core/universe/world/storage/EntityStore.java

public class EntityStore implements WorldProvider

Fields:

FieldTypeDescription
worldWorldParent world
storeStoreComponent store
networkIdCounterAtomicIntegerNetwork ID allocator
entitiesByUuidMap<UUID, Ref>Entities by UUID
networkIdToRefInt2ObjectMap<Ref>By network ID

Key Methods:

World getWorld()
Store<EntityStore> getStore()
void start(IResourceStorage)
void shutdown()
Ref<EntityStore> getRefFromUUID(UUID)
Ref<EntityStore> getRefFromNetworkId(int networkId)
int takeNextNetworkId()

IWorldGen

Location: com/hypixel/hytale/server/core/universe/world/worldgen/IWorldGen.java

public interface IWorldGen

Methods:

WorldGenTimingsCollector getTimings()
CompletableFuture<GeneratedChunk> generate(int seed, long chunkIndex, int chunkX, int chunkZ, LongPredicate shouldContinue)
Transform[] getSpawnPoints(int seed)  // Deprecated
ISpawnProvider getDefaultSpawnProvider(int seed)
void shutdown()

Coordinate Systems

Chunk Encoding

// Encode chunk coordinates to 64-bit long
long index = (chunkX << 32) | (chunkZ & 0xFFFFFFFFL)

// Decode
int chunkX = ChunkUtil.xOfChunkIndex(index)
int chunkZ = ChunkUtil.zOfChunkIndex(index)

Block to Chunk

// Block coordinate to chunk coordinate
int chunkCoord = blockCoord >> 5  // blockCoord / 32

// Local coordinate within chunk
int localCoord = blockCoord & 31  // blockCoord % 32

// Get chunk from block position
long chunkIndex = ChunkUtil.indexChunkFromBlock(blockX, blockZ)

Block Indexing

// Within section (32x32x32)
int blockIndex = ((y & 31) << 10) | ((z & 31) << 5) | (x & 31)

// Decode
int x = blockIndex & 31
int z = (blockIndex >> 5) & 31
int y = (blockIndex >> 10) & 31

Vertical Sections

// 10 sections of 32 blocks each = 320 total height
int sectionIndex = y >> 5  // y / 32
int localY = y & 31        // y % 32

SetBlock Settings Flags

BitEffect
1Don’t notify state update
2Skip block entity creation
4Skip particle effects
8Skip filler placement
64Invalidate lighting
256Perform block update
512Skip height map update

Data Flow

  1. World Loading:

    • Universe loads WorldConfig
    • Creates World instance
    • Initializes ChunkStore and EntityStore
    • ChunkStore loads/generates on demand
  2. Chunk Loading:

    • ChunkStore.getChunkReferenceAsync() initiates
    • Load from disk or generate
    • Runs pre-load processing
    • Marks TICKING when in player range
  3. Block Access:

    • WorldChunk.setBlock() modifies blocks
    • Updates heightmap, lighting, physics
    • Marks chunk for save
    • Notifies clients
  4. Entity Storage:

    • EntityStore manages all entities
    • Tracks by UUID and network ID
    • Notifies systems on changes