Search in sources :

Example 1 with MutableBlockPos

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

the class BYGAbstractTreeFeature method doesSaplingHaveSpaceToGrow.

/**
 * Use this method instead of the previous if the canopy does not have a mirror shape on the X/Z axises.
 * Only used during sapling growth.
 *
 * @param reader            Gives us access to world.
 * @param pos               The start pos of the feature from the decorator/pos of the sapling.
 * @param treeHeight        The height of the given tree.
 * @param canopyStartHeight The start height at which leaves begin to generate. I.E: "randTreeHeight - 15".
 * @param xNegativeDistance Used to check the canopy's negative X offset blocks.
 * @param zNegativeDistance Used to check the canopy's negative Z offset blocks.
 * @param xPositiveDistance Used to check the canopy's positive x offset blocks.
 * @param zPositiveDistance Used to check the canopy's positive Z offset blocks.
 * @param isSapling         Boolean passed in to determine whether or not the tree is being generated during world gen or with a sapling.
 * @param trunkPositions    Typically this is going to be the bottom most logs of the trunk for the tree.
 * @return Determine Whether or not a sapling can grow at the given pos by checking the surrounding area.
 */
public boolean doesSaplingHaveSpaceToGrow(LevelSimulatedReader reader, BlockPos pos, int treeHeight, int canopyStartHeight, int xNegativeDistance, int zNegativeDistance, int xPositiveDistance, int zPositiveDistance, boolean isSapling, BlockPos... trunkPositions) {
    int x = pos.getX();
    int y = pos.getY();
    int z = pos.getZ();
    MutableBlockPos mutable = new MutableBlockPos();
    // Skip if tree is being called during world gen.
    if (isSapling) {
        // Check the tree trunk and determine whether or not there's a block in the way.
        for (int yOffSet = 0; yOffSet <= treeHeight; yOffSet++) {
            if (!canSaplingGrowHere(reader, mutable.set(x, y + yOffSet, z))) {
                return false;
            }
            // If the list of trunk pos(other than the center trunk) is greater than 0, we check each of these trunk pos from the bottom to the tree height.
            if (trunkPositions.length > 0) {
                for (BlockPos trunkPos : trunkPositions) {
                    if (!canSaplingGrowHere(reader, mutable.set(trunkPos.getX(), trunkPos.getY() + yOffSet, trunkPos.getZ()))) {
                        return false;
                    }
                }
            }
        }
        // We use canopyStartHeight instead of 0 because we want to check the area only in the canopy's area and not around the trunk. This makes our saplings much smarter and easier to grow.
        for (int yOffset = canopyStartHeight; yOffset <= treeHeight + 1; ++yOffset) {
            for (int xOffset = -xNegativeDistance; xOffset <= xPositiveDistance; ++xOffset) {
                for (int zOffset = -zNegativeDistance; zOffset <= zPositiveDistance; ++zOffset) {
                    if (!canSaplingGrowHere(reader, mutable.set(x + xOffset, y + yOffset, z + zOffset))) {
                        return false;
                    }
                }
            }
        }
    }
    return true;
}
Also used : MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) BlockPos(net.minecraft.core.BlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 2 with MutableBlockPos

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

the class BYGAbstractTreeFeature method buildTrunk.

public void buildTrunk(WorldGenLevel reader, BYGTreeConfig config, Random random, BlockPos operatingPos, int downRange) {
    MutableBlockPos mutable = new MutableBlockPos().set(operatingPos);
    for (int moveDown = 0; moveDown < downRange; moveDown++) {
        BlockState movingState = reader.getBlockState(mutable);
        if (SPREADABLE_TO_NON_SPREADABLE.containsKey(movingState.getBlock())) {
            reader.setBlock(mutable, SPREADABLE_TO_NON_SPREADABLE.get(movingState.getBlock()).defaultBlockState(), 2);
            break;
        } else {
            if (!FeatureGenUtil.isTerrainOrRock(reader, mutable)) {
                reader.setBlock(mutable, config.getTrunkProvider().getState(random, mutable), 2);
            } else {
                break;
            }
        }
        mutable.move(Direction.DOWN);
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 3 with MutableBlockPos

use of net.minecraft.core.BlockPos.MutableBlockPos in project TinkersConstruct by SlimeKnights.

the class MultiblockCuboid method detectCap.

/**
 * Detects the floor or ceiling of the structure
 * @param world     Level instance
 * @param from      Start position for the cap
 * @param to        End position for the cap
 * @param side      Side of the cube
 * @param consumer  Consumer for any extra positions in this region, specifically frame positions when frame is disabled
 * @return  True if this "cap" is valid, false if not
 */
@SuppressWarnings("deprecation")
protected MultiblockResult detectCap(Level world, BlockPos from, BlockPos to, CuboidSide side, Consumer<Collection<BlockPos>> consumer) {
    // ensure the area is loaded before trying
    if (!world.hasChunksAt(from, to)) {
        return NOT_LOADED;
    }
    // validate frame first
    MutableBlockPos mutable = new MutableBlockPos();
    int height = from.getY();
    if (hasFrame) {
        // function to check a single position in the frame
        Predicate<BlockPos> frameCheck = pos -> isValidBlock(world, pos, side, true);
        // calculate blocks
        // x direction
        Component frameError = side == CuboidSide.CEILING ? INVALID_CEILING_FRAME : INVALID_FLOOR_FRAME;
        for (int x = from.getX(); x <= to.getX(); x++) {
            if (!frameCheck.test(mutable.set(x, height, from.getZ())))
                return MultiblockResult.error(mutable.immutable(), frameError);
            if (!frameCheck.test(mutable.set(x, height, to.getZ())))
                return MultiblockResult.error(mutable.immutable(), frameError);
        }
        // z direction. don't doublecheck corners
        for (int z = from.getZ() + 1; z < to.getZ(); z++) {
            if (!frameCheck.test(mutable.set(from.getX(), height, z)))
                return MultiblockResult.error(mutable.immutable(), frameError);
            if (!frameCheck.test(mutable.set(to.getX(), height, z)))
                return MultiblockResult.error(mutable.immutable(), frameError);
        }
    }
    // validate inside of the floor
    Component blockError = side == CuboidSide.CEILING ? INVALID_CEILING_BLOCK : INVALID_FLOOR_BLOCK;
    for (int z = from.getZ() + 1; z < to.getZ(); z++) {
        for (int x = from.getX() + 1; x < to.getX(); x++) {
            if (!isValidBlock(world, mutable.set(x, height, z), side, false)) {
                return MultiblockResult.error(mutable.immutable(), blockError);
            }
        }
    }
    return MultiblockResult.SUCCESS;
}
Also used : Setter(lombok.Setter) Tag(net.minecraft.nbt.Tag) Getter(lombok.Getter) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) Direction(net.minecraft.core.Direction) RequiredArgsConstructor(lombok.RequiredArgsConstructor) BlockState(net.minecraft.world.level.block.state.BlockState) MultiblockResult.error(slimeknights.tconstruct.smeltery.block.entity.multiblock.MultiblockResult.error) ArrayList(java.util.ArrayList) TagUtil(slimeknights.tconstruct.library.utils.TagUtil) Lists(com.google.common.collect.Lists) AccessLevel(lombok.AccessLevel) Nullable(javax.annotation.Nullable) Plane(net.minecraft.core.Direction.Plane) ImmutableSet(com.google.common.collect.ImmutableSet) Component(net.minecraft.network.chat.Component) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) TConstruct(slimeknights.tconstruct.TConstruct) Consumer(java.util.function.Consumer) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) BlockPos(net.minecraft.core.BlockPos) Level(net.minecraft.world.level.Level) Collections(java.util.Collections) ListTag(net.minecraft.nbt.ListTag) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) BlockPos(net.minecraft.core.BlockPos) Component(net.minecraft.network.chat.Component) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 4 with MutableBlockPos

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

