package com.hypixel.hytale.builtin.blocktick.system; import com.hypixel.hytale.component.AddReason; import com.hypixel.hytale.component.CommandBuffer; import com.hypixel.hytale.component.ComponentType; import com.hypixel.hytale.component.Ref; import com.hypixel.hytale.component.RemoveReason; import com.hypixel.hytale.component.Store; import com.hypixel.hytale.component.query.Query; import com.hypixel.hytale.component.system.RefSystem; import com.hypixel.hytale.math.util.ChunkUtil; import com.hypixel.hytale.server.core.universe.world.chunk.BlockChunk; import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk; import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore; import javax.annotation.Nonnull; public class MergeWaitingBlocksSystem extends RefSystem { private static final ComponentType COMPONENT_TYPE = WorldChunk.getComponentType(); @Override public Query getQuery() { return COMPONENT_TYPE; } @Override public void onEntityAdded( @Nonnull Ref ref, @Nonnull AddReason reason, @Nonnull Store store, @Nonnull CommandBuffer commandBuffer ) { ChunkStore chunkStore = store.getExternalData(); WorldChunk chunk = store.getComponent(ref, COMPONENT_TYPE); int x = chunk.getX(); int z = chunk.getZ(); mergeTickingBlocks(chunkStore, x - 1, z); mergeTickingBlocks(chunkStore, x + 1, z); mergeTickingBlocks(chunkStore, x, z - 1); mergeTickingBlocks(chunkStore, x, z + 1); } @Override public void onEntityRemove( @Nonnull Ref ref, @Nonnull RemoveReason reason, @Nonnull Store store, @Nonnull CommandBuffer commandBuffer ) { } public static void mergeTickingBlocks(@Nonnull ChunkStore store, int x, int z) { BlockChunk blockChunk = store.getChunkComponent(ChunkUtil.indexChunk(x, z), BlockChunk.getComponentType()); if (blockChunk != null) { blockChunk.mergeTickingBlocks(); } } }