260 lines
15 KiB
Diff
260 lines
15 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: AlphaKR93 <dev@alpha93.kr>
|
|
Date: Sat, 26 Oct 2024 13:42:26 +0900
|
|
Subject: [PATCH] Implement alternative noise chunk generator
|
|
|
|
Based on Steveplays28/noisium.
|
|
Copyright (C) 2024 Darion Spaargaren, Licensed under GPL v3.
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
|
|
index a28366b8ed0da356dad6941e0a817d0b7ec43738..a4e655e40282def5d94a598230485f2a02b14eab 100644
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
|
|
@@ -19,9 +19,9 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
|
|
public static final int SECTION_HEIGHT = 16;
|
|
public static final int SECTION_SIZE = 4096;
|
|
public static final int BIOME_CONTAINER_BITS = 2;
|
|
- short nonEmptyBlockCount; // Paper - package private
|
|
- private short tickingBlockCount;
|
|
- private short tickingFluidCount;
|
|
+ public short nonEmptyBlockCount; // Paper - package private // Plazma -> public
|
|
+ public short tickingBlockCount; // Plazma - private -> public
|
|
+ public short tickingFluidCount; // Plazma - private -> public
|
|
public short fluidStateCount; // Pufferfish
|
|
public final PalettedContainer<BlockState> states;
|
|
// CraftBukkit start - read/write
|
|
@@ -35,8 +35,8 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
|
|
}
|
|
}
|
|
|
|
- private int specialCollidingBlocks;
|
|
- private final ca.spottedleaf.moonrise.common.list.IBlockDataList tickingBlocks = new ca.spottedleaf.moonrise.common.list.IBlockDataList();
|
|
+ public int specialCollidingBlocks; // Plazma - private -> public
|
|
+ public final ca.spottedleaf.moonrise.common.list.IBlockDataList tickingBlocks = new ca.spottedleaf.moonrise.common.list.IBlockDataList(); // Plazma - private -> public
|
|
|
|
@Override
|
|
public final int moonrise$getSpecialCollidingBlocks() {
|
|
@@ -271,17 +271,13 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
|
|
// CraftBukkit end
|
|
|
|
public void fillBiomesFromNoise(BiomeResolver biomeSupplier, Climate.Sampler sampler, int x, int y, int z) {
|
|
- PalettedContainer<Holder<Biome>> datapaletteblock = this.biomes.recreate();
|
|
- boolean flag = true;
|
|
+ // Plazma start - Optimize noise
|
|
+ PalettedContainer<Holder<Biome>> block = this.biomes.recreate();
|
|
|
|
- for (int l = 0; l < 4; ++l) {
|
|
- for (int i1 = 0; i1 < 4; ++i1) {
|
|
- for (int j1 = 0; j1 < 4; ++j1) {
|
|
- datapaletteblock.getAndSetUnchecked(l, i1, j1, biomeSupplier.getNoiseBiome(x + l, y + i1, z + j1, sampler));
|
|
- }
|
|
- }
|
|
- }
|
|
+ for (int dY = 0; dY < 4; ++dY) for (int dZ = 0; dZ < 4; ++dZ) for (int dX = 0; dX < 4; ++dX)
|
|
+ block.getAndSetUnchecked(dX, dY, dZ, biomeSupplier.getNoiseBiome(x + dX, y + dY, z + dZ, sampler));
|
|
|
|
- this.biomes = datapaletteblock;
|
|
+ this.biomes = block;
|
|
+ // Plazma end - Optimize noise
|
|
}
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java b/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java
|
|
index 13d3c877b006a4975e7370713e3919c661e7890f..f3e7dcd0a5625c7b4e8a3512ee05637ab298a598 100644
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java
|
|
@@ -30,7 +30,7 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
|
|
public final IdMap<T> registry;
|
|
private final T @org.jetbrains.annotations.Nullable [] presetValues; // Paper - Anti-Xray - Add preset values
|
|
public volatile PalettedContainer.Data<T> data; // Paper - optimise collisions - public
|
|
- private final PalettedContainer.Strategy strategy;
|
|
+ public final PalettedContainer.Strategy strategy; // Plazma - private -> public
|
|
// private final ThreadingDetector threadingDetector = new ThreadingDetector("PalettedContainer"); // Paper - unused
|
|
|
|
public void acquire() {
|
|
@@ -386,7 +386,7 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
|
|
void accept(T object, int count);
|
|
}
|
|
|
|
- static record Data<T>(PalettedContainer.Configuration<T> configuration, BitStorage storage, Palette<T> palette) {
|
|
+ public record Data<T>(PalettedContainer.Configuration<T> configuration, BitStorage storage, Palette<T> palette) { // Plazma - package-private -> public
|
|
public void copyFrom(Palette<T> palette, BitStorage storage) {
|
|
for (int i = 0; i < storage.getSize(); i++) {
|
|
T object = palette.valueFor(storage.get(i));
|
|
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 688d9a2fe0ad0f176cd19a3ed7f2669fef2c962e..e22a7d4f2831b4d03b797cfb043a17c0d61b5f3b 100644
|
|
--- a/src/main/java/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java
|
|
+++ b/src/main/java/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java
|
|
@@ -51,6 +51,7 @@ import org.apache.commons.lang3.mutable.MutableObject;
|
|
|
|
public final class NoiseBasedChunkGenerator extends ChunkGenerator {
|
|
|
|
+ public static boolean PLAZMA_USE_NOISIUM = false; // Plazma - Optimize noise chunk generation
|
|
public static final MapCodec<NoiseBasedChunkGenerator> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
|
|
return instance.group(BiomeSource.CODEC.fieldOf("biome_source").forGetter((chunkgeneratorabstract) -> {
|
|
return chunkgeneratorabstract.biomeSource;
|
|
@@ -270,6 +271,24 @@ public final class NoiseBasedChunkGenerator extends ChunkGenerator {
|
|
int k = Mth.floorDiv(noisesettings.height(), noisesettings.getCellHeight());
|
|
|
|
return k <= 0 ? CompletableFuture.completedFuture(chunk) : CompletableFuture.supplyAsync(Util.wrapThreadWithTaskName("wgen_fill_noise", () -> {
|
|
+ // Plazma start - Optimize noise chunk generation
|
|
+ if (PLAZMA_USE_NOISIUM) {
|
|
+ int l = chunk.getSectionIndex(k * noisesettings.getCellHeight() - 1 + i);
|
|
+ int i1 = chunk.getSectionIndex(i);
|
|
+
|
|
+ var set = chunk.getSections();
|
|
+ for (int j1 = l; j1 >= i1; --j1) set[j1].acquire();
|
|
+
|
|
+ ChunkAccess ichunkaccess1;
|
|
+ try {
|
|
+ ichunkaccess1 = this.doFill(blender, structureAccessor, noiseConfig, chunk, j, k);
|
|
+ } finally {
|
|
+ for (int j1 = l; j1 >= i1; --j1) set[j1].release();
|
|
+ }
|
|
+
|
|
+ return ichunkaccess1;
|
|
+ }
|
|
+ // Plazma end - Optimize noise chunk generation
|
|
int l = chunk.getSectionIndex(k * noisesettings.getCellHeight() - 1 + i);
|
|
int i1 = chunk.getSectionIndex(i);
|
|
Set<LevelChunkSection> set = Sets.newHashSet();
|
|
@@ -377,6 +396,25 @@ public final class NoiseBasedChunkGenerator extends ChunkGenerator {
|
|
|
|
iblockdata = this.debugPreliminarySurfaceLevel(noisechunk, j4, j3, i5, iblockdata);
|
|
if (iblockdata != NoiseBasedChunkGenerator.AIR && !SharedConstants.debugVoidTerrain(chunk.getPos())) {
|
|
+ // Plazma start - Optimize noise
|
|
+ if (PLAZMA_USE_NOISIUM) {
|
|
+ ++chunksection.nonEmptyBlockCount;
|
|
+ if (!iblockdata.getFluidState().isEmpty()) ++chunksection.tickingFluidCount;
|
|
+ if (ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.isSpecialCollidingBlock(iblockdata))
|
|
+ ++chunksection.specialCollidingBlocks;
|
|
+
|
|
+ if (!iblockdata.isRandomlyTicking()) {
|
|
+ ++chunksection.tickingBlockCount;
|
|
+ chunksection.tickingBlocks.remove(k4, k3, j5);
|
|
+ chunksection.tickingBlocks.add(k4, k3, j5, iblockdata);
|
|
+ }
|
|
+
|
|
+ chunksection.states.data.storage().set(
|
|
+ chunksection.states.strategy.getIndex(k4, k3, j5),
|
|
+ chunksection.states.data.palette().idFor(iblockdata)
|
|
+ );
|
|
+ } else
|
|
+ // Plazma end - Optimize noise
|
|
chunksection.setBlockState(k4, k3, j5, iblockdata, false);
|
|
heightmap.update(k4, j3, j5, iblockdata);
|
|
heightmap1.update(k4, j3, j5, iblockdata);
|
|
diff --git a/src/main/java/net/minecraft/world/level/levelgen/NoiseSettings.java b/src/main/java/net/minecraft/world/level/levelgen/NoiseSettings.java
|
|
index 52fcf1b92854e5c67c51a83d31b4a136413b54e0..e8fbf1408102681fabb588c2bcc4a56df9b0152f 100644
|
|
--- a/src/main/java/net/minecraft/world/level/levelgen/NoiseSettings.java
|
|
+++ b/src/main/java/net/minecraft/world/level/levelgen/NoiseSettings.java
|
|
@@ -8,7 +8,7 @@ import net.minecraft.core.QuartPos;
|
|
import net.minecraft.world.level.LevelHeightAccessor;
|
|
import net.minecraft.world.level.dimension.DimensionType;
|
|
|
|
-public record NoiseSettings(int minY, int height, int noiseSizeHorizontal, int noiseSizeVertical) {
|
|
+public record NoiseSettings(int minY, int height, int noiseSizeHorizontal, int noiseSizeVertical, int horizontalCellBlockCount, int verticalCellBlockCount) { // Plazma - Optimize noise
|
|
public static final Codec<NoiseSettings> CODEC = RecordCodecBuilder.<NoiseSettings>create(
|
|
instance -> instance.group(
|
|
Codec.intRange(DimensionType.MIN_Y, DimensionType.MAX_Y).fieldOf("min_y").forGetter(NoiseSettings::minY),
|
|
@@ -16,7 +16,7 @@ public record NoiseSettings(int minY, int height, int noiseSizeHorizontal, int n
|
|
Codec.intRange(1, 4).fieldOf("size_horizontal").forGetter(NoiseSettings::noiseSizeHorizontal),
|
|
Codec.intRange(1, 4).fieldOf("size_vertical").forGetter(NoiseSettings::noiseSizeVertical)
|
|
)
|
|
- .apply(instance, NoiseSettings::new)
|
|
+ .apply(instance, NoiseSettings::create) // Plazma - Optimize noise
|
|
)
|
|
.comapFlatMap(NoiseSettings::guardY, Function.identity());
|
|
protected static final NoiseSettings OVERWORLD_NOISE_SETTINGS = create(-64, 384, 1, 2);
|
|
@@ -36,7 +36,7 @@ public record NoiseSettings(int minY, int height, int noiseSizeHorizontal, int n
|
|
}
|
|
|
|
public static NoiseSettings create(int minimumY, int height, int horizontalSize, int verticalSize) {
|
|
- NoiseSettings noiseSettings = new NoiseSettings(minimumY, height, horizontalSize, verticalSize);
|
|
+ NoiseSettings noiseSettings = new NoiseSettings(minimumY, height, horizontalSize, verticalSize, QuartPos.toBlock(horizontalSize), QuartPos.toBlock(verticalSize)); // Plazma - Optimize noise
|
|
guardY(noiseSettings).error().ifPresent(error -> {
|
|
throw new IllegalStateException(error.message());
|
|
});
|
|
@@ -44,16 +44,16 @@ public record NoiseSettings(int minY, int height, int noiseSizeHorizontal, int n
|
|
}
|
|
|
|
public int getCellHeight() {
|
|
- return QuartPos.toBlock(this.noiseSizeVertical());
|
|
+ return this.noiseSizeHorizontal; // Plazma - Optimize noise
|
|
}
|
|
|
|
public int getCellWidth() {
|
|
- return QuartPos.toBlock(this.noiseSizeHorizontal());
|
|
+ return this.noiseSizeVertical; // Plazma - Optimize noise
|
|
}
|
|
|
|
public NoiseSettings clampToHeightAccessor(LevelHeightAccessor world) {
|
|
int i = Math.max(this.minY, world.getMinBuildHeight());
|
|
int j = Math.min(this.minY + this.height, world.getMaxBuildHeight()) - i;
|
|
- return new NoiseSettings(i, j, this.noiseSizeHorizontal, this.noiseSizeVertical);
|
|
+ return new NoiseSettings(i, j, this.noiseSizeHorizontal, this.noiseSizeVertical, QuartPos.toBlock(this.noiseSizeHorizontal), QuartPos.toBlock(this.noiseSizeVertical)); // Plazma - Optimize noise
|
|
}
|
|
}
|
|
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..89dbfdb315c02a15deae51b176fdd3e0d8b03496 100644
|
|
--- a/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,15 @@ public record MaterialRuleList(List<NoiseChunk.BlockStateFiller> materialRuleLis
|
|
@Nullable
|
|
@Override
|
|
public BlockState calculate(DensityFunction.FunctionContext pos) {
|
|
- for (NoiseChunk.BlockStateFiller blockStateFiller : this.materialRuleList) {
|
|
- BlockState blockState = blockStateFiller.calculate(pos);
|
|
- if (blockState != null) {
|
|
- return blockState;
|
|
- }
|
|
+ // Plazma start - Optimize noise
|
|
+ for (int i = 0; i < this.materialRuleList.size(); i++) {
|
|
+ BlockState state = this.materialRuleList.get(i).calculate(pos);
|
|
+ if (state == null) continue;
|
|
+
|
|
+ return state;
|
|
}
|
|
|
|
return null;
|
|
+ // Plazma end - Optimize noise
|
|
}
|
|
}
|
|
diff --git a/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java b/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java
|
|
index 2f5b59ec72fff421e1bc254ebeba78647c7409fe..7ef541c5d8306ef66214e7150aca0fa53c14d12a 100644
|
|
--- a/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java
|
|
+++ b/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java
|
|
@@ -44,6 +44,8 @@ public class GlobalConfiguration extends ConfigurationPart {
|
|
public WorldGeneration worldgen;
|
|
public class WorldGeneration extends ConfigurationPart {
|
|
|
|
+ boolean useAlternativeNoiseGenerator = OPTIMIZE;
|
|
+
|
|
public LavaSea lavaSea;
|
|
public class LavaSea extends ConfigurationPart {
|
|
|
|
@@ -63,6 +65,11 @@ public class GlobalConfiguration extends ConfigurationPart {
|
|
|
|
}
|
|
|
|
+ @PostProcess
|
|
+ void post() {
|
|
+ net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator.PLAZMA_USE_NOISIUM = this.useAlternativeNoiseGenerator;
|
|
+ }
|
|
+
|
|
}
|
|
|
|
public Entity entity;
|