Search in sources :

Example 36 with org.bukkit.craftbukkit.v1_18_R1.block

use of org.bukkit.craftbukkit.v1_18_R1.block in project NoCheatPlus by NoCheatPlus.

the class BlockCacheCB3043 method fetchBounds.

@Override
public double[] fetchBounds(final int x, final int y, final int z) {
    // TODO: change api for this / use nodes (!)
    @SuppressWarnings("deprecation") final int id = getType(x, y, z).getId();
    final net.minecraft.server.v1_7_R3.Block block = net.minecraft.server.v1_7_R3.Block.e(id);
    if (block == null)
        return null;
    // getData from cache.
    block.updateShape(iBlockAccess, x, y, z);
    // minX, minY, minZ, maxX, maxY, maxZ
    return new double[] { block.x(), block.z(), block.B(), block.y(), block.A(), block.C() };
}
Also used : Block(net.minecraft.server.v1_7_R3.Block)

Example 37 with org.bukkit.craftbukkit.v1_18_R1.block

use of org.bukkit.craftbukkit.v1_18_R1.block in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method showBlockAction.

@Override
public void showBlockAction(Player player, Location location, int action, int state) {
    BlockPos position = new BlockPos(location.getX(), location.getY(), location.getZ());
    Block block = ((CraftWorld) location.getWorld()).getHandle().getBlockState(position).getBlock();
    send(player, new ClientboundBlockEventPacket(position, block, action, state));
}
Also used : FakeBlock(com.denizenscript.denizen.utilities.blocks.FakeBlock) Block(net.minecraft.world.level.block.Block) BlockPos(net.minecraft.core.BlockPos) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Example 38 with org.bukkit.craftbukkit.v1_18_R1.block

use of org.bukkit.craftbukkit.v1_18_R1.block in project Denizen-For-Bukkit by DenizenScript.

the class FakeBlockHelper method handleMapChunkPacket.

public static ClientboundLevelChunkWithLightPacket handleMapChunkPacket(World world, ClientboundLevelChunkWithLightPacket originalPacket, int chunkX, int chunkZ, List<FakeBlock> blocks) {
    try {
        ClientboundLevelChunkWithLightPacket duplicateCorePacket = new ClientboundLevelChunkWithLightPacket(DenizenNetworkManagerImpl.copyPacket(originalPacket));
        copyPacketPaperPatch(duplicateCorePacket, originalPacket);
        FriendlyByteBuf copier = new FriendlyByteBuf(Unpooled.buffer());
        originalPacket.getChunkData().write(copier);
        ClientboundLevelChunkPacketData packet = new ClientboundLevelChunkPacketData(copier, chunkX, chunkZ);
        FriendlyByteBuf serial = originalPacket.getChunkData().getReadBuffer();
        FriendlyByteBuf outputSerial = new FriendlyByteBuf(Unpooled.buffer(serial.readableBytes()));
        List blockEntities = new ArrayList((List) CHUNKDATA_BLOCK_ENTITIES.get(originalPacket.getChunkData()));
        CHUNKDATA_BLOCK_ENTITIES.set(packet, blockEntities);
        ListIterator iterator = blockEntities.listIterator();
        while (iterator.hasNext()) {
            Object blockEnt = iterator.next();
            int xz = CHUNKDATA_BLOCKENTITYINFO_PACKEDXZ.getInt(blockEnt);
            int y = CHUNKDATA_BLOCKENTITYINFO_Y.getInt(blockEnt);
            int x = (chunkX << 4) + ((xz >> 4) & 15);
            int z = (chunkZ << 4) + (xz & 15);
            for (FakeBlock block : blocks) {
                LocationTag loc = block.location;
                if (loc.getBlockX() == x && loc.getBlockY() == y && loc.getBlockZ() == z && block.material != null) {
                    iterator.remove();
                    break;
                }
            }
        }
        int worldMinY = world.getMinHeight();
        int worldMaxY = world.getMaxHeight();
        int minChunkY = worldMinY >> 4;
        int maxChunkY = worldMaxY >> 4;
        Registry<Biome> biomeRegistry = ((CraftWorld) world).getHandle().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY);
        for (int y = minChunkY; y < maxChunkY; y++) {
            int blockCount = serial.readShort();
            // reflected constructors as workaround for spigot remapper bug - Mojang "IdMap" became Spigot "IRegistry" but should be "Registry"
            PalettedContainer<BlockState> states = (PalettedContainer<BlockState>) PALETTEDCONTAINER_CTOR.newInstance(Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), PalettedContainer.Strategy.SECTION_STATES);
            states.read(serial);
            PalettedContainer<Biome> biomes = (PalettedContainer<Biome>) PALETTEDCONTAINER_CTOR.newInstance(biomeRegistry, biomeRegistry.getOrThrow(Biomes.PLAINS), PalettedContainer.Strategy.SECTION_BIOMES);
            biomes.read(serial);
            if (anyBlocksInSection(blocks, y)) {
                int minY = y << 4;
                int maxY = (y << 4) + 16;
                for (FakeBlock block : blocks) {
                    int blockY = block.location.getBlockY();
                    if (blockY >= minY && blockY < maxY && block.material != null) {
                        int blockX = block.location.getBlockX();
                        int blockZ = block.location.getBlockZ();
                        blockX -= (blockX >> 4) * 16;
                        blockY -= (blockY >> 4) * 16;
                        blockZ -= (blockZ >> 4) * 16;
                        BlockState oldState = states.get(blockX, blockY, blockZ);
                        BlockState newState = getNMSState(block);
                        if (oldState.isAir() && !newState.isAir()) {
                            blockCount++;
                        } else if (newState.isAir() && !oldState.isAir()) {
                            blockCount--;
                        }
                        states.set(blockX, blockY, blockZ, newState);
                    }
                }
            }
            outputSerial.writeShort(blockCount);
            states.write(outputSerial);
            biomes.write(outputSerial);
        }
        byte[] outputBytes = outputSerial.array();
        CHUNKDATA_BUFFER_SETTER.invoke(packet, outputBytes);
        CHUNKPACKET_CHUNKDATA_SETTER.invoke(duplicateCorePacket, packet);
        return duplicateCorePacket;
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
    return null;
}
Also used : ClientboundLevelChunkWithLightPacket(net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket) FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) ClientboundLevelChunkPacketData(net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData) ArrayList(java.util.ArrayList) FakeBlock(com.denizenscript.denizen.utilities.blocks.FakeBlock) ListIterator(java.util.ListIterator) LocationTag(com.denizenscript.denizen.objects.LocationTag) Biome(net.minecraft.world.level.biome.Biome) BlockState(net.minecraft.world.level.block.state.BlockState) ArrayList(java.util.ArrayList) List(java.util.List) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld) PalettedContainer(net.minecraft.world.level.chunk.PalettedContainer)

