Search in sources :

Example 11 with CraftBlockData

use of org.bukkit.craftbukkit.v1_14_R1.block.data.CraftBlockData in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelperImpl method setFallingBlockType.

@Override
public void setFallingBlockType(FallingBlock entity, BlockData block) {
    BlockState state = ((CraftBlockData) block).getState();
    FallingBlockEntity nmsEntity = ((CraftFallingBlock) entity).getHandle();
    try {
        FALLINGBLOCK_TYPE_SETTER.invoke(nmsEntity, state);
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
}
Also used : FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) CraftBlockData(org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData) BlockState(net.minecraft.world.level.block.state.BlockState)

Example 12 with CraftBlockData

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

use of org.bukkit.craftbukkit.v1_14_R1.block.data.CraftBlockData in project VanillaSource 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 : ParallelChunk(thpmc.vanilla_source.api.world.parallel.ParallelChunk) java.util(java.util) CraftWorld(org.bukkit.craftbukkit.v1_15_R1.CraftWorld) BlockData(org.bukkit.block.data.BlockData) ChunkPosition(thpmc.vanilla_source.util.ChunkPosition) ParallelWorld(thpmc.vanilla_source.api.world.parallel.ParallelWorld) SectionLevelArray(thpmc.vanilla_source.util.SectionLevelArray) Player(org.bukkit.entity.Player) MultiBlockChangePacketHandler(thpmc.vanilla_source.nms.v1_15_R1.MultiBlockChangePacketHandler) BlockPosition3i(thpmc.vanilla_source.util.BlockPosition3i) Nullable(org.jetbrains.annotations.Nullable) net.minecraft.server.v1_15_R1(net.minecraft.server.v1_15_R1) CraftChunk(org.bukkit.craftbukkit.v1_15_R1.CraftChunk) NMSHandler(thpmc.vanilla_source.nms.v1_15_R1.NMSHandler) CraftBlockData(org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData) BlockChangePacketHandler(thpmc.vanilla_source.nms.v1_15_R1.BlockChangePacketHandler) SectionTypeArray(thpmc.vanilla_source.util.SectionTypeArray) Bukkit(org.bukkit.Bukkit) ChunkPosition(thpmc.vanilla_source.util.ChunkPosition) ParallelChunk(thpmc.vanilla_source.api.world.parallel.ParallelChunk) CraftBlockData(org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData) BlockPosition3i(thpmc.vanilla_source.util.BlockPosition3i) BlockData(org.bukkit.block.data.BlockData) CraftBlockData(org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData)

Example 14 with CraftBlockData

use of org.bukkit.craftbukkit.v1_14_R1.block.data.CraftBlockData in project VanillaSource by TheHollowPlanetMC.

the class BlockChangePacketHandler 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 {
        PacketPlayOutBlockChange blockChange = (PacketPlayOutBlockChange) packet;
        BlockPosition bp = (BlockPosition) a.get(blockChange);
        BlockData blockData = parallelWorld.getBlockData(bp.getX(), bp.getY(), bp.getZ());
        if (blockData == null)
            return packet;
        PacketPlayOutBlockChange newPacket = new PacketPlayOutBlockChange();
        a.set(newPacket, bp);
        newPacket.block = ((CraftBlockData) blockData).getState();
        return newPacket;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return packet;
}
Also used : ParallelWorld(thpmc.vanilla_source.api.world.parallel.ParallelWorld) BlockPosition(net.minecraft.server.v1_16_R3.BlockPosition) ParallelUniverse(thpmc.vanilla_source.api.world.parallel.ParallelUniverse) PacketPlayOutBlockChange(net.minecraft.server.v1_16_R3.PacketPlayOutBlockChange) BlockData(org.bukkit.block.data.BlockData) CraftBlockData(org.bukkit.craftbukkit.v1_16_R3.block.data.CraftBlockData)

Example 15 with CraftBlockData

use of org.bukkit.craftbukkit.v1_14_R1.block.data.CraftBlockData in project VanillaSource 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 {
        ChunkCoordIntPair aValue = (ChunkCoordIntPair) a.get(packet);
        PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[] bValue = (PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[]) b.get(packet);
        int chunkX = aValue.x;
        int chunkZ = aValue.z;
        ParallelChunk parallelChunk = parallelWorld.getChunk(chunkX, chunkZ);
        if (parallelChunk == null)
            return packet;
        PacketPlayOutMultiBlockChange newPacket = new PacketPlayOutMultiBlockChange();
        a.set(newPacket, aValue);
        int length = bValue.length;
        PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[] newInfo = new PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[length];
        for (int index = 0; index < length; index++) {
            PacketPlayOutMultiBlockChange.MultiBlockChangeInfo info = bValue[index];
            BlockPosition bp = info.a();
            BlockData blockData = parallelChunk.getBlockData(bp.getX(), bp.getY(), bp.getZ());
            if (blockData == null) {
                newInfo[index] = info;
            } else {
                newInfo[index] = newPacket.new MultiBlockChangeInfo(info.b(), ((CraftBlockData) blockData).getState());
            }
        }
        b.set(newPacket, newInfo);
        return newPacket;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return packet;
}
Also used : ParallelWorld(thpmc.vanilla_source.api.world.parallel.ParallelWorld) ChunkCoordIntPair(net.minecraft.server.v1_15_R1.ChunkCoordIntPair) PacketPlayOutMultiBlockChange(net.minecraft.server.v1_15_R1.PacketPlayOutMultiBlockChange) BlockPosition(net.minecraft.server.v1_15_R1.BlockPosition) ParallelChunk(thpmc.vanilla_source.api.world.parallel.ParallelChunk) CraftBlockData(org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData) ParallelUniverse(thpmc.vanilla_source.api.world.parallel.ParallelUniverse) BlockData(org.bukkit.block.data.BlockData) CraftBlockData(org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData)

Aggregations

BlockData (org.bukkit.block.data.BlockData)12 BlockState (net.minecraft.world.level.block.state.BlockState)9 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 FallingBlockEntity (net.minecraft.world.entity.item.FallingBlockEntity)5 BlockPosition (net.minecraft.server.v1_15_R1.BlockPosition)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