Search in sources :

Example 16 with IBlockData

use of net.minecraft.server.v1_16_R3.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_16_R3.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_16_R3.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_16_R3.IBlockData in project THP-Engine by TheHollowPlanetMC.

the class PacketManager method createMultiBlockChangePacket.

public static Set<Object> createMultiBlockChangePacket(ParallelWorld parallelWorld, Set<BlockPosition3i> blocks) {
    Map<BlockPosition3i, Set<BlockPosition3i>> chunkMap = new HashMap<>();
    for (BlockPosition3i bp : blocks) {
        chunkMap.computeIfAbsent(new BlockPosition3i(bp.getX() >> 4, bp.getY() >> 4, bp.getZ() >> 4), cp -> new HashSet<>()).add(bp);
    }
    Set<Object> packets = new HashSet<>();
    for (Map.Entry<BlockPosition3i, Set<BlockPosition3i>> entry : chunkMap.entrySet()) {
        BlockPosition3i sectionPosition = entry.getKey();
        Set<BlockPosition3i> bps = entry.getValue();
        ParallelChunk parallelChunk = parallelWorld.getChunk(sectionPosition.getX(), sectionPosition.getZ());
        if (parallelChunk == null)
            continue;
        SectionTypeArray sectionTypeArray = parallelChunk.getSectionTypeArray(sectionPosition.getY());
        if (sectionTypeArray == null)
            continue;
        List<Short> coordList = new ArrayList<>();
        List<IBlockData> dataList = new ArrayList<>();
        for (BlockPosition3i bp : bps) {
            IBlockData iBlockData = (IBlockData) sectionTypeArray.getType(bp.getX() & 0xF, bp.getY() & 0xF, bp.getZ() & 0xF);
            if (iBlockData == null)
                continue;
            coordList.add((short) ((bp.getX() & 0xF) << 8 | (bp.getZ() & 0xF) << 4 | bp.getY() & 0xF));
            dataList.add(iBlockData);
        }
        short[] coordArray = new short[coordList.size()];
        IBlockData[] dataArray = new IBlockData[dataList.size()];
        for (int i = 0; i < coordList.size(); i++) {
            coordArray[i] = coordList.get(i);
            dataArray[i] = dataList.get(i);
        }
        try {
            PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange();
            MultiBlockChangePacketHandler.a.set(packet, SectionPosition.a(sectionPosition.getX(), sectionPosition.getY(), sectionPosition.getZ()));
            MultiBlockChangePacketHandler.b.set(packet, coordArray);
            MultiBlockChangePacketHandler.c.set(packet, dataArray);
            MultiBlockChangePacketHandler.d.setBoolean(packet, true);
            packets.add(packet);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return packets;
}
Also used : java.util(java.util) BlockData(org.bukkit.block.data.BlockData) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) Player(org.bukkit.entity.Player) SectionTypeArray(thpmc.engine.util.SectionTypeArray) ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) Nullable(org.jetbrains.annotations.Nullable) BlockChangePacketHandler(thpmc.engine.nms.v1_16_R3.BlockChangePacketHandler) NMSHandler(thpmc.engine.nms.v1_16_R3.NMSHandler) ParallelChunk(thpmc.engine.api.world.parallel.ParallelChunk) CraftBlockData(org.bukkit.craftbukkit.v1_16_R3.block.data.CraftBlockData) CraftChunk(org.bukkit.craftbukkit.v1_16_R3.CraftChunk) BlockPosition3i(thpmc.engine.util.BlockPosition3i) SectionLevelArray(thpmc.engine.util.SectionLevelArray) MultiBlockChangePacketHandler(thpmc.engine.nms.v1_16_R3.MultiBlockChangePacketHandler) Bukkit(org.bukkit.Bukkit) ParallelChunk(thpmc.engine.api.world.parallel.ParallelChunk) SectionTypeArray(thpmc.engine.util.SectionTypeArray) BlockPosition3i(thpmc.engine.util.BlockPosition3i)

