Search in sources :

Example 21 with WorldChunk

use of net.minecraft.world.chunk.WorldChunk in project sodium-fabric by CaffeineMC.

the class ChunkGraph method getOpenChunkFaces.

private Set<Direction> getOpenChunkFaces(BlockPos pos) {
    WorldChunk chunk = this.world.getChunk(pos.getX() >> 4, pos.getZ() >> 4);
    ChunkSection section = chunk.getSectionArray()[pos.getY() >> 4];
    if (section == null || section.isEmpty()) {
        return EnumSet.allOf(Direction.class);
    }
    ChunkOcclusionDataBuilder occlusionBuilder = new ChunkOcclusionDataBuilder();
    BlockPos.Mutable mpos = new BlockPos.Mutable();
    for (int x = 0; x < 16; x++) {
        for (int y = 0; y < 16; y++) {
            for (int z = 0; z < 16; z++) {
                BlockState state = section.getBlockState(x, y, z);
                mpos.set(x, y, z);
                if (state.isFullOpaque(this.world, mpos)) {
                    occlusionBuilder.markClosed(mpos);
                }
            }
        }
    }
    return occlusionBuilder.getOpenFaces(pos);
}
Also used : BlockState(net.minecraft.block.BlockState) WorldChunk(net.minecraft.world.chunk.WorldChunk) ChunkOcclusionDataBuilder(net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder) ChunkSection(net.minecraft.world.chunk.ChunkSection)

Example 22 with WorldChunk

use of net.minecraft.world.chunk.WorldChunk in project sodium-fabric by CaffeineMC.

the class MixinChunkRendererRegion method test.

@Inject(method = "<init>", at = @At("RETURN"))
private void test(World world, int chunkX, int chunkZ, WorldChunk[][] chunks, BlockPos startPos, BlockPos endPos, CallbackInfo ci) {
    final BlockState defaultState = Blocks.AIR.getDefaultState();
    final int minX = startPos.getX();
    final int minY = startPos.getY();
    final int minZ = startPos.getZ();
    final int maxX = endPos.getX();
    final int maxY = endPos.getY();
    final int maxZ = endPos.getZ();
    for (int z = minZ; z <= maxZ; z++) {
        for (int x = minX; x <= maxX; x++) {
            WorldChunk worldChunk = chunks[(x >> 4) - chunkX][(z >> 4) - chunkZ];
            for (int y = minY; y <= maxY; y++) {
                BlockState state;
                if (y >= 0 && y < 256) {
                    ChunkSection section = worldChunk.getSectionArray()[y >> 4];
                    if (section != null) {
                        state = section.getBlockState(x & 15, y & 15, z & 15);
                    } else {
                        state = defaultState;
                    }
                } else {
                    state = defaultState;
                }
                int i = this.getIndex(x, y, z);
                this.blockStates[i] = state;
            }
        }
    }
}
Also used : BlockState(net.minecraft.block.BlockState) WorldChunk(net.minecraft.world.chunk.WorldChunk) ChunkSection(net.minecraft.world.chunk.ChunkSection) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 23 with WorldChunk

use of net.minecraft.world.chunk.WorldChunk in project KiwiClient by TangyKiwi.

the class WorldUtils method getLoadedChunks.

public static List<WorldChunk> getLoadedChunks() {
    List<WorldChunk> chunks = new ArrayList<>();
    int viewDist = mc.options.viewDistance;
    for (int x = -viewDist; x <= viewDist; x++) {
        for (int z = -viewDist; z <= viewDist; z++) {
            WorldChunk chunk = mc.world.getChunkManager().getWorldChunk((int) mc.player.getX() / 16 + x, (int) mc.player.getZ() / 16 + z);
            if (chunk != null) {
                chunks.add(chunk);
            }
        }
    }
    return chunks;
}
Also used : WorldChunk(net.minecraft.world.chunk.WorldChunk) ArrayList(java.util.ArrayList)

