All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fastasyncworldedit.core.util.CachedTextureUtil Maven / Gradle / Ivy

Go to download

Blazingly fast Minecraft world manipulation for artists, builders and everyone else.

There is a newer version: 2.9.2
Show newest version
package com.fastasyncworldedit.core.util;

import com.sk89q.worldedit.world.block.BlockType;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;

import java.io.FileNotFoundException;

public class CachedTextureUtil extends DelegateTextureUtil {

    private final TextureUtil parent;
    private final transient Int2ObjectOpenHashMap colorBlockMap;
    private final transient Int2ObjectOpenHashMap colorBiomeMap;
    private final transient Int2ObjectOpenHashMap colorLayerMap;

    public CachedTextureUtil(TextureUtil parent) throws FileNotFoundException {
        super(parent);
        this.parent = parent;
        this.colorBlockMap = new Int2ObjectOpenHashMap<>();
        this.colorLayerMap = new Int2ObjectOpenHashMap<>();
        this.colorBiomeMap = new Int2ObjectOpenHashMap<>();
    }

    @Override
    public BlockType[] getNearestLayer(int color) {
        BlockType[] closest = colorLayerMap.get(color);
        if (closest != null) {
            return closest;
        }
        closest = parent.getNearestLayer(color);
        if (closest != null) {
            colorLayerMap.put(color, closest.clone());
        }
        return closest;
    }

    @Override
    public BiomeColor getNearestBiome(int color) {
        Integer value = colorBiomeMap.get(color);
        if (value != null) {
            return getBiome(value);
        }
        BiomeColor result = parent.getNearestBiome(color);
        if (result != null) {
            colorBiomeMap.put(color, (Integer) result.id);
        }
        return result;
    }

    @Override
    public BlockType getNearestBlock(int color) {
        BlockType value = colorBlockMap.get(color);
        if (value != null) {
            return value;
        }
        BlockType result = parent.getNearestBlock(color);
        if (result != null) {
            colorBlockMap.put(color, result);
        }
        return result;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy