use of slimeknights.tconstruct.smeltery.block.entity.multiblock.MultiblockResult.error 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 slimeknights.tconstruct.smeltery.block.entity.multiblock.MultiblockResult.error 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;
}
Aggregations