use of mekanism.common.lib.math.voxel.VoxelCuboid in project Mekanism by mekanism.
the class MultiblockData method readUpdateTag.
public void readUpdateTag(CompoundNBT tag) {
NBTUtils.setIntIfPresent(tag, NBTConstants.VOLUME, this::setVolume);
NBTUtils.setBlockPosIfPresent(tag, NBTConstants.RENDER_LOCATION, value -> renderLocation = value);
bounds = new VoxelCuboid(NBTUtil.readBlockPos(tag.getCompound(NBTConstants.MIN)), NBTUtil.readBlockPos(tag.getCompound(NBTConstants.MAX)));
NBTUtils.setUUIDIfPresentElse(tag, NBTConstants.INVENTORY_ID, value -> inventoryID = value, () -> inventoryID = null);
}
use of mekanism.common.lib.math.voxel.VoxelCuboid in project Mekanism by mekanism.
the class MultiblockData method setShape.
public boolean setShape(IShape shape) {
if (shape instanceof VoxelCuboid) {
VoxelCuboid cuboid = (VoxelCuboid) shape;
bounds = cuboid;
renderLocation = cuboid.getMinPos().relative(Direction.UP);
setVolume(bounds.length() * bounds.width() * bounds.height());
return true;
}
return false;
}
use of mekanism.common.lib.math.voxel.VoxelCuboid in project Mekanism by mekanism.
the class StructureHelper method fetchCuboid.
/**
* Fetch a cuboid with all 6 sides present. Quicker than using the below algorithm with all sides.
*
* @param structure structure to check
* @param minBounds minimum size of the cuboid
* @param maxBounds maximum size of the cuboid
*
* @return found cuboid, or null if it doesn't exist
*/
public static VoxelCuboid fetchCuboid(Structure structure, VoxelCuboid minBounds, VoxelCuboid maxBounds) {
VoxelCuboid prev = null;
for (Axis axis : Axis.AXES) {
NavigableMap<Integer, VoxelPlane> majorAxisMap = structure.getMajorAxisMap(axis);
Map.Entry<Integer, VoxelPlane> firstMajor = majorAxisMap.firstEntry(), lastMajor = majorAxisMap.lastEntry();
if (firstMajor == null || !firstMajor.getValue().equals(lastMajor.getValue()) || !firstMajor.getValue().isFull()) {
// or if the plane is missing pieces then fail
return null;
}
VoxelCuboid cuboid = VoxelCuboid.from(firstMajor.getValue(), lastMajor.getValue(), firstMajor.getKey(), lastMajor.getKey());
// if this is the first axial cuboid check, make sure we have the correct bounds
if (prev == null && (!cuboid.greaterOrEqual(minBounds) || !maxBounds.greaterOrEqual(cuboid))) {
return null;
}
// if this isn't the first axial cuboid check, make sure the cuboids match
if (prev != null && !prev.equals(cuboid)) {
return null;
}
// check to make sure that we don't have any framed minor planes sticking out of our cuboid
NavigableMap<Integer, VoxelPlane> minorAxisMap = structure.getMinorAxisMap(axis);
if (!minorAxisMap.isEmpty()) {
if (hasOutOfBoundsNegativeMinor(minorAxisMap, firstMajor.getKey()) || hasOutOfBoundsPositiveMinor(minorAxisMap, lastMajor.getKey())) {
return null;
}
}
prev = cuboid;
}
return prev;
}
use of mekanism.common.lib.math.voxel.VoxelCuboid in project Mekanism by mekanism.
the class StructureHelper method fetchCuboid.
/**
* Fetch a cuboid with a defined amount of sides. At least two sides should be provided; otherwise it's impossible to discern the overall dimensions about the
* cuboid.
*
* @param structure structure to check
* @param minBounds minimum size of the cuboid
* @param maxBounds maximum size of the cuboid
* @param sides sides to check
* @param tolerance how many missing blocks are tolerated in the completed structure (will double count edges & triple count corners)
*
* @return found cuboid, or null if it doesn't exist
*/
public static VoxelCuboid fetchCuboid(Structure structure, VoxelCuboid minBounds, VoxelCuboid maxBounds, Set<CuboidSide> sides, int tolerance) {
// make sure we have enough sides to create cuboidal dimensions
if (sides.size() < 2) {
return null;
}
int missing = 0;
CuboidBuilder builder = new CuboidBuilder();
for (CuboidSide side : sides) {
Axis axis = side.getAxis(), horizontal = axis.horizontal(), vertical = axis.vertical();
NavigableMap<Integer, VoxelPlane> majorAxisMap = structure.getMajorAxisMap(axis);
Map.Entry<Integer, VoxelPlane> majorEntry = side.getFace().isPositive() ? majorAxisMap.lastEntry() : majorAxisMap.firstEntry();
// fail fast if the plane doesn't exist
if (majorEntry == null) {
return null;
}
VoxelPlane plane = majorEntry.getValue();
// handle missing blocks based on tolerance value
missing += plane.getMissing();
if (missing > tolerance) {
return null;
}
int majorKey = majorEntry.getKey();
// set bounds from dimension of plane's axis
builder.set(side, majorKey);
// update cuboidal dimensions from each corner of the plane
if (!builder.trySet(CuboidSide.get(Face.NEGATIVE, horizontal), plane.getMinCol()) || !builder.trySet(CuboidSide.get(Face.POSITIVE, horizontal), plane.getMaxCol()) || !builder.trySet(CuboidSide.get(Face.NEGATIVE, vertical), plane.getMinRow()) || !builder.trySet(CuboidSide.get(Face.POSITIVE, vertical), plane.getMaxRow())) {
return null;
}
// check to make sure that we don't have any framed minor planes sticking out of our plane
NavigableMap<Integer, VoxelPlane> minorAxisMap = structure.getMinorAxisMap(axis);
if (!minorAxisMap.isEmpty()) {
if (side.getFace().isPositive()) {
if (hasOutOfBoundsPositiveMinor(minorAxisMap, majorKey)) {
return null;
}
} else if (hasOutOfBoundsNegativeMinor(minorAxisMap, majorKey)) {
return null;
}
}
}
VoxelCuboid ret = builder.build();
// make sure the cuboid has the correct bounds
if (!ret.greaterOrEqual(minBounds) || !maxBounds.greaterOrEqual(ret)) {
return null;
}
return ret;
}
Aggregations