use of team.creative.creativecore.common.util.type.list.SingletonList 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