mirror of
https://github.com/Dreeam-qwq/Gale.git
synced 2026-01-06 15:41:56 +00:00
389 lines
24 KiB
Diff
389 lines
24 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Martijn Muijsers <martijnmuijsers@live.nl>
|
|
Date: Fri, 3 Feb 2023 23:17:33 +0100
|
|
Subject: [PATCH] Yielding memoized Supplier
|
|
|
|
License: AGPL-3.0 (https://www.gnu.org/licenses/agpl-3.0.html)
|
|
Gale - https://galemc.org
|
|
|
|
diff --git a/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java
|
|
index 47a3580caef45ffe71446c247d4e06e332b2fda2..0b7d6bdd9d0543a4b37abfdd67c9fda4688134de 100644
|
|
--- a/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java
|
|
+++ b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java
|
|
@@ -41,6 +41,7 @@ import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
import org.bukkit.configuration.ConfigurationSection;
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
+import org.galemc.gale.executor.lock.YieldingMemoizedSupplier;
|
|
import org.jetbrains.annotations.VisibleForTesting;
|
|
import org.slf4j.Logger;
|
|
import org.spigotmc.SpigotConfig;
|
|
@@ -127,7 +128,7 @@ public class PaperConfigurations extends Configurations<GlobalConfiguration, Wor
|
|
See https://docs.papermc.io/paper/configuration for more information.
|
|
""";
|
|
|
|
- public static final Supplier<SpigotWorldConfig> SPIGOT_WORLD_DEFAULTS = Suppliers.memoize(() -> new SpigotWorldConfig(RandomStringUtils.randomAlphabetic(255)) { // Gale - Gale configuration
|
|
+ public static final Supplier<SpigotWorldConfig> SPIGOT_WORLD_DEFAULTS = new YieldingMemoizedSupplier<>(() -> new SpigotWorldConfig(RandomStringUtils.randomAlphabetic(255)) { // Gale - Gale configuration, yielding memoized Supplier
|
|
@Override // override to ensure "verbose" is false
|
|
public void init() {
|
|
SpigotConfig.readConfig(SpigotWorldConfig.class, this);
|
|
diff --git a/src/main/java/io/papermc/paper/console/BrigadierCommandCompleter.java b/src/main/java/io/papermc/paper/console/BrigadierCommandCompleter.java
|
|
index 0627c98cae0b5ebdd71a849ae1299d7d3d581850..b0ea72d8a186a8e2758d0b2e3204cc81463085d4 100644
|
|
--- a/src/main/java/io/papermc/paper/console/BrigadierCommandCompleter.java
|
|
+++ b/src/main/java/io/papermc/paper/console/BrigadierCommandCompleter.java
|
|
@@ -15,6 +15,7 @@ import net.minecraft.commands.CommandSourceStack;
|
|
import net.minecraft.network.chat.ComponentUtils;
|
|
import net.minecraft.server.dedicated.DedicatedServer;
|
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
+import org.galemc.gale.executor.lock.YieldingMemoizedSupplier;
|
|
import org.jline.reader.Candidate;
|
|
import org.jline.reader.LineReader;
|
|
import org.jline.reader.ParsedLine;
|
|
@@ -27,7 +28,7 @@ public final class BrigadierCommandCompleter {
|
|
|
|
public BrigadierCommandCompleter(final @NonNull DedicatedServer server) {
|
|
this.server = server;
|
|
- this.commandSourceStack = Suppliers.memoize(this.server::createCommandSourceStack);
|
|
+ this.commandSourceStack = new YieldingMemoizedSupplier<>(this.server::createCommandSourceStack); // Gale - yielding memoized Supplier
|
|
}
|
|
|
|
public void complete(final @NonNull LineReader reader, final @NonNull ParsedLine line, final @NonNull List<Candidate> candidates, final @NonNull List<Completion> existing) {
|
|
diff --git a/src/main/java/io/papermc/paper/console/BrigadierCommandHighlighter.java b/src/main/java/io/papermc/paper/console/BrigadierCommandHighlighter.java
|
|
index dd9d77d7c7f1a5a130a1f4c15e5b1e68ae3753e1..c3661b25ae8b4dc5e9d7e9bb0e14f6d2b314f309 100644
|
|
--- a/src/main/java/io/papermc/paper/console/BrigadierCommandHighlighter.java
|
|
+++ b/src/main/java/io/papermc/paper/console/BrigadierCommandHighlighter.java
|
|
@@ -9,6 +9,7 @@ import java.util.regex.Pattern;
|
|
import net.minecraft.commands.CommandSourceStack;
|
|
import net.minecraft.server.dedicated.DedicatedServer;
|
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
+import org.galemc.gale.executor.lock.YieldingMemoizedSupplier;
|
|
import org.jline.reader.Highlighter;
|
|
import org.jline.reader.LineReader;
|
|
import org.jline.utils.AttributedString;
|
|
@@ -22,7 +23,7 @@ public final class BrigadierCommandHighlighter implements Highlighter {
|
|
|
|
public BrigadierCommandHighlighter(final @NonNull DedicatedServer server) {
|
|
this.server = server;
|
|
- this.commandSourceStack = Suppliers.memoize(this.server::createCommandSourceStack);
|
|
+ this.commandSourceStack = new YieldingMemoizedSupplier<>(this.server::createCommandSourceStack); // Gale - yielding memoized Supplier
|
|
}
|
|
|
|
@Override
|
|
diff --git a/src/main/java/net/minecraft/util/ExtraCodecs.java b/src/main/java/net/minecraft/util/ExtraCodecs.java
|
|
index 57fae84be749bd4a61a0c700a5cefce7122643e6..c695b59c17f441ab7e2065817c0c5242866c0e55 100644
|
|
--- a/src/main/java/net/minecraft/util/ExtraCodecs.java
|
|
+++ b/src/main/java/net/minecraft/util/ExtraCodecs.java
|
|
@@ -1,7 +1,6 @@
|
|
package net.minecraft.util;
|
|
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
-import com.google.common.base.Suppliers;
|
|
import com.google.common.collect.ImmutableList;
|
|
import com.google.gson.JsonElement;
|
|
import com.google.gson.JsonParseException;
|
|
@@ -52,6 +51,7 @@ import org.apache.commons.lang3.mutable.MutableObject;
|
|
import org.joml.AxisAngle4f;
|
|
import org.joml.Matrix4f;
|
|
import org.joml.Quaternionf;
|
|
+import org.galemc.gale.executor.lock.YieldingMemoizedSupplier;
|
|
import org.joml.Vector3f;
|
|
|
|
public class ExtraCodecs {
|
|
@@ -542,7 +542,7 @@ public class ExtraCodecs {
|
|
|
|
static record LazyInitializedCodec<A>(Supplier<Codec<A>> delegate) implements Codec<A> {
|
|
LazyInitializedCodec {
|
|
- delegate = Suppliers.memoize(delegate::get); // Gale - dev import deobfuscation fixes
|
|
+ delegate = new YieldingMemoizedSupplier<>(delegate::get); // Gale - dev import deobfuscation fixes, yielding memoized Supplier
|
|
}
|
|
|
|
public <T> DataResult<Pair<A, T>> decode(DynamicOps<T> dynamicOps, T object) {
|
|
diff --git a/src/main/java/net/minecraft/util/LazyLoadedValue.java b/src/main/java/net/minecraft/util/LazyLoadedValue.java
|
|
index 906d4bca809fe2ae6b45e7212be8547b81422b01..3ceff89ef71768826be1156538dc70f25d68488a 100644
|
|
--- a/src/main/java/net/minecraft/util/LazyLoadedValue.java
|
|
+++ b/src/main/java/net/minecraft/util/LazyLoadedValue.java
|
|
@@ -1,6 +1,7 @@
|
|
package net.minecraft.util;
|
|
|
|
-import com.google.common.base.Suppliers;
|
|
+import org.galemc.gale.executor.lock.YieldingMemoizedSupplier;
|
|
+
|
|
import java.util.function.Supplier;
|
|
|
|
/** @deprecated */
|
|
@@ -9,7 +10,7 @@ public class LazyLoadedValue<T> {
|
|
private final Supplier<T> factory;
|
|
|
|
public LazyLoadedValue(Supplier<T> delegate) {
|
|
- this.factory = Suppliers.memoize(delegate::get);
|
|
+ this.factory = new YieldingMemoizedSupplier<>(delegate); // Gale - yielding memoized Supplier
|
|
}
|
|
|
|
public T get() {
|
|
diff --git a/src/main/java/net/minecraft/util/datafix/fixes/ChunkProtoTickListFix.java b/src/main/java/net/minecraft/util/datafix/fixes/ChunkProtoTickListFix.java
|
|
index d6de68b4b0edabf37ba551b91bbe6682895b2a82..b4cf65c1b84a4ebcf4a362ec614f5fd7a585ab2e 100644
|
|
--- a/src/main/java/net/minecraft/util/datafix/fixes/ChunkProtoTickListFix.java
|
|
+++ b/src/main/java/net/minecraft/util/datafix/fixes/ChunkProtoTickListFix.java
|
|
@@ -1,6 +1,5 @@
|
|
package net.minecraft.util.datafix.fixes;
|
|
|
|
-import com.google.common.base.Suppliers;
|
|
import com.google.common.collect.ImmutableMap;
|
|
import com.google.common.collect.ImmutableSet;
|
|
import com.mojang.datafixers.DSL;
|
|
@@ -24,6 +23,7 @@ import java.util.function.Supplier;
|
|
import java.util.stream.Stream;
|
|
import javax.annotation.Nullable;
|
|
import org.apache.commons.lang3.mutable.MutableInt;
|
|
+import org.galemc.gale.executor.lock.YieldingMemoizedSupplier;
|
|
|
|
public class ChunkProtoTickListFix extends DataFix {
|
|
private static final int SECTION_WIDTH = 16;
|
|
@@ -64,7 +64,7 @@ public class ChunkProtoTickListFix extends DataFix {
|
|
}
|
|
|
|
typedx2.getOptionalTyped(opticFinder4).ifPresent((typed3) -> { // Gale - dev import deobfuscation fixes
|
|
- int2ObjectMap.put(i, Suppliers.memoize(() -> {
|
|
+ int2ObjectMap.put(i, new YieldingMemoizedSupplier<>(() -> { // Gale - yielding memoized Supplier
|
|
// Gale start - dev import deobfuscation fixes
|
|
List<? extends Dynamic<?>> list = typed.getOptionalTyped(opticFinder6).map((typedx3) -> {
|
|
return typedx3.write().result().map((dynamic3) -> {
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java b/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java
|
|
index c84908095a93d42826b21bf5f3490410fb0a5708..6d2ef064400304fb96f9ec5174b926371d01ed7c 100644
|
|
--- a/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java
|
|
+++ b/src/main/java/net/minecraft/world/inventory/AbstractContainerMenu.java
|
|
@@ -33,6 +33,7 @@ import net.minecraft.world.flag.FeatureFlagSet;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
+import org.galemc.gale.executor.lock.YieldingMemoizedSupplier;
|
|
import org.slf4j.Logger;
|
|
|
|
// CraftBukkit start
|
|
@@ -238,7 +239,7 @@ public abstract class AbstractContainerMenu {
|
|
ItemStack itemstack = ((Slot) this.slots.get(i)).getItem();
|
|
|
|
Objects.requireNonNull(itemstack);
|
|
- Supplier<ItemStack> supplier = Suppliers.memoize(itemstack::copy);
|
|
+ Supplier<ItemStack> supplier = new YieldingMemoizedSupplier<>(itemstack::copy); // Gale - yielding memoized Supplier
|
|
|
|
this.triggerSlotListeners(i, itemstack, supplier);
|
|
this.synchronizeSlotToRemote(i, itemstack, supplier);
|
|
diff --git a/src/main/java/net/minecraft/world/item/HoneycombItem.java b/src/main/java/net/minecraft/world/item/HoneycombItem.java
|
|
index f0b720eafc538f97d788f89bd2f2e9da0ff84a19..d12020b2eca0130340436d38247f933f6b246f01 100644
|
|
--- a/src/main/java/net/minecraft/world/item/HoneycombItem.java
|
|
+++ b/src/main/java/net/minecraft/world/item/HoneycombItem.java
|
|
@@ -16,12 +16,13 @@ import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.world.level.block.Blocks;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.gameevent.GameEvent;
|
|
+import org.galemc.gale.executor.lock.YieldingMemoizedSupplier;
|
|
|
|
public class HoneycombItem extends Item {
|
|
- public static final Supplier<BiMap<Block, Block>> WAXABLES = Suppliers.memoize(() -> {
|
|
+ public static final Supplier<BiMap<Block, Block>> WAXABLES = new YieldingMemoizedSupplier<>(() -> { // Gale - yielding memoized Supplier
|
|
return ImmutableBiMap.<Block, Block>builder().put(Blocks.COPPER_BLOCK, Blocks.WAXED_COPPER_BLOCK).put(Blocks.EXPOSED_COPPER, Blocks.WAXED_EXPOSED_COPPER).put(Blocks.WEATHERED_COPPER, Blocks.WAXED_WEATHERED_COPPER).put(Blocks.OXIDIZED_COPPER, Blocks.WAXED_OXIDIZED_COPPER).put(Blocks.CUT_COPPER, Blocks.WAXED_CUT_COPPER).put(Blocks.EXPOSED_CUT_COPPER, Blocks.WAXED_EXPOSED_CUT_COPPER).put(Blocks.WEATHERED_CUT_COPPER, Blocks.WAXED_WEATHERED_CUT_COPPER).put(Blocks.OXIDIZED_CUT_COPPER, Blocks.WAXED_OXIDIZED_CUT_COPPER).put(Blocks.CUT_COPPER_SLAB, Blocks.WAXED_CUT_COPPER_SLAB).put(Blocks.EXPOSED_CUT_COPPER_SLAB, Blocks.WAXED_EXPOSED_CUT_COPPER_SLAB).put(Blocks.WEATHERED_CUT_COPPER_SLAB, Blocks.WAXED_WEATHERED_CUT_COPPER_SLAB).put(Blocks.OXIDIZED_CUT_COPPER_SLAB, Blocks.WAXED_OXIDIZED_CUT_COPPER_SLAB).put(Blocks.CUT_COPPER_STAIRS, Blocks.WAXED_CUT_COPPER_STAIRS).put(Blocks.EXPOSED_CUT_COPPER_STAIRS, Blocks.WAXED_EXPOSED_CUT_COPPER_STAIRS).put(Blocks.WEATHERED_CUT_COPPER_STAIRS, Blocks.WAXED_WEATHERED_CUT_COPPER_STAIRS).put(Blocks.OXIDIZED_CUT_COPPER_STAIRS, Blocks.WAXED_OXIDIZED_CUT_COPPER_STAIRS).build();
|
|
});
|
|
- public static final Supplier<BiMap<Block, Block>> WAX_OFF_BY_BLOCK = Suppliers.memoize(() -> {
|
|
+ public static final Supplier<BiMap<Block, Block>> WAX_OFF_BY_BLOCK = new YieldingMemoizedSupplier<>(() -> { // Gale - yielding memoized Supplier
|
|
return WAXABLES.get().inverse();
|
|
});
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/PathNavigationRegion.java b/src/main/java/net/minecraft/world/level/PathNavigationRegion.java
|
|
index efe922810507c96183a56a5e81a7b14214d8747b..b87c9a6189161e776fa488c1ac6215edca596184 100644
|
|
--- a/src/main/java/net/minecraft/world/level/PathNavigationRegion.java
|
|
+++ b/src/main/java/net/minecraft/world/level/PathNavigationRegion.java
|
|
@@ -24,6 +24,7 @@ import net.minecraft.world.level.material.FluidState;
|
|
import net.minecraft.world.level.material.Fluids;
|
|
import net.minecraft.world.phys.AABB;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
+import org.galemc.gale.executor.lock.YieldingMemoizedSupplier;
|
|
|
|
public class PathNavigationRegion implements BlockGetter, CollisionGetter {
|
|
protected final int centerX;
|
|
@@ -35,7 +36,7 @@ public class PathNavigationRegion implements BlockGetter, CollisionGetter {
|
|
|
|
public PathNavigationRegion(Level world, BlockPos minPos, BlockPos maxPos) {
|
|
this.level = world;
|
|
- this.plains = Suppliers.memoize(() -> {
|
|
+ this.plains = new YieldingMemoizedSupplier<>(() -> { // Gale - yielding memoized Supplier
|
|
return world.registryAccess().registryOrThrow(Registries.BIOME).getHolderOrThrow(Biomes.PLAINS);
|
|
});
|
|
this.centerX = SectionPos.blockToSectionCoord(minPos.getX());
|
|
diff --git a/src/main/java/net/minecraft/world/level/biome/BiomeGenerationSettings.java b/src/main/java/net/minecraft/world/level/biome/BiomeGenerationSettings.java
|
|
index 3f9628ec396a11ffd49270be7996d13f606366b6..3f7e8bb767ba4e886549cf487a20f62c3519012a 100644
|
|
--- a/src/main/java/net/minecraft/world/level/biome/BiomeGenerationSettings.java
|
|
+++ b/src/main/java/net/minecraft/world/level/biome/BiomeGenerationSettings.java
|
|
@@ -26,6 +26,7 @@ import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver;
|
|
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
|
import net.minecraft.world.level.levelgen.feature.Feature;
|
|
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
|
+import org.galemc.gale.executor.lock.YieldingMemoizedSupplier;
|
|
import org.slf4j.Logger;
|
|
|
|
public class BiomeGenerationSettings {
|
|
@@ -46,12 +47,12 @@ public class BiomeGenerationSettings {
|
|
BiomeGenerationSettings(Map<GenerationStep.Carving, HolderSet<ConfiguredWorldCarver<?>>> carvers, List<HolderSet<PlacedFeature>> features) {
|
|
this.carvers = carvers;
|
|
this.features = features;
|
|
- this.flowerFeatures = Suppliers.memoize(() -> {
|
|
+ this.flowerFeatures = new YieldingMemoizedSupplier<>(() -> { // Gale - yielding memoized Supplier
|
|
return features.stream().flatMap(HolderSet::stream).map(Holder::value).flatMap(PlacedFeature::getFeatures).filter((feature) -> {
|
|
return feature.feature() == Feature.FLOWER;
|
|
}).collect(ImmutableList.toImmutableList());
|
|
});
|
|
- this.featureSet = Suppliers.memoize(() -> {
|
|
+ this.featureSet = new YieldingMemoizedSupplier<>(() -> { // Gale - yielding memoized Supplier
|
|
return features.stream().flatMap(HolderSet::stream).map(Holder::value).collect(Collectors.toSet());
|
|
});
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/WeatheringCopper.java b/src/main/java/net/minecraft/world/level/block/WeatheringCopper.java
|
|
index 16bd93606ac4a9c34108a92dd4b98cb4600221d9..f4aeb2a4cafe7fe0782660c0e7fd94ae216a8940 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/WeatheringCopper.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/WeatheringCopper.java
|
|
@@ -6,12 +6,13 @@ import com.google.common.collect.ImmutableBiMap;
|
|
import java.util.Optional;
|
|
import java.util.function.Supplier;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
+import org.galemc.gale.executor.lock.YieldingMemoizedSupplier;
|
|
|
|
public interface WeatheringCopper extends ChangeOverTimeBlock<WeatheringCopper.WeatherState> {
|
|
- Supplier<BiMap<Block, Block>> NEXT_BY_BLOCK = Suppliers.memoize(() -> {
|
|
+ Supplier<BiMap<Block, Block>> NEXT_BY_BLOCK = new YieldingMemoizedSupplier<>(() -> { // Gale - yielding memoized Supplier
|
|
return ImmutableBiMap.<Block, Block>builder().put(Blocks.COPPER_BLOCK, Blocks.EXPOSED_COPPER).put(Blocks.EXPOSED_COPPER, Blocks.WEATHERED_COPPER).put(Blocks.WEATHERED_COPPER, Blocks.OXIDIZED_COPPER).put(Blocks.CUT_COPPER, Blocks.EXPOSED_CUT_COPPER).put(Blocks.EXPOSED_CUT_COPPER, Blocks.WEATHERED_CUT_COPPER).put(Blocks.WEATHERED_CUT_COPPER, Blocks.OXIDIZED_CUT_COPPER).put(Blocks.CUT_COPPER_SLAB, Blocks.EXPOSED_CUT_COPPER_SLAB).put(Blocks.EXPOSED_CUT_COPPER_SLAB, Blocks.WEATHERED_CUT_COPPER_SLAB).put(Blocks.WEATHERED_CUT_COPPER_SLAB, Blocks.OXIDIZED_CUT_COPPER_SLAB).put(Blocks.CUT_COPPER_STAIRS, Blocks.EXPOSED_CUT_COPPER_STAIRS).put(Blocks.EXPOSED_CUT_COPPER_STAIRS, Blocks.WEATHERED_CUT_COPPER_STAIRS).put(Blocks.WEATHERED_CUT_COPPER_STAIRS, Blocks.OXIDIZED_CUT_COPPER_STAIRS).build();
|
|
});
|
|
- Supplier<BiMap<Block, Block>> PREVIOUS_BY_BLOCK = Suppliers.memoize(() -> {
|
|
+ Supplier<BiMap<Block, Block>> PREVIOUS_BY_BLOCK = new YieldingMemoizedSupplier<>(() -> { // Gale - yielding memoized Supplier
|
|
return NEXT_BY_BLOCK.get().inverse();
|
|
});
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
|
|
index 42ecfc1237bfc724dc9134a6a8bae3670251449e..0a1ecc1a88fee4b68a69d95c417a663a320febca 100644
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
|
|
@@ -76,6 +76,7 @@ import net.minecraft.world.level.levelgen.structure.placement.RandomSpreadStruct
|
|
import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement;
|
|
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager;
|
|
import org.apache.commons.lang3.mutable.MutableBoolean;
|
|
+import org.galemc.gale.executor.lock.YieldingMemoizedSupplier;
|
|
|
|
public abstract class ChunkGenerator {
|
|
|
|
@@ -93,7 +94,7 @@ public abstract class ChunkGenerator {
|
|
public ChunkGenerator(BiomeSource biomeSource, Function<Holder<Biome>, BiomeGenerationSettings> generationSettingsGetter) {
|
|
this.biomeSource = biomeSource;
|
|
this.generationSettingsGetter = generationSettingsGetter;
|
|
- this.featuresPerStep = Suppliers.memoize(() -> {
|
|
+ this.featuresPerStep = new YieldingMemoizedSupplier<>(() -> { // Gale - yielding memoized Supplier
|
|
return FeatureSorter.buildFeaturesPerStep(List.copyOf(biomeSource.possibleBiomes()), (holder) -> {
|
|
return ((BiomeGenerationSettings) generationSettingsGetter.apply(holder)).features();
|
|
}, true);
|
|
diff --git a/src/main/java/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java b/src/main/java/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java
|
|
index 66205f6d99c629ce0e7e7d7b29394674bde115fb..14da533ccca35ba18190424c6d1074ce7e4de574 100644
|
|
--- a/src/main/java/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java
|
|
+++ b/src/main/java/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java
|
|
@@ -49,6 +49,7 @@ import net.minecraft.world.level.levelgen.blending.Blender;
|
|
import net.minecraft.world.level.levelgen.carver.CarvingContext;
|
|
import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver;
|
|
import org.apache.commons.lang3.mutable.MutableObject;
|
|
+import org.galemc.gale.executor.lock.YieldingMemoizedSupplier;
|
|
|
|
public final class NoiseBasedChunkGenerator extends ChunkGenerator {
|
|
|
|
@@ -67,7 +68,7 @@ public final class NoiseBasedChunkGenerator extends ChunkGenerator {
|
|
public NoiseBasedChunkGenerator(BiomeSource biomeSource, Holder<NoiseGeneratorSettings> settings) {
|
|
super(biomeSource);
|
|
this.settings = settings;
|
|
- this.globalFluidPicker = Suppliers.memoize(() -> {
|
|
+ this.globalFluidPicker = new YieldingMemoizedSupplier<>(() -> { // Gale - yielding memoized Supplier
|
|
// Gale start - Lithium - cache world generator sea level
|
|
var fluidPicker = NoiseBasedChunkGenerator.createFluidPicker((NoiseGeneratorSettings) settings.value());
|
|
this.cachedSeaLevel = settings.value().seaLevel();
|
|
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 45b0706a48c4bf44923a2590f34913b7373de8f4..5990287d2ffaa32accb2444d6627ed29dc65d60d 100644
|
|
--- a/src/main/java/net/minecraft/world/level/levelgen/SurfaceRules.java
|
|
+++ b/src/main/java/net/minecraft/world/level/levelgen/SurfaceRules.java
|
|
@@ -28,6 +28,7 @@ import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.chunk.ChunkAccess;
|
|
import net.minecraft.world.level.levelgen.placement.CaveSurface;
|
|
import net.minecraft.world.level.levelgen.synth.NormalNoise;
|
|
+import org.galemc.gale.executor.lock.YieldingMemoizedSupplier;
|
|
|
|
public class SurfaceRules {
|
|
public static final SurfaceRules.ConditionSource ON_FLOOR = stoneDepthCheck(0, false, CaveSurface.FLOOR);
|
|
@@ -310,7 +311,7 @@ public class SurfaceRules {
|
|
|
|
protected void updateY(int stoneDepthAbove, int stoneDepthBelow, int fluidHeight, int blockX, int blockY, int blockZ) {
|
|
++this.lastUpdateY;
|
|
- this.biome = Suppliers.memoize(() -> {
|
|
+ this.biome = new YieldingMemoizedSupplier<>(() -> { // Gale - yielding memoized Supplier
|
|
return this.biomeGetter.apply(this.pos.set(blockX, blockY, blockZ));
|
|
});
|
|
this.blockY = blockY;
|
|
diff --git a/src/main/java/org/galemc/gale/executor/lock/YieldingMemoizedSupplier.java b/src/main/java/org/galemc/gale/executor/lock/YieldingMemoizedSupplier.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..8732ea0a07a88117e0e6a2fe073a48bad4ff8b19
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/galemc/gale/executor/lock/YieldingMemoizedSupplier.java
|
|
@@ -0,0 +1,60 @@
|
|
+// Gale - yielding memoized Supplier
|
|
+
|
|
+package org.galemc.gale.executor.lock;
|
|
+
|
|
+import com.google.common.base.Suppliers;
|
|
+import org.galemc.gale.concurrent.Mutex;
|
|
+import org.galemc.gale.concurrent.ThreadAwareNonReentrantLock;
|
|
+import org.jetbrains.annotations.Nullable;
|
|
+
|
|
+import java.util.function.Supplier;
|
|
+
|
|
+/**
|
|
+ * A replacement for {@link Suppliers#memoize} that provides thread-safety
|
|
+ * with a {@link YieldingLock} instead of by a <code>synchronized</code> block.
|
|
+ * <br>
|
|
+ * The {@link #get()} method of this supplier must not be reachable from the body of the original supplier.
|
|
+ * To assure this, the lock used internally is a {@link ThreadAwareNonReentrantLock}.
|
|
+ * <br>
|
|
+ * The original {@link Supplier} will be de-referenced once the value has been provided once,
|
|
+ * so that it may be garbage collected.
|
|
+ */
|
|
+public class YieldingMemoizedSupplier<T extends @Nullable Object> implements Supplier<T> {
|
|
+
|
|
+ private volatile @Nullable Supplier<T> delegate;
|
|
+ private volatile boolean initialized;
|
|
+ @Nullable T value;
|
|
+ private final YieldingLock lock = new MultipleWaitingBaseThreadsYieldingLock(new ThreadAwareNonReentrantLock(Mutex.createLock()));
|
|
+
|
|
+ public YieldingMemoizedSupplier(Supplier<T> delegate) {
|
|
+ this.delegate = delegate;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public T get() {
|
|
+ if (!this.initialized) {
|
|
+ this.lock.lock();
|
|
+ try {
|
|
+ if (!this.initialized) {
|
|
+ T t = this.delegate.get();
|
|
+ this.value = t;
|
|
+ this.initialized = true;
|
|
+ this.delegate = null;
|
|
+ return t;
|
|
+ }
|
|
+ } finally {
|
|
+ this.lock.unlock();
|
|
+ }
|
|
+ }
|
|
+ return value;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public String toString() {
|
|
+ var delegate = this.delegate;
|
|
+ return this.getClass().getSimpleName() + "("
|
|
+ + (delegate == null ? "<supplier that returned " + this.value + ">" : delegate)
|
|
+ + ")";
|
|
+ }
|
|
+
|
|
+}
|