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);
}
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;
}
}
}
}
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;
}
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);
}
}
}
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;
}
Aggregations