Example 39 with org.bukkit.craftbukkit.v1_18_R1.block

use of org.bukkit.craftbukkit.v1_18_R1.block in project Denizen-For-Bukkit by DenizenScript.

the class BlockHelperImpl method ringBell.

@Override
public void ringBell(Bell block) {
    org.bukkit.block.data.type.Bell bellData = (org.bukkit.block.data.type.Bell) block.getBlockData();
    Direction face = Direction.byName(bellData.getFacing().name());
    Direction dir = Direction.NORTH;
    switch(bellData.getAttachment()) {
        case DOUBLE_WALL:
        case SINGLE_WALL:
            switch(face) {
                case NORTH:
                case SOUTH:
                    dir = Direction.EAST;
                    break;
            }
            break;
        case FLOOR:
            dir = face;
            break;
    }
    CraftBlock craftBlock = (CraftBlock) block.getBlock();
    ((BellBlock) Blocks.BELL).attemptToRing(craftBlock.getCraftWorld().getHandle(), craftBlock.getPosition(), dir);
}
Also used : BellBlock(net.minecraft.world.level.block.BellBlock) org.bukkit.block(org.bukkit.block) org.bukkit.craftbukkit.v1_18_R1.block(org.bukkit.craftbukkit.v1_18_R1.block) Direction(net.minecraft.core.Direction)

Example 40 with org.bukkit.craftbukkit.v1_18_R1.block

use of org.bukkit.craftbukkit.v1_18_R1.block 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_18_R1.block.data.CraftBlockData) BlockState(net.minecraft.world.level.block.state.BlockState)

Aggregations

Block (net.minecraft.server.v1_10_R1.Block)7 Block (net.minecraft.server.v1_11_R1.Block)7 Block (net.minecraft.server.v1_12_R1.Block)7 BlockPosition (net.minecraft.server.v1_10_R1.BlockPosition)6 BlockPosition (net.minecraft.server.v1_11_R1.BlockPosition)6 BlockPosition (net.minecraft.server.v1_12_R1.BlockPosition)6 Block (net.minecraft.server.v1_8_R3.Block)6 PathPoint (net.minecraft.server.v1_11_R1.PathPoint)4 BlockPosition (net.minecraft.server.v1_8_R3.BlockPosition)4 Block (net.minecraft.world.level.block.Block)4 ArrayList (java.util.ArrayList)3 MutableBlockPosition (net.minecraft.server.v1_10_R1.BlockPosition.MutableBlockPosition)3 PathPoint (net.minecraft.server.v1_10_R1.PathPoint)3 MutableBlockPosition (net.minecraft.server.v1_11_R1.BlockPosition.MutableBlockPosition)3 MutableBlockPosition (net.minecraft.server.v1_12_R1.BlockPosition.MutableBlockPosition)3 PathPoint (net.minecraft.server.v1_12_R1.PathPoint)3 PathPoint (net.minecraft.server.v1_8_R3.PathPoint)3 CraftItemStack (org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack)3 FallingBlock (org.bukkit.entity.FallingBlock)3 FakeBlock (com.denizenscript.denizen.utilities.blocks.FakeBlock)2