Example 24 with WorldChunk

use of net.minecraft.world.chunk.WorldChunk in project roadrunner by MaxNeedsSnacks.

the class ThreadedAnvilChunkStorageMixin method startWatchingChunk.

protected void startWatchingChunk(ServerPlayerEntity player, int x, int z) {
    ForgeEventFactory.fireChunkWatch(true, player, new ChunkPos(x, z), this.world);
    ChunkHolder holder = this.getChunkHolder(ChunkPos.toLong(x, z));
    if (holder != null) {
        WorldChunk chunk = holder.getWorldChunk();
        if (chunk != null) {
            this.sendChunkDataPackets(player, new Packet[2], chunk);
        }
    }
}
Also used : WorldChunk(net.minecraft.world.chunk.WorldChunk) ChunkHolder(net.minecraft.server.world.ChunkHolder) ChunkPos(net.minecraft.util.math.ChunkPos)

Example 25 with WorldChunk

use of net.minecraft.world.chunk.WorldChunk in project roadrunner by MaxNeedsSnacks.

the class RedstoneWireBlockMixin method getReceivedPower.

/**
 * Calculate the redstone power a wire at the given location receives from the
 * blocks around it.
 */
private int getReceivedPower(World world, BlockPos pos) {
    WorldChunk chunk = world.getWorldChunk(pos);
    int power = MIN;
    for (Direction dir : DIRECTIONS_VERTICAL) {
        BlockPos side = pos.offset(dir);
        BlockState neighbor = chunk.getBlockState(side);
        // below a wire, it does not receive any power from that direction.
        if (!neighbor.isAir() && !neighbor.isOf(this)) {
            power = Math.max(power, this.getPowerFromVertical(world, side, neighbor, dir));
            if (power >= MAX) {
                return MAX;
            }
        }
    }
    // In vanilla this check is done up to 4 times.
    BlockPos up = pos.up();
    boolean checkWiresAbove = !chunk.getBlockState(up).isSolidBlock(world, up);
    for (Direction dir : DIRECTIONS_HORIZONTAL) {
        power = Math.max(power, this.getPowerFromSide(world, pos.offset(dir), dir, checkWiresAbove));
        if (power >= MAX) {
            return MAX;
        }
    }
    return power;
}
Also used : BlockState(net.minecraft.block.BlockState) WorldChunk(net.minecraft.world.chunk.WorldChunk) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.math.Direction)

Aggregations

WorldChunk (net.minecraft.world.chunk.WorldChunk)34 BlockPos (net.minecraft.util.math.BlockPos)15 BlockState (net.minecraft.block.BlockState)9 ChunkPos (net.minecraft.util.math.ChunkPos)8 Inject (org.spongepowered.asm.mixin.injection.Inject)8 ClientPlayerEntity (net.minecraft.client.network.ClientPlayerEntity)6 PlayerUtils (at.haha007.edenclient.utils.PlayerUtils)4 ConfigSubscriber (at.haha007.edenclient.utils.config.ConfigSubscriber)4 PerWorldConfig (at.haha007.edenclient.utils.config.PerWorldConfig)4 Collectors (java.util.stream.Collectors)4 PlayerTickCallback (at.haha007.edenclient.callbacks.PlayerTickCallback)3 CommandManager (at.haha007.edenclient.command.CommandManager)3 ChatColor (at.haha007.edenclient.utils.ChatColor)3 PlayerUtils.sendModMessage (at.haha007.edenclient.utils.PlayerUtils.sendModMessage)3 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)3 CommandContext (com.mojang.brigadier.context.CommandContext)3 Biome (com.seedfinding.mcbiome.biome.Biome)3 BiomeSource (com.seedfinding.mcbiome.source.BiomeSource)3 BlockEntity (net.minecraft.block.entity.BlockEntity)3 Direction (net.minecraft.util.math.Direction)3