mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2026-01-06 15:51:31 +00:00
Upstream has released updates that appear to apply and compile correctly Leaves Changes: LeavesMC/Leaves@88819fe8 Add mc-old hopper suck-in behavior (#395) LeavesMC/Leaves@7394e8dd Fix papermc repo LeavesMC/Leaves@85c7bf11 Remove cache-world-generator-sea-level (#392) LeavesMC/Leaves@00798036 init 1.21.4, and boom! LeavesMC/Leaves@91fc24da build change, but weight not work LeavesMC/Leaves@4ccdf459 just work LeavesMC/Leaves@05ee2e36 Build changes, and delete timings LeavesMC/Leaves@fcc859dc Fix API patches (#406) LeavesMC/Leaves@6a1259df 0006/0129 LeavesMC/Leaves@3e3b05df 0009/0129 LeavesMC/Leaves@c3255c4f 0011/0129 LeavesMC/Leaves@6284c7b6 0018/0129 LeavesMC/Leaves@7abdc88c 0030/0129 LeavesMC/Leaves@4d119ff9 0035/0129 LeavesMC/Leaves@60baed99 0043/0129 LeavesMC/Leaves@dc319d5b 0048/0129 LeavesMC/Leaves@73a505d5 0049/0129 LeavesMC/Leaves@016b29dd 0057/0129 LeavesMC/Leaves@c9cf5af8 0065/0129 LeavesMC/Leaves@330b79ff 0086/0129 (#408) LeavesMC/Leaves@06c1d946 0087/0129 LeavesMC/Leaves@bf4bc284 0091/0129 LeavesMC/Leaves@102a3b70 0097/0129 LeavesMC/Leaves@53b43fed 0101/0129 LeavesMC/Leaves@892f3925 102/129 LeavesMC/Leaves@08c3043a 0107/0129 LeavesMC/Leaves@48764d8e 0112/0129 LeavesMC/Leaves@8380feff 0118/0129 LeavesMC/Leaves@e51603db 0129/0129, 100% patched LeavesMC/Leaves@ef851152 fix some LeavesMC/Leaves@9b7c6e88 server work LeavesMC/Leaves@272b7dcb Protocol... (#409) LeavesMC/Leaves@7be1bc97 Make jade better LeavesMC/Leaves@5350f6ea Make action work LeavesMC/Leaves@f07c26c8 fix action jar
102 lines
5.1 KiB
Diff
102 lines
5.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
|
|
Date: Fri, 14 Jun 2024 23:19:55 +0800
|
|
Subject: [PATCH] Reduce worldgen allocations
|
|
|
|
This change optimizes the way SurfaceRules update their biome supplier,avoiding unnecessary object creations and thus reducing memory allocations
|
|
during world generation. The update method now reuses the existing PositionalBiomeGetter object if it's already present, otherwise it
|
|
initializes a new one.
|
|
Additionally, the tryApply method in SurfaceRules now avoids iterator
|
|
allocation by directly accessing the rules list, which further contributes
|
|
to reducing garbage collection pressure during world generation.
|
|
|
|
diff --git a/net/minecraft/world/level/levelgen/NoiseChunk.java b/net/minecraft/world/level/levelgen/NoiseChunk.java
|
|
index f861f9e087182470a3bbb22678dbdacb8a73e943..a3d0d17178eedfaef83e2e0df6b1c2d7784d8656 100644
|
|
--- a/net/minecraft/world/level/levelgen/NoiseChunk.java
|
|
+++ b/net/minecraft/world/level/levelgen/NoiseChunk.java
|
|
@@ -362,7 +362,17 @@ public class NoiseChunk implements DensityFunction.ContextProvider, DensityFunct
|
|
}
|
|
|
|
protected DensityFunction wrap(DensityFunction densityFunction) {
|
|
- return this.wrapped.computeIfAbsent(densityFunction, this::wrapNew);
|
|
+ // Leaf start - Reduce worldgen allocations
|
|
+ // Avoid lambda allocation
|
|
+ DensityFunction func = this.wrapped.get(densityFunction);
|
|
+
|
|
+ if (func == null) {
|
|
+ func = this.wrapNew(densityFunction);
|
|
+ this.wrapped.put(densityFunction, func);
|
|
+ }
|
|
+
|
|
+ return func;
|
|
+ // Leaf end - Reduce worldgen allocations
|
|
}
|
|
|
|
private DensityFunction wrapNew(DensityFunction densityFunction) {
|
|
diff --git a/net/minecraft/world/level/levelgen/SurfaceRules.java b/net/minecraft/world/level/levelgen/SurfaceRules.java
|
|
index 0948c8db90605a15a043b5c5bc74edecd7f9db1b..009e8a270c25614d03413d8b8b1f39c2da8ba12f 100644
|
|
--- a/net/minecraft/world/level/levelgen/SurfaceRules.java
|
|
+++ b/net/minecraft/world/level/levelgen/SurfaceRules.java
|
|
@@ -313,8 +313,15 @@ public class SurfaceRules {
|
|
}
|
|
|
|
protected void updateY(int stoneDepthAbove, int stoneDepthBelow, int waterHeight, int blockX, int blockY, int blockZ) {
|
|
- this.lastUpdateY++;
|
|
- this.biome = Suppliers.memoize(() -> this.biomeGetter.apply(this.pos.set(blockX, blockY, blockZ)));
|
|
+ // Leaf start - Reduce worldgen allocations
|
|
+ // Reuse supplier object instead of creating new ones every time
|
|
+ ++this.lastUpdateY;
|
|
+ Supplier<Holder<Biome>> getter = this.biome;
|
|
+ if (getter == null) {
|
|
+ this.biome = getter = new org.dreeam.leaf.util.biome.PositionalBiomeGetter(this.biomeGetter, this.pos);
|
|
+ }
|
|
+ ((org.dreeam.leaf.util.biome.PositionalBiomeGetter) getter).update(blockX, blockY, blockZ);
|
|
+ // Leaf end - Reduce worldgen allocations
|
|
this.blockY = blockY;
|
|
this.waterHeight = waterHeight;
|
|
this.stoneDepthBelow = stoneDepthBelow;
|
|
@@ -582,8 +589,13 @@ public class SurfaceRules {
|
|
@Nullable
|
|
@Override
|
|
public BlockState tryApply(int x, int y, int z) {
|
|
- for (SurfaceRules.SurfaceRule surfaceRule : this.rules) {
|
|
- BlockState blockState = surfaceRule.tryApply(x, y, z);
|
|
+ // Leaf start - Reduce worldgen allocations
|
|
+ // Avoid iterator allocation
|
|
+ int size = this.rules.size();
|
|
+ //noinspection ForLoopReplaceableByForEach
|
|
+ for (int i = 0; i < size; i++) {
|
|
+ BlockState blockState = this.rules.get(i).tryApply(x, y, z);
|
|
+ // Leaf end - Reduce worldgen allocations
|
|
if (blockState != null) {
|
|
return blockState;
|
|
}
|
|
diff --git a/net/minecraft/world/level/levelgen/material/MaterialRuleList.java b/net/minecraft/world/level/levelgen/material/MaterialRuleList.java
|
|
index 1605cc013d5a89a5d3cb68365bdcc18e2dd0a921..a3b5f74b5f9a0f4e62dee67e50f51e9e6b78d7fd 100644
|
|
--- a/net/minecraft/world/level/levelgen/material/MaterialRuleList.java
|
|
+++ b/net/minecraft/world/level/levelgen/material/MaterialRuleList.java
|
|
@@ -9,13 +9,17 @@ public record MaterialRuleList(NoiseChunk.BlockStateFiller[] materialRuleList) i
|
|
@Nullable
|
|
@Override
|
|
public BlockState calculate(DensityFunction.FunctionContext context) {
|
|
- for (NoiseChunk.BlockStateFiller blockStateFiller : this.materialRuleList) {
|
|
- BlockState blockState = blockStateFiller.calculate(context);
|
|
- if (blockState != null) {
|
|
- return blockState;
|
|
- }
|
|
+ // Leaf start - Reduce worldgen allocations
|
|
+ // Avoid iterator allocation
|
|
+ BlockState blockState = null;
|
|
+ int length = this.materialRuleList.length;
|
|
+
|
|
+ for (int i = 0; blockState == null && i < length; i++) {
|
|
+ NoiseChunk.BlockStateFiller blockStateFiller = this.materialRuleList[i];
|
|
+ blockState = blockStateFiller.calculate(context);
|
|
}
|
|
|
|
- return null;
|
|
+ return blockState;
|
|
+ // Leaf end - Reduce worldgen allocations
|
|
}
|
|
}
|