Skip to content

Commit

Permalink
Remove stream in PlacedFeature (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH authored Nov 12, 2024
1 parent aa4cd01 commit a3e3e98
Show file tree
Hide file tree
Showing 49 changed files with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions patches/server/0102-Remove-stream-in-PlacedFeature.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: HaHaWTH <[email protected]>
Date: Tue, 9 Nov 2077 00:00:00 +0800
Subject: [PATCH] Remove stream in PlacedFeature

Stream operation in PlacedFeature take much time generating features,
replace them with for loop uwu
Before: 3684ms
After: 673ms

diff --git a/src/main/java/net/minecraft/world/level/levelgen/placement/PlacedFeature.java b/src/main/java/net/minecraft/world/level/levelgen/placement/PlacedFeature.java
index 43ef3fdd7af5883f4846b253d76e06da0f31729e..422e9ed66052c67dab674ee548b1471307a991f5 100644
--- a/src/main/java/net/minecraft/world/level/levelgen/placement/PlacedFeature.java
+++ b/src/main/java/net/minecraft/world/level/levelgen/placement/PlacedFeature.java
@@ -41,19 +41,25 @@ public record PlacedFeature(Holder<ConfiguredFeature<?, ?>> feature, List<Placem
}

private boolean placeWithContext(PlacementContext context, RandomSource random, BlockPos pos) {
- Stream<BlockPos> stream = Stream.of(pos);
+ // Leaf start - Remove stream in PlacedFeature
+ List<BlockPos> positions = java.util.Collections.singletonList(pos);

for (PlacementModifier placementModifier : this.placement) {
- stream = stream.flatMap(posx -> placementModifier.getPositions(context, random, posx));
+ List<BlockPos> newPositions = new java.util.ArrayList<>();
+ for (BlockPos posx : positions) {
+ placementModifier.getPositions(context, random, posx).forEach(newPositions::add);
+ }
+ positions = newPositions;
}

ConfiguredFeature<?, ?> configuredFeature = this.feature.value();
MutableBoolean mutableBoolean = new MutableBoolean();
- stream.forEach(placedPos -> {
+ for (BlockPos placedPos : positions) {
if (configuredFeature.place(context.getLevel(), context.generator(), random, placedPos)) {
mutableBoolean.setTrue();
}
- });
+ }
+ // Leaf end - Remove stream in PlacedFeature
return mutableBoolean.isTrue();
}

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit a3e3e98

Please sign in to comment.