Search in sources :

Example 16 with IBlockData

use of net.minecraft.server.v1_14_R1.IBlockData in project dynmap by webbukkit.

the class BukkitVersionHelperSpigot116_3 method getBlockNames.

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

Example 17 with IBlockData

use of net.minecraft.server.v1_14_R1.IBlockData in project dynmap by webbukkit.

the class BukkitVersionHelperSpigot116_3 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.REGISTRY_ID.a();
    DynmapBlockState.Builder bld = new DynmapBlockState.Builder();
    // Loop through block data states
    for (int i = 0; i < cnt; i++) {
        IBlockData bd = Block.getByCombinedId(i);
        Block b = bd.getBlock();
        String bname = IRegistry.BLOCK.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.f(bd, BlockAccessAir.INSTANCE, BlockPosition.ZERO);
        // 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.AIR) {
            bld.setAir();
        }
        if ((bd.getBlock() instanceof BlockRotatable) && (bd.getMaterial() == Material.WOOD)) {
            bld.setLog();
        }
        if (mat == Material.LEAVES) {
            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.server.v1_16_R2.BlockRotatable) HashMap(java.util.HashMap) IdentityHashMap(java.util.IdentityHashMap) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) Material(net.minecraft.server.v1_16_R2.Material) BukkitMaterial(org.dynmap.bukkit.helper.BukkitMaterial) IBlockData(net.minecraft.server.v1_16_R2.IBlockData) Block(net.minecraft.server.v1_16_R2.Block) BlockFluids(net.minecraft.server.v1_16_R2.BlockFluids)

Example 18 with IBlockData

use of net.minecraft.server.v1_14_R1.IBlockData in project dynmap by webbukkit.

the class BukkitVersionHelperSpigot116 method getBlockNames.

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

Example 19 with IBlockData

use of net.minecraft.server.v1_14_R1.IBlockData in project THP-Engine by TheHollowPlanetMC.

the class MultiBlockChangePacketHandler method rewrite.

@Override
public Object rewrite(Object packet, EnginePlayer EnginePlayer, boolean cacheSetting) {
    ParallelUniverse universe = EnginePlayer.getUniverse();
    if (universe == null)
        return packet;
    String worldName = EnginePlayer.getBukkitPlayer().getWorld().getName();
    ParallelWorld parallelWorld = universe.getWorld(worldName);
    try {
        SectionPosition aValue = (SectionPosition) a.get(packet);
        int chunkX = aValue.getX();
        int chunkZ = aValue.getZ();
        ParallelChunk parallelChunk = parallelWorld.getChunk(chunkX, chunkZ);
        if (parallelChunk == null)
            return packet;
        SectionTypeArray sectionTypeArray = parallelChunk.getSectionTypeArray(aValue.getY());
        if (sectionTypeArray == null)
            return packet;
        short[] bValue = (short[]) b.get(packet);
        IBlockData[] cValueClone = ((IBlockData[]) c.get(packet)).clone();
        for (int i = 0; i < bValue.length; i++) {
            short coord = bValue[i];
            int x = coord >> 8;
            int y = coord & 0xF;
            int z = (coord >> 4) & 0xF;
            IBlockData iBlockData = (IBlockData) sectionTypeArray.getType(x, y, z);
            if (iBlockData != null) {
                cValueClone[i] = iBlockData;
            }
        }
        boolean dValue = d.getBoolean(packet);
        PacketPlayOutMultiBlockChange newPacket = new PacketPlayOutMultiBlockChange();
        a.set(newPacket, aValue);
        b.set(newPacket, bValue);
        c.set(newPacket, cValueClone);
        d.set(newPacket, dValue);
        return newPacket;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return packet;
}
Also used : ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) SectionPosition(net.minecraft.server.v1_16_R3.SectionPosition) PacketPlayOutMultiBlockChange(net.minecraft.server.v1_16_R3.PacketPlayOutMultiBlockChange) ParallelChunk(thpmc.engine.api.world.parallel.ParallelChunk) SectionTypeArray(thpmc.engine.util.SectionTypeArray) IBlockData(net.minecraft.server.v1_16_R3.IBlockData) ParallelUniverse(thpmc.engine.api.world.parallel.ParallelUniverse)

Example 20 with IBlockData

use of net.minecraft.server.v1_14_R1.IBlockData in project MechanicsMain by WeaponMechanics.

the class Block_1_14_R1 method getMultiBlockMaskPacket.

private PacketPlayOutMultiBlockChange getMultiBlockMaskPacket(List<Block> blocks, @Nullable IBlockData mask) {
    net.minecraft.server.v1_14_R1.Chunk chunk = ((CraftChunk) blocks.get(0).getChunk()).getHandle();
    // Setup default information
    PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange(0, new short[0], chunk);
    PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[] changes = new PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[blocks.size()];
    for (int i = 0; i < blocks.size(); i++) {
        Block block = blocks.get(i);
        // Where the block is relative to the chunk it is in
        int x = block.getX() & 0xF;
        int y = block.getY();
        int z = block.getZ() & 0xF;
        // Setting the (x, y, z) location into VarInt format
        short location = (short) (x << 12 | y | z << 8);
        // If mask is null, then undo the mask. Otherwise set the mask
        if (mask == null) {
            changes[i] = packet.new MultiBlockChangeInfo(location, chunk);
        } else {
            changes[i] = packet.new MultiBlockChangeInfo(location, mask);
        }
    }
    ReflectionUtil.setField(multiBlockChangeB, packet, changes);
    return packet;
}
Also used : PacketPlayOutMultiBlockChange(net.minecraft.server.v1_14_R1.PacketPlayOutMultiBlockChange) Block(org.bukkit.block.Block) CraftChunk(org.bukkit.craftbukkit.v1_14_R1.CraftChunk)

Aggregations

HashMap (java.util.HashMap)24 ArrayList (java.util.ArrayList)20 Block (org.bukkit.block.Block)19 List (java.util.List)16 IBlockData (net.minecraft.server.v1_16_R3.IBlockData)16 NotNull (org.jetbrains.annotations.NotNull)16 Chunk (org.bukkit.Chunk)15 IBlockData (net.minecraft.server.v1_12_R1.IBlockData)11 IBlockData (net.minecraft.server.v1_14_R1.IBlockData)10 BlockPosition (net.minecraft.server.v1_12_R1.BlockPosition)9 IBlockData (net.minecraft.server.v1_10_R1.IBlockData)8 BlockPosition (net.minecraft.server.v1_14_R1.BlockPosition)8 IBlockData (net.minecraft.server.v1_15_R1.IBlockData)8 BlockPosition (net.minecraft.server.v1_16_R3.BlockPosition)8 BlockPosition (net.minecraft.server.v1_10_R1.BlockPosition)7 IBlockData (net.minecraft.server.v1_11_R1.IBlockData)7 BlockPosition (net.minecraft.server.v1_8_R3.BlockPosition)7 IBlockData (net.minecraft.server.v1_8_R3.IBlockData)7 IdentityHashMap (java.util.IdentityHashMap)6 BlockPosition (net.minecraft.server.v1_11_R1.BlockPosition)6