use of net.minecraft.core.BlockPos.MutableBlockPos in project BYG by AOCAWOL.
the class BYGAbstractTreeFeature method getTransformedPos.
public static BlockPos getTransformedPos(BYGTreeConfig config, BlockPos startPos, BlockPos pos) {
Rotation rotation = config.getRotation();
Mirror mirror = config.getMirror();
BlockPos blockPos = FeatureGenUtil.extractOffset(startPos, pos);
if (blockPos instanceof MutableBlockPos) {
FeatureGenUtil.transformMutable((MutableBlockPos) blockPos, mirror, rotation);
((MutableBlockPos) blockPos).move(startPos.getX(), 0, startPos.getZ());
return blockPos;
}
return FeatureGenUtil.transform(blockPos, mirror, rotation).offset(startPos.getX(), 0, startPos.getZ());
}
use of net.minecraft.core.BlockPos.MutableBlockPos in project TinkersConstruct by SlimeKnights.
the class MultiblockCuboid method detectLayer.
/**
* Detects an inner layer of the structure. That is, an area with an empty center
* @param world Level instance
* @param from Start position for the layer
* @param to End position for the layer
* @param consumer Consumer for any extra positions in this region
* @return True if this layer is valid, false otherwise
*/
@SuppressWarnings("deprecation")
protected MultiblockResult detectLayer(Level world, BlockPos from, BlockPos to, Consumer<Collection<BlockPos>> consumer) {
// ensure its loaded
if (!world.hasChunksAt(from, to)) {
return NOT_LOADED;
}
// temporary list of position candidates, so we can only add them if successful
List<BlockPos> candidates = Lists.newArrayList();
// 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, CuboidSide.WALL, true);
// we only have 4 corner blocks to check
if (!frameCheck.test(from))
return MultiblockResult.error(from.immutable(), INVALID_WALL_FRAME);
if (!frameCheck.test(mutable.set(from.getX(), height, to.getZ())))
return MultiblockResult.error(mutable.immutable(), INVALID_WALL_FRAME);
if (!frameCheck.test(mutable.set(to.getX(), height, from.getZ())))
return MultiblockResult.error(mutable.immutable(), INVALID_WALL_FRAME);
if (!frameCheck.test(to))
return MultiblockResult.error(to.immutable(), INVALID_WALL_FRAME);
}
// validate the inside
for (int x = from.getX() + 1; x < to.getX(); x++) {
for (int z = from.getZ() + 1; z < to.getZ(); z++) {
// ensure its a valid block for inside the structure
mutable.set(x, height, z);
if (isInnerBlock(world, mutable)) {
// any non airblocks are added to extra blocks, this region is ignored by default
if (!world.isEmptyBlock(mutable)) {
candidates.add(mutable.immutable());
}
} else {
return MultiblockResult.error(mutable.immutable(), INVALID_INNER_BLOCK);
}
}
}
// validate the 4 sides
Predicate<BlockPos> wallCheck = pos -> isValidBlock(world, pos, CuboidSide.WALL, false);
for (int x = from.getX() + 1; x < to.getX(); x++) {
if (!wallCheck.test(mutable.set(x, height, from.getZ())))
return MultiblockResult.error(mutable.immutable(), INVALID_WALL_BLOCK);
if (!wallCheck.test(mutable.set(x, height, to.getZ())))
return MultiblockResult.error(mutable.immutable(), INVALID_WALL_BLOCK);
}
for (int z = from.getZ() + 1; z < to.getZ(); z++) {
if (!wallCheck.test(mutable.set(from.getX(), height, z)))
return MultiblockResult.error(mutable.immutable(), INVALID_WALL_BLOCK);
if (!wallCheck.test(mutable.set(to.getX(), height, z)))
return MultiblockResult.error(mutable.immutable(), INVALID_WALL_BLOCK);
}
// was successful, add all candidates
consumer.accept(candidates);
return MultiblockResult.SUCCESS;
}
use of net.minecraft.core.BlockPos.MutableBlockPos in project TinkersConstruct by SlimeKnights.
the class AbstractWalkerModifier method onWalk.
@Override
public void onWalk(IToolStackView tool, int level, LivingEntity living, BlockPos prevPos, BlockPos newPos) {
if (living.isOnGround() && !tool.isBroken() && !living.level.isClientSide) {
float radius = Math.min(16, getRadius(tool, level));
MutableBlockPos mutable = new MutableBlockPos();
Level world = living.level;
Vec3 posVec = living.position();
BlockPos center = new BlockPos(posVec.x, posVec.y + 0.5, posVec.z);
for (BlockPos pos : BlockPos.betweenClosed(center.offset(-radius, 0, -radius), center.offset(radius, 0, radius))) {
if (pos.closerThan(living.position(), radius)) {
walkOn(tool, level, living, world, pos, mutable);
if (tool.isBroken()) {
break;
}
}
}
}
}
use of net.minecraft.core.BlockPos.MutableBlockPos in project Create by Creators-of-Create.
the class ConnectedPillarBlock method updateColumn.
private BlockState updateColumn(Level level, BlockPos pos, BlockState state, boolean present) {
MutableBlockPos currentPos = new MutableBlockPos();
Axis axis = state.getValue(AXIS);
for (Direction connection : Iterate.directions) {
if (connection.getAxis() == axis)
continue;
boolean connect = true;
Move: for (Direction movement : Iterate.directionsInAxis(axis)) {
currentPos.set(pos);
for (int i = 0; i < 1000; i++) {
if (!level.isAreaLoaded(currentPos, 1))
break;
BlockState other1 = currentPos.equals(pos) ? state : level.getBlockState(currentPos);
BlockState other2 = level.getBlockState(currentPos.relative(connection));
boolean col1 = canConnect(state, other1);
boolean col2 = canConnect(state, other2);
currentPos.move(movement);
if (!col1 && !col2)
break;
if (col1 && col2)
continue;
connect = false;
break Move;
}
}
state = setConnection(state, connection, connect);
}
return state;
}
use of net.minecraft.core.BlockPos.MutableBlockPos in project Create by Creators-of-Create.
the class LayeredOreFeature method place.
public boolean place(FeaturePlaceContext<ConfigDrivenOreConfiguration> pContext) {
Random random = pContext.random();
BlockPos blockpos = pContext.origin();
WorldGenLevel worldgenlevel = pContext.level();
ConfigDrivenOreConfiguration config = pContext.config();
List<LayerPattern> patternPool = config.getLayers();
if (patternPool.isEmpty())
return false;
LayerPattern layerPattern = patternPool.get(random.nextInt(patternPool.size()));
int placedAmount = 0;
int size = config.getSize();
int radius = Mth.ceil(config.getSize() / 2f);
int x0 = blockpos.getX() - radius;
int y0 = blockpos.getY() - radius;
int z0 = blockpos.getZ() - radius;
int width = size + 1;
int length = size + 1;
int height = size + 1;
if (blockpos.getY() >= worldgenlevel.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, blockpos.getX(), blockpos.getZ()))
return false;
List<LayerPattern.Layer> resolvedLayers = new ArrayList<>();
List<Float> layerDiameterOffsets = new ArrayList<>();
MutableBlockPos mutablePos = new MutableBlockPos();
BulkSectionAccess bulksectionaccess = new BulkSectionAccess(worldgenlevel);
int layerCoordinate = random.nextInt(4);
int slantyCoordinate = random.nextInt(3);
float slope = random.nextFloat() * .75f;
try {
for (int x = 0; x < width; x++) {
float dx = x * 2f / width - 1;
if (dx * dx > 1)
continue;
for (int y = 0; y < height; y++) {
float dy = y * 2f / height - 1;
if (dx * dx + dy * dy > 1)
continue;
if (worldgenlevel.isOutsideBuildHeight(y0 + y))
continue;
for (int z = 0; z < length; z++) {
float dz = z * 2f / height - 1;
int layerIndex = layerCoordinate == 0 ? z : layerCoordinate == 1 ? x : y;
if (slantyCoordinate != layerCoordinate)
layerIndex += Mth.floor(slantyCoordinate == 0 ? z : slantyCoordinate == 1 ? x : y) * slope;
while (layerIndex >= resolvedLayers.size()) {
Layer next = layerPattern.rollNext(resolvedLayers.isEmpty() ? null : resolvedLayers.get(resolvedLayers.size() - 1), random);
float offset = random.nextFloat() * .5f + .5f;
for (int i = 0; i < next.minSize + random.nextInt(1 + next.maxSize - next.minSize); i++) {
resolvedLayers.add(next);
layerDiameterOffsets.add(offset);
}
}
if (dx * dx + dy * dy + dz * dz > 1 * layerDiameterOffsets.get(layerIndex))
continue;
LayerPattern.Layer layer = resolvedLayers.get(layerIndex);
List<TargetBlockState> state = layer.rollBlock(random);
int currentX = x0 + x;
int currentY = y0 + y;
int currentZ = z0 + z;
mutablePos.set(currentX, currentY, currentZ);
if (!worldgenlevel.ensureCanWrite(mutablePos))
continue;
LevelChunkSection levelchunksection = bulksectionaccess.getSection(mutablePos);
if (levelchunksection == null)
continue;
int i3 = SectionPos.sectionRelative(currentX);
int j3 = SectionPos.sectionRelative(currentY);
int k3 = SectionPos.sectionRelative(currentZ);
BlockState blockstate = levelchunksection.getBlockState(i3, j3, k3);
for (OreConfiguration.TargetBlockState oreconfiguration$targetblockstate : state) {
if (!canPlaceOre(blockstate, bulksectionaccess::getBlockState, random, config, oreconfiguration$targetblockstate, mutablePos))
continue;
if (oreconfiguration$targetblockstate.state.isAir())
continue;
levelchunksection.setBlockState(i3, j3, k3, oreconfiguration$targetblockstate.state, false);
++placedAmount;
break;
}
}
}
}
} catch (Throwable throwable1) {
try {
bulksectionaccess.close();
} catch (Throwable throwable) {
throwable1.addSuppressed(throwable);
}
throw throwable1;
}
bulksectionaccess.close();
return placedAmount > 0;
}
Aggregations