Example 20 with IBlockData

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

the class PacketManager method sendClearChunkMultiBlockChangePacketAtPrimaryThread.

public static void sendClearChunkMultiBlockChangePacketAtPrimaryThread(Player player, ParallelChunk parallelChunk, NMSHandler nmsHandler) {
    if (!Bukkit.isPrimaryThread())
        throw new IllegalStateException("DO NOT CALL FROM ASYNC THREAD!");
    org.bukkit.World world = Bukkit.getWorld(parallelChunk.getWorld().getName());
    if (world == null)
        return;
    if (player.getWorld() != world)
        return;
    org.bukkit.Chunk chunk = world.getChunkAt(parallelChunk.getChunkX(), parallelChunk.getChunkZ());
    net.minecraft.server.v1_16_R3.Chunk nmsChunk = ((CraftChunk) chunk).getHandle();
    for (int sectionIndex = 0; sectionIndex < 16; sectionIndex++) {
        SectionTypeArray sectionTypeArray = parallelChunk.getSectionTypeArray(sectionIndex);
        if (sectionTypeArray == null)
            continue;
        ChunkSection chunkSection = nmsChunk.getSections()[sectionIndex];
        if (chunkSection == null)
            continue;
        List<Short> coordList = new ArrayList<>();
        List<IBlockData> dataList = new ArrayList<>();
        boolean notEmpty = sectionTypeArray.threadsafeIteration((x, y, z, iBlockData) -> {
            coordList.add((short) (x << 8 | z << 4 | y));
            IBlockData chunkData = chunkSection.getType(x, y, z);
            if (chunkData == null)
                chunkData = ((CraftBlockData) org.bukkit.Material.AIR.createBlockData()).getState();
            dataList.add(chunkData);
        });
        if (!notEmpty)
            continue;
        short[] coordArray = new short[coordList.size()];
        IBlockData[] dataArray = new IBlockData[dataList.size()];
        for (int i = 0; i < coordList.size(); i++) {
            coordArray[i] = coordList.get(i);
            dataArray[i] = dataList.get(i);
        }
        try {
            PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange();
            MultiBlockChangePacketHandler.a.set(packet, SectionPosition.a(parallelChunk.getChunkX(), sectionIndex, parallelChunk.getChunkZ()));
            MultiBlockChangePacketHandler.b.set(packet, coordArray);
            MultiBlockChangePacketHandler.c.set(packet, dataArray);
            MultiBlockChangePacketHandler.d.setBoolean(packet, true);
            nmsHandler.sendPacket(player, packet);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : SectionTypeArray(thpmc.engine.util.SectionTypeArray) CraftBlockData(org.bukkit.craftbukkit.v1_16_R3.block.data.CraftBlockData) net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) CraftChunk(org.bukkit.craftbukkit.v1_16_R3.CraftChunk)

Aggregations

HashMap (java.util.HashMap)25 ArrayList (java.util.ArrayList)20 Block (org.bukkit.block.Block)17 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_14_R1.IBlockData)10 BlockPosition (net.minecraft.server.v1_16_R3.BlockPosition)10 IBlockData (net.minecraft.server.v1_12_R1.IBlockData)9 IBlockData (net.minecraft.server.v1_10_R1.IBlockData)8 BlockPosition (net.minecraft.server.v1_12_R1.BlockPosition)8 IBlockData (net.minecraft.server.v1_15_R1.IBlockData)8 IdentityHashMap (java.util.IdentityHashMap)7 BlockPosition (net.minecraft.server.v1_10_R1.BlockPosition)7 IBlockData (net.minecraft.server.v1_11_R1.IBlockData)7 BlockPosition (net.minecraft.server.v1_11_R1.BlockPosition)6 BlockPosition (net.minecraft.server.v1_14_R1.BlockPosition)6 IBlockData (net.minecraft.server.v1_16_R2.IBlockData)6 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)6