Search in sources :

Example 41 with DynmapBlockState

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

the class TopoHDShader method setHidden.

private void setHidden(String bn) {
    DynmapBlockState bs = DynmapBlockState.getBaseStateByName(bn);
    for (int i = 0; i < bs.getStateCount(); i++) {
        DynmapBlockState b = bs.getState(i);
        hiddenids.set(b.globalStateIndex);
    }
}
Also used : DynmapBlockState(org.dynmap.renderer.DynmapBlockState)

Example 42 with DynmapBlockState

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

the class DynmapExpCommand 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);
    IdMapper<BlockState> bsids = Block.BLOCK_STATE_REGISTRY;
    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.getId(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;
        }
        ResourceLocation ui = b.getRegistryName();
        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.world.level.block.state.properties.Property<?> p : bs.getProperties()) {
                if (statename.length() > 0) {
                    statename += ",";
                }
                statename += p.getName() + "=" + bs.getValue(p).toString();
            }
            int lightAtten = 15;
            try {
                // Workaround for mods with broken block state logic...
                lightAtten = bs.isSolidRender(EmptyBlockGetter.INSTANCE, BlockPos.ZERO) ? 15 : (bs.propagatesSkylightDown(EmptyBlockGetter.INSTANCE, BlockPos.ZERO) ? 0 : 1);
            } catch (Exception x) {
                Log.warning(String.format("Exception while checking lighting data for block state: %s[%s]", bn, statename));
                Log.verboseinfo("Exception: " + x.toString());
            }
            // 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 LiquidBlock)) {
                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 : DynmapBlockState(org.dynmap.renderer.DynmapBlockState) GsonBuilder(com.google.gson.GsonBuilder) RequiredArgumentBuilder(com.mojang.brigadier.builder.RequiredArgumentBuilder) Material(net.minecraft.world.level.material.Material) CancellationException(java.util.concurrent.CancellationException) ExecutionException(java.util.concurrent.ExecutionException) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) JsonParseException(com.google.gson.JsonParseException) BlockState(net.minecraft.world.level.block.state.BlockState) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) ResourceLocation(net.minecraft.resources.ResourceLocation) LiquidBlock(net.minecraft.world.level.block.LiquidBlock) Block(net.minecraft.world.level.block.Block) LiquidBlock(net.minecraft.world.level.block.LiquidBlock)

Example 43 with DynmapBlockState

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

the class DynmapExpCommand 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);
    ObjectIntIdentityMap<BlockState> bsids = Block.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.getId(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;
        }
        ResourceLocation ui = b.getRegistryName();
        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<?> p : bs.getProperties()) {
                if (statename.length() > 0) {
                    statename += ",";
                }
                statename += p.getName() + "=" + bs.get(p).toString();
            }
            int lightAtten = 15;
            try {
                // Workaround for mods with broken block state logic...
                lightAtten = bs.isOpaqueCube(EmptyBlockReader.INSTANCE, BlockPos.ZERO) ? 15 : (bs.propagatesSkylightDown(EmptyBlockReader.INSTANCE, BlockPos.ZERO) ? 0 : 1);
            } catch (Exception x) {
                Log.warning(String.format("Exception while checking lighting data for block state: %s[%s]", bn, statename));
                Log.verboseinfo("Exception: " + x.toString());
            }
            // 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 FlowingFluidBlock)) {
                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 : FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) GsonBuilder(com.google.gson.GsonBuilder) RequiredArgumentBuilder(com.mojang.brigadier.builder.RequiredArgumentBuilder) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) Material(net.minecraft.block.material.Material) CommandException(net.minecraft.command.CommandException) CancellationException(java.util.concurrent.CancellationException) ExecutionException(java.util.concurrent.ExecutionException) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) JsonParseException(com.google.gson.JsonParseException) BlockState(net.minecraft.block.BlockState) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) ResourceLocation(net.minecraft.util.ResourceLocation) Block(net.minecraft.block.Block) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock)

Example 44 with DynmapBlockState

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

