Search in sources :

Example 36 with MutableBlockPos

use of net.minecraft.core.BlockPos.MutableBlockPos in project Applied-Energistics-2 by AppliedEnergistics.

the class TestOreGenCommand method checkChunk.

private void checkChunk(CommandSourceStack sender, ServerLevel level, ChunkPos cp, Stats stats) {
    ChunkAccess chunk = level.getChunk(cp.x, cp.z, ChunkStatus.FULL, false);
    if (chunk == null) {
        sendLine(sender, "Skipping chunk %s", cp);
        return;
    }
    ChunkStats chunkStats = new ChunkStats();
    MutableBlockPos blockPos = new MutableBlockPos();
    sendLine(sender, "Checking chunk %s", cp);
    for (int x = cp.getMinBlockX(); x <= cp.getMaxBlockX(); x++) {
        blockPos.setX(x);
        for (int z = cp.getMinBlockZ(); z <= cp.getMaxBlockZ(); z++) {
            blockPos.setZ(z);
            for (int y = level.getMinBuildHeight(); y < level.getHeight(); y++) {
                blockPos.setY(y);
                BlockState state = chunk.getBlockState(blockPos);
                if (state == quartzOre) {
                    chunkStats.minHeight = Math.min(chunkStats.minHeight, y);
                    chunkStats.maxHeight = Math.max(chunkStats.maxHeight, y);
                    chunkStats.quartzOreCount++;
                } else if (state == deepslateQuartzOre) {
                    chunkStats.deepslateMinHeight = Math.min(chunkStats.deepslateMinHeight, y);
                    chunkStats.deepslateMaxHeight = Math.max(chunkStats.deepslateMaxHeight, y);
                    chunkStats.deepslateQuartzOreCount++;
                }
            }
        }
    }
    stats.chunks.add(chunkStats);
}
Also used : ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) BlockState(net.minecraft.world.level.block.state.BlockState) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 37 with MutableBlockPos

use of net.minecraft.core.BlockPos.MutableBlockPos in project Applied-Energistics-2 by AppliedEnergistics.

the class MBCalculator method calculateMultiblock.

public void calculateMultiblock(ServerLevel level, BlockPos loc) {
    if (isModificationInProgress()) {
        return;
    }
    IAECluster currentCluster = target.getCluster();
    if (currentCluster != null && currentCluster.isDestroyed()) {
        // If we're still part of a cluster that is in the process of being destroyed,
        return;
    // don't recalc.
    }
    try {
        final MutableBlockPos min = loc.mutable();
        final MutableBlockPos max = loc.mutable();
        // find size of MB structure...
        while (this.isValidBlockEntityAt(level, min.getX() - 1, min.getY(), min.getZ())) {
            min.setX(min.getX() - 1);
        }
        while (this.isValidBlockEntityAt(level, min.getX(), min.getY() - 1, min.getZ())) {
            min.setY(min.getY() - 1);
        }
        while (this.isValidBlockEntityAt(level, min.getX(), min.getY(), min.getZ() - 1)) {
            min.setZ(min.getZ() - 1);
        }
        while (this.isValidBlockEntityAt(level, max.getX() + 1, max.getY(), max.getZ())) {
            max.setX(max.getX() + 1);
        }
        while (this.isValidBlockEntityAt(level, max.getX(), max.getY() + 1, max.getZ())) {
            max.setY(max.getY() + 1);
        }
        while (this.isValidBlockEntityAt(level, max.getX(), max.getY(), max.getZ() + 1)) {
            max.setZ(max.getZ() + 1);
        }
        if (this.checkMultiblockScale(min, max) && this.verifyUnownedRegion(level, min, max)) {
            try {
                if (!this.verifyInternalStructure(level, min, max)) {
                    this.disconnect();
                    return;
                }
            } catch (Exception err) {
                this.disconnect();
                return;
            }
            boolean updateGrid = false;
            TCluster cluster = this.target.getCluster();
            if (cluster == null || !cluster.getBoundsMin().equals(min) || !cluster.getBoundsMax().equals(max)) {
                cluster = this.createCluster(level, min, max);
                setModificationInProgress(cluster);
                // NOTE: The following will break existing clusters within the bounds
                this.updateBlockEntities(cluster, level, min, max);
                updateGrid = true;
            } else {
                setModificationInProgress(cluster);
            }
            cluster.updateStatus(updateGrid);
            return;
        }
    } catch (Throwable err) {
        AELog.debug(err);
    } finally {
        setModificationInProgress(null);
    }
    this.disconnect();
}
Also used : MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 38 with MutableBlockPos

use of net.minecraft.core.BlockPos.MutableBlockPos in project Applied-Energistics-2 by AppliedEnergistics.

