Search in sources :

Example 26 with CraftBlockData

use of org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData in project THP-Engine by TheHollowPlanetMC.

the class PacketManager method createBlockChangePacket.

@Nullable
public static Object createBlockChangePacket(ParallelWorld parallelWorld, int blockX, int blockY, int blockZ) {
    PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange();
    BlockData blockData = parallelWorld.getBlockData(blockX, blockY, blockZ);
    if (blockData == null)
        return null;
    try {
        BlockChangePacketHandler.a.set(packet, new BlockPosition(blockX, blockY, blockZ));
        packet.block = ((CraftBlockData) blockData).getState();
        return packet;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : BlockData(org.bukkit.block.data.BlockData) CraftBlockData(org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData) Nullable(org.jetbrains.annotations.Nullable)

Example 27 with CraftBlockData

use of org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData in project THP-Engine by TheHollowPlanetMC.

the class PacketManager method createMultiBlockChangePacket.

public static Set<Object> createMultiBlockChangePacket(ParallelWorld parallelWorld, Set<BlockPosition3i> blocks) {
    Map<ChunkPosition, Set<BlockPosition3i>> chunkMap = new HashMap<>();
    for (BlockPosition3i bp : blocks) {
        chunkMap.computeIfAbsent(new ChunkPosition(bp.getX(), bp.getZ()), cp -> new HashSet<>()).add(bp);
    }
    Set<Object> packets = new HashSet<>();
    for (Map.Entry<ChunkPosition, Set<BlockPosition3i>> entry : chunkMap.entrySet()) {
        ChunkPosition chunkPosition = entry.getKey();
        Set<BlockPosition3i> bps = entry.getValue();
        ParallelChunk parallelChunk = parallelWorld.getChunk(chunkPosition.x, chunkPosition.z);
        if (parallelChunk == null)
            continue;
        PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange();
        List<PacketPlayOutMultiBlockChange.MultiBlockChangeInfo> infoList = new ArrayList<>();
        for (BlockPosition3i bp : bps) {
            BlockData blockData = parallelChunk.getBlockData(bp.getX(), bp.getY(), bp.getZ());
            if (blockData == null)
                continue;
            short loc = (short) ((bp.getX() & 0xF) << 12 | (bp.getZ() & 0xF) << 8 | bp.getY());
            infoList.add(packet.new MultiBlockChangeInfo(loc, ((CraftBlockData) blockData).getState()));
        }
        PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[] array = infoList.toArray(new PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[infoList.size()]);
        try {
            MultiBlockChangePacketHandler.a.set(packet, new ChunkCoordIntPair(chunkPosition.x, chunkPosition.z));
            MultiBlockChangePacketHandler.b.set(packet, array);
            packets.add(packet);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return packets;
}
Also used : java.util(java.util) CraftWorld(org.bukkit.craftbukkit.v1_15_R1.CraftWorld) BlockData(org.bukkit.block.data.BlockData) Player(org.bukkit.entity.Player) SectionTypeArray(thpmc.engine.util.SectionTypeArray) ParallelWorld(thpmc.engine.api.world.parallel.ParallelWorld) BlockChangePacketHandler(thpmc.engine.nms.v1_15_R1.BlockChangePacketHandler) MultiBlockChangePacketHandler(thpmc.engine.nms.v1_15_R1.MultiBlockChangePacketHandler) Nullable(org.jetbrains.annotations.Nullable) net.minecraft.server.v1_15_R1(net.minecraft.server.v1_15_R1) ParallelChunk(thpmc.engine.api.world.parallel.ParallelChunk) ChunkPosition(thpmc.engine.util.ChunkPosition) CraftChunk(org.bukkit.craftbukkit.v1_15_R1.CraftChunk) NMSHandler(thpmc.engine.nms.v1_15_R1.NMSHandler) CraftBlockData(org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData) BlockPosition3i(thpmc.engine.util.BlockPosition3i) SectionLevelArray(thpmc.engine.util.SectionLevelArray) Bukkit(org.bukkit.Bukkit) ChunkPosition(thpmc.engine.util.ChunkPosition) ParallelChunk(thpmc.engine.api.world.parallel.ParallelChunk) CraftBlockData(org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData) BlockPosition3i(thpmc.engine.util.BlockPosition3i) BlockData(org.bukkit.block.data.BlockData) CraftBlockData(org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData)

Example 28 with CraftBlockData

use of org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData in project Mohist by MohistMC.

the class CraftBlockData method newData.

public static CraftBlockData newData(Material material, String data) {
    Preconditions.checkArgument(material == null || material.isBlock(), "Cannot get data for not block %s", material);
    BlockState blockData;
    Block block = CraftMagicNumbers.getBlock(material);
    Map<net.minecraft.world.level.block.state.properties.Property<?>, Comparable<?>> parsed = null;
    // Data provided, use it
    if (data != null) {
        try {
            // Material provided, force that material in
            if (block != null) {
                data = net.minecraft.core.Registry.BLOCK.getKey(block) + data;
            }
            StringReader reader = new StringReader(data);
            BlockStateParser arg = new BlockStateParser(reader, false).parse(false);
            Preconditions.checkArgument(!reader.canRead(), "Spurious trailing data: " + data);
            blockData = arg.getState();
            parsed = arg.getProperties();
        } catch (CommandSyntaxException ex) {
            throw new IllegalArgumentException("Could not parse data: " + data, ex);
        }
    } else {
        blockData = block.defaultBlockState();
    }
    CraftBlockData craft = fromData(blockData);
    craft.parsedStates = parsed;
    return craft;
}
Also used : BlockStateParser(net.minecraft.commands.arguments.blocks.BlockStateParser) BlockState(net.minecraft.world.level.block.state.BlockState) StringReader(com.mojang.brigadier.StringReader) CraftBlock(org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock) Block(net.minecraft.world.level.block.Block) BooleanProperty(net.minecraft.world.level.block.state.properties.BooleanProperty) EnumProperty(net.minecraft.world.level.block.state.properties.EnumProperty) IntegerProperty(net.minecraft.world.level.block.state.properties.IntegerProperty) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException)

Example 29 with CraftBlockData

use of org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData in project Mohist by MohistMC.

the class CraftMinecart method setDisplayBlockData.

@Override
public void setDisplayBlockData(BlockData blockData) {
    if (blockData != null) {
        BlockState block = ((CraftBlockData) blockData).getState();
        this.getHandle().setDisplayBlockState(block);
    } else {
        // Set block to air (default) and set the flag to not have a display block.
        this.getHandle().setDisplayBlockState(Blocks.AIR.defaultBlockState());
        this.getHandle().setCustomDisplay(false);
    }
}
Also used : CraftBlockData(org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData) BlockState(net.minecraft.world.level.block.state.BlockState)

Example 30 with CraftBlockData

use of org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData in project VanillaSource 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.vanilla_source.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

BlockData (org.bukkit.block.data.BlockData)12 BlockState (net.minecraft.world.level.block.state.BlockState)11 CraftBlockData (org.bukkit.craftbukkit.v1_16_R3.block.data.CraftBlockData)9 CraftBlockData (org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData)8 Nullable (org.jetbrains.annotations.Nullable)6 BlockPosition (net.minecraft.server.v1_15_R1.BlockPosition)4 FallingBlockEntity (net.minecraft.world.entity.item.FallingBlockEntity)4 ParallelWorld (thpmc.engine.api.world.parallel.ParallelWorld)4 ParallelWorld (thpmc.vanilla_source.api.world.parallel.ParallelWorld)4 BlockPos (net.minecraft.core.BlockPos)3 ServerLevel (net.minecraft.server.level.ServerLevel)3 BlockPosition (net.minecraft.server.v1_16_R3.BlockPosition)3 CraftBlockData (org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData)3 CraftBlockData (org.bukkit.craftbukkit.v1_18_R1.block.data.CraftBlockData)3 CraftBlockData (org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData)3 ParallelUniverse (thpmc.engine.api.world.parallel.ParallelUniverse)3 ParallelUniverse (thpmc.vanilla_source.api.world.parallel.ParallelUniverse)3 java.util (java.util)2 List (java.util.List)2 BlockState (net.minecraft.block.BlockState)2