Search in sources :

Example 1 with IBlockData

use of net.minecraft.world.level.block.state.IBlockData 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)

Example 2 with IBlockData

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

the class BukkitVersionHelperSpigot117 method getBlockNames.

/**
 * Get block short name list
 */
@Override
public String[] getBlockNames() {
    int cnt = Block.p.a();
    String[] names = new String[cnt];
    for (int i = 0; i < cnt; i++) {
        IBlockData bd = Block.getByCombinedId(i);
        names[i] = IRegistry.W.getKey(bd.getBlock()).toString();
        Log.info(i + ": blk=" + names[i] + ", bd=" + bd.toString());
    }
    return names;
}
Also used : IBlockData(net.minecraft.world.level.block.state.IBlockData) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 3 with IBlockData

use of net.minecraft.world.level.block.state.IBlockData 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 4 with IBlockData

use of net.minecraft.world.level.block.state.IBlockData 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 5 with IBlockData

use of net.minecraft.world.level.block.state.IBlockData in project SSB-OneBlock by BG-Software-LLC.

the class NMSAdapter_v1_17_R1 method simulateToolBreak.

@Override
public void simulateToolBreak(Player bukkitPlayer, org.bukkit.block.Block bukkitBlock) {
    EntityPlayer entityPlayer = ((CraftPlayer) bukkitPlayer).getHandle();
    ItemStack itemStack = entityPlayer.getItemInMainHand();
    WorldServer worldServer = ((CraftWorld) bukkitBlock.getWorld()).getHandle();
    BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
    IBlockData blockData = worldServer.getType(blockPosition);
    itemStack.a(worldServer, blockData, blockPosition, entityPlayer);
}
Also used : IBlockData(net.minecraft.world.level.block.state.IBlockData) BlockPosition(net.minecraft.core.BlockPosition) EntityPlayer(net.minecraft.server.level.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer) WorldServer(net.minecraft.server.level.WorldServer) ItemStack(net.minecraft.world.item.ItemStack) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld)

Aggregations

IBlockData (net.minecraft.world.level.block.state.IBlockData)11 Block (net.minecraft.world.level.block.Block)7 NBTTagString (net.minecraft.nbt.NBTTagString)6 BlockPosition (net.minecraft.core.BlockPosition)5 ArrayList (java.util.ArrayList)4 MinecraftKey (net.minecraft.resources.MinecraftKey)4 GsonBuilder (com.google.gson.GsonBuilder)3 HashMap (java.util.HashMap)3 IdentityHashMap (java.util.IdentityHashMap)3 WorldServer (net.minecraft.server.level.WorldServer)3 BlockFluids (net.minecraft.world.level.block.BlockFluids)3 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)3 DynmapBlockState (org.dynmap.renderer.DynmapBlockState)3 ComplexCollisionBox (cc.funkemunky.api.utils.world.types.ComplexCollisionBox)2 SimpleCollisionBox (cc.funkemunky.api.utils.world.types.SimpleCollisionBox)2 EntityPlayer (net.minecraft.server.level.EntityPlayer)2 ItemStack (net.minecraft.world.item.ItemStack)2 World (net.minecraft.world.level.World)2 AxisAlignedBB (net.minecraft.world.phys.AxisAlignedBB)2 VoxelShape (net.minecraft.world.phys.shapes.VoxelShape)2