use of team.creative.creativecore.common.util.math.base.Facing in project CreativeCore by CreativeMD.
the class BoxUtils method includeMaxRotationInBox.
private static void includeMaxRotationInBox(IncludeBox box, Vec3d vec, Axis axis, CollisionCoordinator coordinator) {
double rotation = coordinator.getRotationDegree(axis);
if (rotation == 0)
return;
Matrix3 matrix = coordinator.getRotationMatrix(axis);
Double length = null;
BooleanRotation state = BooleanRotation.get(axis, vec);
boolean positive = rotation > 0;
int quarterRotation = 90;
if (rotation >= 90) {
while (quarterRotation <= Math.abs(rotation) && quarterRotation < 360) {
Facing facing = positive ? state.clockwiseMaxFacing() : state.counterMaxClockwiseFacing();
if (length == null)
length = lengthIgnoreAxis(vec, axis);
box.include(facing, length);
if (coordinator.translation != null)
box.include(facing, length + coordinator.translation.get(facing.axis));
state = state.clockwise();
quarterRotation += 90;
}
}
matrix.transform(vec);
box.include(vec);
if (quarterRotation <= 360 && !state.is(vec)) {
Facing facing = positive ? state.clockwiseMaxFacing() : state.counterMaxClockwiseFacing();
if (length == null)
length = lengthIgnoreAxis(vec, axis);
box.include(facing, length);
if (coordinator.translation != null)
box.include(facing, length + coordinator.translation.get(facing.axis));
}
}
use of team.creative.creativecore.common.util.math.base.Facing in project CreativeCore by CreativeMD.
the class BlockUpdateLevelSystem method blockChanged.
public void blockChanged(BlockPos pos) {
BlockState state = level.getBlockState(pos);
if (state.isAir()) {
// Shrinking
if (allBlocks.remove(pos) && edgePositions.remove(pos)) {
for (int i = 0; i < Facing.values().length; i++) {
Facing facing = Facing.values()[i];
Axis axis = facing.axis.toVanilla();
int bound = getBound(facing);
if (bound == pos.get(axis)) {
List<BlockPos> remaining = new ArrayList<>();
for (BlockPos edge : edgePositions) if (edge.get(axis) == bound)
remaining.add(edge);
if (remaining.isEmpty()) {
int newBound = facing.positive ? Integer.MIN_VALUE : Integer.MAX_VALUE;
for (BlockPos scan : allBlocks) newBound = facing.positive ? Math.max(newBound, scan.get(axis)) : Math.min(newBound, scan.get(axis));
for (BlockPos scan : allBlocks) if (scan.get(axis) == newBound) {
remaining.add(scan);
edgePositions.add(scan);
}
setBound(facing, newBound);
}
levelBoundListeners.forEach(x -> x.rescan(level, this, facing, remaining, facing.positive ? bound + 1 : bound));
}
}
}
} else if (allBlocks.add(pos) && !isWithinBoundsNoEdge(pos)) {
// Expanding
for (int i = 0; i < Facing.values().length; i++) {
Facing facing = Facing.values()[i];
Axis axis = facing.axis.toVanilla();
int bound = getBound(facing);
if (bound == pos.get(axis)) {
List<BlockPos> remaining = new ArrayList<>();
edgePositions.add(pos);
for (BlockPos edge : edgePositions) if (edge.get(axis) == bound)
remaining.add(edge);
levelBoundListeners.forEach(x -> x.rescan(level, this, facing, remaining, facing.positive ? bound + 1 : bound));
} else if (bound > pos.get(axis)) {
for (Iterator<BlockPos> itr = edgePositions.iterator(); itr.hasNext(); ) {
BlockPos edge = itr.next();
if (edge.get(axis) == bound && !isEdgeExcept(edge, facing))
itr.remove();
}
edgePositions.add(pos);
levelBoundListeners.forEach(x -> x.rescan(level, this, facing, new SingletonList<>(pos), facing.positive ? bound + 1 : bound));
}
}
}
}
Aggregations