mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-24 01:19:25 +00:00
[ci skip] Format patches
This commit is contained in:
@@ -5,7 +5,7 @@ Subject: [PATCH] Decompile fix
|
|||||||
|
|
||||||
|
|
||||||
diff --git a/src/main/java/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java b/src/main/java/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java
|
diff --git a/src/main/java/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java b/src/main/java/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java
|
||||||
index bc885d2cc95572ec68f1df62555fdba7998b1d93..663b3b12d9a7cdc04b7f86ccfe6bc6fcfd5028bc 100644
|
index b2a4ae4388758f89fcd0dc3b0c4c03bf46fa5470..a4f9de18d40d5d85a809af3777b00eb75b1af027 100644
|
||||||
--- a/src/main/java/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java
|
--- a/src/main/java/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java
|
||||||
+++ b/src/main/java/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java
|
+++ b/src/main/java/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java
|
||||||
@@ -34,7 +34,7 @@ public interface CustomPacketPayload {
|
@@ -34,7 +34,7 @@ public interface CustomPacketPayload {
|
||||||
@@ -17,3 +17,46 @@ index bc885d2cc95572ec68f1df62555fdba7998b1d93..663b3b12d9a7cdc04b7f86ccfe6bc6fc
|
|||||||
streamCodec.encode(value, (T)payload);
|
streamCodec.encode(value, (T)payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/Brain.java b/src/main/java/net/minecraft/world/entity/ai/Brain.java
|
||||||
|
index afbb027021acfbe25d534a84f1750e420bbde6e0..2ae8c9d56d88987b750e57025d313cfa9300c7e4 100644
|
||||||
|
--- a/src/main/java/net/minecraft/world/entity/ai/Brain.java
|
||||||
|
+++ b/src/main/java/net/minecraft/world/entity/ai/Brain.java
|
||||||
|
@@ -79,7 +79,7 @@ public class Brain<E extends LivingEntity> {
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> DataResult<Brain<E>> decode(DynamicOps<T> dynamicOps, MapLike<T> mapLike) {
|
||||||
|
- MutableObject<DataResult<Builder<Brain.MemoryValue<?>>>> mutableObject = new MutableObject<>(
|
||||||
|
+ MutableObject<DataResult<Builder<Brain.MemoryValue<?>>>> mutableObject2 = new MutableObject<>( // Leaf - Decompile fix
|
||||||
|
DataResult.success(ImmutableList.builder())
|
||||||
|
);
|
||||||
|
mapLike.entries()
|
||||||
|
@@ -91,10 +91,10 @@ public class Brain<E extends LivingEntity> {
|
||||||
|
DataResult<? extends Brain.MemoryValue<?>> dataResult2 = dataResult.flatMap(
|
||||||
|
memoryType -> this.captureRead((MemoryModuleType<T>)memoryType, dynamicOps, (T)pair.getSecond())
|
||||||
|
);
|
||||||
|
- mutableObject.setValue(mutableObject.getValue().apply2(Builder::add, dataResult2));
|
||||||
|
+ mutableObject2.setValue(mutableObject2.getValue().apply2(Builder::add, dataResult2)); // Leaf - Decompile fix
|
||||||
|
}
|
||||||
|
);
|
||||||
|
- ImmutableList<Brain.MemoryValue<?>> immutableList = mutableObject.getValue()
|
||||||
|
+ ImmutableList<Brain.MemoryValue<?>> immutableList = mutableObject2.getValue() // Leaf - Decompile fix
|
||||||
|
.resultOrPartial(Brain.LOGGER::error)
|
||||||
|
.map(Builder::build)
|
||||||
|
.orElseGet(ImmutableList::of);
|
||||||
|
@@ -194,14 +194,14 @@ public class Brain<E extends LivingEntity> {
|
||||||
|
if (optional == null) {
|
||||||
|
throw new IllegalStateException("Unregistered memory fetched: " + type);
|
||||||
|
} else {
|
||||||
|
- return optional.map(ExpirableValue::getValue);
|
||||||
|
+ return (Optional<U>) optional.map(ExpirableValue::getValue); // Leaf - Decompile fix
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public <U> Optional<U> getMemoryInternal(MemoryModuleType<U> type) {
|
||||||
|
Optional<? extends ExpirableValue<?>> optional = this.memories.get(type);
|
||||||
|
- return optional == null ? null : optional.map(ExpirableValue::getValue);
|
||||||
|
+ return optional == null ? null : (Optional<U>) optional.map(ExpirableValue::getValue); // Leaf - Decompile fix
|
||||||
|
}
|
||||||
|
|
||||||
|
public <U> long getTimeUntilExpiry(MemoryModuleType<U> type) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
||||||
Date: Sat, 5 Oct 2024 15:39:15 -0400
|
Date: Sat, 5 Oct 2024 15:39:15 -0400
|
||||||
Subject: [PATCH] Optimize trial spawner ticking
|
Subject: [PATCH] Remove stream in trial spawner ticking
|
||||||
|
|
||||||
|
|
||||||
diff --git a/src/main/java/net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerState.java b/src/main/java/net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerState.java
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerState.java b/src/main/java/net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerState.java
|
||||||
51
patches/server/0091-Remove-stream-in-Brain.patch
Normal file
51
patches/server/0091-Remove-stream-in-Brain.patch
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
|
||||||
|
Date: Sat, 26 Oct 2024 00:06:04 +0800
|
||||||
|
Subject: [PATCH] Remove stream in Brain
|
||||||
|
|
||||||
|
Dreeam TODO: Check this
|
||||||
|
|
||||||
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/Brain.java b/src/main/java/net/minecraft/world/entity/ai/Brain.java
|
||||||
|
index 2ae8c9d56d88987b750e57025d313cfa9300c7e4..f6439fb10031a8f17ce3a5bee9f6e89275edebc7 100644
|
||||||
|
--- a/src/main/java/net/minecraft/world/entity/ai/Brain.java
|
||||||
|
+++ b/src/main/java/net/minecraft/world/entity/ai/Brain.java
|
||||||
|
@@ -69,13 +69,17 @@ public class Brain<E extends LivingEntity> {
|
||||||
|
mutableObject.setValue(
|
||||||
|
(new MapCodec<Brain<E>>() {
|
||||||
|
public <T> Stream<T> keys(DynamicOps<T> dynamicOps) {
|
||||||
|
- return memoryModules.stream()
|
||||||
|
- .flatMap(
|
||||||
|
- memoryType -> memoryType.getCodec()
|
||||||
|
- .map(codec -> BuiltInRegistries.MEMORY_MODULE_TYPE.getKey((MemoryModuleType<?>)memoryType))
|
||||||
|
- .stream()
|
||||||
|
- )
|
||||||
|
- .map(id -> dynamicOps.createString(id.toString()));
|
||||||
|
+ // Leaf start - Optimize Brain
|
||||||
|
+ List<String> results = new java.util.ArrayList<>();
|
||||||
|
+ for (MemoryModuleType<?> memoryType : memoryModules) {
|
||||||
|
+ Optional<?> codecOptional = memoryType.getCodec();
|
||||||
|
+ if (codecOptional.isPresent()) {
|
||||||
|
+ net.minecraft.resources.ResourceLocation id = BuiltInRegistries.MEMORY_MODULE_TYPE.getKey(memoryType);
|
||||||
|
+ results.add(id.toString());
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ return results.stream().map(dynamicOps::createString);
|
||||||
|
+ // Leaf end - Optimize Brain
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> DataResult<Brain<E>> decode(DynamicOps<T> dynamicOps, MapLike<T> mapLike) {
|
||||||
|
@@ -152,7 +156,13 @@ public class Brain<E extends LivingEntity> {
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream<Brain.MemoryValue<?>> memories() {
|
||||||
|
- return this.memories.entrySet().stream().map(entry -> Brain.MemoryValue.createUnchecked(entry.getKey(), entry.getValue()));
|
||||||
|
+ // Leaf start - Optimize Brain
|
||||||
|
+ List<Brain.MemoryValue<?>> result = new java.util.ArrayList<>();
|
||||||
|
+ for (Entry<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> entry : this.memories.entrySet()) {
|
||||||
|
+ result.add(Brain.MemoryValue.createUnchecked(entry.getKey(), entry.getValue()));
|
||||||
|
+ }
|
||||||
|
+ return result.stream();
|
||||||
|
+ // Leaf end - Optimize Brain
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasMemoryValue(MemoryModuleType<?> type) {
|
||||||
@@ -3,6 +3,7 @@ From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
|
|||||||
Date: Sat, 26 Oct 2024 00:56:24 +0800
|
Date: Sat, 26 Oct 2024 00:56:24 +0800
|
||||||
Subject: [PATCH] Remove stream in BehaviorUtils
|
Subject: [PATCH] Remove stream in BehaviorUtils
|
||||||
|
|
||||||
|
Dreeam TODO: Check this
|
||||||
|
|
||||||
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorUtils.java b/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorUtils.java
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorUtils.java b/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorUtils.java
|
||||||
index 74fe07a3737728b67987ef794103346c1e428109..e2de86d7a86fde183c3ece4de0a1f899a7c3b8b0 100644
|
index 74fe07a3737728b67987ef794103346c1e428109..e2de86d7a86fde183c3ece4de0a1f899a7c3b8b0 100644
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
|
||||||
|
Date: Sat, 26 Oct 2024 00:06:04 +0800
|
||||||
|
Subject: [PATCH] Replace brain maps with optimized collection
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/Brain.java b/src/main/java/net/minecraft/world/entity/ai/Brain.java
|
||||||
|
index f6439fb10031a8f17ce3a5bee9f6e89275edebc7..2e0859cd62fd064d43aaf3ac24269d159a6bd49e 100644
|
||||||
|
--- a/src/main/java/net/minecraft/world/entity/ai/Brain.java
|
||||||
|
+++ b/src/main/java/net/minecraft/world/entity/ai/Brain.java
|
||||||
|
@@ -45,14 +45,18 @@ public class Brain<E extends LivingEntity> {
|
||||||
|
static final Logger LOGGER = LogUtils.getLogger();
|
||||||
|
private final Supplier<Codec<Brain<E>>> codec;
|
||||||
|
private static final int SCHEDULE_UPDATE_DELAY = 20;
|
||||||
|
- private final Map<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memories = Maps.newHashMap();
|
||||||
|
- private final Map<SensorType<? extends Sensor<? super E>>, Sensor<? super E>> sensors = Maps.newLinkedHashMap();
|
||||||
|
- private final Map<Integer, Map<Activity, Set<BehaviorControl<? super E>>>> availableBehaviorsByPriority = Maps.newTreeMap();
|
||||||
|
+ // Leaf start - Optimize Brain
|
||||||
|
+ private final Map<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memories = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>();
|
||||||
|
+ private final Map<SensorType<? extends Sensor<? super E>>, Sensor<? super E>> sensors = new it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap<>();
|
||||||
|
+ private final Map<Integer, Map<Activity, Set<BehaviorControl<? super E>>>> availableBehaviorsByPriority = new it.unimi.dsi.fastutil.objects.Object2ObjectRBTreeMap<>();
|
||||||
|
+ // Leaf end - Optimize Brain
|
||||||
|
private Schedule schedule = Schedule.EMPTY;
|
||||||
|
- private final Map<Activity, Set<Pair<MemoryModuleType<?>, MemoryStatus>>> activityRequirements = Maps.newHashMap();
|
||||||
|
- private final Map<Activity, Set<MemoryModuleType<?>>> activityMemoriesToEraseWhenStopped = Maps.newHashMap();
|
||||||
|
- private Set<Activity> coreActivities = Sets.newHashSet();
|
||||||
|
- private final Set<Activity> activeActivities = Sets.newHashSet();
|
||||||
|
+ // Leaf start - Optimize Brain
|
||||||
|
+ private final Map<Activity, Set<Pair<MemoryModuleType<?>, MemoryStatus>>> activityRequirements = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>();
|
||||||
|
+ private final Map<Activity, Set<MemoryModuleType<?>>> activityMemoriesToEraseWhenStopped = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>();
|
||||||
|
+ private Set<Activity> coreActivities = new it.unimi.dsi.fastutil.objects.ObjectOpenHashSet<>();
|
||||||
|
+ private final Set<Activity> activeActivities = new it.unimi.dsi.fastutil.objects.ObjectOpenHashSet<>();
|
||||||
|
+ // Leaf end - Optimize Brain
|
||||||
|
private Activity defaultActivity = Activity.IDLE;
|
||||||
|
private long lastScheduleUpdate = -9999L;
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
|
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
|
||||||
Date: Fri, 14 Jun 2024 23:19:55 +0800
|
Date: Fri, 14 Jun 2024 23:19:55 +0800
|
||||||
Subject: [PATCH] Reduce-worldgen-allocations
|
Subject: [PATCH] Reduce worldgen allocations
|
||||||
|
|
||||||
This change optimizes the way SurfaceRules update their biome supplier,avoiding unnecessary object creations and thus reducing memory 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
|
during world generation. The update method now reuses the existing PositionalBiomeGetter object if it's already present, otherwise it
|
||||||
@@ -11,7 +11,7 @@ allocation by directly accessing the rules list, which further contributes
|
|||||||
to reducing garbage collection pressure during world generation.
|
to reducing garbage collection pressure during world generation.
|
||||||
|
|
||||||
diff --git a/src/main/java/net/minecraft/world/level/levelgen/NoiseChunk.java b/src/main/java/net/minecraft/world/level/levelgen/NoiseChunk.java
|
diff --git a/src/main/java/net/minecraft/world/level/levelgen/NoiseChunk.java b/src/main/java/net/minecraft/world/level/levelgen/NoiseChunk.java
|
||||||
index 5e89428321d91edb893826b0eb0b9050d327d310..2bee2988b5019d81da25784ef60feb3589f32538 100644
|
index 5e89428321d91edb893826b0eb0b9050d327d310..3e8882e4779d6037025e7ee26ebbb46a55a7e52d 100644
|
||||||
--- a/src/main/java/net/minecraft/world/level/levelgen/NoiseChunk.java
|
--- a/src/main/java/net/minecraft/world/level/levelgen/NoiseChunk.java
|
||||||
+++ b/src/main/java/net/minecraft/world/level/levelgen/NoiseChunk.java
|
+++ b/src/main/java/net/minecraft/world/level/levelgen/NoiseChunk.java
|
||||||
@@ -359,7 +359,14 @@ public class NoiseChunk implements DensityFunction.ContextProvider, DensityFunct
|
@@ -359,7 +359,14 @@ public class NoiseChunk implements DensityFunction.ContextProvider, DensityFunct
|
||||||
@@ -26,12 +26,12 @@ index 5e89428321d91edb893826b0eb0b9050d327d310..2bee2988b5019d81da25784ef60feb35
|
|||||||
+ this.wrapped.put(function, func);
|
+ this.wrapped.put(function, func);
|
||||||
+ }
|
+ }
|
||||||
+ return func;
|
+ return func;
|
||||||
+ // Leaf end
|
+ // Leaf end - Avoid lambda allocation
|
||||||
}
|
}
|
||||||
|
|
||||||
private DensityFunction wrapNew(DensityFunction function) {
|
private DensityFunction wrapNew(DensityFunction function) {
|
||||||
diff --git a/src/main/java/net/minecraft/world/level/levelgen/SurfaceRules.java b/src/main/java/net/minecraft/world/level/levelgen/SurfaceRules.java
|
diff --git a/src/main/java/net/minecraft/world/level/levelgen/SurfaceRules.java b/src/main/java/net/minecraft/world/level/levelgen/SurfaceRules.java
|
||||||
index 9df053ddff459d4aab478106c6e66a5fc3cda8f6..24ba023c0789984dd173e982030c29406c110428 100644
|
index 9df053ddff459d4aab478106c6e66a5fc3cda8f6..49e2aee0093eb8fa34fc7fe11f376c1dd67aa5f1 100644
|
||||||
--- a/src/main/java/net/minecraft/world/level/levelgen/SurfaceRules.java
|
--- a/src/main/java/net/minecraft/world/level/levelgen/SurfaceRules.java
|
||||||
+++ b/src/main/java/net/minecraft/world/level/levelgen/SurfaceRules.java
|
+++ b/src/main/java/net/minecraft/world/level/levelgen/SurfaceRules.java
|
||||||
@@ -314,8 +314,14 @@ public class SurfaceRules {
|
@@ -314,8 +314,14 @@ public class SurfaceRules {
|
||||||
@@ -47,7 +47,7 @@ index 9df053ddff459d4aab478106c6e66a5fc3cda8f6..24ba023c0789984dd173e982030c2940
|
|||||||
+ this.biome = getter = new org.dreeam.leaf.util.biome.PositionalBiomeGetter(this.biomeGetter, this.pos);
|
+ 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);
|
+ ((org.dreeam.leaf.util.biome.PositionalBiomeGetter)getter).update(blockX, blockY, blockZ);
|
||||||
+ // Leaf end
|
+ // Leaf end - Reuse supplier object instead of creating new ones every time
|
||||||
this.blockY = blockY;
|
this.blockY = blockY;
|
||||||
this.waterHeight = fluidHeight;
|
this.waterHeight = fluidHeight;
|
||||||
this.stoneDepthBelow = stoneDepthBelow;
|
this.stoneDepthBelow = stoneDepthBelow;
|
||||||
@@ -62,12 +62,12 @@ index 9df053ddff459d4aab478106c6e66a5fc3cda8f6..24ba023c0789984dd173e982030c2940
|
|||||||
+ //noinspection ForLoopReplaceableByForEach
|
+ //noinspection ForLoopReplaceableByForEach
|
||||||
+ for (int i = 0; i < size; i++) {
|
+ for (int i = 0; i < size; i++) {
|
||||||
+ BlockState blockState = this.rules.get(i).tryApply(x, y, z);
|
+ BlockState blockState = this.rules.get(i).tryApply(x, y, z);
|
||||||
+ // Leaf end
|
+ // Leaf end - Avoid iterator allocation
|
||||||
if (blockState != null) {
|
if (blockState != null) {
|
||||||
return blockState;
|
return blockState;
|
||||||
}
|
}
|
||||||
diff --git a/src/main/java/net/minecraft/world/level/levelgen/material/MaterialRuleList.java b/src/main/java/net/minecraft/world/level/levelgen/material/MaterialRuleList.java
|
diff --git a/src/main/java/net/minecraft/world/level/levelgen/material/MaterialRuleList.java b/src/main/java/net/minecraft/world/level/levelgen/material/MaterialRuleList.java
|
||||||
index afdbc74a3012fa717f59ecef613567338d285b7b..b219a5c1a489f337ceb96a80246fa8c8121f8a4f 100644
|
index afdbc74a3012fa717f59ecef613567338d285b7b..088e02e0941341fea958413176f49ae262e04d2a 100644
|
||||||
--- a/src/main/java/net/minecraft/world/level/levelgen/material/MaterialRuleList.java
|
--- a/src/main/java/net/minecraft/world/level/levelgen/material/MaterialRuleList.java
|
||||||
+++ b/src/main/java/net/minecraft/world/level/levelgen/material/MaterialRuleList.java
|
+++ b/src/main/java/net/minecraft/world/level/levelgen/material/MaterialRuleList.java
|
||||||
@@ -10,13 +10,16 @@ public record MaterialRuleList(List<NoiseChunk.BlockStateFiller> materialRuleLis
|
@@ -10,13 +10,16 @@ public record MaterialRuleList(List<NoiseChunk.BlockStateFiller> materialRuleLis
|
||||||
@@ -79,7 +79,7 @@ index afdbc74a3012fa717f59ecef613567338d285b7b..b219a5c1a489f337ceb96a80246fa8c8
|
|||||||
- if (blockState != null) {
|
- if (blockState != null) {
|
||||||
- return blockState;
|
- return blockState;
|
||||||
- }
|
- }
|
||||||
+ // Leaf start - avoid iterator allocation
|
+ // Leaf start - Avoid iterator allocation
|
||||||
+ BlockState blockState = null;
|
+ BlockState blockState = null;
|
||||||
+ int s = this.materialRuleList.size();
|
+ int s = this.materialRuleList.size();
|
||||||
+
|
+
|
||||||
@@ -90,7 +90,7 @@ index afdbc74a3012fa717f59ecef613567338d285b7b..b219a5c1a489f337ceb96a80246fa8c8
|
|||||||
|
|
||||||
- return null;
|
- return null;
|
||||||
+ return blockState;
|
+ return blockState;
|
||||||
+ // Leaf end
|
+ // Leaf end - Avoid iterator allocation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
diff --git a/src/main/java/org/dreeam/leaf/util/biome/PositionalBiomeGetter.java b/src/main/java/org/dreeam/leaf/util/biome/PositionalBiomeGetter.java
|
diff --git a/src/main/java/org/dreeam/leaf/util/biome/PositionalBiomeGetter.java b/src/main/java/org/dreeam/leaf/util/biome/PositionalBiomeGetter.java
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
||||||
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
|
|
||||||
Date: Sat, 26 Oct 2024 00:06:04 +0800
|
|
||||||
Subject: [PATCH] Optimize Brain
|
|
||||||
|
|
||||||
|
|
||||||
diff --git a/src/main/java/net/minecraft/world/entity/ai/Brain.java b/src/main/java/net/minecraft/world/entity/ai/Brain.java
|
|
||||||
index afbb027021acfbe25d534a84f1750e420bbde6e0..2e0859cd62fd064d43aaf3ac24269d159a6bd49e 100644
|
|
||||||
--- a/src/main/java/net/minecraft/world/entity/ai/Brain.java
|
|
||||||
+++ b/src/main/java/net/minecraft/world/entity/ai/Brain.java
|
|
||||||
@@ -45,14 +45,18 @@ public class Brain<E extends LivingEntity> {
|
|
||||||
static final Logger LOGGER = LogUtils.getLogger();
|
|
||||||
private final Supplier<Codec<Brain<E>>> codec;
|
|
||||||
private static final int SCHEDULE_UPDATE_DELAY = 20;
|
|
||||||
- private final Map<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memories = Maps.newHashMap();
|
|
||||||
- private final Map<SensorType<? extends Sensor<? super E>>, Sensor<? super E>> sensors = Maps.newLinkedHashMap();
|
|
||||||
- private final Map<Integer, Map<Activity, Set<BehaviorControl<? super E>>>> availableBehaviorsByPriority = Maps.newTreeMap();
|
|
||||||
+ // Leaf start - Optimize Brain
|
|
||||||
+ private final Map<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memories = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>();
|
|
||||||
+ private final Map<SensorType<? extends Sensor<? super E>>, Sensor<? super E>> sensors = new it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap<>();
|
|
||||||
+ private final Map<Integer, Map<Activity, Set<BehaviorControl<? super E>>>> availableBehaviorsByPriority = new it.unimi.dsi.fastutil.objects.Object2ObjectRBTreeMap<>();
|
|
||||||
+ // Leaf end - Optimize Brain
|
|
||||||
private Schedule schedule = Schedule.EMPTY;
|
|
||||||
- private final Map<Activity, Set<Pair<MemoryModuleType<?>, MemoryStatus>>> activityRequirements = Maps.newHashMap();
|
|
||||||
- private final Map<Activity, Set<MemoryModuleType<?>>> activityMemoriesToEraseWhenStopped = Maps.newHashMap();
|
|
||||||
- private Set<Activity> coreActivities = Sets.newHashSet();
|
|
||||||
- private final Set<Activity> activeActivities = Sets.newHashSet();
|
|
||||||
+ // Leaf start - Optimize Brain
|
|
||||||
+ private final Map<Activity, Set<Pair<MemoryModuleType<?>, MemoryStatus>>> activityRequirements = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>();
|
|
||||||
+ private final Map<Activity, Set<MemoryModuleType<?>>> activityMemoriesToEraseWhenStopped = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>();
|
|
||||||
+ private Set<Activity> coreActivities = new it.unimi.dsi.fastutil.objects.ObjectOpenHashSet<>();
|
|
||||||
+ private final Set<Activity> activeActivities = new it.unimi.dsi.fastutil.objects.ObjectOpenHashSet<>();
|
|
||||||
+ // Leaf end - Optimize Brain
|
|
||||||
private Activity defaultActivity = Activity.IDLE;
|
|
||||||
private long lastScheduleUpdate = -9999L;
|
|
||||||
|
|
||||||
@@ -69,17 +73,21 @@ public class Brain<E extends LivingEntity> {
|
|
||||||
mutableObject.setValue(
|
|
||||||
(new MapCodec<Brain<E>>() {
|
|
||||||
public <T> Stream<T> keys(DynamicOps<T> dynamicOps) {
|
|
||||||
- return memoryModules.stream()
|
|
||||||
- .flatMap(
|
|
||||||
- memoryType -> memoryType.getCodec()
|
|
||||||
- .map(codec -> BuiltInRegistries.MEMORY_MODULE_TYPE.getKey((MemoryModuleType<?>)memoryType))
|
|
||||||
- .stream()
|
|
||||||
- )
|
|
||||||
- .map(id -> dynamicOps.createString(id.toString()));
|
|
||||||
+ // Leaf start - Optimize Brain
|
|
||||||
+ List<String> results = new java.util.ArrayList<>();
|
|
||||||
+ for (MemoryModuleType<?> memoryType : memoryModules) {
|
|
||||||
+ Optional<?> codecOptional = memoryType.getCodec();
|
|
||||||
+ if (codecOptional.isPresent()) {
|
|
||||||
+ net.minecraft.resources.ResourceLocation id = BuiltInRegistries.MEMORY_MODULE_TYPE.getKey(memoryType);
|
|
||||||
+ results.add(id.toString());
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ return results.stream().map(dynamicOps::createString);
|
|
||||||
+ // Leaf end - Optimize Brain
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> DataResult<Brain<E>> decode(DynamicOps<T> dynamicOps, MapLike<T> mapLike) {
|
|
||||||
- MutableObject<DataResult<Builder<Brain.MemoryValue<?>>>> mutableObject = new MutableObject<>(
|
|
||||||
+ MutableObject<DataResult<Builder<Brain.MemoryValue<?>>>> mutableObject2 = new MutableObject<>( // Leaf - Decompile fix
|
|
||||||
DataResult.success(ImmutableList.builder())
|
|
||||||
);
|
|
||||||
mapLike.entries()
|
|
||||||
@@ -91,10 +99,10 @@ public class Brain<E extends LivingEntity> {
|
|
||||||
DataResult<? extends Brain.MemoryValue<?>> dataResult2 = dataResult.flatMap(
|
|
||||||
memoryType -> this.captureRead((MemoryModuleType<T>)memoryType, dynamicOps, (T)pair.getSecond())
|
|
||||||
);
|
|
||||||
- mutableObject.setValue(mutableObject.getValue().apply2(Builder::add, dataResult2));
|
|
||||||
+ mutableObject2.setValue(mutableObject2.getValue().apply2(Builder::add, dataResult2)); // Leaf - Decompile fix
|
|
||||||
}
|
|
||||||
);
|
|
||||||
- ImmutableList<Brain.MemoryValue<?>> immutableList = mutableObject.getValue()
|
|
||||||
+ ImmutableList<Brain.MemoryValue<?>> immutableList = mutableObject2.getValue() // Leaf - Decompile fix
|
|
||||||
.resultOrPartial(Brain.LOGGER::error)
|
|
||||||
.map(Builder::build)
|
|
||||||
.orElseGet(ImmutableList::of);
|
|
||||||
@@ -152,7 +160,13 @@ public class Brain<E extends LivingEntity> {
|
|
||||||
}
|
|
||||||
|
|
||||||
Stream<Brain.MemoryValue<?>> memories() {
|
|
||||||
- return this.memories.entrySet().stream().map(entry -> Brain.MemoryValue.createUnchecked(entry.getKey(), entry.getValue()));
|
|
||||||
+ // Leaf start - Optimize Brain
|
|
||||||
+ List<Brain.MemoryValue<?>> result = new java.util.ArrayList<>();
|
|
||||||
+ for (Entry<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> entry : this.memories.entrySet()) {
|
|
||||||
+ result.add(Brain.MemoryValue.createUnchecked(entry.getKey(), entry.getValue()));
|
|
||||||
+ }
|
|
||||||
+ return result.stream();
|
|
||||||
+ // Leaf end - Optimize Brain
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasMemoryValue(MemoryModuleType<?> type) {
|
|
||||||
@@ -194,14 +208,14 @@ public class Brain<E extends LivingEntity> {
|
|
||||||
if (optional == null) {
|
|
||||||
throw new IllegalStateException("Unregistered memory fetched: " + type);
|
|
||||||
} else {
|
|
||||||
- return optional.map(ExpirableValue::getValue);
|
|
||||||
+ return (Optional<U>) optional.map(ExpirableValue::getValue); // Leaf - Decompile fix
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public <U> Optional<U> getMemoryInternal(MemoryModuleType<U> type) {
|
|
||||||
Optional<? extends ExpirableValue<?>> optional = this.memories.get(type);
|
|
||||||
- return optional == null ? null : optional.map(ExpirableValue::getValue);
|
|
||||||
+ return optional == null ? null : (Optional<U>) optional.map(ExpirableValue::getValue); // Leaf - Decompile fix
|
|
||||||
}
|
|
||||||
|
|
||||||
public <U> long getTimeUntilExpiry(MemoryModuleType<U> type) {
|
|
||||||
Reference in New Issue
Block a user