Search in sources :

Example 1 with BlockRotatable

use of net.minecraft.world.level.block.BlockRotatable in project dynmap by webbukkit.

the class BukkitVersionHelperSpigot117 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>();
    int cnt = Block.p.a();
    // Loop through block data states
    DynmapBlockState.Builder bld = new DynmapBlockState.Builder();
    for (int i = 0; i < cnt; i++) {
        IBlockData bd = Block.getByCombinedId(i);
        Block b = bd.getBlock();
        String bname = IRegistry.W.getKey(bd.getBlock()).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);
        }
        Material mat = bd.getMaterial();
        // 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.isSolid()) {
            bld.setSolid();
        }
        if (mat == Material.a) {
            bld.setAir();
        }
        if ((bd.getBlock() instanceof BlockRotatable) && (bd.getMaterial() == Material.z)) {
            bld.setLog();
        }
        if (mat == Material.E) {
            bld.setLeaves();
        }
        if ((!bd.getFluid().isEmpty()) && ((bd.getBlock() 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 : BlockRotatable(net.minecraft.world.level.block.BlockRotatable) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) GsonBuilder(com.google.gson.GsonBuilder) BukkitMaterial(org.dynmap.bukkit.helper.BukkitMaterial) Material(net.minecraft.world.level.material.Material) NBTTagString(net.minecraft.nbt.NBTTagString) IBlockData(net.minecraft.world.level.block.state.IBlockData) Block(net.minecraft.world.level.block.Block) BlockFluids(net.minecraft.world.level.block.BlockFluids)

Aggregations

GsonBuilder (com.google.gson.GsonBuilder)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 NBTTagString (net.minecraft.nbt.NBTTagString)1 Block (net.minecraft.world.level.block.Block)1 BlockFluids (net.minecraft.world.level.block.BlockFluids)1 BlockRotatable (net.minecraft.world.level.block.BlockRotatable)1 IBlockData (net.minecraft.world.level.block.state.IBlockData)1 Material (net.minecraft.world.level.material.Material)1 BukkitMaterial (org.dynmap.bukkit.helper.BukkitMaterial)1 DynmapBlockState (org.dynmap.renderer.DynmapBlockState)1