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