// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.server.core.universe.world.worldgen;

import javax.annotation.Nonnull;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.server.core.universe.world.chunk.BlockComponentChunk;
import com.hypixel.hytale.math.vector.Vector3i;
import com.hypixel.hytale.server.core.universe.world.meta.BlockState;
import javax.annotation.Nullable;
import com.hypixel.hytale.math.util.ChunkUtil;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
import com.hypixel.hytale.component.Holder;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;

public class GeneratedBlockStateChunk
{
    private final Int2ObjectMap<Holder<ChunkStore>> mapping;
    
    public GeneratedBlockStateChunk() {
        this.mapping = new Int2ObjectOpenHashMap<Holder<ChunkStore>>();
    }
    
    public Holder<ChunkStore> getState(final int x, final int y, final int z) {
        return this.mapping.get(ChunkUtil.indexBlockInColumn(x, y, z));
    }
    
    public void setState(final int x, final int y, final int z, @Nullable final Holder<ChunkStore> state) {
        final int index = ChunkUtil.indexBlockInColumn(x, y, z);
        if (state == null) {
            this.mapping.remove(index);
        }
        else {
            final BlockState blockState = BlockState.getBlockState(state);
            if (blockState != null) {
                blockState.setPosition(new Vector3i(x, y, z));
            }
            this.mapping.put(index, state);
        }
    }
    
    @Nonnull
    public BlockComponentChunk toBlockComponentChunk() {
        return new BlockComponentChunk(this.mapping, new Int2ObjectOpenHashMap<Ref<ChunkStore>>());
    }
}
