Search in sources :

Example 1 with MinecraftKey

use of net.minecraft.resources.MinecraftKey in project dynmap by webbukkit.

the class BukkitVersionHelperSpigot118_2 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.o;
    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.U.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.o().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)

Example 2 with MinecraftKey

use of net.minecraft.resources.MinecraftKey in project dynmap by webbukkit.

the class BukkitVersionHelperSpigot118 method getBlockNames.

/**
 * Get block short name list
 */
@Override
public String[] getBlockNames() {
    RegistryBlockID<IBlockData> bsids = Block.p;
    Block baseb = null;
    Iterator<IBlockData> iter = bsids.iterator();
    ArrayList<String> names = new ArrayList<String>();
    while (iter.hasNext()) {
        IBlockData bs = iter.next();
        Block b = bs.b();
        // If this is new block vs last, it's the base block state
        if (b != baseb) {
            baseb = b;
            continue;
        }
        MinecraftKey id = RegistryBlocks.X.b(b);
        String bn = id.toString();
        if (bn != null) {
            names.add(bn);
            Log.info("block=" + bn);
        }
    }
    return names.toArray(new String[0]);
}
Also used : IBlockData(net.minecraft.world.level.block.state.IBlockData) ArrayList(java.util.ArrayList) Block(net.minecraft.world.level.block.Block) NBTTagString(net.minecraft.nbt.NBTTagString) MinecraftKey(net.minecraft.resources.MinecraftKey)

Example 3 with MinecraftKey

use of net.minecraft.resources.MinecraftKey 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)

Example 4 with MinecraftKey

use of net.minecraft.resources.MinecraftKey in project dynmap by webbukkit.

the class BukkitVersionHelperSpigot118_2 method getBlockNames.

/**
 * Get block short name list
 */
@Override
public String[] getBlockNames() {
    RegistryBlockID<IBlockData> bsids = Block.o;
    Block baseb = null;
    Iterator<IBlockData> iter = bsids.iterator();
    ArrayList<String> names = new ArrayList<String>();
    while (iter.hasNext()) {
        IBlockData bs = iter.next();
        Block b = bs.b();
        // If this is new block vs last, it's the base block state
        if (b != baseb) {
            baseb = b;
            continue;
        }
        MinecraftKey id = RegistryBlocks.U.b(b);
        String bn = id.toString();
        if (bn != null) {
            names.add(bn);
            Log.info("block=" + bn);
        }
    }
    return names.toArray(new String[0]);
}
Also used : IBlockData(net.minecraft.world.level.block.state.IBlockData) ArrayList(java.util.ArrayList) Block(net.minecraft.world.level.block.Block) NBTTagString(net.minecraft.nbt.NBTTagString) MinecraftKey(net.minecraft.resources.MinecraftKey)

Aggregations

ArrayList (java.util.ArrayList)4 NBTTagString (net.minecraft.nbt.NBTTagString)4 MinecraftKey (net.minecraft.resources.MinecraftKey)4 Block (net.minecraft.world.level.block.Block)4 IBlockData (net.minecraft.world.level.block.state.IBlockData)4 GsonBuilder (com.google.gson.GsonBuilder)2 HashMap (java.util.HashMap)2 IdentityHashMap (java.util.IdentityHashMap)2 BlockFluids (net.minecraft.world.level.block.BlockFluids)2 DynmapBlockState (org.dynmap.renderer.DynmapBlockState)2