From 3433d919d2e63501593ae53b9f29f10c11dda6f3 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Wed, 30 Oct 2024 21:06:15 -0400 Subject: [PATCH] See ya later streamagator - Switch to enhanced for loops over streams due to their performance issues - Fixes #5043 --- .../contraptions/ContraptionCollider.java | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/ContraptionCollider.java b/src/main/java/com/simibubi/create/content/contraptions/ContraptionCollider.java index 5be8ff1087..3c542c490c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/ContraptionCollider.java +++ b/src/main/java/com/simibubi/create/content/contraptions/ContraptionCollider.java @@ -14,7 +14,6 @@ import org.apache.commons.lang3.mutable.MutableObject; import org.apache.commons.lang3.tuple.MutablePair; -import com.google.common.base.Predicates; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllMovementBehaviours; import com.simibubi.create.AllPackets; @@ -161,8 +160,7 @@ static void collideEntities(AbstractContraptionEntity contraptionEntity) { List bbs = new ArrayList<>(); List potentialHits = getPotentiallyCollidedShapes(world, contraption, localBB.expandTowards(motionCopy)); - potentialHits.forEach(shape -> shape.toAabbs() - .forEach(bbs::add)); + potentialHits.forEach(shape -> bbs.addAll(shape.toAabbs())); return bbs; }); @@ -669,19 +667,23 @@ private static List getPotentiallyCollidedShapes(Level world, Contra BlockPos min = BlockPos.containing(blockScanBB.minX, blockScanBB.minY, blockScanBB.minZ); BlockPos max = BlockPos.containing(blockScanBB.maxX, blockScanBB.maxY, blockScanBB.maxZ); - List potentialHits = BlockPos.betweenClosedStream(min, max) - .filter(contraption.getBlocks()::containsKey) - .filter(Predicates.not(contraption::isHiddenInPortal)) - .map(p -> { - BlockState blockState = contraption.getBlocks() - .get(p).state(); - BlockPos pos = contraption.getBlocks() - .get(p).pos(); - VoxelShape collisionShape = blockState.getCollisionShape(world, p); - return collisionShape.move(pos.getX(), pos.getY(), pos.getZ()); - }) - .filter(Predicates.not(VoxelShape::isEmpty)) - .toList(); + List potentialHits = new ArrayList<>(); + + for (BlockPos p : BlockPos.betweenClosed(min, max)) { + if (contraption.blocks.containsKey(p) && !contraption.isHiddenInPortal(p)) { + StructureBlockInfo info = contraption.getBlocks().get(p); + + BlockState blockState = info.state(); + BlockPos pos = info.pos(); + + VoxelShape collisionShape = blockState.getCollisionShape(world, p) + .move(pos.getX(), pos.getY(), pos.getZ()); + + if (!collisionShape.isEmpty()) { + potentialHits.add(collisionShape); + } + } + } return potentialHits; }