more work

This commit is contained in:
AlphaKR93
2024-11-02 16:39:08 +09:00
parent 2028e19bf8
commit 33701c1eca
48 changed files with 7230 additions and 145 deletions

View File

@@ -1,57 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: AlphaKR93 <dev@alpha93.kr>
Date: Mon, 4 Dec 2023 23:12:47 +0900
Subject: [PATCH] Optimise state lookup more
diff --git a/src/main/java/io/papermc/paper/util/table/ZeroCollidingReferenceStateTable.java b/src/main/java/io/papermc/paper/util/table/ZeroCollidingReferenceStateTable.java
index 57d0cd3ad6f972e986c72a57f1a6e36003f190c2..50d97c5ab33f33b81dbafd7cf42da5afd9856eeb 100644
--- a/src/main/java/io/papermc/paper/util/table/ZeroCollidingReferenceStateTable.java
+++ b/src/main/java/io/papermc/paper/util/table/ZeroCollidingReferenceStateTable.java
@@ -17,6 +17,7 @@ public final class ZeroCollidingReferenceStateTable {
protected final StateHolder<?, ?> this_state;
protected long[] index_table;
+ public long[] index_table() { return this.index_table; } // Plazma - Getter
protected StateHolder<?, ?>[][] value_table;
public ZeroCollidingReferenceStateTable(final StateHolder<?, ?> state, final Map<Property<?>, Comparable<?>> this_map) {
diff --git a/src/main/java/net/minecraft/world/level/block/state/StateHolder.java b/src/main/java/net/minecraft/world/level/block/state/StateHolder.java
index 45744d86e9582a93a0cec26009deea091080fbbe..5dd9473c55a08a775aa406901a0e54ef6f63837a 100644
--- a/src/main/java/net/minecraft/world/level/block/state/StateHolder.java
+++ b/src/main/java/net/minecraft/world/level/block/state/StateHolder.java
@@ -114,6 +114,12 @@ public abstract class StateHolder<O, S> {
}
public <T extends Comparable<T>, V extends T> S trySetValue(Property<T> property, V value) {
+ // Plazma start - Optimise state lookup more
+ final S ret = (S) this.optimisedTable.get(property, value);
+ if (ret == null) throw new IllegalArgumentException("Cannot set property " + property + " to " + value + " on " + this.owner + ", it is not an allowed value");
+ return ret;
+ /*
+ // Plazma end - Optimise state lookup more
Comparable<?> comparable = this.values.get(property);
if (comparable != null && !comparable.equals(value)) {
S object = this.neighbours.get(property, value);
@@ -125,10 +131,11 @@ public abstract class StateHolder<O, S> {
} else {
return (S)this;
}
+ */ // Plazma - Optimise state lookup more
}
public void populateNeighbours(Map<Map<Property<?>, Comparable<?>>, S> states) {
- if (this.neighbours != null) {
+ if (this.optimisedTable.index_table() != null) { // Plazma - optimise state lookup
throw new IllegalStateException();
} else {
Table<Property<?>, Comparable<?>, S> table = HashBasedTable.create();
@@ -143,7 +150,7 @@ public abstract class StateHolder<O, S> {
}
}
- this.neighbours = (Table<Property<?>, Comparable<?>, S>)(table.isEmpty() ? table : ArrayTable.create(table)); this.optimisedTable.loadInTable((Table)this.neighbours, this.values); // Paper - optimise state lookup
+ this.optimisedTable.loadInTable((Table) (table.isEmpty() ? table : ArrayTable.create(table)), this.values); // Plazma - Optimize state lookup more
}
}

View File

@@ -1,259 +0,0 @@
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;

View File

@@ -1,282 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?IPECTER=20=EC=9D=B4=ED=8C=A9=ED=84=B0?=
<80433772+IPECTER@users.noreply.github.com>
Date: Sun, 25 Aug 2024 05:21:35 +0900
Subject: [PATCH] Blazingly-simple-farm-checks
diff --git a/src/main/java/net/minecraft/world/level/block/CropBlock.java b/src/main/java/net/minecraft/world/level/block/CropBlock.java
index 2077cb5dcf2352c9d5b502744aeb9a66df256939..e5db5467863e7e408e3ca23dbaed3879d9b31110 100644
--- a/src/main/java/net/minecraft/world/level/block/CropBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/CropBlock.java
@@ -81,28 +81,81 @@ public class CropBlock extends BushBlock implements BonemealableBlock {
int i = this.getAge(state);
if (i < this.getMaxAge()) {
- float f = CropBlock.getGrowthSpeed(this, world, pos);
-
- // Spigot start
- int modifier;
- if (this == Blocks.BEETROOTS) {
- modifier = world.spigotConfig.beetrootModifier;
- } else if (this == Blocks.CARROTS) {
- modifier = world.spigotConfig.carrotModifier;
- } else if (this == Blocks.POTATOES) {
- modifier = world.spigotConfig.potatoModifier;
- // Paper start - Fix Spigot growth modifiers
- } else if (this == Blocks.TORCHFLOWER_CROP) {
- modifier = world.spigotConfig.torchFlowerModifier;
- // Paper end - Fix Spigot growth modifiers
+ // Plazma start - Blazingly simple farm checks
+ if (world.plazmaConfig().blazinglySimpleFarmChecks.enabled) {
+ // These checks are similar to getGrowthSpeed, but we have "inlined" them because we want to access stuff like the farm block data later on
+ // Is the block below us moisturised?
+ BlockPos farmlandBelowTheCurrentBlock = pos.below();
+ BlockState farmlandBelowTheCurrentBlockData = world.getBlockState(farmlandBelowTheCurrentBlock);
+ double f = world.plazmaConfig().blazinglySimpleFarmChecks.defaultGrowthSpeed;
+ boolean isCurrentFarmlandStateMoist = false;
+ if (farmlandBelowTheCurrentBlockData.is(Blocks.FARMLAND)) {
+ if ((Integer) farmlandBelowTheCurrentBlockData.getValue(FarmBlock.MOISTURE) > 0) {
+ // If we are currently moist, increase the speed!
+ f = world.plazmaConfig().blazinglySimpleFarmChecks.moistGrowthSpeed;
+ isCurrentFarmlandStateMoist = true;
+ }
+ }
+ // If we are skipping the middle aging stages, we need to change the growth speed and the next stage accordingly
+ if (world.plazmaConfig().blazinglySimpleFarmChecks.skipMiddleAgingStagesForCrops) {
+ f = f / getMaxAge();
+ i = getMaxAge() - 1;
+ }
+
+ // Spigot start
+ int modifier;
+ if (this == Blocks.BEETROOTS) {
+ modifier = world.spigotConfig.beetrootModifier;
+ } else if (this == Blocks.CARROTS) {
+ modifier = world.spigotConfig.carrotModifier;
+ } else if (this == Blocks.POTATOES) {
+ modifier = world.spigotConfig.potatoModifier;
+ // Paper start
+ } else if (this == Blocks.TORCHFLOWER_CROP) {
+ modifier = world.spigotConfig.torchFlowerModifier;
+ // Paper end
+ } else {
+ modifier = world.spigotConfig.wheatModifier;
+ }
+
+ if (random.nextFloat() < (modifier / (100.0f * (Math.floor((25.0F / f) + 1))))) { // Spigot - SPIGOT-7159: Better modifier resolution
+ // Spigot end
+ if (!CraftEventFactory.handleBlockGrowEvent(world, pos, this.getStateForAge(i + 1), 2)) {
+ return;
+ }
+
+ // Now that we know that the crop will grow... is the next stage the crop's max age? If yes, we are going to check if the farm land is moist!
+ if (i + 1 == getMaxAge() && isCurrentFarmlandStateMoist && !FarmBlock.isNearWater(world, farmlandBelowTheCurrentBlock)) {
+ // Whoops, farm land ain't moist!
+ // From FarmBlock, set the moisture to 0
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleMoistureChangeEvent(world, farmlandBelowTheCurrentBlock, (BlockState) farmlandBelowTheCurrentBlockData.setValue(FarmBlock.MOISTURE, 0), 2); // CraftBukkit
+ }
+ }
} else {
- modifier = world.spigotConfig.wheatModifier;
- }
+ float f = CropBlock.getGrowthSpeed(this, world, pos);
+
+ // Spigot start
+ int modifier;
+ if (this == Blocks.BEETROOTS) {
+ modifier = world.spigotConfig.beetrootModifier;
+ } else if (this == Blocks.CARROTS) {
+ modifier = world.spigotConfig.carrotModifier;
+ } else if (this == Blocks.POTATOES) {
+ modifier = world.spigotConfig.potatoModifier;
+ // Paper start - Fix Spigot growth modifiers
+ } else if (this == Blocks.TORCHFLOWER_CROP) {
+ modifier = world.spigotConfig.torchFlowerModifier;
+ // Paper end - Fix Spigot growth modifiers
+ } else {
+ modifier = world.spigotConfig.wheatModifier;
+ }
- if (random.nextFloat() < (modifier / (100.0f * (Math.floor((25.0F / f) + 1))))) { // Spigot - SPIGOT-7159: Better modifier resolution
- // Spigot end
- CraftEventFactory.handleBlockGrowEvent(world, pos, this.getStateForAge(i + 1), 2); // CraftBukkit
+ if (random.nextFloat() < (modifier / (100.0f * (Math.floor((25.0F / f) + 1))))) { // Spigot - SPIGOT-7159: Better modifier resolution
+ // Spigot end
+ CraftEventFactory.handleBlockGrowEvent(world, pos, this.getStateForAge(i + 1), 2); // CraftBukkit
+ }
}
+ // Plazma end
}
}
diff --git a/src/main/java/net/minecraft/world/level/block/FarmBlock.java b/src/main/java/net/minecraft/world/level/block/FarmBlock.java
index 0c39126ce51439cce05747161aba43bce33a12d8..2016e3d7832ba75331697c46803f8e4142bf01ee 100644
--- a/src/main/java/net/minecraft/world/level/block/FarmBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/FarmBlock.java
@@ -92,6 +92,19 @@ public class FarmBlock extends Block {
@Override
public void randomTick(BlockState state, ServerLevel world, BlockPos pos, RandomSource random) {
int i = (Integer) state.getValue(FarmBlock.MOISTURE);
+ // Plazma start - Blazingly simple farm checks
+ if (world.plazmaConfig().blazinglySimpleFarmChecks.enabled) {
+ if (i == 0) { // We only care about non-moisturised farm blocks
+ if (FarmBlock.isNearWater(world, pos)) {
+ // Make it MOIST!
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleMoistureChangeEvent(world, pos, (BlockState) state.setValue(FarmBlock.MOISTURE, 7), 2); // CraftBukkit
+ } else if (!FarmBlock.shouldMaintainFarmland(world, pos)) {
+ FarmBlock.turnToDirt((Entity) null, state, world, pos);
+ }
+ }
+ return;
+ }
+ // Plazma end
if (i > 0 && world.paperConfig().tickRates.wetFarmland != 1 && (world.paperConfig().tickRates.wetFarmland < 1 || (net.minecraft.server.MinecraftServer.currentTick + pos.hashCode()) % world.paperConfig().tickRates.wetFarmland != 0)) { return; } // Paper - Configurable random tick rates for blocks
if (i == 0 && world.paperConfig().tickRates.dryFarmland != 1 && (world.paperConfig().tickRates.dryFarmland < 1 || (net.minecraft.server.MinecraftServer.currentTick + pos.hashCode()) % world.paperConfig().tickRates.dryFarmland != 0)) { return; } // Paper - Configurable random tick rates for blocks
@@ -166,7 +179,7 @@ public class FarmBlock extends Block {
return world.getBlockState(pos.above()).is(BlockTags.MAINTAINS_FARMLAND);
}
- private static boolean isNearWater(LevelReader world, BlockPos pos) {
+ public static boolean isNearWater(LevelReader world, BlockPos pos) { // Plazma - Blazingly simple farm checks - private -> public
// Paper start - Perf: remove abstract block iteration
int xOff = pos.getX();
int yOff = pos.getY();
diff --git a/src/main/java/net/minecraft/world/level/block/StemBlock.java b/src/main/java/net/minecraft/world/level/block/StemBlock.java
index 121a872cd750a87b779895687ae1abf5bb77b088..53e55b51c53995e2ec9314e1fc656dd5cd22dd67 100644
--- a/src/main/java/net/minecraft/world/level/block/StemBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/StemBlock.java
@@ -73,36 +73,87 @@ public class StemBlock extends BushBlock implements BonemealableBlock {
@Override
public void randomTick(BlockState state, ServerLevel world, BlockPos pos, RandomSource random) {
if (world.getRawBrightness(pos, 0) >= 9) {
- float f = CropBlock.getGrowthSpeed(this, world, pos);
-
- if (random.nextFloat() < ((this == Blocks.PUMPKIN_STEM ? world.spigotConfig.pumpkinModifier : world.spigotConfig.melonModifier) / (100.0f * (Math.floor((25.0F / f) + 1))))) { // Spigot - SPIGOT-7159: Better modifier resolution
- int i = (Integer) state.getValue(StemBlock.AGE);
-
- if (i < 7) {
- state = (BlockState) state.setValue(StemBlock.AGE, i + 1);
- CraftEventFactory.handleBlockGrowEvent(world, pos, state, 2); // CraftBukkit
- } else {
- Direction enumdirection = Direction.Plane.HORIZONTAL.getRandomDirection(random);
- BlockPos blockposition1 = pos.relative(enumdirection);
- BlockState iblockdata1 = world.getBlockState(blockposition1.below());
-
- if (world.getBlockState(blockposition1).isAir() && (iblockdata1.is(Blocks.FARMLAND) || iblockdata1.is(BlockTags.DIRT))) {
- Registry<Block> iregistry = world.registryAccess().registryOrThrow(Registries.BLOCK);
- Optional<Block> optional = iregistry.getOptional(this.fruit);
- Optional<Block> optional1 = iregistry.getOptional(this.attachedStem);
-
- if (optional.isPresent() && optional1.isPresent()) {
- // CraftBukkit start
- if (!CraftEventFactory.handleBlockGrowEvent(world, blockposition1, ((Block) optional.get()).defaultBlockState())) {
- return;
+ // Plazma start - Blazingly simple farm checks
+ if (world.plazmaConfig().blazinglySimpleFarmChecks.enabled) {
+ // These checks are similar to getGrowthSpeed, but we have "inlined" them because we want to access stuff like the farm block data later on
+ // Is the block below us moisturised?
+ BlockPos farmlandBelowTheCurrentBlock = pos.below();
+ BlockState farmlandBelowTheCurrentBlockData = world.getBlockState(farmlandBelowTheCurrentBlock);
+ double f = world.plazmaConfig().blazinglySimpleFarmChecks.defaultGrowthSpeed;
+ boolean isCurrentFarmlandStateMoist = false;
+ if (farmlandBelowTheCurrentBlockData.is(Blocks.FARMLAND)) {
+ if ((Integer) farmlandBelowTheCurrentBlockData.getValue(FarmBlock.MOISTURE) > 0) {
+ // If we are currently moist, increase the speed!
+ f = world.plazmaConfig().blazinglySimpleFarmChecks.moistGrowthSpeed;
+ isCurrentFarmlandStateMoist = true;
+ }
+ }
+
+ if (random.nextFloat() < ((this == Blocks.PUMPKIN_STEM ? world.spigotConfig.pumpkinModifier : world.spigotConfig.melonModifier) / (100.0f * (Math.floor((25.0F / f) + 1))))) { // Spigot - SPIGOT-7159: Better modifier resolution
+ int i = (Integer) state.getValue(StemBlock.AGE);
+
+ if (i < 7) {
+ state = (BlockState) state.setValue(StemBlock.AGE, i + 1);
+ CraftEventFactory.handleBlockGrowEvent(world, pos, state, 2); // CraftBukkit
+ } else {
+ Direction enumdirection = Direction.Plane.HORIZONTAL.getRandomDirection(random);
+ BlockPos blockposition1 = pos.relative(enumdirection);
+ BlockState iblockdata1 = world.getBlockState(blockposition1.below());
+
+ if (world.getBlockState(blockposition1).isAir() && (iblockdata1.is(Blocks.FARMLAND) || iblockdata1.is(BlockTags.DIRT))) {
+ Registry<Block> iregistry = world.registryAccess().registryOrThrow(Registries.BLOCK);
+ Optional<Block> optional = iregistry.getOptional(this.fruit);
+ Optional<Block> optional1 = iregistry.getOptional(this.attachedStem);
+
+ if (optional.isPresent() && optional1.isPresent()) {
+ // CraftBukkit start
+ if (!CraftEventFactory.handleBlockGrowEvent(world, blockposition1, ((Block) optional.get()).defaultBlockState())) {
+ return;
+ }
+ // CraftBukkit end
+ // Now that we know that the crop will grow... is the next stage the crop's max age? If yes, we are going to check if the farm land is moist!
+ if (isCurrentFarmlandStateMoist && !FarmBlock.isNearWater(world, farmlandBelowTheCurrentBlock)) {
+ // Whoops, farm land ain't moist!
+ // From FarmBlock, set the moisture to 0
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleMoistureChangeEvent(world, farmlandBelowTheCurrentBlock, (BlockState) farmlandBelowTheCurrentBlockData.setValue(FarmBlock.MOISTURE, 0), 2); // CraftBukkit
+ }
+ world.setBlockAndUpdate(pos, (BlockState) ((Block) optional1.get()).defaultBlockState().setValue(HorizontalDirectionalBlock.FACING, enumdirection));
+ }
+ }
+ }
+ }
+ } else {
+ float f = CropBlock.getGrowthSpeed(this, world, pos);
+
+ if (random.nextFloat() < ((this == Blocks.PUMPKIN_STEM ? world.spigotConfig.pumpkinModifier : world.spigotConfig.melonModifier) / (100.0f * (Math.floor((25.0F / f) + 1))))) { // Spigot - SPIGOT-7159: Better modifier resolution
+ int i = (Integer) state.getValue(StemBlock.AGE);
+
+ if (i < 7) {
+ state = (BlockState) state.setValue(StemBlock.AGE, i + 1);
+ CraftEventFactory.handleBlockGrowEvent(world, pos, state, 2); // CraftBukkit
+ } else {
+ Direction enumdirection = Direction.Plane.HORIZONTAL.getRandomDirection(random);
+ BlockPos blockposition1 = pos.relative(enumdirection);
+ BlockState iblockdata1 = world.getBlockState(blockposition1.below());
+
+ if (world.getBlockState(blockposition1).isAir() && (iblockdata1.is(Blocks.FARMLAND) || iblockdata1.is(BlockTags.DIRT))) {
+ Registry<Block> iregistry = world.registryAccess().registryOrThrow(Registries.BLOCK);
+ Optional<Block> optional = iregistry.getOptional(this.fruit);
+ Optional<Block> optional1 = iregistry.getOptional(this.attachedStem);
+
+ if (optional.isPresent() && optional1.isPresent()) {
+ // CraftBukkit start
+ if (!CraftEventFactory.handleBlockGrowEvent(world, blockposition1, ((Block) optional.get()).defaultBlockState())) {
+ return;
+ }
+ // CraftBukkit end
+ world.setBlockAndUpdate(pos, (BlockState) ((Block) optional1.get()).defaultBlockState().setValue(HorizontalDirectionalBlock.FACING, enumdirection));
}
- // CraftBukkit end
- world.setBlockAndUpdate(pos, (BlockState) ((Block) optional1.get()).defaultBlockState().setValue(HorizontalDirectionalBlock.FACING, enumdirection));
}
}
}
}
-
+ // Plazma end
}
}
diff --git a/src/main/java/org/plazmamc/plazma/configurations/WorldConfigurations.java b/src/main/java/org/plazmamc/plazma/configurations/WorldConfigurations.java
index 9d6d4400be8bf189308cbd0cb14afa1ff0191a57..f96305be3b6e7c33d553764bdf4d8f2635939f9d 100644
--- a/src/main/java/org/plazmamc/plazma/configurations/WorldConfigurations.java
+++ b/src/main/java/org/plazmamc/plazma/configurations/WorldConfigurations.java
@@ -102,4 +102,15 @@ public class WorldConfigurations extends ConfigurationPart {
}
+ public BlazinglySimpleFarmChecks blazinglySimpleFarmChecks;
+ public class BlazinglySimpleFarmChecks extends ConfigurationPart {
+
+ public boolean enabled = OPTIMIZE;ㅈ
+ public double defaultGrowthSpeed = 1.0;
+ public double moistGrowthSpeed = 5.0;
+ public boolean skipMiddleAgingStagesForCrops = false;
+
+
+ }
+
}

View File

@@ -1,350 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: AlphaKR93 <dev@alpha93.kr>
Date: Sun, 27 Oct 2024 15:07:43 +0900
Subject: [PATCH] TickControl System
Based on snackbag/TT20
Copyright (C) 2024 snackbag, Licensed under AGPL v3.0
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 5cd9b92bc..6773081b6 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1668,6 +1668,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
public void tickServer(BooleanSupplier shouldKeepTicking) {
+ org.plazmamc.plazma.util.TickControl.tick(); // Plazma - TickControl System
org.spigotmc.WatchdogThread.tick(); // Spigot
long i = Util.getNanos();
int j = this.pauseWhileEmptySeconds() * 20;
diff --git a/src/main/java/net/minecraft/server/dedicated/ServerWatchdog.java b/src/main/java/net/minecraft/server/dedicated/ServerWatchdog.java
index 660a14203..d092bef5e 100644
--- a/src/main/java/net/minecraft/server/dedicated/ServerWatchdog.java
+++ b/src/main/java/net/minecraft/server/dedicated/ServerWatchdog.java
@@ -34,6 +34,7 @@ public class ServerWatchdog implements Runnable {
@Override
public void run() {
while (this.server.isRunning()) {
+ if (org.plazmamc.plazma.configurations.GlobalConfiguration.get().tickControl.enabled) return; // Plazma - TickControl System
long l = this.server.getNextTickTime();
long m = Util.getNanos();
long n = m - l;
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index bb168636c..b55ad2615 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -579,7 +579,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
this.lastSpawnState = spawnercreature_d;
//profiler.popPush("spawnAndTick"); // Purpur
boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !this.level.players().isEmpty(); // CraftBukkit
- int k = this.level.getGameRules().getInt(GameRules.RULE_RANDOMTICKING);
+ int k = org.plazmamc.plazma.util.TickControl.calc(this.level.getGameRules().getInt(GameRules.RULE_RANDOMTICKING), it -> it.accelerate.randomTick, false); // Plazma - TickControl system
List list1;
if (flag && (this.spawnEnemies || this.spawnFriendlies)) {
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index d5662fd0b..48ea65f67 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -879,7 +879,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
this.setDayTime(this.preciseTime);
} else
// Purpur end
- this.setDayTime(this.levelData.getDayTime() + 1L);
+ // Plazma start - TickControl System
+ if (org.plazmamc.plazma.configurations.GlobalConfiguration.get().tickControl.accelerate.dayTime)
+ this.setDayTime(this.levelData.getDayTime() + org.plazmamc.plazma.util.TickControl.missedTicks() + 1L);
+ else
+ this.setDayTime(this.levelData.getDayTime() + 1L);
+ // Plazma end - TickControl System
}
}
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 4653b25a8..9e9dd4ae1 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -562,6 +562,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
}
this.tickEffects();
+ if (org.plazmamc.plazma.configurations.GlobalConfiguration.get().tickControl.delay.potionEffect) for (int i = 0; i < org.plazmamc.plazma.util.TickControl.missedTicks(); i++) this.tickEffects(); // Plazma - TickControl System
this.animStepO = this.animStep;
this.yBodyRotO = this.yBodyRot;
this.yHeadRotO = this.yHeadRot;
diff --git a/src/main/java/net/minecraft/world/entity/PortalProcessor.java b/src/main/java/net/minecraft/world/entity/PortalProcessor.java
index b4a824996..1e6b32ad6 100644
--- a/src/main/java/net/minecraft/world/entity/PortalProcessor.java
+++ b/src/main/java/net/minecraft/world/entity/PortalProcessor.java
@@ -24,7 +24,7 @@ public class PortalProcessor {
return false;
} else {
this.insidePortalThisTick = false;
- return canUsePortals && this.portalTime++ >= this.portal.getPortalTransitionTime(world, entity);
+ return canUsePortals && this.increaseTick() >= this.portal.getPortalTransitionTime(world, entity); // Plazma - TickControl System
}
}
@@ -41,6 +41,14 @@ public class PortalProcessor {
this.portalTime = Math.max(this.portalTime - 4, 0);
}
+ // Plazma start - TickControl System
+ private int increaseTick() {
+ if (!org.plazmamc.plazma.configurations.GlobalConfiguration.get().tickControl.delay.portalUse)
+ this.portalTime += org.plazmamc.plazma.util.TickControl.missedTicks();
+ return this.portalTime++;
+ }
+ // Plazma end - TickControl System
+
public boolean hasExpired() {
return this.portalTime <= 0;
}
diff --git a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
index 89d89a1b0..7c4228c0b 100644
--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
@@ -158,6 +158,7 @@ public class ItemEntity extends Entity implements TraceableEntity {
if (this.getItem().isEmpty()) {
this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
} else {
+ if (this.pickupDelay > 0 && org.plazmamc.plazma.configurations.GlobalConfiguration.get().tickControl.delay.itemPickup) this.pickupDelay = Math.max(this.pickupDelay - org.plazmamc.plazma.util.TickControl.missedTicks(), 0); // Plazma - TickControl System
super.tick();
// Paper start - remove anti tick skipping measures / wall time - revert to vanilla
if (this.pickupDelay > 0 && this.pickupDelay != 32767) {
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
index c1d068fa9..27361bde0 100644
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
@@ -302,6 +302,11 @@ public abstract class Player extends LivingEntity {
if (this.sleepCounter > 100) {
this.sleepCounter = 100;
}
+ // Plazma start - TickControl System
+ else if (this.sleepCounter < 100 && org.plazmamc.plazma.configurations.GlobalConfiguration.get().tickControl.delay.sleep && org.plazmamc.plazma.util.TickControl.missedTicks() > 0) {
+ this.sleepCounter += org.plazmamc.plazma.util.TickControl.missedTicks();
+ }
+ // Plazma end - TickControl System
if (!this.level().isClientSide && this.level().isDay()) {
this.stopSleepInBed(false, true);
diff --git a/src/main/java/net/minecraft/world/item/Item.java b/src/main/java/net/minecraft/world/item/Item.java
index 3d948c8d3..0c77997e0 100644
--- a/src/main/java/net/minecraft/world/item/Item.java
+++ b/src/main/java/net/minecraft/world/item/Item.java
@@ -260,7 +260,7 @@ public class Item implements FeatureElement, ItemLike {
public int getUseDuration(ItemStack stack, LivingEntity user) {
Consumable consumable = stack.get(DataComponents.CONSUMABLE);
- return consumable != null ? consumable.consumeTicks() : 0;
+ return consumable != null ? org.plazmamc.plazma.util.TickControl.calc(consumable.eatDurationTicks(), it -> it.delay.itemUse, true) : 0; // Plazma - TickControl System
}
public boolean releaseUsing(ItemStack stack, Level world, LivingEntity user, int remainingUseTicks) {
diff --git a/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java b/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
index 852bfe68a..3cb943ea4 100644
--- a/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
+++ b/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
@@ -336,13 +336,14 @@ public abstract class BlockBehaviour implements FeatureElement {
protected float getDestroyProgress(BlockState state, Player player, BlockGetter world, BlockPos pos) {
float f = state.getDestroySpeed(world, pos);
- if (f == -1.0F) {
- return 0.0F;
- } else {
- int i = player.hasCorrectToolForDrops(state) ? 30 : 100;
-
- return player.getDestroySpeed(state) / f / (float) i;
- }
+ // Plazma start - TickControl system
+ if (f == -1.0F) return 0.0F;
+ return org.plazmamc.plazma.util.TickControl.calc(
+ player.getDestroySpeed(state) / f / (player.hasCorrectToolForDrops(state) ? 30 : 100),
+ it -> it.delay.blockBreak,
+ false
+ );
+ // Plazma end - TickControl system
}
protected void spawnAfterBreak(BlockState state, ServerLevel world, BlockPos pos, ItemStack tool, boolean dropExperience) {}
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
index 9cc1a79dd25c63af6986e721ceff5560cf56b7d1..c45224e142905921305da51139d5fd3f51583cca 100644
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
@@ -1036,8 +1036,18 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
this.chunkCoordinateKey = chunkCoordinateKey; // Plazma - Port SparklyPaper patches; Optimize TickingBlockEntity
}
+ // Plazma start - TickControl System
+ private void tickTicker(BlockState iblockdata) {
+ this.ticker.tick(LevelChunk.this.level, this.blockEntity.getBlockPos(), iblockdata, this.blockEntity);
+
+ if (!org.plazmamc.plazma.util.TickControl.shouldTickAgain(iblockdata.getBlock())) return;
+ for (int i = 0; i < org.plazmamc.plazma.util.TickControl.missedTicks(); i++)
+ this.ticker.tick(LevelChunk.this.level, this.blockEntity.getBlockPos(), iblockdata, this.blockEntity);
+ }
+ // Plazma end - TickControl System
+
@Override
- public void tick() {
+ public final void tick() { // Plazma - TickControl System (make final)
if (!this.blockEntity.isRemoved() && this.blockEntity.hasLevel()) {
BlockPos blockposition = this.blockEntity.getBlockPos();
@@ -1050,7 +1060,7 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
BlockState iblockdata = LevelChunk.this.getBlockState(blockposition);
if (this.blockEntity.getType().isValid(iblockdata)) {
- this.ticker.tick(LevelChunk.this.level, this.blockEntity.getBlockPos(), iblockdata, this.blockEntity);
+ this.tickTicker(iblockdata); // Plazma - TickControl System
this.loggedInvalidBlockState = false;
// Paper start - Remove the Block Entity if it's invalid
} else {
diff --git a/src/main/java/net/minecraft/world/level/material/LavaFluid.java b/src/main/java/net/minecraft/world/level/material/LavaFluid.java
index 2d492d849ff73a738dfbcb16507feb89bf19a962..67206b9c754dfe90002e0bcf6995eae60b852acd 100644
--- a/src/main/java/net/minecraft/world/level/material/LavaFluid.java
+++ b/src/main/java/net/minecraft/world/level/material/LavaFluid.java
@@ -180,7 +180,7 @@ public abstract class LavaFluid extends FlowingFluid {
@Override
public int getTickDelay(LevelReader world) {
- return world.dimensionType().ultraWarm() ? world.getWorldBorder().world.purpurConfig.lavaSpeedNether : world.getWorldBorder().world.purpurConfig.lavaSpeedNotNether; // Purpur
+ return org.plazmamc.plazma.util.TickControl.calc(world.dimensionType().ultraWarm() ? world.getWorldBorder().world.purpurConfig.lavaSpeedNether : world.getWorldBorder().world.purpurConfig.lavaSpeedNotNether, it -> it.delay.lavaFluid, true); // Purpur // Plazma - TickControl system
}
@Override
diff --git a/src/main/java/net/minecraft/world/level/material/WaterFluid.java b/src/main/java/net/minecraft/world/level/material/WaterFluid.java
index 0fc89b33864000a262ec5369708f7aedeaf6dc0b..5055730053d9d9c1da0a5252654c936c75d04fb6 100644
--- a/src/main/java/net/minecraft/world/level/material/WaterFluid.java
+++ b/src/main/java/net/minecraft/world/level/material/WaterFluid.java
@@ -122,7 +122,7 @@ public abstract class WaterFluid extends FlowingFluid {
@Override
public int getTickDelay(LevelReader world) {
- return world.getWorldBorder().world.plazmaConfig().block.waterFlowingTick; // Plazma - Configurable water flowing speed
+ return org.plazmamc.plazma.util.TickControl.calc(world.getWorldBorder().world.plazmaConfig().block.waterFlowingTick, it -> it.delay.waterFluid, true); // Plazma - Configurable water flowing speed; TickControl System
}
@Override
diff --git a/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java b/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java
index 49bce6e28e12f3729cab5628cf3e0f508a56d0d7..2a88a25793e6d963a9a08e615a72c6ed1677a18b 100644
--- a/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java
+++ b/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java
@@ -146,4 +146,39 @@ public class GlobalConfiguration extends ConfigurationPart {
}
+ public TickControl tickControl;
+ public class TickControl extends ConfigurationPart {
+
+ public boolean enabled = false;
+
+ public Delay delay;
+ public class Delay extends ConfigurationPart {
+
+ public boolean sleep = true;
+ public boolean itemUse = true;
+ public boolean portalUse = true;
+ public boolean lavaFluid = true;
+ public boolean waterFluid = true;
+ public boolean blockBreak = true;
+ public boolean itemPickup = true;
+ public boolean potionEffect = true;
+
+ }
+
+ public Accelerate accelerate;
+ public class Accelerate extends ConfigurationPart {
+
+ public boolean dayTime = true;
+ public boolean randomTick = true;
+ public boolean blockEntity = true;
+
+ }
+
+ @PostProcess
+ void post() {
+ org.plazmamc.plazma.util.TickControl.post(this);
+ }
+
+ }
+
}
diff --git a/src/main/java/org/plazmamc/plazma/util/TickControl.java b/src/main/java/org/plazmamc/plazma/util/TickControl.java
new file mode 100644
index 0000000000000000000000000000000000000000..c8db7b9f590a34b38448a970baaa79dd73eab8d8
--- /dev/null
+++ b/src/main/java/org/plazmamc/plazma/util/TickControl.java
@@ -0,0 +1,57 @@
+package org.plazmamc.plazma.util;
+
+import net.minecraft.world.level.block.Block;
+import org.jspecify.annotations.NonNull;
+import org.jspecify.annotations.Nullable;
+import org.plazmamc.plazma.configurations.GlobalConfiguration;
+import java.util.function.Function;
+
+import static net.minecraft.server.MinecraftServer.getServer;
+
+public final class TickControl {
+
+
+ private static @Nullable TickControl INSTANCE;
+ private final GlobalConfiguration.TickControl configuration;
+ private int missedTicks = 0;
+
+ private TickControl(GlobalConfiguration.TickControl configuration) {
+ this.configuration = configuration;
+ }
+
+ public static void tick() {
+ if (INSTANCE == null) return;
+ INSTANCE.missedTicks -= INSTANCE.missedTicks;
+ INSTANCE.missedTicks += (int) (getServer().tickTimes5s.getAverage() / 50 - 1);
+ }
+
+ public static void post(GlobalConfiguration.TickControl configuration) {
+ if (!configuration.enabled) {
+ INSTANCE = null;
+ return;
+ }
+
+ INSTANCE = new TickControl(configuration);
+ }
+
+ public static float calc(float original, @NonNull Function<GlobalConfiguration.TickControl, Boolean> isAffected, boolean swap) {
+ if (INSTANCE == null || !isAffected.apply(INSTANCE.configuration) || original == 0) return original;
+ if (swap) return (float) Math.max(original * getServer().tps5s.getAverage() / 20, 1);
+ return (float) (original * 20 / getServer().tps5s.getAverage());
+ }
+
+ public static int calc(int original, @NonNull Function<GlobalConfiguration.TickControl, Boolean> isAccelerated, boolean swap) {
+ return (int) Math.ceil(calc((float) original, isAccelerated, swap));
+ }
+
+ public static int missedTicks() {
+ if (INSTANCE == null) return 0;
+ return INSTANCE.missedTicks;
+ }
+
+ public static boolean shouldTickAgain(Block block) {
+ // TODO: Configurable block masking
+ return INSTANCE != null && !INSTANCE.configuration.accelerate.blockEntity;
+ }
+
+}

View File

@@ -1,66 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: scriptlinestudios <scriptlinestudios@protonmail.com>
Date: Thu, 31 Oct 2024 12:00:37 +0200
Subject: [PATCH] improve random block selection RNG
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index 507671476c3d2d92a2fdb05be24443af27d26dcf..aa97b6a1c4dd1e23cd3a1657efd8a9109b053354 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -123,16 +123,13 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
public final Thread thread;
private final boolean isDebug;
private int skyDarken;
- protected int randValue = RandomSource.create().nextInt();
+ protected long randValue = RandomSource.create().nextLong();
protected final int addend = 1013904223;
protected float oRainLevel;
public float rainLevel;
protected float oThunderLevel;
public float thunderLevel;
public final RandomSource random = RandomSource.create();
- /** @deprecated */
- @Deprecated
- private final RandomSource threadSafeRandom = RandomSource.createThreadSafe();
private final Holder<DimensionType> dimensionTypeRegistration;
public final WritableLevelData levelData;
private final Supplier<ProfilerFiller> profiler;
@@ -1327,15 +1324,18 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
}
public void playSound(@Nullable Player source, double x, double y, double z, SoundEvent sound, SoundSource category, float volume, float pitch) {
- this.playSeededSound(source, x, y, z, sound, category, volume, pitch, this.threadSafeRandom.nextLong());
+ this.randValue++;
+ this.playSeededSound(source, x, y, z, sound, category, volume, pitch, this.randValue);
}
public void playSound(@Nullable Player source, double x, double y, double z, Holder<SoundEvent> sound, SoundSource category, float volume, float pitch) {
- this.playSeededSound(source, x, y, z, sound, category, volume, pitch, this.threadSafeRandom.nextLong());
+ this.randValue++;
+ this.playSeededSound(source, x, y, z, sound, category, volume, pitch, this.randValue);
}
public void playSound(@Nullable Player source, Entity entity, SoundEvent sound, SoundSource category, float volume, float pitch) {
- this.playSeededSound(source, entity, BuiltInRegistries.SOUND_EVENT.wrapAsHolder(sound), category, volume, pitch, this.threadSafeRandom.nextLong());
+ this.randValue++;
+ this.playSeededSound(source, entity, BuiltInRegistries.SOUND_EVENT.wrapAsHolder(sound), category, volume, pitch, this.randValue);
}
public void playLocalSound(BlockPos pos, SoundEvent sound, SoundSource category, float volume, float pitch, boolean useDistance) {
@@ -1950,10 +1950,12 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
public abstract RecipeManager getRecipeManager();
public BlockPos getBlockRandomPos(int x, int y, int z, int l) {
- this.randValue = this.randValue * 3 + 1013904223;
- int i1 = this.randValue >> 2;
+ this.randValue = (((long)(x ^ 16691) << 32 | ((z ^ 19391) & 0xffffffffL)) << 8 | ((this.randValue + 2319389831L) * 11 & 0xFF));
+ long i1 = Long.reverse(randValue*randValue<<39);
+ long i2 = Long.reverse(randValue*randValue<<41);
+ long i3 = Long.reverse(randValue*randValue<<23);
- return new BlockPos(x + (i1 & 15), y + (i1 >> 16 & l), z + (i1 >> 8 & 15));
+ return new BlockPos(x + ((int)i1 & 15), y + ((int)i2 & l), z + ((int)i3 & 15));
}
public boolean noSave() {