Search in sources :

Example 31 with ChunkSection

use of net.minecraft.world.chunk.ChunkSection in project Magma-1.16.x by magmafoundation.

the class CraftChunk method contains.

@Override
public boolean contains(BlockData block) {
    Preconditions.checkArgument(block != null, "Block cannot be null");
    Predicate<net.minecraft.block.BlockState> nms = Predicates.equalTo(((CraftBlockData) block).getState());
    for (ChunkSection section : getHandle().getSections()) {
        if (section != null && section.getStates().maybeHas(nms)) {
            return true;
        }
    }
    return false;
}
Also used : BlockState(org.bukkit.block.BlockState) ChunkSection(net.minecraft.world.chunk.ChunkSection)

Example 32 with ChunkSection

use of net.minecraft.world.chunk.ChunkSection in project LoliServer by Loli-Server.

the class CraftChunkData method setBlock.

private void setBlock(int x, int y, int z, net.minecraft.block.BlockState type) {
    if (x != (x & 0xf) || y < 0 || y >= maxHeight || z != (z & 0xf)) {
        return;
    }
    ChunkSection section = getChunkSection(y, true);
    section.setBlockState(x, y & 0xf, z, type);
    if (type.getBlock().hasTileEntity(type.getBlock().defaultBlockState())) {
        if (tiles == null) {
            tiles = new HashSet<>();
        }
        tiles.add(new BlockPos(x, y, z));
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) ChunkSection(net.minecraft.world.chunk.ChunkSection)

Example 33 with ChunkSection

use of net.minecraft.world.chunk.ChunkSection in project TheAPI by TheDevTec.

the class v1_16_R3_Mohist method setBlock.

@Override
public void setBlock(Object chunk, int x, int y, int z, Object IblockData, int data) {
    net.minecraft.world.chunk.Chunk c = (net.minecraft.world.chunk.Chunk) chunk;
    ChunkSection sc = c.func_76587_i()[y >> 4];
    if (sc == null) {
        c.func_76587_i()[y >> 4] = sc = new ChunkSection(y >> 4 << 4);
    }
    BlockPos pos = new BlockPos(x, y, z);
    // REMOVE TILE ENTITY
    c.func_177434_r().remove(pos);
    sc.func_186049_g().func_222639_b(x & 15, y & 15, z & 15, (net.minecraft.block.BlockState) IblockData);
    // ADD TILE ENTITY
    if (((net.minecraft.block.BlockState) IblockData).func_177230_c() instanceof ITileEntityProvider) {
        TileEntity ent = ((ITileEntityProvider) ((net.minecraft.block.BlockState) IblockData).func_177230_c()).func_196283_a_(c.func_177412_p());
        c.func_177434_r().put(pos, ent);
        Object packet = ent.func_189518_D_();
        Bukkit.getOnlinePlayers().forEach(player -> BukkitLoader.getPacketHandler().send(player, packet));
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITileEntityProvider(net.minecraft.block.ITileEntityProvider) BlockPos(net.minecraft.util.math.BlockPos) Chunk(org.bukkit.Chunk) CraftChunk(org.bukkit.craftbukkit.v1_16_R3.CraftChunk) ChunkSection(net.minecraft.world.chunk.ChunkSection)

Example 34 with ChunkSection

use of net.minecraft.world.chunk.ChunkSection in project TheAPI by TheDevTec.

the class v1_16_R3_Mohist method getBlock.

@Override
public Object getBlock(Object chunk, int x, int y, int z) {
    net.minecraft.world.chunk.Chunk c = (net.minecraft.world.chunk.Chunk) chunk;
    ChunkSection sc = c.func_76587_i()[y >> 4];
    if (sc == null)
        return Blocks.field_150350_a.func_176223_P();
    return sc.func_186049_g().func_186016_a(x & 15, y & 15, z & 15);
}
Also used : Chunk(org.bukkit.Chunk) CraftChunk(org.bukkit.craftbukkit.v1_16_R3.CraftChunk) ChunkSection(net.minecraft.world.chunk.ChunkSection)

Example 35 with ChunkSection

use of net.minecraft.world.chunk.ChunkSection in project lithium-fabric by CaffeineMC.

the class WorldChunkMixin method getBlockState.

/**
 * @reason Reduce method size to help the JVM inline
 * @author JellySquid
 */
@Overwrite
public BlockState getBlockState(BlockPos pos) {
    int x = pos.getX();
    int y = pos.getY();
    int z = pos.getZ();
    int chunkY = this.getSectionIndex(y);
    ChunkSection[] sectionArray = this.getSectionArray();
    if (chunkY >= 0 && chunkY < sectionArray.length) {
        ChunkSection section = sectionArray[chunkY];
        // Chunk Sections that only contain air and cave_air are treated as empty
        if (!section.isEmpty()) {
            return section.getBlockState(x & 15, y & 15, z & 15);
        }
    }
    return DEFAULT_BLOCK_STATE;
}
Also used : ChunkSection(net.minecraft.world.chunk.ChunkSection) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

ChunkSection (net.minecraft.world.chunk.ChunkSection)36 Chunk (net.minecraft.world.chunk.Chunk)11 BlockState (net.minecraft.block.BlockState)10 BlockPos (net.minecraft.util.math.BlockPos)8 Overwrite (org.spongepowered.asm.mixin.Overwrite)8 WorldChunk (net.minecraft.world.chunk.WorldChunk)5 Inject (org.spongepowered.asm.mixin.injection.Inject)5 TileEntity (net.minecraft.tileentity.TileEntity)3 BiomeContainer (net.minecraft.world.biome.BiomeContainer)3 ArrayList (java.util.ArrayList)2 Block (net.minecraft.block.Block)2 ITileEntityProvider (net.minecraft.block.ITileEntityProvider)2 PathNodeType (net.minecraft.entity.ai.pathing.PathNodeType)2 FluidState (net.minecraft.fluid.FluidState)2 CompoundNBT (net.minecraft.nbt.CompoundNBT)2 NBTUtil (net.minecraft.nbt.NBTUtil)2 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)2 ChunkPos (net.minecraft.util.math.ChunkPos)2 PalettedContainer (net.minecraft.util.palette.PalettedContainer)2 CollisionView (net.minecraft.world.CollisionView)2