the class MeteoriteSpawner method trySpawnMeteoriteAtSuitableHeight.

public PlacedMeteoriteSettings trySpawnMeteoriteAtSuitableHeight(LevelReader level, BlockPos startPos, float coreRadius, CraterType craterType, boolean pureCrater) {
    int stepSize = Math.min(5, (int) Math.ceil(coreRadius) + 1);
    int minY = 10 + stepSize;
    MutableBlockPos mutablePos = startPos.mutable();
    mutablePos.move(Direction.DOWN, stepSize);
    while (mutablePos.getY() > minY) {
        PlacedMeteoriteSettings spawned = trySpawnMeteorite(level, mutablePos, coreRadius, craterType, pureCrater);
        if (spawned != null) {
            return spawned;
        }
        mutablePos.setY(mutablePos.getY() - stepSize);
    }
    return null;
}
Also used : PlacedMeteoriteSettings(appeng.worldgen.meteorite.PlacedMeteoriteSettings) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 5 with MutableBlockPos

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

the class MeteoriteSpawner method areSurroundingsSuitable.

private boolean areSurroundingsSuitable(LevelReader level, BlockPos pos) {
    int realValidBlocks = 0;
    MutableBlockPos testPos = new MutableBlockPos();
    for (int i = pos.getX() - 6; i < pos.getX() + 6; i++) {
        testPos.setX(i);
        for (int j = pos.getY() - 6; j < pos.getY() + 6; j++) {
            testPos.setY(j);
            for (int k = pos.getZ() - 6; k < pos.getZ() + 6; k++) {
                testPos.setZ(k);
                Block block = level.getBlockState(testPos).getBlock();
                realValidBlocks++;
            }
        }
    }
    int validBlocks = 0;
    for (int i = pos.getX() - 15; i < pos.getX() + 15; i++) {
        testPos.setX(i);
        for (int j = pos.getY() - 15; j < pos.getY() + 15; j++) {
            testPos.setY(j);
            for (int k = pos.getZ() - 15; k < pos.getZ() + 15; k++) {
                testPos.setZ(k);
                validBlocks++;
            }
        }
    }
    final int minBlocks = 200;
    return validBlocks > minBlocks && realValidBlocks > 80;
}
Also used : Block(net.minecraft.world.level.block.Block) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Aggregations

MutableBlockPos (net.minecraft.core.BlockPos.MutableBlockPos)30 BlockState (net.minecraft.world.level.block.state.BlockState)15 BlockPos (net.minecraft.core.BlockPos)14 Direction (net.minecraft.core.Direction)9 ArrayList (java.util.ArrayList)7 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 Random (java.util.Random)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 Getter (lombok.Getter)2 RequiredArgsConstructor (lombok.RequiredArgsConstructor)2