Search in sources :

Example 1 with CraftBlockData

use of org.bukkit.craftbukkit.v1_19_R1.block.data.CraftBlockData 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 {
        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.engine.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.engine.api.world.parallel.ParallelChunk) CraftBlockData(org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData) ParallelUniverse(thpmc.engine.api.world.parallel.ParallelUniverse) BlockData(org.bukkit.block.data.BlockData) CraftBlockData(org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData)

Example 2 with CraftBlockData

use of org.bukkit.craftbukkit.v1_19_R1.block.data.CraftBlockData in project THP-Engine 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.engine.api.world.parallel.ParallelWorld) BlockPosition(net.minecraft.server.v1_16_R3.BlockPosition) ParallelUniverse(thpmc.engine.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 3 with CraftBlockData

use of org.bukkit.craftbukkit.v1_19_R1.block.data.CraftBlockData 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)

Example 4 with CraftBlockData

use of org.bukkit.craftbukkit.v1_19_R1.block.data.CraftBlockData in project Iris by VolmitSoftware.

the class NMSBinding18_1 method createPalette.

@Override
public MCAPaletteAccess createPalette() {
    MCAIdMapper<BlockState> registry = registryCache.aquireNasty(() -> {
        Field cf = net.minecraft.core.IdMapper.class.getDeclaredField("tToId");
        Field df = net.minecraft.core.IdMapper.class.getDeclaredField("idToT");
        Field bf = net.minecraft.core.IdMapper.class.getDeclaredField("nextId");
        cf.setAccessible(true);
        df.setAccessible(true);
        bf.setAccessible(true);
        net.minecraft.core.IdMapper<BlockState> blockData = Block.BLOCK_STATE_REGISTRY;
        int b = bf.getInt(blockData);
        Object2IntMap<BlockState> c = (Object2IntMap<BlockState>) cf.get(blockData);
        List<BlockState> d = (List<BlockState>) df.get(blockData);
        return new MCAIdMapper<BlockState>(c, d, b);
    });
    MCAPalette<BlockState> global = globalCache.aquireNasty(() -> new MCAGlobalPalette<>(registry, ((CraftBlockData) AIR).getState()));
    MCAPalettedContainer<BlockState> container = new MCAPalettedContainer<>(global, registry, i -> ((CraftBlockData) NBTWorld.getBlockData(i)).getState(), i -> NBTWorld.getCompound(CraftBlockData.fromData(i)), ((CraftBlockData) AIR).getState());
    return new MCAWrappedPalettedContainer<>(container, i -> NBTWorld.getCompound(CraftBlockData.fromData(i)), i -> ((CraftBlockData) NBTWorld.getBlockData(i)).getState());
}
Also used : Object2IntMap(it.unimi.dsi.fastutil.objects.Object2IntMap) Field(java.lang.reflect.Field) CraftBlockData(org.bukkit.craftbukkit.v1_18_R1.block.data.CraftBlockData) BlockState(net.minecraft.world.level.block.state.BlockState) List(java.util.List) MCAPalettedContainer(com.volmit.iris.util.nbt.mca.palette.MCAPalettedContainer) MCAWrappedPalettedContainer(com.volmit.iris.util.nbt.mca.palette.MCAWrappedPalettedContainer) MCAIdMapper(com.volmit.iris.util.nbt.mca.palette.MCAIdMapper)

Example 5 with CraftBlockData

use of org.bukkit.craftbukkit.v1_19_R1.block.data.CraftBlockData in project Movecraft by APDevTeam.

the class IWorldHandler method setBlockFast.

@Override
public void setBlockFast(@NotNull Location location, @NotNull MovecraftRotation rotation, @NotNull BlockData data) {
    BlockState blockData;
    if (data instanceof CraftBlockData) {
        blockData = ((CraftBlockData) data).getState();
    } else {
        blockData = (BlockState) data;
    }
    blockData = blockData.rotate(ROTATION[rotation.ordinal()]);
    Level world = ((CraftWorld) (location.getWorld())).getHandle();
    BlockPos BlockPos = locationToPosition(MathUtils.bukkit2MovecraftLoc(location));
    setBlockFast(world, BlockPos, blockData);
}
Also used : CraftBlockData(org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData) BlockState(net.minecraft.world.level.block.state.BlockState) ServerLevel(net.minecraft.server.level.ServerLevel) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld)

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 BlockState (net.minecraft.block.BlockState)2 net.minecraft.server.v1_15_R1 (net.minecraft.server.v1_15_R1)2