Skip to content

Commit

Permalink
See ya later streamagator
Browse files Browse the repository at this point in the history
- Switch to enhanced for loops over streams due to their performance issues
- Fixes Creators-of-Create#5043
  • Loading branch information
IThundxr committed Oct 31, 2024
1 parent d39f899 commit 3433d91
Showing 1 changed file with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -161,8 +160,7 @@ static void collideEntities(AbstractContraptionEntity contraptionEntity) {
List<AABB> bbs = new ArrayList<>();
List<VoxelShape> potentialHits =
getPotentiallyCollidedShapes(world, contraption, localBB.expandTowards(motionCopy));
potentialHits.forEach(shape -> shape.toAabbs()
.forEach(bbs::add));
potentialHits.forEach(shape -> bbs.addAll(shape.toAabbs()));
return bbs;

});
Expand Down Expand Up @@ -669,19 +667,23 @@ private static List<VoxelShape> 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<VoxelShape> 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<VoxelShape> 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;
}
Expand Down

0 comments on commit 3433d91

Please sign in to comment.