the class SpatialStorageChunkGenerator method fillChunk.

private void fillChunk(ChunkAccess chunk) {
    MutableBlockPos mutPos = new MutableBlockPos();
    for (int cx = 0; cx < 16; cx++) {
        mutPos.setX(cx);
        for (int cz = 0; cz < 16; cz++) {
            // FIXME: It's likely a bad idea to fill Y in the inner-loop given the storage
            // layout of chunks
            mutPos.setZ(cz);
            for (int cy = 0; cy < HEIGHT; cy++) {
                mutPos.setY(cy);
                chunk.setBlockState(mutPos, defaultBlockState, false);
            }
        }
    }
}
Also used : MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 39 with MutableBlockPos

use of net.minecraft.core.BlockPos.MutableBlockPos in project BYG by AOCAWOL.

the class BYGAbstractTreeFeature method setDisk.

public void setDisk(WorldGenLevel world, Random random, BlockPos pos, BYGTreeConfig config) {
    if (!(world instanceof WorldGenRegion) || config.getDiskRadius() <= 0)
        return;
    setSeed(world.getSeed());
    MutableBlockPos mutable = new MutableBlockPos().set(pos);
    int diskRadius = config.getDiskRadius();
    for (int x = -diskRadius; x <= diskRadius; x++) {
        for (int z = -diskRadius; z <= diskRadius; z++) {
            int squaredDistance = x * x + z * z;
            if (squaredDistance <= diskRadius * diskRadius) {
                mutable.set(pos).move(x, 0, z);
                // Roughen the radius of the disks a bit
                double diskRoughnessNoise = fastNoise.GetNoise(mutable.getX() * 0.04F, mutable.getY() * 0.01F, mutable.getZ() * 0.04F);
                if (squaredDistance > diskRadius * diskRadius * 0.8f && diskRoughnessNoise > -0.3D && diskRoughnessNoise < 0.3D)
                    continue;
                if (FeatureGenUtil.isTerrainOrRock(world, mutable)) {
                    if (world.getBlockState(mutable.above()).isAir() || FeatureGenUtil.isPlant(world, mutable.above())) {
                        world.setBlock(mutable, config.getDiskProvider().getState(random, mutable), 2);
                    }
                }
            }
        }
    }
}
Also used : WorldGenRegion(net.minecraft.server.level.WorldGenRegion) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 40 with MutableBlockPos

use of net.minecraft.core.BlockPos.MutableBlockPos in project BYG by AOCAWOL.

the class BYGAbstractTreeFeature method isAnotherTreeNearby.

/**
 * Checks the area surrounding the position for any blocks using either the log or leaves tag.
 * <p>
 * Called only during world gen.
 *
 * @param reader     Gives us access to world
 * @param pos        The given pos of either the feature during world gen or the sapling.
 * @param treeHeight The height of the given tree.
 * @param distance   Checks the surrounding pos
 * @param isSapling  Boolean passed in to determine whether or not the tree is being generated during world gen or with a sapling.
 * @return Determines whether or not any tree is within the given distance
 */
public boolean isAnotherTreeNearby(LevelSimulatedReader reader, BlockPos pos, int treeHeight, int distance, boolean isSapling) {
    int x = pos.getX();
    int y = pos.getY();
    int z = pos.getZ();
    MutableBlockPos mutable = new MutableBlockPos();
    // Skip if tree is being spawned with a sapling.
    if (!isSapling) {
        for (int yOffset = 0; yOffset <= treeHeight + 1; ++yOffset) {
            for (int xOffset = -distance; xOffset <= distance; ++xOffset) {
                for (int zOffset = -distance; zOffset <= distance; ++zOffset) {
                    if (isAnotherTreeHere(reader, mutable.set(x + xOffset, y + yOffset, z + zOffset))) {
                        return false;
                    }
                }
            }
        }
    }
    return true;
}
Also used : MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Aggregations

MutableBlockPos (net.minecraft.core.BlockPos.MutableBlockPos)60 BlockPos (net.minecraft.core.BlockPos)32 BlockState (net.minecraft.world.level.block.state.BlockState)31 Random (java.util.Random)16 WorldGenLevel (net.minecraft.world.level.WorldGenLevel)16 Direction (net.minecraft.core.Direction)11 ArrayList (java.util.ArrayList)8 Block (net.minecraft.world.level.block.Block)4 Level (net.minecraft.world.level.Level)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Lists (com.google.common.collect.Lists)2 Vector3f (com.mojang.math.Vector3f)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Set (java.util.Set)2 Consumer (java.util.function.Consumer)2 Predicate (java.util.function.Predicate)2 Nullable (javax.annotation.Nullable)2 AccessLevel (lombok.AccessLevel)2