Search in sources :

Example 61 with DynmapBlockState

use of org.dynmap.renderer.DynmapBlockState in project dynmap by webbukkit.

the class DynmapPlugin method initializeBlockStates.

/**
 * Initialize block states (org.dynmap.blockstate.DynmapBlockState)
 */
public void initializeBlockStates() {
    // Simple map - scale as needed
    stateByID = new DynmapBlockState[512 * 32];
    // Default to air
    Arrays.fill(stateByID, DynmapBlockState.AIR);
    IdList<BlockState> bsids = Block.STATE_IDS;
    DynmapBlockState basebs = null;
    Block baseb = null;
    int baseidx = 0;
    Iterator<BlockState> iter = bsids.iterator();
    DynmapBlockState.Builder bld = new DynmapBlockState.Builder();
    while (iter.hasNext()) {
        BlockState bs = iter.next();
        int idx = bsids.getRawId(bs);
        if (idx >= stateByID.length) {
            int plen = stateByID.length;
            // grow array by 10%
            stateByID = Arrays.copyOf(stateByID, idx * 11 / 10);
            Arrays.fill(stateByID, plen, stateByID.length, DynmapBlockState.AIR);
        }
        Block b = bs.getBlock();
        // If this is new block vs last, it's the base block state
        if (b != baseb) {
            basebs = null;
            baseidx = idx;
            baseb = b;
        }
        Identifier ui = Registry.BLOCK.getId(b);
        if (ui == null) {
            continue;
        }
        String bn = ui.getNamespace() + ":" + ui.getPath();
        // Only do defined names, and not "air"
        if (!bn.equals(DynmapBlockState.AIR_BLOCK)) {
            Material mat = bs.getMaterial();
            String statename = "";
            for (net.minecraft.state.property.Property<?> p : bs.getProperties()) {
                if (statename.length() > 0) {
                    statename += ",";
                }
                statename += p.getName() + "=" + bs.get(p).toString();
            }
            int lightAtten = bs.isOpaqueFullCube(EmptyBlockView.INSTANCE, BlockPos.ORIGIN) ? 15 : (bs.isTranslucent(EmptyBlockView.INSTANCE, BlockPos.ORIGIN) ? 0 : 1);
            // Log.info("statename=" + bn + "[" + statename + "], lightAtten=" + lightAtten);
            // Fill in base attributes
            bld.setBaseState(basebs).setStateIndex(idx - baseidx).setBlockName(bn).setStateName(statename).setMaterial(mat.toString()).setLegacyBlockID(idx).setAttenuatesLight(lightAtten);
            if (mat.isSolid()) {
                bld.setSolid();
            }
            if (mat == Material.AIR) {
                bld.setAir();
            }
            if (mat == Material.WOOD) {
                bld.setLog();
            }
            if (mat == Material.LEAVES) {
                bld.setLeaves();
            }
            if ((!bs.getFluidState().isEmpty()) && !(bs.getBlock() instanceof FluidBlock)) {
                bld.setWaterlogged();
            }
            // Build state
            DynmapBlockState dbs = bld.build();
            stateByID[idx] = dbs;
            if (basebs == null) {
                basebs = dbs;
            }
        }
    }
// for (int gidx = 0; gidx < DynmapBlockState.getGlobalIndexMax(); gidx++) {
// DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(gidx);
// Log.info(gidx + ":" + bs.toString() + ", gidx=" + bs.globalStateIndex + ", sidx=" + bs.stateIndex);
// }
}
Also used : FluidBlock(net.minecraft.block.FluidBlock) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) Material(net.minecraft.block.Material) BlockState(net.minecraft.block.BlockState) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) Identifier(net.minecraft.util.Identifier) FluidBlock(net.minecraft.block.FluidBlock) Block(net.minecraft.block.Block)

Example 62 with DynmapBlockState

use of org.dynmap.renderer.DynmapBlockState in project dynmap by webbukkit.

the class DynmapPlugin method initializeBlockStates.

/**
 * Initialize block states (org.dynmap.blockstate.DynmapBlockState)
 */