the class DynmapExpCommand 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);
    IdMapper<BlockState> bsids = Block.BLOCK_STATE_REGISTRY;
    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.getId(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;
        }
        ResourceLocation ui = b.getRegistryName();
        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.world.level.block.state.properties.Property<?> p : bs.getProperties()) {
                if (statename.length() > 0) {
                    statename += ",";
                }
                statename += p.getName() + "=" + bs.getValue(p).toString();
            }
            int lightAtten = 15;
            try {
                // Workaround for mods with broken block state logic...
                lightAtten = bs.isSolidRender(EmptyBlockGetter.INSTANCE, BlockPos.ZERO) ? 15 : (bs.propagatesSkylightDown(EmptyBlockGetter.INSTANCE, BlockPos.ZERO) ? 0 : 1);
            } catch (Exception x) {
                Log.warning(String.format("Exception while checking lighting data for block state: %s[%s]", bn, statename));
                Log.verboseinfo("Exception: " + x.toString());
            }
            // 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 LiquidBlock)) {
                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 : DynmapBlockState(org.dynmap.renderer.DynmapBlockState) GsonBuilder(com.google.gson.GsonBuilder) RequiredArgumentBuilder(com.mojang.brigadier.builder.RequiredArgumentBuilder) Material(net.minecraft.world.level.material.Material) CancellationException(java.util.concurrent.CancellationException) ExecutionException(java.util.concurrent.ExecutionException) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) JsonParseException(com.google.gson.JsonParseException) BlockState(net.minecraft.world.level.block.state.BlockState) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) ResourceLocation(net.minecraft.resources.ResourceLocation) LiquidBlock(net.minecraft.world.level.block.LiquidBlock) Block(net.minecraft.world.level.block.Block) LiquidBlock(net.minecraft.world.level.block.LiquidBlock)

Example 45 with DynmapBlockState

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

the class BukkitVersionHelperSpigot118 method initializeBlockStates.

/**
 * Initialize block states (org.dynmap.blockstate.DynmapBlockState)
 */
@Override
public void initializeBlockStates() {
    dataToState = new IdentityHashMap<IBlockData, DynmapBlockState>();
    HashMap<String, DynmapBlockState> lastBlockState = new HashMap<String, DynmapBlockState>();
    RegistryBlockID<IBlockData> bsids = Block.p;
    Block baseb = null;
    Iterator<IBlockData> iter = bsids.iterator();
    ArrayList<String> names = new ArrayList<String>();
    // Loop through block data states
    DynmapBlockState.Builder bld = new DynmapBlockState.Builder();
    while (iter.hasNext()) {
        IBlockData bd = iter.next();
        Block b = bd.b();
        MinecraftKey id = RegistryBlocks.X.b(b);
        String bname = id.toString();
        // See if we have seen this one
        DynmapBlockState lastbs = lastBlockState.get(bname);
        int idx = 0;
        if (lastbs != null) {
            // Yes
            // Get number of states so far, since this is next
            idx = lastbs.getStateCount();
        }
        // Build state name
        String sb = "";
        String fname = bd.toString();
        int off1 = fname.indexOf('[');
        if (off1 >= 0) {
            int off2 = fname.indexOf(']');
            sb = fname.substring(off1 + 1, off2);
        }
        net.minecraft.world.level.material.Material mat = bd.c();
        // getLightBlock
        int lightAtten = b.g(bd, BlockAccessAir.a, BlockPosition.b);
        // Log.info("statename=" + bname + "[" + sb + "], lightAtten=" + lightAtten);
        // Fill in base attributes
        bld.setBaseState(lastbs).setStateIndex(idx).setBlockName(bname).setStateName(sb).setMaterial(mat.toString()).setAttenuatesLight(lightAtten);
        if (mat.b()) {
            bld.setSolid();
        }
        if (mat == net.minecraft.world.level.material.Material.a) {
            bld.setAir();
        }
        if (mat == net.minecraft.world.level.material.Material.z) {
            bld.setLog();
        }
        if (mat == net.minecraft.world.level.material.Material.F) {
            bld.setLeaves();
        }
        if ((!bd.n().c()) && ((bd.b() instanceof BlockFluids) == false)) {
            // Test if fluid type for block is not empty
            bld.setWaterlogged();
        }
        // Build state
        DynmapBlockState dbs = bld.build();
        dataToState.put(bd, dbs);
        lastBlockState.put(bname, (lastbs == null) ? dbs : lastbs);
        Log.verboseinfo("blk=" + bname + ", idx=" + idx + ", state=" + sb + ", waterlogged=" + dbs.isWaterlogged());
    }
}
Also used : IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) GsonBuilder(com.google.gson.GsonBuilder) ArrayList(java.util.ArrayList) NBTTagString(net.minecraft.nbt.NBTTagString) MinecraftKey(net.minecraft.resources.MinecraftKey) IBlockData(net.minecraft.world.level.block.state.IBlockData) Block(net.minecraft.world.level.block.Block) BlockFluids(net.minecraft.world.level.block.BlockFluids)

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