public void initializeBlockStates() {
    // Simple map - scale as needed
    stateByID = new DynmapBlockState[512 * 32];
    // Default to air
    Arrays.fill(stateByID, DynmapBlockState.AIR);
    IdList<BlockState> bsids = Block.STATE_IDS;
    DynmapBlockState basebs = null;
    Block baseb = null;
    int baseidx = 0;
    Iterator<BlockState> iter = bsids.iterator();
    DynmapBlockState.Builder bld = new DynmapBlockState.Builder();
    while (iter.hasNext()) {
        BlockState bs = iter.next();
        int idx = bsids.getRawId(bs);
        if (idx >= stateByID.length) {
            int plen = stateByID.length;
            // grow array by 10%
            stateByID = Arrays.copyOf(stateByID, idx * 11 / 10);
            Arrays.fill(stateByID, plen, stateByID.length, DynmapBlockState.AIR);
        }
        Block b = bs.getBlock();
        // If this is new block vs last, it's the base block state
        if (b != baseb) {
            basebs = null;
            baseidx = idx;
            baseb = b;
        }
        Identifier ui = Registry.BLOCK.getId(b);
        if (ui == null) {
            continue;
        }
        String bn = ui.getNamespace() + ":" + ui.getPath();
        // Only do defined names, and not "air"
        if (!bn.equals(DynmapBlockState.AIR_BLOCK)) {
            Material mat = bs.getMaterial();
            String statename = "";
            for (net.minecraft.state.property.Property<?> p : bs.getProperties()) {
                if (statename.length() > 0) {
                    statename += ",";
                }
                statename += p.getName() + "=" + bs.get(p).toString();
            }
            int lightAtten = bs.isOpaqueFullCube(EmptyBlockView.INSTANCE, BlockPos.ORIGIN) ? 15 : (bs.isTranslucent(EmptyBlockView.INSTANCE, BlockPos.ORIGIN) ? 0 : 1);
            // Log.info("statename=" + bn + "[" + statename + "], lightAtten=" + lightAtten);
            // Fill in base attributes
            bld.setBaseState(basebs).setStateIndex(idx - baseidx).setBlockName(bn).setStateName(statename).setMaterial(mat.toString()).setLegacyBlockID(idx).setAttenuatesLight(lightAtten);
            if (mat.isSolid()) {
                bld.setSolid();
            }
            if (mat == Material.AIR) {
                bld.setAir();
            }
            if (mat == Material.WOOD) {
                bld.setLog();
            }
            if (mat == Material.LEAVES) {
                bld.setLeaves();
            }
            if ((!bs.getFluidState().isEmpty()) && !(bs.getBlock() instanceof FluidBlock)) {
                bld.setWaterlogged();
            }
            // Build state
            DynmapBlockState dbs = bld.build();
            stateByID[idx] = dbs;
            if (basebs == null) {
                basebs = dbs;
            }
        }
    }
// for (int gidx = 0; gidx < DynmapBlockState.getGlobalIndexMax(); gidx++) {
// DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(gidx);
// Log.info(gidx + ":" + bs.toString() + ", gidx=" + bs.globalStateIndex + ", sidx=" + bs.stateIndex);
// }
}
Also used : FluidBlock(net.minecraft.block.FluidBlock) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) Material(net.minecraft.block.Material) BlockState(net.minecraft.block.BlockState) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) Identifier(net.minecraft.util.Identifier) FluidBlock(net.minecraft.block.FluidBlock) Block(net.minecraft.block.Block)

Aggregations

DynmapBlockState (org.dynmap.renderer.DynmapBlockState)62 HashMap (java.util.HashMap)12 ArrayList (java.util.ArrayList)10 IdentityHashMap (java.util.IdentityHashMap)10 Block (net.minecraft.block.Block)10 GsonBuilder (com.google.gson.GsonBuilder)9 BlockState (net.minecraft.block.BlockState)9 BitSet (java.util.BitSet)7 RequiredArgumentBuilder (com.mojang.brigadier.builder.RequiredArgumentBuilder)6 File (java.io.File)6 FluidBlock (net.minecraft.block.FluidBlock)6 Material (net.minecraft.block.Material)6 Identifier (net.minecraft.util.Identifier)6 Block (net.minecraft.world.level.block.Block)6 RenderPatch (org.dynmap.renderer.RenderPatch)6 JsonParseException (com.google.gson.JsonParseException)5 IOException (java.io.IOException)5 CancellationException (java.util.concurrent.CancellationException)5 ExecutionException (java.util.concurrent.ExecutionException)5 ZipFile (java.util.zip.ZipFile)5