9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-19 14:59:25 +00:00

Reworked version #29

This commit is contained in:
Artem Ostrasev
2025-07-23 14:13:43 +03:00
committed by GitHub
346 changed files with 14806 additions and 9905 deletions

View File

@@ -61,4 +61,4 @@ body:
- type: input
attributes:
label: Error log (if applicable)
description: If you are reporting a console error, upload any relevant errors or full log to either https://bin.bxteam.org/, https://mclo.gs/ or https://pastes.dev/, save and the paste the link in this box.
description: If you are reporting a console error, upload any relevant errors or full log to either https://pastes.dev or https://mclo.gs, save and the paste the link in this box.

View File

@@ -62,8 +62,8 @@ jobs:
PARALLELISM=$(($(nproc) * 2))
./gradlew applyAllPatches --stacktrace --parallel --max-workers=$PARALLELISM --build-cache --no-daemon
- name: Build Paperclip Jar
run: ./gradlew createMojmapPaperclipJar --stacktrace --parallel --no-daemon
- name: Build Shuttle Jar
run: ./gradlew createMojmapShuttleJar --stacktrace --parallel --no-daemon
- name: Prepare Release Info
run: bash scripts/releaseInfo.sh

View File

@@ -26,11 +26,11 @@ jobs:
- name: Apply Patches
run: ./gradlew applyAllPatches --stacktrace --no-daemon
- name: Build Paperclip Jar
run: ./gradlew createMojmapPaperclipJar --stacktrace --no-daemon
- name: Build Shuttle Jar
run: ./gradlew createMojmapShuttleJar --stacktrace --no-daemon
- name: Upload Artifacts
uses: actions/upload-artifact@main
with:
name: DivineMC
path: divinemc-server/build/libs/divinemc-paperclip-*-mojmap.jar
path: divinemc-server/build/libs/divinemc-shuttle-*-mojmap.jar

View File

@@ -7,25 +7,22 @@
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/BX-Team/DivineMC/build-1217.yml?logo=GoogleAnalytics&logoColor=ffffff&style=for-the-badge)](https://github.com/BX-Team/DivineMC/actions)
[![Discord](https://img.shields.io/discord/931595732752953375?color=5865F2&label=discord&style=for-the-badge)](https://discord.gg/qNyybSSPm5)
DivineMC is a high-performance [Purpur](https://github.com/PurpurMC/Purpur) fork focused on maximizing server performance while maintaining plugin compatibility.
DivineMC is a multi-functional fork of [Purpur](https://github.com/PurpurMC/Purpur), which focuses on the flexibility of your server and its optimization
</div>
> [!WARNING]
> DivineMC is a performance-oriented fork. Make sure to take backups **before** switching to it. We also welcome a new contributor to help us improve the fork.
## ⚙️ Features
- **Based on [Purpur](https://github.com/PurpurMC/Purpur)** that adds a high customization level to the server.
- **Regionized Chunk Ticking** feature that allows to tick chunks in parallel, similar to how Folia does it.
- Implemented **Parallel world ticking** feature, that allows to server take advantage of multiple CPU cores to tick worlds.
- Implemented **Secure Seed** mod that changes default 64-bit seed to a 1024-bit seed, making it almost impossible to crack the seed.
- **Optimized chunk generation** that can generate chunks up to 70% faster than vanilla.
- **Async** pathfinding, entity tracker, mob spawning and chunk sending.
- Implemented **Linear region file format**
- **Fully compatible** with Bukkit, Spigot and Paper plugins
- **Fixes** some Minecraft bugs
- Integrated with [Sentry](https://sentry.io/welcome/) to easy track all errors coming from your server in excruciating detail (original by [Pufferfish](https://github.com/pufferfish-gg/Pufferfish))
- and more...
- **Based on [Purpur](https://github.com/PurpurMC/Purpur)** - Adds a high customization level to your server
- **Regionized Chunk Ticking** - Tick chunks in parallel, similar to how Folia does it
- **Parallel World Ticking** - Leverage multiple CPU cores for world processing
- **Async Operations** - Pathfinding, entity tracker, mob spawning, joining and chunk sending
- **Secure Seed** - Enhanced 1024-bit seed system (vs standard 64-bit) for maximum security
- **Linear Region File Format** - Optimize your world with the old V1/V2 linear format and the new Buffered format
- **Mod Protocols Support** - Compatible with Syncmatica, Apple Skin, Jade and Xaero's Map
- **Fully Compatible** - Works seamlessly with Bukkit, Spigot and Paper plugins
- **Bug Fixes** - Resolves various Minecraft issues (~10)
- **Sentry Integration** - Detailed error tracking and monitoring (original by [Pufferfish](https://github.com/pufferfish-gg/Pufferfish))
*...and much more!*
## 📥 Downloading & Installing
If you want to install DivineMC, you can read our [installation documentation](https://bxteam.org/docs/divinemc/getting-started/installation).
@@ -40,7 +37,7 @@ Run the following commands in the root directory:
```bash
> ./gradlew applyAllPatches # apply all patches
> ./gradlew createMojmapPaperclipJar # build the server jar
> ./gradlew createMojmapShuttleJar # build the server jar
```
For anything else you can refer to our [contribution guide](https://bxteam.org/docs/divinemc/development/contributing).
@@ -81,21 +78,19 @@ We also have a [Javadoc](https://repo.bxteam.org/javadoc/snapshots/org/bxteam/di
DivineMC is licensed under the GNU General Public License v3.0. You can find the license [here](LICENSE).
## 📜 Credits
DivineMC includes patches from other forks, and without these forks, DivineMC wouldn't exist today. Here are the list of these forks:
DivineMC includes patches from other projects, and without these projects, DivineMC wouldn't exist today. Here is a small list of projects that DivineMC takes patches from:
- [Purpur](https://github.com/PurpurMC/Purpur)
- <details>
<summary>📜 Expand to see forks that DivineMC takes patches from.</summary>
<p>
<a href="https://github.com/Bloom-host/Petal">Petal</a><br>
<a href="https://github.com/fxmorin/carpet-fixes">Carpet Fixes</a><br>
<a href="https://github.com/ProjectEdenGG/Parchment">Parchment</a><br>
<a href="https://github.com/LeavesMC/Leaves">Leaves</a><br>
<a href="https://github.com/SparklyPower/SparklyPaper">SparklyPaper</a><br>
<a href="https://github.com/plasmoapp/matter">Matter</a><br>
<a href="https://github.com/CraftCanvasMC/Canvas">Canvas</a><br>
<a href="https://github.com/Winds-Studio/Leaf">Leaf</a><br>
</p>
</details>
- [Petal](https://github.com/Bloom-host/Petal)
- [carpet-fixes](https://github.com/fxmorin/carpet-fixes)
- [Parchment](https://github.com/ProjectEdenGG/Parchment)
- [Leaves](https://github.com/LeavesMC/Leaves)
- [SparklyPaper](https://github.com/SparklyPower/SparklyPaper)
- [matter](https://github.com/plasmoapp/matter)
- [Leaf](https://github.com/Winds-Studio/Leaf)
- [C2ME](https://github.com/RelativityMC/C2ME-fabric)
- [VMP](https://github.com/RelativityMC/VMP-fabric)
- [EntityCulling](https://github.com/tr7zw/EntityCulling)
- ... and others
If you want to know more about other forks and see other Minecraft projects, you can go to our [list of different Minecraft server Software](https://gist.github.com/NONPLAYT/48742353af8ae36bcef5d1c36de9730a).

View File

@@ -6,34 +6,15 @@ private-f net.minecraft.world.level.levelgen.NoiseChunk$FlatCache noiseFiller
private-f net.minecraft.world.level.levelgen.NoiseChunk$NoiseInterpolator noiseFiller
private-f net.minecraft.world.level.levelgen.RandomState router
private-f net.minecraft.world.level.levelgen.RandomState sampler
public ca.spottedleaf.moonrise.patches.chunk_system.scheduling.executor.RadiusAwarePrioritisedExecutor$Task
public ca.spottedleaf.moonrise.patches.chunk_system.scheduling.executor.RadiusAwarePrioritisedExecutor$Task chunkX
public ca.spottedleaf.moonrise.patches.chunk_system.scheduling.executor.RadiusAwarePrioritisedExecutor$Task chunkZ
public ca.spottedleaf.moonrise.patches.chunk_system.scheduling.task.ChunkProgressionTask chunkX
public ca.spottedleaf.moonrise.patches.chunk_system.scheduling.task.ChunkProgressionTask chunkZ
public ca.spottedleaf.moonrise.patches.chunk_system.scheduling.task.ChunkProgressionTask world
public ca.spottedleaf.moonrise.patches.chunk_system.scheduling.task.GenericDataLoadTask chunkX
public ca.spottedleaf.moonrise.patches.chunk_system.scheduling.task.GenericDataLoadTask chunkZ
public ca.spottedleaf.moonrise.patches.chunk_system.scheduling.task.GenericDataLoadTask world
public ca.spottedleaf.moonrise.patches.chunk_system.scheduling.task.GenericDataLoadTask$ProcessOffMainTask
public ca.spottedleaf.moonrise.patches.chunk_system.scheduling.task.GenericDataLoadTask$ProcessOnMainTask
public net.minecraft.util.Mth SIN
public net.minecraft.world.entity.ai.Brain sensors
public net.minecraft.world.entity.ai.memory.NearestVisibleLivingEntities lineOfSightTest
public net.minecraft.world.entity.ai.memory.NearestVisibleLivingEntities nearbyEntities
public net.minecraft.world.entity.ai.sensing.Sensor scanRate
public net.minecraft.world.entity.ai.sensing.Sensor timeToTick
public net.minecraft.world.level.ServerExplosion damageSource
public net.minecraft.world.level.ServerExplosion source
public net.minecraft.world.level.chunk.LevelChunk$RebindableTickingBlockEntityWrapper
public net.minecraft.world.level.chunk.LevelChunk$RebindableTickingBlockEntityWrapper rebind(Lnet/minecraft/world/level/block/entity/TickingBlockEntity;)V
public net.minecraft.world.level.chunk.LevelChunk$RebindableTickingBlockEntityWrapper ticker
public net.minecraft.world.level.chunk.LevelChunkSection nonEmptyBlockCount
public net.minecraft.world.level.chunk.LevelChunkSection tickingBlockCount
public net.minecraft.world.level.chunk.LevelChunkSection tickingFluidCount
public net.minecraft.world.level.chunk.PalettedContainer palette
public net.minecraft.world.level.chunk.PalettedContainer strategy
public net.minecraft.world.level.chunk.PalettedContainer$Data palette
public net.minecraft.world.entity.animal.armadillo.Armadillo scuteTime
public net.minecraft.world.entity.animal.frog.Tadpole getTicksLeftUntilAdult()I
public net.minecraft.world.level.chunk.PaletteResize
public net.minecraft.world.level.chunk.storage.RegionFile getOversizedData(II)Lnet/minecraft/nbt/CompoundTag;
public net.minecraft.world.level.chunk.storage.RegionFile isOversized(II)Z
public net.minecraft.world.level.chunk.storage.RegionFile recalculateHeader()Z
@@ -66,22 +47,11 @@ public net.minecraft.world.level.levelgen.Xoroshiro128PlusPlus seedHi
public net.minecraft.world.level.levelgen.Xoroshiro128PlusPlus seedLo
public net.minecraft.world.level.levelgen.XoroshiroRandomSource randomNumberGenerator
public net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool rawTemplates
public net.minecraft.world.level.levelgen.structure.structures.WoodlandMansionPieces$SimpleGrid
public net.minecraft.world.level.levelgen.synth.BlendedNoise mainNoise
public net.minecraft.world.level.levelgen.synth.BlendedNoise maxLimitNoise
public net.minecraft.world.level.levelgen.synth.BlendedNoise minLimitNoise
public net.minecraft.world.level.levelgen.synth.BlendedNoise smearScaleMultiplier
public net.minecraft.world.level.levelgen.synth.BlendedNoise xzFactor
public net.minecraft.world.level.levelgen.synth.BlendedNoise xzMultiplier
public net.minecraft.world.level.levelgen.synth.BlendedNoise xzScale
public net.minecraft.world.level.levelgen.synth.BlendedNoise yFactor
public net.minecraft.world.level.levelgen.synth.BlendedNoise yMultiplier
public net.minecraft.world.level.levelgen.synth.BlendedNoise yScale
public net.minecraft.world.level.levelgen.synth.ImprovedNoise p
public net.minecraft.world.level.levelgen.synth.PerlinNoise amplitudes
public net.minecraft.world.level.levelgen.synth.PerlinNoise lowestFreqInputFactor
public net.minecraft.world.level.levelgen.synth.PerlinNoise lowestFreqValueFactor
public net.minecraft.world.level.levelgen.synth.PerlinNoise noiseLevels
public net.minecraft.world.level.levelgen.synth.SimplexNoise p
public net.minecraft.world.level.pathfinder.SwimNodeEvaluator allowBreaching
public net.minecraft.world.level.storage.loot.LootPool entries
public net.minecraft.world.level.storage.loot.LootTable pools
public net.minecraft.world.level.storage.loot.entries.CompositeEntryBase children
public net.minecraft.world.level.storage.loot.entries.LootPoolEntryContainer conditions
public net.minecraft.world.level.storage.loot.entries.NestedLootTable contents
public net.minecraft.world.level.storage.loot.predicates.CompositeLootItemCondition terms
public-f ca.spottedleaf.moonrise.paper.PaperHooks

View File

@@ -1,5 +1,6 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import kotlin.system.measureTimeMillis
plugins {
java
@@ -91,6 +92,7 @@ subprojects {
mavenCentral()
maven(paperMavenPublicUrl)
maven("https://jitpack.io")
maven("https://s01.oss.sonatype.org/content/repositories/snapshots")
}
extensions.configure<PublishingExtension> {
@@ -105,6 +107,76 @@ subprojects {
}
}
tasks.register<Jar>("createMojmapShuttleJar") {
dependsOn(":divinemc-server:createMojmapPaperclipJar", "shuttle:shadowJar")
outputs.upToDateWhen { false }
val paperclipJarTask = project(":divinemc-server").tasks.getByName("createMojmapPaperclipJar")
val shuttleJarTask = project(":shuttle").tasks.getByName("shadowJar")
val paperclipJar = paperclipJarTask.outputs.files.singleFile
val shuttleJar = shuttleJarTask.outputs.files.singleFile
val outputDir = paperclipJar.parentFile
val tempDir = File(outputDir, "tempJarWork")
val newJarName = "divinemc-shuttle-${properties["version"]}-mojmap.jar"
doFirst {
val time = measureTimeMillis {
println("Recompiling Paperclip with Shuttle sources...")
tempDir.deleteRecursively()
tempDir.mkdirs()
copy {
from(zipTree(paperclipJar))
into(tempDir)
}
val oldPackagePath = "io/papermc/paperclip/"
tempDir.walkTopDown()
.filter { it.isFile && it.relativeTo(tempDir).path.startsWith(oldPackagePath) }
.forEach { it.delete() }
val shuttlePackagePath = "org/bxteam/shuttle/"
copy {
from(zipTree(shuttleJar))
include("$shuttlePackagePath**")
into(tempDir)
}
tempDir.walkBottomUp()
.filter { it.isDirectory && it.listFiles().isNullOrEmpty() }
.forEach { it.delete() }
val metaInfDir = File(tempDir, "META-INF")
metaInfDir.mkdirs()
File(metaInfDir, "main-class").writeText("net.minecraft.server.Main")
}
println("Finished build in ${time}ms")
}
archiveFileName.set(newJarName)
destinationDirectory.set(outputDir)
from(tempDir)
manifest {
attributes(
"Main-Class" to "org.bxteam.shuttle.Shuttle",
"Enable-Native-Access" to "ALL-UNNAMED",
"Premain-Class" to "org.bxteam.shuttle.patch.InstrumentationManager",
"Agent-Class" to "org.bxteam.shuttle.patch.InstrumentationManager",
"Launcher-Agent-Class" to "org.bxteam.shuttle.patch.InstrumentationManager",
"Can-Redefine-Classes" to true,
"Can-Retransform-Classes" to true
)
}
doLast {
tempDir.deleteRecursively()
}
}
tasks.register("printMinecraftVersion") {
doLast {
println(providers.gradleProperty("mcVersion").get().trim())

View File

@@ -0,0 +1,45 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sun, 6 Jul 2025 01:23:49 +0300
Subject: [PATCH] Vectorized map color conversion
Original patch by: Kevin Raneri <kevin.raneri@gmail.com>
As part of: Pufferfish (https://github.com/pufferfish-gg/Pufferfish)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Pufferfish description:
This patch does not add any API that should be used by plugins. Any
classes and methods added by this patch should NOT be used in plugins.
diff --git a/src/main/java/org/bukkit/map/MapPalette.java b/src/main/java/org/bukkit/map/MapPalette.java
index 2b9e4aa8cf35e7106e510e547954ee7e1bcf3d81..482a08c38748d82313e02f6f699006aa83a071bc 100644
--- a/src/main/java/org/bukkit/map/MapPalette.java
+++ b/src/main/java/org/bukkit/map/MapPalette.java
@@ -35,7 +35,7 @@ public final class MapPalette {
}
@NotNull
- static final Color[] colors = {
+ public static final Color[] colors = { // DivineMC - Vectorized map color conversion - package -> public
// Start generate - MapPalette#colors
// @GeneratedFrom 1.21.7
new Color(0x00000000, true),
@@ -395,9 +395,15 @@ public final class MapPalette {
temp.getRGB(0, 0, temp.getWidth(), temp.getHeight(), pixels, 0, temp.getWidth());
byte[] result = new byte[temp.getWidth() * temp.getHeight()];
- for (int i = 0; i < pixels.length; i++) {
- result[i] = matchColor(new Color(pixels[i], true));
+ // DivineMC start - Vectorized map color conversion
+ if ((mapColorCache != null && mapColorCache.isCached()) || !gg.pufferfish.pufferfish.simd.SIMDDetection.isEnabled) {
+ for (int i = 0; i < pixels.length; i++) {
+ result[i] = matchColor(new Color(pixels[i], true));
+ }
+ } else {
+ gg.pufferfish.pufferfish.simd.VectorMapPalette.matchColorVectorized(pixels, result);
}
+ // DivineMC end - Vectorized map color conversion
return result;
}

View File

@@ -1,29 +0,0 @@
--- a/src/main/java/org/bukkit/map/MapPalette.java
+++ b/src/main/java/org/bukkit/map/MapPalette.java
@@ -35,7 +_,7 @@
}
@NotNull
- static final Color[] colors = {
+ public static final Color[] colors = { // DivineMC - Pufferfish SIMD - make public
// Start generate - MapPalette#colors
// @GeneratedFrom 1.21.7
new Color(0x00000000, true),
@@ -395,9 +_,15 @@
temp.getRGB(0, 0, temp.getWidth(), temp.getHeight(), pixels, 0, temp.getWidth());
byte[] result = new byte[temp.getWidth() * temp.getHeight()];
- for (int i = 0; i < pixels.length; i++) {
- result[i] = matchColor(new Color(pixels[i], true));
+ // DivineMC start - Pufferfish SIMD
+ if (gg.pufferfish.pufferfish.simd.SIMDDetection.isEnabled) {
+ gg.pufferfish.pufferfish.simd.VectorMapPalette.matchColorVectorized(pixels, result);
+ } else {
+ for (int i = 0; i < pixels.length; i++) {
+ result[i] = matchColor(new Color(pixels[i], true));
+ }
}
+ // DivineMC end - Pufferfish SIMD
return result;
}

View File

@@ -1,22 +1,24 @@
package gg.pufferfish.pufferfish.simd;
import org.slf4j.Logger;
import jdk.incubator.vector.FloatVector;
import jdk.incubator.vector.IntVector;
import jdk.incubator.vector.VectorSpecies;
import org.slf4j.Logger;
@Deprecated
public class SIMDChecker {
public static boolean canEnable(Logger logger) {
private final VectorSpecies<Integer> ISPEC;
private final VectorSpecies<Float> FSPEC;
public SIMDChecker(VectorSpecies<Integer> ISPEC, VectorSpecies<Float> FSPEC) {
this.ISPEC = ISPEC;
this.FSPEC = FSPEC;
}
public boolean canEnable(Logger logger) {
try {
if (SIMDDetection.getJavaVersion() < 17) {
if ((SIMDDetection.getJavaVersion() < SIMDDetection.MIN_JAVA_VERSION || SIMDDetection.getJavaVersion() > SIMDDetection.MAX_JAVA_VERSION)) {
return false;
} else {
SIMDDetection.testRun = true;
VectorSpecies<Integer> ISPEC = IntVector.SPECIES_PREFERRED;
VectorSpecies<Float> FSPEC = FloatVector.SPECIES_PREFERRED;
logger.info("Max SIMD vector size on this system is {} bits (int)", ISPEC.vectorBitSize());
logger.info("Max SIMD vector size on this system is {} bits (float)", FSPEC.vectorBitSize());
@@ -27,7 +29,10 @@ public class SIMDChecker {
return true;
}
} catch (NoClassDefFoundError | Exception ignored) {} // Basically, we don't do anything. This lets us detect if it's not functional and disable it.
} catch (NoClassDefFoundError | Exception ignored) {
// Basically, we don't do anything. This lets us detect if it's not functional and disable it.
}
return false;
}
}

View File

@@ -1,27 +1,30 @@
package gg.pufferfish.pufferfish.simd;
import jdk.incubator.vector.FloatVector;
import jdk.incubator.vector.IntVector;
import org.slf4j.Logger;
@Deprecated
public class SIMDDetection {
public static boolean isEnabled = false;
public static boolean versionLimited = false;
public static boolean testRun = false;
@Deprecated
public static final int MAX_JAVA_VERSION = 25;
public static final int MIN_JAVA_VERSION = 21;
public static boolean canEnable(Logger logger) {
try {
return SIMDChecker.canEnable(logger);
SIMDChecker checker = new SIMDChecker(IntVector.SPECIES_PREFERRED, FloatVector.SPECIES_PREFERRED);
return checker.canEnable(logger);
} catch (NoClassDefFoundError | Exception ignored) {
return false;
}
}
@Deprecated
public static int getJavaVersion() {
// https://stackoverflow.com/a/2591122
String version = System.getProperty("java.version");
if(version.startsWith("1.")) {
if (version.startsWith("1.")) {
version = version.substring(2, 3);
} else {
int dot = version.indexOf(".");

View File

@@ -72,7 +72,7 @@
}
}
val log4jPlugins = sourceSets.create("log4jPlugins") {
@@ -156,10 +_,23 @@
@@ -156,10 +_,21 @@
}
dependencies {
@@ -84,11 +84,9 @@
+ implementation ("me.carleslc.Simple-YAML:Simple-Yaml:1.8.4") {
+ exclude(group="org.yaml", module="snakeyaml")
+ }
+ implementation("net.objecthunter:exp4j:0.4.8")
+ implementation("org.agrona:agrona:2.0.1")
+ implementation("net.openhft:zero-allocation-hashing:0.16")
+ implementation("com.github.luben:zstd-jni:1.5.6-9")
+ implementation("com.github.luben:zstd-jni:1.5.7-3")
+ implementation("org.lz4:lz4-java:1.8.0")
+ implementation("net.openhft:zero-allocation-hashing:0.16")
+ // DivineMC end - Dependencies
+
implementation("ca.spottedleaf:concurrentutil:0.0.3")
@@ -187,8 +185,9 @@
val gitBranch = git.exec(providers, "rev-parse", "--abbrev-ref", "HEAD").get().trim()
+ val experimental = rootProject.providers.gradleProperty("experimental").get() // DivineMC - Experimental flag
attributes(
"Main-Class" to "org.bukkit.craftbukkit.Main",
- "Main-Class" to "org.bukkit.craftbukkit.Main",
- "Implementation-Title" to "Purpur", // Purpur
+ "Main-Class" to "net.minecraft.server.Main", // DivineMC - Rebrand
+ "Implementation-Title" to "DivineMC", // DivineMC - Rebrand
"Implementation-Version" to implementationVersion,
"Implementation-Vendor" to date,
@@ -209,3 +208,12 @@
)
for (tld in setOf("net", "com", "org")) {
attributes("$tld/bukkit", "Sealed" to true)
@@ -333,7 +_,7 @@
block: JavaExec.() -> Unit
): TaskProvider<JavaExec> = register<JavaExec>(name) {
group = "runs"
- mainClass.set("org.bukkit.craftbukkit.Main")
+ mainClass.set("net.minecraft.server.Main") // DivineMC - Rebrand
standardInput = System.`in`
workingDir = rootProject.layout.projectDirectory
.dir(providers.gradleProperty("paper.runWorkDir").getOrElse("run"))

View File

@@ -17,11 +17,123 @@ index 394443d00e661715439be1e56dddc129947699a4..480ad57a6b7b74e6b83e9c6ceb69ea1f
public CrashReport(String title, Throwable exception) {
io.papermc.paper.util.StacktraceDeobfuscator.INSTANCE.deobfuscateThrowable(exception); // Paper
diff --git a/net/minecraft/network/protocol/common/custom/BrandPayload.java b/net/minecraft/network/protocol/common/custom/BrandPayload.java
index 97844ec1ccc986eb3d3a185d78a03ceeca49fc1a..5e40ec3fbe6e6d5f98ad98df7d4c27d6de615778 100644
--- a/net/minecraft/network/protocol/common/custom/BrandPayload.java
+++ b/net/minecraft/network/protocol/common/custom/BrandPayload.java
@@ -12,7 +12,7 @@ public record BrandPayload(String brand) implements CustomPacketPayload {
}
private void write(FriendlyByteBuf buffer) {
- buffer.writeUtf(this.brand);
+ buffer.writeUtf(org.purpurmc.purpur.PurpurConfig.f3Name + "§r"); // DivineMC - Update Purpur rebrand settings
}
@Override
diff --git a/net/minecraft/server/Main.java b/net/minecraft/server/Main.java
index b06c2c4aa77edafb374f7cf0406cf4d29c6e7f9f..c3ac5ba5d8084fefc0e9f58b09b521ef516126eb 100644
--- a/net/minecraft/server/Main.java
+++ b/net/minecraft/server/Main.java
@@ -64,41 +64,39 @@ import org.slf4j.Logger;
public class Main {
private static final Logger LOGGER = LogUtils.getLogger();
+ public static void main(String[] arguments) {
+ OptionSet optionSet = org.bxteam.divinemc.DivineBootstrap.bootstrap(arguments);
+
+ io.papermc.paper.ServerBuildInfo info = io.papermc.paper.ServerBuildInfo.buildInfo();
+ if (io.papermc.paper.ServerBuildInfoImpl.IS_EXPERIMENTAL) {
+ LOGGER.warn("Running an experimental version of {}, please proceed with caution.", info.brandName());
+ }
+
+ main(optionSet);
+ }
+
@SuppressForbidden(
reason = "System.out needed before bootstrap"
)
@DontObfuscate
public static void main(final OptionSet optionSet) { // CraftBukkit - replaces main(String[] args)
+ Path path2 = Paths.get("eula.txt");
+ Eula eula = new Eula(path2);
+ boolean eulaAgreed = Boolean.getBoolean("com.mojang.eula.agree");
+ if (eulaAgreed) {
+ LOGGER.error("You have used the Spigot command line EULA agreement flag.");
+ LOGGER.error("By using this setting you are indicating your agreement to Mojang's EULA (https://aka.ms/MinecraftEULA).");
+ LOGGER.error("If you do not agree to the above EULA please stop your server and remove this flag immediately.");
+ }
+ if (!eula.hasAgreedToEULA() && !eulaAgreed) {
+ LOGGER.info("You need to agree to the EULA in order to run the server. Go to eula.txt for more info.");
+ return;
+ }
+
io.papermc.paper.util.LogManagerShutdownThread.hook(); // Paper - Improved watchdog support
SharedConstants.tryDetectVersion();
- /* CraftBukkit start - Replace everything
- OptionParser optionParser = new OptionParser();
- OptionSpec<Void> optionSpec = optionParser.accepts("nogui");
- OptionSpec<Void> optionSpec1 = optionParser.accepts("initSettings", "Initializes 'server.properties' and 'eula.txt', then quits");
- OptionSpec<Void> optionSpec2 = optionParser.accepts("demo");
- OptionSpec<Void> optionSpec3 = optionParser.accepts("bonusChest");
- OptionSpec<Void> optionSpec4 = optionParser.accepts("forceUpgrade");
- OptionSpec<Void> optionSpec5 = optionParser.accepts("eraseCache");
- OptionSpec<Void> optionSpec6 = optionParser.accepts("recreateRegionFiles");
- OptionSpec<Void> optionSpec7 = optionParser.accepts("safeMode", "Loads level with vanilla datapack only");
- OptionSpec<Void> optionSpec8 = optionParser.accepts("help").forHelp();
- OptionSpec<String> optionSpec9 = optionParser.accepts("universe").withRequiredArg().defaultsTo(".");
- OptionSpec<String> optionSpec10 = optionParser.accepts("world").withRequiredArg();
- OptionSpec<Integer> optionSpec11 = optionParser.accepts("port").withRequiredArg().ofType(Integer.class).defaultsTo(-1);
- OptionSpec<String> optionSpec12 = optionParser.accepts("serverId").withRequiredArg();
- OptionSpec<Void> optionSpec13 = optionParser.accepts("jfrProfile");
- OptionSpec<Path> optionSpec14 = optionParser.accepts("pidFile").withRequiredArg().withValuesConvertedBy(new PathConverter());
- OptionSpec<String> optionSpec15 = optionParser.nonOptions();
try {
- OptionSet optionSet = optionParser.parse(args);
- if (optionSet.has(optionSpec8)) {
- optionParser.printHelpOn(System.err);
- return;
- }
- */ // CraftBukkit end
- try {
-
Path path = (Path) optionSet.valueOf("pidFile"); // CraftBukkit
if (path != null) {
writePidFile(path);
@@ -124,8 +122,6 @@ public class Main {
DedicatedServerSettings dedicatedServerSettings = new DedicatedServerSettings(optionSet); // CraftBukkit - CLI argument support
dedicatedServerSettings.forceSave();
RegionFileVersion.configure(dedicatedServerSettings.getProperties().regionFileComression);
- Path path2 = Paths.get("eula.txt");
- Eula eula = new Eula(path2);
// Paper start - load config files early for access below if needed
org.bukkit.configuration.file.YamlConfiguration bukkitConfiguration = io.papermc.paper.configuration.PaperConfigurations.loadLegacyConfigFile((File) optionSet.valueOf("bukkit-settings"));
org.bukkit.configuration.file.YamlConfiguration spigotConfiguration = io.papermc.paper.configuration.PaperConfigurations.loadLegacyConfigFile((File) optionSet.valueOf("spigot-settings"));
@@ -148,19 +144,6 @@ public class Main {
return;
}
- // Spigot start
- boolean eulaAgreed = Boolean.getBoolean("com.mojang.eula.agree");
- if (eulaAgreed) {
- LOGGER.error("You have used the Spigot command line EULA agreement flag.");
- LOGGER.error("By using this setting you are indicating your agreement to Mojang's EULA (https://aka.ms/MinecraftEULA).");
- LOGGER.error("If you do not agree to the above EULA please stop your server and remove this flag immediately.");
- }
- if (!eula.hasAgreedToEULA() && !eulaAgreed) {
- // Spigot end
- LOGGER.info("You need to agree to the EULA in order to run the server. Go to eula.txt for more info.");
- return;
- }
-
// Paper start - Detect headless JRE
String awtException = io.papermc.paper.util.ServerEnvironment.awtDependencyCheck();
if (awtException != null) {
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index ac0ed2e7261a0d698fafd5b314108ff38a169073..8f32168ff0371a9168bbf9b08b2154200f8131a0 100644
index 3de43e4edb33bb2c657a315ad2676ce44ee3bd6a..2d01252a66e59f69ff69055b83d7e881f2f3e5cd 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1183,6 +1183,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1184,6 +1184,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
protected void runServer() {
try {
@@ -30,7 +142,7 @@ index ac0ed2e7261a0d698fafd5b314108ff38a169073..8f32168ff0371a9168bbf9b08b215420
throw new IllegalStateException("Failed to initialize server");
}
diff --git a/net/minecraft/server/gui/MinecraftServerGui.java b/net/minecraft/server/gui/MinecraftServerGui.java
index 614c7d9f673c926562acc8fa3b3788623900db41..33456c7c106abbddf743e1203a6e8122cf10b797 100644
index 614c7d9f673c926562acc8fa3b3788623900db41..937469a134e721c47e235a34acc565f12adf85ff 100644
--- a/net/minecraft/server/gui/MinecraftServerGui.java
+++ b/net/minecraft/server/gui/MinecraftServerGui.java
@@ -51,7 +51,7 @@ public class MinecraftServerGui extends JComponent {
@@ -38,7 +150,7 @@ index 614c7d9f673c926562acc8fa3b3788623900db41..33456c7c106abbddf743e1203a6e8122
}
- final JFrame jFrame = new JFrame("Purpur Minecraft server"); // Purpur - Improve GUI
+ final JFrame jFrame = new JFrame("DivineMC Minecraft server"); // Purpur - Improve GUI // DivineMC - Rebrand
+ final JFrame jFrame = new JFrame(org.purpurmc.purpur.PurpurConfig.serverGUIName); // Purpur - Improve GUI // DivineMC - Update Purpur rebrand settings
final MinecraftServerGui minecraftServerGui = new MinecraftServerGui(server);
jFrame.setDefaultCloseOperation(2);
jFrame.add(minecraftServerGui);
@@ -47,7 +159,7 @@ index 614c7d9f673c926562acc8fa3b3788623900db41..33456c7c106abbddf743e1203a6e8122
jFrame.setVisible(true);
// Paper start - Improve ServerGUI
- jFrame.setName("Purpur Minecraft server"); // Purpur - Improve GUI
+ jFrame.setName("DivineMC Minecraft server"); // Purpur - Improve GUI // DivineMC - Rebrand
+ jFrame.setName(org.purpurmc.purpur.PurpurConfig.serverGUIName); // Purpur - Improve GUI // DivineMC - Update Purpur rebrand settings
try {
jFrame.setIconImage(javax.imageio.ImageIO.read(java.util.Objects.requireNonNull(MinecraftServerGui.class.getClassLoader().getResourceAsStream("logo.png"))));
} catch (java.io.IOException ignore) {
@@ -56,7 +168,7 @@ index 614c7d9f673c926562acc8fa3b3788623900db41..33456c7c106abbddf743e1203a6e8122
public void windowClosing(WindowEvent event) {
if (!minecraftServerGui.isClosing.getAndSet(true)) {
- jFrame.setTitle("Purpur Minecraft server - shutting down!"); // Purpur - Improve GUI
+ jFrame.setTitle("DivineMC Minecraft server - shutting down!"); // Purpur - Improve GUI // DivineMC - Rebrand
+ jFrame.setTitle(org.purpurmc.purpur.PurpurConfig.serverGUIName + " - shutting down!"); // Purpur - Improve GUI // DivineMC - Update Purpur rebrand settings
server.halt(true);
minecraftServerGui.runFinalizers();
}

View File

@@ -5,27 +5,28 @@ Subject: [PATCH] Configuration
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
index debea77d5777b90c6b17b225e27e6b3c72370175..f5761420749110ca8811533c3fb5d80c8b025c67 100644
index 536a3da1d87e1d4087977196c5766f6550a95e47..bbe93d1861541991215d32186eec82fa8602fea2 100644
--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -193,6 +193,15 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@@ -162,6 +162,8 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
this.setLocalIp(properties.serverIp);
}
+ org.bxteam.divinemc.config.DivineConfig.init((java.io.File) options.valueOf("divinemc-settings")); // DivineMC - Configuration
+
// Spigot start
this.setPlayerList(new DedicatedPlayerList(this, this.registries(), this.playerDataStorage));
org.spigotmc.SpigotConfig.init((java.io.File) this.options.valueOf("spigot-settings"));
@@ -193,6 +195,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
}
org.purpurmc.purpur.PurpurConfig.registerCommands();
// Purpur end - Purpur config files
+ // DivineMC start - Configuration
+ try {
+ org.bxteam.divinemc.config.DivineConfig.init((java.io.File) options.valueOf("divinemc-settings"));
+ } catch (Exception e) {
+ DedicatedServer.LOGGER.error("Unable to load DivineMC configuration", e);
+ return false;
+ }
+ org.bxteam.divinemc.command.DivineCommands.registerCommands(this);
+ // DivineMC end - Configuration
+ org.bxteam.divinemc.command.DivineCommands.registerCommands(this); // DivineMC - Configuration
com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // Paper - load version history now
// DivineMC start - Pufferfish SIMD
// DivineMC start - Pufferfish: SIMD Support
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
index 801c4e8e01590beeb3633275f58d436d87ad746e..5ffaae02967dbc079619d35c2b8e3f7763b75d38 100644
index 848f936a26429d844ad439ca336dbcb8d81f09e8..2c60b1c8ecb54c4c9526a2b2f6e6698b77359065 100644
--- a/net/minecraft/world/level/Level.java
+++ b/net/minecraft/world/level/Level.java
@@ -161,6 +161,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl

View File

@@ -213,7 +213,7 @@ index 18071dcc69cc28471dddb7de94e803ec1e5fc2e4..aa25f5ebaf7d1b22825b962b02dcae02
}
}
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index ea40b39a90aacceedabf2637049968137d495132..7a3775185d5c80f43456a595f22a9ebf19760bd6 100644
index 2d01252a66e59f69ff69055b83d7e881f2f3e5cd..824f9200b66639ad1e3e821c8ae2ea4c66fe0b30 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -114,19 +114,8 @@ import net.minecraft.util.TimeUtil;
@@ -260,7 +260,7 @@ index ea40b39a90aacceedabf2637049968137d495132..7a3775185d5c80f43456a595f22a9ebf
LOGGER.info("Stopping server");
Commands.COMMAND_SENDING_POOL.shutdownNow(); // Paper - Perf: Async command map building; Shutdown and don't bother finishing
@@ -1274,50 +1253,38 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1275,50 +1254,38 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// Spigot end
boolean flag = l == 0L;
@@ -336,7 +336,7 @@ index ea40b39a90aacceedabf2637049968137d495132..7a3775185d5c80f43456a595f22a9ebf
this.isReady = true;
JvmProfiler.INSTANCE.onServerTick(this.smoothedTickTimeMillis);
}
@@ -1489,7 +1456,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1490,7 +1457,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@Override
public void doRunTask(TickTask task) {
@@ -344,7 +344,7 @@ index ea40b39a90aacceedabf2637049968137d495132..7a3775185d5c80f43456a595f22a9ebf
super.doRunTask(task);
}
@@ -1579,12 +1545,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1580,12 +1546,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.ticksUntilAutosave--;
// Paper start - Incremental chunk and player saving
@@ -357,7 +357,7 @@ index ea40b39a90aacceedabf2637049968137d495132..7a3775185d5c80f43456a595f22a9ebf
final boolean fullSave = autosavePeriod > 0 && this.tickCount % autosavePeriod == 0;
try {
this.isSaving = true;
@@ -1599,10 +1563,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1600,10 +1564,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
} finally {
this.isSaving = false;
}
@@ -368,7 +368,7 @@ index ea40b39a90aacceedabf2637049968137d495132..7a3775185d5c80f43456a595f22a9ebf
this.runAllTasks(); // Paper - move runAllTasks() into full server tick (previously for timings)
this.server.spark.executeMainThreadTasks(); // Paper - spark
// Paper start - Server Tick Events
@@ -1611,7 +1573,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1612,7 +1574,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
new com.destroystokyo.paper.event.server.ServerTickEndEvent(this.tickCount, ((double)(endTime - lastTick) / 1000000D), remaining).callEvent();
// Paper end - Server Tick Events
this.server.spark.tickEnd(((double)(endTime - lastTick) / 1000000D)); // Paper - spark
@@ -376,7 +376,7 @@ index ea40b39a90aacceedabf2637049968137d495132..7a3775185d5c80f43456a595f22a9ebf
long l = Util.getNanos() - nanos;
int i1 = this.tickCount % 100;
this.aggregatedTickTimesNanos = this.aggregatedTickTimesNanos - this.tickTimesNanos[i1];
@@ -1624,16 +1585,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1625,16 +1586,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.tickTimes60s.add(this.tickCount, l);
// Paper end - Add tick times API and /mspt command
this.logTickMethodTime(nanos);
@@ -393,7 +393,7 @@ index ea40b39a90aacceedabf2637049968137d495132..7a3775185d5c80f43456a595f22a9ebf
LOGGER.debug("Autosave finished");
}
@@ -1701,7 +1658,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1702,7 +1659,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
public final io.papermc.paper.threadedregions.EntityScheduler.EntitySchedulerTickList entitySchedulerTickList = new io.papermc.paper.threadedregions.EntityScheduler.EntitySchedulerTickList(); // Paper - optimise Folia entity scheduler
protected void tickChildren(BooleanSupplier hasTimeLeft) {
@@ -401,7 +401,7 @@ index ea40b39a90aacceedabf2637049968137d495132..7a3775185d5c80f43456a595f22a9ebf
this.getPlayerList().getPlayers().forEach(serverPlayer1 -> serverPlayer1.connection.suspendFlushing());
this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit
// Paper start - optimise Folia entity scheduler
@@ -1716,9 +1672,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1717,9 +1673,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// Paper end - optimise Folia entity scheduler
io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.ADVENTURE_CLICK_MANAGER.handleQueue(this.tickCount); // Paper
io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.DIALOG_CLICK_MANAGER.handleQueue(this.tickCount); // Paper
@@ -411,7 +411,7 @@ index ea40b39a90aacceedabf2637049968137d495132..7a3775185d5c80f43456a595f22a9ebf
// CraftBukkit start
// Run tasks that are waiting on processing
@@ -1754,17 +1708,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1755,17 +1709,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
serverLevel.updateLagCompensationTick(); // Paper - lag compensation
net.minecraft.world.level.block.entity.HopperBlockEntity.skipHopperEvents = serverLevel.paperConfig().hopper.disableMoveEvent || org.bukkit.event.inventory.InventoryMoveItemEvent.getHandlerList().getRegisteredListeners().length == 0; // Paper - Perf: Optimize Hoppers
serverLevel.hasRidableMoveEvent = org.purpurmc.purpur.event.entity.RidableMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Purpur - Ridables
@@ -429,7 +429,7 @@ index ea40b39a90aacceedabf2637049968137d495132..7a3775185d5c80f43456a595f22a9ebf
try {
serverLevel.tick(hasTimeLeft);
} catch (Throwable var7) {
@@ -1773,34 +1722,24 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1774,34 +1723,24 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
throw new ReportedException(crashReport);
}
@@ -464,7 +464,7 @@ index ea40b39a90aacceedabf2637049968137d495132..7a3775185d5c80f43456a595f22a9ebf
}
public void tickConnection() {
@@ -1816,14 +1755,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1817,14 +1756,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
public void forceTimeSynchronization() {
@@ -479,7 +479,7 @@ index ea40b39a90aacceedabf2637049968137d495132..7a3775185d5c80f43456a595f22a9ebf
}
public boolean isLevelEnabled(Level level) {
@@ -2639,55 +2573,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -2640,55 +2574,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
// CraftBukkit end
@@ -535,7 +535,7 @@ index ea40b39a90aacceedabf2637049968137d495132..7a3775185d5c80f43456a595f22a9ebf
public Path getWorldPath(LevelResource levelResource) {
return this.storageSource.getLevelPath(levelResource);
}
@@ -2737,24 +2622,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -2738,24 +2623,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
return this.isSaving;
}
@@ -560,7 +560,7 @@ index ea40b39a90aacceedabf2637049968137d495132..7a3775185d5c80f43456a595f22a9ebf
public int getMaxChainedNeighborUpdates() {
return 1000000;
}
@@ -2864,55 +2731,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -2865,55 +2732,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
public record ServerResourcePackInfo(UUID id, String url, String hash, boolean isRequired, @Nullable Component prompt) {
}
@@ -1067,10 +1067,10 @@ index b10cb4a73df58a5fe64e88868733ba41616f59e4..9f9cbe6056f8a4eeca64c40872d7403b
+ // DivineMC end - Completely remove Mojang profiler
}
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
index de4d7908542128fe4e3b256482a624f0e6bea683..7ac82a49e3c64d1a41a2870c5cf9900812329a57 100644
index 80d04f4eb5122d571409a50f5921c3403dacf31f..ac35fc08574a72be356c48fb6e1cfafe36cd0860 100644
--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -815,12 +815,6 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@@ -809,12 +809,6 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
return this.settings.getProperties().serverResourcePackInfo;
}
@@ -1128,7 +1128,7 @@ index 4221af18f5087badb5cd8c7cf66ab3312edf0394..e9d861182439eecacfab2ac431726e8a
ChunkPyramid chunkPyramid = needsGeneration ? ChunkPyramid.GENERATION_PYRAMID : ChunkPyramid.LOADING_PYRAMID;
return chunkPyramid.getStepTo(this.targetStatus).getAccumulatedRadiusOf(status);
diff --git a/net/minecraft/server/level/ChunkMap.java b/net/minecraft/server/level/ChunkMap.java
index eb352aa4296abc3ed4cf31c590bc0be66daf4de3..edda52a8430386238be4963e8ea2406f0c2d4df3 100644
index 6c648f2395b2f00180a71a4f6b50a6be51970d39..c0d996fb99f053863ce623889add3feb70d7137d 100644
--- a/net/minecraft/server/level/ChunkMap.java
+++ b/net/minecraft/server/level/ChunkMap.java
@@ -62,8 +62,6 @@ import net.minecraft.util.CsvOutput;
@@ -4006,7 +4006,7 @@ index 39a604c9a53930b53d959b1d2eb504aa964e9a58..0d0380e3955836ce125f777841477503
@Override
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index fa829d84cd47b68426bb30f662de6e05b608cc69..02f39e3dc420a5bd49cd6e247c9b1894dc49d303 100644
index b50753d2316afa4a59799e49e985642977a24813..5bc7f37290eb99145a2ea3e40d31180f3494979b 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -80,8 +80,6 @@ import net.minecraft.tags.TagKey;
@@ -4018,7 +4018,7 @@ index fa829d84cd47b68426bb30f662de6e05b608cc69..02f39e3dc420a5bd49cd6e247c9b1894
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.Nameable;
@@ -873,8 +871,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -874,8 +872,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
// CraftBukkit end
public void baseTick() {
@@ -4027,7 +4027,7 @@ index fa829d84cd47b68426bb30f662de6e05b608cc69..02f39e3dc420a5bd49cd6e247c9b1894
if (firstTick && this instanceof net.minecraft.world.entity.NeutralMob neutralMob) neutralMob.tickInitialPersistentAnger(level); // Paper - Prevent entity loading causing async lookups
this.inBlockState = null;
if (this.isPassenger() && this.getVehicle().isRemoved()) {
@@ -928,8 +924,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -929,8 +925,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
if (this.level() instanceof ServerLevel serverLevelx && this instanceof Leashable) {
Leashable.tickLeash(serverLevelx, (Entity & Leashable)this);
}
@@ -4036,7 +4036,7 @@ index fa829d84cd47b68426bb30f662de6e05b608cc69..02f39e3dc420a5bd49cd6e247c9b1894
}
public void setSharedFlagOnFire(boolean isOnFire) {
@@ -1150,8 +1144,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -1152,8 +1146,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
}
@@ -4045,7 +4045,7 @@ index fa829d84cd47b68426bb30f662de6e05b608cc69..02f39e3dc420a5bd49cd6e247c9b1894
if (this.stuckSpeedMultiplier.lengthSqr() > 1.0E-7) {
movement = movement.multiply(this.stuckSpeedMultiplier);
this.stuckSpeedMultiplier = Vec3.ZERO;
@@ -1160,7 +1152,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -1162,7 +1154,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
// Paper start - ignore movement changes while inactive.
if (isTemporarilyActive && !(this instanceof ItemEntity) && movement == getDeltaMovement() && type == MoverType.SELF) {
setDeltaMovement(Vec3.ZERO);
@@ -4053,7 +4053,7 @@ index fa829d84cd47b68426bb30f662de6e05b608cc69..02f39e3dc420a5bd49cd6e247c9b1894
return;
}
// Paper end
@@ -1185,8 +1176,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -1187,8 +1178,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
this.setPos(vec32);
}
@@ -4062,7 +4062,7 @@ index fa829d84cd47b68426bb30f662de6e05b608cc69..02f39e3dc420a5bd49cd6e247c9b1894
boolean flag = !Mth.equal(movement.x, vec3.x);
boolean flag1 = !Mth.equal(movement.z, vec3.z);
this.horizontalCollision = flag || flag1;
@@ -1209,7 +1198,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -1211,7 +1200,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
if (this.isRemoved()) {
@@ -4071,7 +4071,7 @@ index fa829d84cd47b68426bb30f662de6e05b608cc69..02f39e3dc420a5bd49cd6e247c9b1894
} else {
if (this.horizontalCollision) {
Vec3 deltaMovement = this.getDeltaMovement();
@@ -1253,7 +1242,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -1255,7 +1244,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
float blockSpeedFactor = this.getBlockSpeedFactor();
this.setDeltaMovement(this.getDeltaMovement().multiply(blockSpeedFactor, 1.0, blockSpeedFactor));
@@ -4079,7 +4079,7 @@ index fa829d84cd47b68426bb30f662de6e05b608cc69..02f39e3dc420a5bd49cd6e247c9b1894
}
}
// Paper start - detailed watchdog information
@@ -3466,8 +3454,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -3468,8 +3456,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
this.processPortalCooldown();
if (this.portalProcess != null) {
if (this.portalProcess.processPortalTeleportation(serverLevel, this, this.canUsePortal(false))) {
@@ -4088,7 +4088,7 @@ index fa829d84cd47b68426bb30f662de6e05b608cc69..02f39e3dc420a5bd49cd6e247c9b1894
this.setPortalCooldown();
TeleportTransition portalDestination = this.portalProcess.getPortalDestination(serverLevel, this);
if (portalDestination != null) {
@@ -3477,8 +3463,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -3479,8 +3465,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
this.teleport(portalDestination);
}
}
@@ -4097,7 +4097,7 @@ index fa829d84cd47b68426bb30f662de6e05b608cc69..02f39e3dc420a5bd49cd6e247c9b1894
} else if (this.portalProcess.hasExpired()) {
this.portalProcess = null;
}
@@ -4045,15 +4029,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4047,15 +4031,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
entity.teleport(this.calculatePassengerTransition(teleportTransition, entity));
}
@@ -4113,7 +4113,7 @@ index fa829d84cd47b68426bb30f662de6e05b608cc69..02f39e3dc420a5bd49cd6e247c9b1894
return this;
}
@@ -4069,11 +4050,8 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4071,11 +4052,8 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
}
@@ -4125,7 +4125,7 @@ index fa829d84cd47b68426bb30f662de6e05b608cc69..02f39e3dc420a5bd49cd6e247c9b1894
return null;
} else {
// Paper start - Fix item duplication and teleport issues
@@ -4093,7 +4071,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4095,7 +4073,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
newLevel.resetEmptyTime();
teleportTransition.postTeleportTransition().onTransition(entityx);
this.teleportSpectators(teleportTransition, oldLevel);
@@ -4493,7 +4493,7 @@ index cf6ff7b7b4a007d7ff4b3c5a25d4f5a36422c683..c5275d6069a491c3c2b2de175b76fb87
}
diff --git a/net/minecraft/world/entity/animal/armadillo/Armadillo.java b/net/minecraft/world/entity/animal/armadillo/Armadillo.java
index 0da5c51c4830cf1826261f4d8877303b34c6cb87..6fbeaff7178a21338920d6738767033260b7a726 100644
index e4578193f58417c7ef2776bb3d831ba55c553aec..2a7a078e05e16e73e43a24e108d207bce2e876bb 100644
--- a/net/minecraft/world/entity/animal/armadillo/Armadillo.java
+++ b/net/minecraft/world/entity/animal/armadillo/Armadillo.java
@@ -23,8 +23,6 @@ import net.minecraft.util.ByIdMap;
@@ -4604,7 +4604,7 @@ index 1d5079602e7ae1042e2bb92209dded4007f703da..c6e4966d3e4fdb7c91577fc1693fb669
}
diff --git a/net/minecraft/world/entity/animal/frog/Tadpole.java b/net/minecraft/world/entity/animal/frog/Tadpole.java
index 6932e85b3db0205f9a69d9ef965a934f100e6bcf..c0e12a6e5dd2b7e12e4cc40f6795228de6b470cc 100644
index 3bb197054f5197c0b8c4e2d4714d695255d5ecfa..f85626b690b02908fac3979d277b293ec48aa451 100644
--- a/net/minecraft/world/entity/animal/frog/Tadpole.java
+++ b/net/minecraft/world/entity/animal/frog/Tadpole.java
@@ -12,8 +12,6 @@ import net.minecraft.server.level.ServerLevel;
@@ -4920,7 +4920,7 @@ index 07d7c4737635f671f33b8f73001d67928fc75782..f2c82217811712625df594667330a73f
LOGGER.info("Loaded {} recipes", object.values().size());
}
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
index 1ad419b4a2ad4610a0a8d18b26665a7ec0ccc960..4c1ce7e85f9c3315635472047ffaf15a711aeffd 100644
index 2c60b1c8ecb54c4c9526a2b2f6e6698b77359065..abf90aabf47f1bac805b2d40585c2e3c41b5cfe9 100644
--- a/net/minecraft/world/level/Level.java
+++ b/net/minecraft/world/level/Level.java
@@ -35,8 +35,6 @@ import net.minecraft.util.AbortableIterationConsumer;
@@ -4957,15 +4957,15 @@ index 1ad419b4a2ad4610a0a8d18b26665a7ec0ccc960..4c1ce7e85f9c3315635472047ffaf15a
this.tickingBlockEntities = true;
if (!this.pendingBlockEntityTickers.isEmpty()) {
this.blockEntityTickers.addAll(this.pendingBlockEntityTickers);
@@ -1529,7 +1523,6 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
this.blockEntityTickers.removeAll(toRemove); // Paper - Fix MC-117075
@@ -1527,7 +1521,6 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
this.blockEntityTickers.removeMarkedEntries(); // DivineMC - optimize block entity removals - Fix MC-117075
this.tickingBlockEntities = false;
- profilerFiller.pop();
this.spigotConfig.currentPrimedTnt = 0; // Spigot
}
@@ -1781,7 +1774,6 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
@@ -1779,7 +1772,6 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
@Override
public List<Entity> getEntities(@Nullable Entity entity, AABB boundingBox, Predicate<? super Entity> predicate) {
@@ -4973,7 +4973,7 @@ index 1ad419b4a2ad4610a0a8d18b26665a7ec0ccc960..4c1ce7e85f9c3315635472047ffaf15a
List<Entity> list = Lists.newArrayList();
// Paper start - rewrite chunk system
@@ -1810,8 +1802,6 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
@@ -1808,8 +1800,6 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
public <T extends Entity> void getEntities(final EntityTypeTest<Entity, T> entityTypeTest,
final AABB boundingBox, final Predicate<? super T> predicate,
final List<? super T> into, final int maxCount) {
@@ -5015,7 +5015,7 @@ index fa06ecacc27f619853c8db76d909ab4ba75dc529..345d4b80bd4383e0fb66d744d87bc8ef
// Paper start - Add mobcaps commands
diff --git a/net/minecraft/world/level/ServerExplosion.java b/net/minecraft/world/level/ServerExplosion.java
index 1d3b16d3f60a394fe69e10ef1bb6052bb937070a..d0c4d63320fb5f58c43b38ebc333e9a7be487a5d 100644
index b80924fbe054b00fe5117df896358e330f41e993..1669c21534a453c9cf16b992df7a6bf276dea887 100644
--- a/net/minecraft/world/level/ServerExplosion.java
+++ b/net/minecraft/world/level/ServerExplosion.java
@@ -13,8 +13,6 @@ import net.minecraft.Util;
@@ -5039,7 +5039,7 @@ index 1d3b16d3f60a394fe69e10ef1bb6052bb937070a..d0c4d63320fb5f58c43b38ebc333e9a7
if (this.fire) {
diff --git a/net/minecraft/world/level/chunk/LevelChunk.java b/net/minecraft/world/level/chunk/LevelChunk.java
index 8084b524dc0c10cb801b6d8beccbde89de9c55d2..53c77efe2f86c5dfb5f02fa0b1886e8cda2e3862 100644
index 8345405116202b59055f5343fc26b82f48008050..dbb4142ea38cdf484e74c81103cebb024ae8813d 100644
--- a/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/net/minecraft/world/level/chunk/LevelChunk.java
@@ -24,8 +24,6 @@ import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData;
@@ -5115,7 +5115,7 @@ index 81de6c1bbef1cafd3036e736dd305fbedc8368c6..c2baadcdceb1df6a881d6f73aa4eb4dd
// Paper end - Perf: remove streams and optimize collection
}
diff --git a/net/minecraft/world/ticks/LevelTicks.java b/net/minecraft/world/ticks/LevelTicks.java
index 66abc2e7adee60fa98eed1ba36e018814fd02cad..0a9805d42142678ca5213c511235daa6505ddbf3 100644
index 769037ecd67b2ed92067bba4e5f7ac9383c3d456..2f88649c398d7f60f10532eb6b36ce1c27bcbdcc 100644
--- a/net/minecraft/world/ticks/LevelTicks.java
+++ b/net/minecraft/world/ticks/LevelTicks.java
@@ -23,8 +23,6 @@ import net.minecraft.Util;

View File

@@ -175,10 +175,10 @@ index 345d4b80bd4383e0fb66d744d87bc8ef4100fd32..68a074a1eb11b158af773a2c44aa49d5
private static boolean isRightDistanceToPlayerAndSpawnPoint(ServerLevel level, ChunkAccess chunk, BlockPos.MutableBlockPos pos, double distance) {
diff --git a/net/minecraft/world/level/chunk/ChunkAccess.java b/net/minecraft/world/level/chunk/ChunkAccess.java
index 5e9f3856c384dbb2bd462121b903cd2b326e4376..19f74518923783d8d5560b526a1f267dabd23156 100644
index 182c14b660f8860bed627eed4e01fd4002153e9a..81511de113c292549fe5fe720a15bf3e0497ca84 100644
--- a/net/minecraft/world/level/chunk/ChunkAccess.java
+++ b/net/minecraft/world/level/chunk/ChunkAccess.java
@@ -92,6 +92,7 @@ public abstract class ChunkAccess implements BiomeManager.NoiseBiomeSource, Ligh
@@ -88,6 +88,7 @@ public abstract class ChunkAccess implements BiomeManager.NoiseBiomeSource, Ligh
public org.bukkit.craftbukkit.persistence.DirtyCraftPersistentDataContainer persistentDataContainer = new org.bukkit.craftbukkit.persistence.DirtyCraftPersistentDataContainer(ChunkAccess.DATA_TYPE_REGISTRY);
// CraftBukkit end
public final Registry<Biome> biomeRegistry; // CraftBukkit

View File

@@ -25,7 +25,7 @@ index c4a4f08272b34f72dea4feaaeb66d153b2aab8c8..be5da5a81246b4f4abe19f7c0cf68990
}
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
index 6e8075618baf98fcc396f0b5e241a806805b3d94..37f5bd2a63e2ec074fbc55d366e0d128f1918089 100644
index 4c1ce7e85f9c3315635472047ffaf15a711aeffd..9625213b7c1295b813071dbedea5366510c7072f 100644
--- a/net/minecraft/world/level/Level.java
+++ b/net/minecraft/world/level/Level.java
@@ -1171,6 +1171,12 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl

View File

@@ -15,7 +15,7 @@ The delay is currently set to 2 seconds, however, we may want to adjust this bef
This patch fixes PaperMC/Paper#9581
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
index e93a006cde4dd85a9976e0d6a64643755ba99fb7..62e89385fcdc3fa0202863f3199c98a2df4be2a6 100644
index bdc1200ef5317fdaf58973bf580b0a672aee800f..1ed2ae41e47b2446bf1835efc8bad369408d52da 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
@@ -48,6 +48,7 @@ public final class RegionizedPlayerChunkLoader {
@@ -27,10 +27,10 @@ index e93a006cde4dd85a9976e0d6a64643755ba99fb7..62e89385fcdc3fa0202863f3199c98a2
public static final int GENERATED_TICKET_LEVEL = ChunkHolderManager.FULL_LOADED_TICKET_LEVEL;
public static final int LOADED_TICKET_LEVEL = ChunkTaskScheduler.getTicketLevel(ChunkStatus.EMPTY);
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
index e1ca822d41311e3be44c52badb907619ca681cf9..bd6cff4916fdf379ee887259d18ee274ff2f8bc6 100644
index 8a67672f1175769ac213099331453fbae59442fa..c70b5ce2dc8cbcdea8715339a63e038f94849bfb 100644
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -316,6 +316,13 @@ public abstract class PlayerList {
@@ -315,6 +315,13 @@ public abstract class PlayerList {
// this.broadcastAll(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(player))); // CraftBukkit - replaced with loop below
// Paper start - Fire PlayerJoinEvent when Player is actually ready; correctly register player BEFORE PlayerJoinEvent, so the entity is valid and doesn't require tick delay hacks
player.supressTrackerForLogin = true;

View File

@@ -1,741 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Fri, 31 Jan 2025 21:50:46 +0300
Subject: [PATCH] Misc Optimizations
diff --git a/com/mojang/math/Transformation.java b/com/mojang/math/Transformation.java
index 5fb382be4d86328690c49f2a5a0c3ec698a38e21..f333d9028f315e7912dd335c8158abd525c27ecd 100644
--- a/com/mojang/math/Transformation.java
+++ b/com/mojang/math/Transformation.java
@@ -52,6 +52,7 @@ public final class Transformation {
} else {
this.matrix = matrix;
}
+ ensureDecomposed(); // DivineMC - Math Optimizations
}
public Transformation(@Nullable Vector3f translation, @Nullable Quaternionf leftRotation, @Nullable Vector3f scale, @Nullable Quaternionf rightRotation) {
@@ -61,6 +62,7 @@ public final class Transformation {
this.scale = scale != null ? scale : new Vector3f(1.0F, 1.0F, 1.0F);
this.rightRotation = rightRotation != null ? rightRotation : new Quaternionf();
this.decomposed = true;
+ ensureDecomposed(); // DivineMC - Math Optimizations
}
public static Transformation identity() {
diff --git a/net/minecraft/core/MappedRegistry.java b/net/minecraft/core/MappedRegistry.java
index 4715a60760c2c9079313db9016000bfb5c65e070..fce8f1caca81f47f704bc0237147e9999cc5732c 100644
--- a/net/minecraft/core/MappedRegistry.java
+++ b/net/minecraft/core/MappedRegistry.java
@@ -33,10 +33,12 @@ public class MappedRegistry<T> implements WritableRegistry<T> {
private final ResourceKey<? extends Registry<T>> key;
private final ObjectList<Holder.Reference<T>> byId = new ObjectArrayList<>(256);
private final Reference2IntMap<T> toId = Util.make(new Reference2IntOpenHashMap<>(2048), map -> map.defaultReturnValue(-1)); // Paper - Perf: Use bigger expected size to reduce collisions
- private final Map<ResourceLocation, Holder.Reference<T>> byLocation = new HashMap<>(2048); // Paper - Perf: Use bigger expected size to reduce collisions
- private final Map<ResourceKey<T>, Holder.Reference<T>> byKey = new HashMap<>(2048); // Paper - Perf: Use bigger expected size to reduce collisions
- private final Map<T, Holder.Reference<T>> byValue = new IdentityHashMap<>(2048); // Paper - Perf: Use bigger expected size to reduce collisions
- private final Map<ResourceKey<T>, RegistrationInfo> registrationInfos = new IdentityHashMap<>(2048); // Paper - Perf: Use bigger expected size to reduce collisions
+ // DivineMC start - Some optimizations
+ private final Map<ResourceLocation, Holder.Reference<T>> byLocation = new java.util.concurrent.ConcurrentHashMap<>(2048); // Paper - Perf: Use bigger expected size to reduce collisions
+ private final Map<ResourceKey<T>, Holder.Reference<T>> byKey = new java.util.concurrent.ConcurrentHashMap<>(2048); // Paper - Perf: Use bigger expected size to reduce collisions
+ private final Map<T, Holder.Reference<T>> byValue = Collections.synchronizedMap(new IdentityHashMap<>(2048)); // Paper - Perf: Use bigger expected size to reduce collisions
+ private final Map<ResourceKey<T>, RegistrationInfo> registrationInfos = Collections.synchronizedMap(new IdentityHashMap<>(2048)); // Paper - Perf: Use bigger expected size to reduce collisions
+ // DivineMC end - Some optimizations
private Lifecycle registryLifecycle;
private final Map<TagKey<T>, HolderSet.Named<T>> frozenTags = new IdentityHashMap<>();
MappedRegistry.TagSet<T> allTags = MappedRegistry.TagSet.unbound();
diff --git a/net/minecraft/network/Connection.java b/net/minecraft/network/Connection.java
index e72eda830644851656fae3118c513d7bd701be45..cdacbfa64bda461d4f24c2a85db9feae7766b597 100644
--- a/net/minecraft/network/Connection.java
+++ b/net/minecraft/network/Connection.java
@@ -601,13 +601,7 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
if (!(this.packetListener instanceof net.minecraft.server.network.ServerLoginPacketListenerImpl loginPacketListener)
|| loginPacketListener.state != net.minecraft.server.network.ServerLoginPacketListenerImpl.State.VERIFYING
|| Connection.joinAttemptsThisTick++ < MAX_PER_TICK) {
- // Paper start - detailed watchdog information
- net.minecraft.network.protocol.PacketUtils.packetProcessing.push(this.packetListener);
- try {
tickablePacketListener.tick();
- } finally {
- net.minecraft.network.protocol.PacketUtils.packetProcessing.pop();
- } // Paper end - detailed watchdog information
} // Paper end - Buffer joins to world
}
diff --git a/net/minecraft/network/VarInt.java b/net/minecraft/network/VarInt.java
index 4897ff4648083ebe737ae5b32bae344af27357e4..0d103821d7220daa5cc0d5d3231e794fca0ca055 100644
--- a/net/minecraft/network/VarInt.java
+++ b/net/minecraft/network/VarInt.java
@@ -52,16 +52,43 @@ public class VarInt {
public static ByteBuf write(ByteBuf buffer, int value) {
// Paper start - Optimize VarInts
- // Peel the one and two byte count cases explicitly as they are the most common VarInt sizes
- // that the proxy will write, to improve inlining.
- if ((value & (0xFFFFFFFF << 7)) == 0) {
- buffer.writeByte(value);
- } else if ((value & (0xFFFFFFFF << 14)) == 0) {
- int w = (value & 0x7F | 0x80) << 8 | (value >>> 7);
- buffer.writeShort(w);
- } else {
- writeOld(buffer, value);
+ // DivineMC start - Misc optimizations
+ int bytesNeeded = getByteSize(value);
+
+ switch (bytesNeeded) {
+ case 1:
+ buffer.writeByte(value);
+ break;
+ case 2:
+ int w2 = ((value & 0x7F) << 8) | (value >>> 7) | 0x00008000;
+ buffer.writeShort(w2);
+ break;
+ case 3:
+ int w3 = (value & 0x7F) << 16
+ | (value & 0x3F80) << 1
+ | (value >>> 14)
+ | 0x00808000;
+ buffer.writeMedium(w3);
+ break;
+ case 4:
+ int w4 = (value & 0x7F) << 24
+ | ((value & 0x3F80) << 9)
+ | (value & 0x1FC000) >> 6
+ | (value >>> 21)
+ | 0x80808000;
+ buffer.writeInt(w4);
+ break;
+ case 5:
+ int w5 = (value & 0x7F) << 24
+ | (value & 0x3F80) << 9
+ | (value & 0x1FC000) >> 6
+ | ((value >>> 21) & 0x7F)
+ | 0x80808080;
+ buffer.writeInt(w5);
+ buffer.writeByte(value >>> 28);
+ break;
}
+ // DivineMC end - Slightly optimized VarInt#write
return buffer;
}
public static ByteBuf writeOld(ByteBuf buffer, int value) {
diff --git a/net/minecraft/network/protocol/PacketUtils.java b/net/minecraft/network/protocol/PacketUtils.java
index 4535858701b2bb232b9d2feb2af6551526232ddc..e65c62dbe4c1560ae153e4c4344e9194c783a2f4 100644
--- a/net/minecraft/network/protocol/PacketUtils.java
+++ b/net/minecraft/network/protocol/PacketUtils.java
@@ -21,8 +21,6 @@ public class PacketUtils {
public static <T extends PacketListener> void ensureRunningOnSameThread(Packet<T> packet, T processor, BlockableEventLoop<?> executor) throws RunningOnDifferentThreadException {
if (!executor.isSameThread()) {
executor.executeIfPossible(() -> {
- packetProcessing.push(processor); // Paper - detailed watchdog information
- try { // Paper - detailed watchdog information
if (processor instanceof net.minecraft.server.network.ServerCommonPacketListenerImpl serverCommonPacketListener && serverCommonPacketListener.processedDisconnect) return; // Paper - Don't handle sync packets for kicked players
if (processor.shouldHandleMessage(packet)) {
try {
@@ -37,12 +35,6 @@ public class PacketUtils {
} else {
LOGGER.debug("Ignoring packet due to disconnection: {}", packet);
}
- // Paper start - detailed watchdog information
- } finally {
- totalMainThreadPacketsProcessed.getAndIncrement();
- packetProcessing.pop();
- }
- // Paper end - detailed watchdog information
});
throw RunningOnDifferentThreadException.RUNNING_ON_DIFFERENT_THREAD;
}
@@ -69,22 +61,4 @@ public class PacketUtils {
packetListener.fillCrashReport(crashReport);
}
-
- // Paper start - detailed watchdog information
- public static final java.util.concurrent.ConcurrentLinkedDeque<PacketListener> packetProcessing = new java.util.concurrent.ConcurrentLinkedDeque<>();
- static final java.util.concurrent.atomic.AtomicLong totalMainThreadPacketsProcessed = new java.util.concurrent.atomic.AtomicLong();
-
- public static long getTotalProcessedPackets() {
- return totalMainThreadPacketsProcessed.get();
- }
-
- public static java.util.List<PacketListener> getCurrentPacketProcessors() {
- java.util.List<PacketListener> listeners = new java.util.ArrayList<>(4);
- for (PacketListener listener : packetProcessing) {
- listeners.add(listener);
- }
-
- return listeners;
- }
- // Paper end - detailed watchdog information
}
diff --git a/net/minecraft/server/level/ChunkTrackingView.java b/net/minecraft/server/level/ChunkTrackingView.java
index bee90335677f7d8b01589ce5cfd81a40fd422886..a5e488d14fd2016ee188b114d0e681562b5b09cc 100644
--- a/net/minecraft/server/level/ChunkTrackingView.java
+++ b/net/minecraft/server/level/ChunkTrackingView.java
@@ -73,12 +73,12 @@ public interface ChunkTrackingView {
}
static boolean isWithinDistance(int centerX, int centerZ, int viewDistance, int x, int z, boolean includeOuterChunksAdjacentToViewBorder) {
- int i = includeOuterChunksAdjacentToViewBorder ? 2 : 1;
- long l = Math.max(0, Math.abs(x - centerX) - i);
- long l1 = Math.max(0, Math.abs(z - centerZ) - i);
- long l2 = l * l + l1 * l1;
- int i1 = viewDistance * viewDistance;
- return l2 < i1;
+ // DivineMC start - Some optimizations
+ int actualViewDistance = viewDistance + (includeOuterChunksAdjacentToViewBorder ? 1 : 0);
+ int xDistance = Math.abs(centerX - x);
+ int zDistance = Math.abs(centerZ - z);
+ return xDistance <= actualViewDistance && zDistance <= actualViewDistance;
+ // DivineMC end - Some optimizations
}
public record Positioned(ChunkPos center, int viewDistance) implements ChunkTrackingView {
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
index 75c8ce32e68f92e20201e9c243f46f2be716eac8..879d6eb8e72b63bc95d8028cbc2f6e93e516ab1d 100644
--- a/net/minecraft/server/level/ServerChunkCache.java
+++ b/net/minecraft/server/level/ServerChunkCache.java
@@ -567,8 +567,10 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
try {
this.chunkMap.collectSpawningChunks(list);
// Paper start - chunk tick iteration optimisation
- this.shuffleRandom.setSeed(this.level.random.nextLong());
- if (!this.level.paperConfig().entities.spawning.perPlayerMobSpawns) Util.shuffle(list, this.shuffleRandom); // Paper - Optional per player mob spawns; do not need this when per-player is enabled
+ if (!this.level.paperConfig().entities.spawning.perPlayerMobSpawns) {
+ this.shuffleRandom.setSeed(this.level.random.nextLong()); // DivineMC - Misc Optimizations
+ Util.shuffle(list, this.shuffleRandom); // Paper - Optional per player mob spawns; do not need this when per-player is enabled
+ }
// Paper end - chunk tick iteration optimisation
for (LevelChunk levelChunk : list) {
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
index 2560799fe6ec006916a2bc9915355a358ab6c8bb..740f6324eeb4021bc45d27d6145ff71282c761c2 100644
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -1321,13 +1321,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
// Paper end - log detailed entity tick information
public void tickNonPassenger(Entity entity) {
- // Paper start - log detailed entity tick information
ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread("Cannot tick an entity off-main");
- try {
- if (currentlyTickingEntity.get() == null) {
- currentlyTickingEntity.lazySet(entity);
- }
- // Paper end - log detailed entity tick information
entity.setOldPosAndRot();
entity.tickCount++;
entity.totalEntityAge++; // Paper - age-like counter for all entities
@@ -1340,13 +1334,6 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
for (Entity entity1 : entity.getPassengers()) {
this.tickPassenger(entity, entity1, isActive); // Paper - EAR 2
}
- // Paper start - log detailed entity tick information
- } finally {
- if (currentlyTickingEntity.get() == entity) {
- currentlyTickingEntity.lazySet(null);
- }
- }
- // Paper end - log detailed entity tick information
}
private void tickPassenger(Entity ridingEntity, Entity passengerEntity, final boolean isActive) { // Paper - EAR 2
diff --git a/net/minecraft/util/ClassInstanceMultiMap.java b/net/minecraft/util/ClassInstanceMultiMap.java
index 2a708ae0d5bb209650b525e3c56051f8b5655074..4c7670224f0c90c1d0d833ff0b3d908846133b4a 100644
--- a/net/minecraft/util/ClassInstanceMultiMap.java
+++ b/net/minecraft/util/ClassInstanceMultiMap.java
@@ -14,9 +14,9 @@ import java.util.Map.Entry;
import net.minecraft.Util;
public class ClassInstanceMultiMap<T> extends AbstractCollection<T> {
- private final Map<Class<?>, List<T>> byClass = Maps.newHashMap();
+ private final Map<Class<?>, List<T>> byClass = new it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap<>(); // DivineMC - Misc Optimizations
private final Class<T> baseClass;
- private final List<T> allInstances = Lists.newArrayList();
+ private final List<T> allInstances = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>(); // DivineMC - Misc Optimizations
public ClassInstanceMultiMap(Class<T> baseClass) {
this.baseClass = baseClass;
@@ -56,13 +56,27 @@ public class ClassInstanceMultiMap<T> extends AbstractCollection<T> {
}
public <S> Collection<S> find(Class<S> type) {
+ // DivineMC start - Some optimizations
+ List<T> cached = this.byClass.get(type);
+ if (cached != null) return (Collection<S>) cached;
+
if (!this.baseClass.isAssignableFrom(type)) {
throw new IllegalArgumentException("Don't know how to search for " + type);
} else {
- List<? extends T> list = this.byClass
- .computeIfAbsent(type, clazz -> this.allInstances.stream().filter(clazz::isInstance).collect(Util.toMutableList()));
- return (Collection<S>)Collections.unmodifiableCollection(list);
+ List<? extends T> list = this.byClass.computeIfAbsent(type,
+ typeClass -> {
+ it.unimi.dsi.fastutil.objects.ObjectArrayList<T> ts = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>(this.allInstances.size());
+ for (Object _allElement : ((it.unimi.dsi.fastutil.objects.ObjectArrayList<T>) this.allInstances).elements()) {
+ if (typeClass.isInstance(_allElement)) {
+ ts.add((T) _allElement);
+ }
+ }
+ return ts;
+ }
+ );
+ return (Collection<S>) list;
}
+ // DivineMC end - Some optimizations
}
@Override
diff --git a/net/minecraft/util/CrudeIncrementalIntIdentityHashBiMap.java b/net/minecraft/util/CrudeIncrementalIntIdentityHashBiMap.java
index f28fbf81a417a678726d3f77b3999054676d522e..7ff32b1f93b31fafd13f4e0857d14d85ef1f28c7 100644
--- a/net/minecraft/util/CrudeIncrementalIntIdentityHashBiMap.java
+++ b/net/minecraft/util/CrudeIncrementalIntIdentityHashBiMap.java
@@ -52,23 +52,23 @@ public class CrudeIncrementalIntIdentityHashBiMap<K> implements IdMap<K>, ca.spo
@Nullable
@Override
- public K byId(int value) {
+ public synchronized K byId(int value) { // DivineMC - Misc Optimizations
return value >= 0 && value < this.byId.length ? this.byId[value] : null;
}
- private int getValue(int key) {
+ private synchronized int getValue(int key) { // DivineMC - Misc Optimizations
return key == -1 ? -1 : this.values[key];
}
- public boolean contains(K value) {
+ public synchronized boolean contains(K value) { // DivineMC - Misc Optimizations
return this.getId(value) != -1;
}
- public boolean contains(int value) {
+ public synchronized boolean contains(int value) { // DivineMC - Misc Optimizations
return this.byId(value) != null;
}
- public int add(K object) {
+ public synchronized int add(K object) { // DivineMC - Misc Optimizations
int i = this.nextId();
this.addMapping(object, i);
return i;
@@ -106,7 +106,7 @@ public class CrudeIncrementalIntIdentityHashBiMap<K> implements IdMap<K>, ca.spo
// Paper end - optimise palette reads
}
- public void addMapping(K object, int intKey) {
+ public synchronized void addMapping(K object, int intKey) { // DivineMC - Misc Optimizations
int max = Math.max(intKey, this.size + 1);
if (max >= this.keys.length * 0.8F) {
int i = this.keys.length << 1;
@@ -173,11 +173,11 @@ public class CrudeIncrementalIntIdentityHashBiMap<K> implements IdMap<K>, ca.spo
}
@Override
- public Iterator<K> iterator() {
+ public synchronized Iterator<K> iterator() { // DivineMC - Misc Optimizations
return Iterators.filter(Iterators.forArray(this.byId), Predicates.notNull());
}
- public void clear() {
+ public synchronized void clear() { // DivineMC - Misc Optimizations
Arrays.fill(this.keys, null);
Arrays.fill(this.byId, null);
this.nextId = 0;
diff --git a/net/minecraft/util/Mth.java b/net/minecraft/util/Mth.java
index e2602c6d817794616eb05a471077447804b835a1..d5a9fd918621708c5bcbf56e33513a6765122d1c 100644
--- a/net/minecraft/util/Mth.java
+++ b/net/minecraft/util/Mth.java
@@ -46,11 +46,11 @@ public class Mth {
private static final double[] COS_TAB = new double[257];
public static float sin(float value) {
- return SIN[(int)(value * 10430.378F) & 65535];
+ return net.caffeinemc.mods.lithium.common.util.math.CompactSineLUT.sin(value); // DivineMC - Math Optimizations
}
public static float cos(float value) {
- return SIN[(int)(value * 10430.378F + 16384.0F) & 65535];
+ return net.caffeinemc.mods.lithium.common.util.math.CompactSineLUT.cos(value); // DivineMC - Math Optimizations
}
public static float sqrt(float value) {
@@ -58,18 +58,15 @@ public class Mth {
}
public static int floor(float value) {
- int i = (int)value;
- return value < i ? i - 1 : i;
+ return (int) Math.floor(value); // DivineMC - Math Optimizations
}
public static int floor(double value) {
- int i = (int)value;
- return value < i ? i - 1 : i;
+ return (int) Math.floor(value); // DivineMC - Math Optimizations
}
public static long lfloor(double value) {
- long l = (long)value;
- return value < l ? l - 1L : l;
+ return (long) Math.floor(value); // DivineMC - Math Optimizations
}
public static float abs(float value) {
@@ -81,13 +78,11 @@ public class Mth {
}
public static int ceil(float value) {
- int i = (int)value;
- return value > i ? i + 1 : i;
+ return (int) Math.ceil(value); // DivineMC - Math Optimizations
}
public static int ceil(double value) {
- int i = (int)value;
- return value > i ? i + 1 : i;
+ return (int) Math.ceil(value); // DivineMC - Math Optimizations
}
public static int clamp(int value, int min, int max) {
@@ -123,15 +118,7 @@ public class Mth {
}
public static double absMax(double x, double y) {
- if (x < 0.0) {
- x = -x;
- }
-
- if (y < 0.0) {
- y = -y;
- }
-
- return Math.max(x, y);
+ return Math.max(Math.abs(x), Math.abs(y)); // DivineMC - Math Optimizations
}
public static int floorDiv(int dividend, int divisor) {
@@ -162,14 +149,26 @@ public class Mth {
return Math.floorMod(x, y);
}
- public static float positiveModulo(float numerator, float denominator) {
+ public static float positiveModuloForAnyDenominator(float numerator, float denominator) { // DivineMC - Math Optimizations
return (numerator % denominator + denominator) % denominator;
}
- public static double positiveModulo(double numerator, double denominator) {
+ public static double positiveModuloForAnyDenominator(double numerator, double denominator) { // DivineMC - Math Optimizations
return (numerator % denominator + denominator) % denominator;
}
+ // DivineMC start - Math Optimizations
+ public static float positiveModuloForPositiveIntegerDenominator(float numerator, float denominator) {
+ var modulo = numerator % denominator;
+ return modulo < 0 ? modulo + denominator : modulo;
+ }
+
+ public static double positiveModuloForPositiveIntegerDenominator(double numerator, double denominator) {
+ var modulo = numerator % denominator;
+ return modulo < 0 ? modulo + denominator : modulo;
+ }
+ // DivineMC end - Math Optimizations
+
public static boolean isMultipleOf(int number, int multiple) {
return number % multiple == 0;
}
diff --git a/net/minecraft/util/RandomSource.java b/net/minecraft/util/RandomSource.java
index 8516d47b0ba79d91638837199e7ae0fb6cb44a79..71444431b10582f5917c1795275ccdadd2364c3c 100644
--- a/net/minecraft/util/RandomSource.java
+++ b/net/minecraft/util/RandomSource.java
@@ -12,7 +12,7 @@ public interface RandomSource {
double GAUSSIAN_SPREAD_FACTOR = 2.297;
static RandomSource create() {
- return create(RandomSupport.generateUniqueSeed());
+ return createThreadSafe(); // DivineMC - Misc Optimizations
}
@Deprecated
@@ -21,7 +21,7 @@ public interface RandomSource {
}
static RandomSource create(long seed) {
- return new LegacyRandomSource(seed);
+ return new ThreadSafeLegacyRandomSource(seed); // DivineMC - Misc Optimizations
}
static RandomSource createNewThreadLocalInstance() {
diff --git a/net/minecraft/util/debugchart/DebugSampleSubscriptionTracker.java b/net/minecraft/util/debugchart/DebugSampleSubscriptionTracker.java
index a18240418a19a95147341a634527d774f3d5bb92..66f74ad2a194a6676574da2932cf4677f9383ecd 100644
--- a/net/minecraft/util/debugchart/DebugSampleSubscriptionTracker.java
+++ b/net/minecraft/util/debugchart/DebugSampleSubscriptionTracker.java
@@ -14,7 +14,7 @@ public class DebugSampleSubscriptionTracker {
public static final int STOP_SENDING_AFTER_MS = 10000;
private final PlayerList playerList;
private final Map<RemoteDebugSampleType, Map<ServerPlayer, DebugSampleSubscriptionTracker.SubscriptionStartedAt>> subscriptions;
- private final Queue<DebugSampleSubscriptionTracker.SubscriptionRequest> subscriptionRequestQueue = new LinkedList<>();
+ private final java.util.List<SubscriptionRequest> subscriptionRequestQueue = java.util.Collections.synchronizedList(new LinkedList<>()); // DivineMC - Misc Optimizations
public DebugSampleSubscriptionTracker(PlayerList playerList) {
this.playerList = playerList;
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 02f39e3dc420a5bd49cd6e247c9b1894dc49d303..ddc8095dfb6acce493e66034e47ee9a1f3497e5d 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -155,7 +155,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
// Paper start - Share random for entities to make them more random
- public static RandomSource SHARED_RANDOM = new RandomRandomSource();
+ public static RandomSource SHARED_RANDOM = new net.minecraft.world.level.levelgen.ThreadSafeLegacyRandomSource(net.minecraft.world.level.levelgen.RandomSupport.generateUniqueSeed()); // DivineMC - Misc Optimizations
// Paper start - replace random
private static final class RandomRandomSource extends ca.spottedleaf.moonrise.common.util.ThreadUnsafeRandom {
public RandomRandomSource() {
@@ -1108,28 +1108,9 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return this.onGround;
}
- // Paper start - detailed watchdog information
- public final Object posLock = new Object(); // Paper - log detailed entity tick information
-
- @Nullable
- private Vec3 moveVector;
- private double moveStartX;
- private double moveStartY;
- private double moveStartZ;
- // Paper end - detailed watchdog information
-
public void move(MoverType type, Vec3 movement) {
final Vec3 originalMovement = movement; // Paper - Expose pre-collision velocity
- // Paper start - detailed watchdog information
ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread("Cannot move an entity off-main");
- synchronized (this.posLock) {
- this.moveStartX = this.getX();
- this.moveStartY = this.getY();
- this.moveStartZ = this.getZ();
- this.moveVector = movement;
- }
- try {
- // Paper end - detailed watchdog information
if (this.noPhysics) {
this.setPos(this.getX() + movement.x, this.getY() + movement.y, this.getZ() + movement.z);
} else {
@@ -1244,13 +1225,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
this.setDeltaMovement(this.getDeltaMovement().multiply(blockSpeedFactor, 1.0, blockSpeedFactor));
}
}
- // Paper start - detailed watchdog information
- } finally {
- synchronized (this.posLock) { // Paper
- this.moveVector = null;
- } // Paper
- }
- // Paper end - detailed watchdog information
}
private void applyMovementEmissionAndPlaySound(Entity.MovementEmission movementEmission, Vec3 movement, BlockPos pos, BlockState state) {
@@ -4921,9 +4895,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
public void setDeltaMovement(Vec3 deltaMovement) {
- synchronized (this.posLock) { // Paper - detailed watchdog information
this.deltaMovement = deltaMovement;
- } // Paper - detailed watchdog information
}
public void addDeltaMovement(Vec3 addend) {
@@ -5021,9 +4993,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
// Paper end - Block invalid positions and bounding box
if (this.position.x != x || this.position.y != y || this.position.z != z) {
- synchronized (this.posLock) { // Paper - detailed watchdog information
this.position = new Vec3(x, y, z);
- } // Paper - detailed watchdog information
int floor = Mth.floor(x);
int floor1 = Mth.floor(y);
int floor2 = Mth.floor(z);
diff --git a/net/minecraft/world/entity/ExperienceOrb.java b/net/minecraft/world/entity/ExperienceOrb.java
index c8354d46ed909090f7c15f396863bf7d73afcefa..382ef2dad5e995bc01f6492218b8c8f7a930d6ac 100644
--- a/net/minecraft/world/entity/ExperienceOrb.java
+++ b/net/minecraft/world/entity/ExperienceOrb.java
@@ -195,6 +195,7 @@ public class ExperienceOrb extends Entity {
if (this.age >= 6000) {
this.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
}
+ if (this.count == 0) this.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DISCARD); // DivineMC - discard when count is 0
}
}
diff --git a/net/minecraft/world/level/GameRules.java b/net/minecraft/world/level/GameRules.java
index d510503a8ad272255aeba20a916642828023fd19..2d9bf302b779602d733187c6f86e52467f0dc540 100644
--- a/net/minecraft/world/level/GameRules.java
+++ b/net/minecraft/world/level/GameRules.java
@@ -288,7 +288,7 @@ public class GameRules {
}
private GameRules(Map<GameRules.Key<?>, GameRules.Value<?>> rules, FeatureFlagSet enabledFeatures) {
- this.rules = rules;
+ this.rules = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>(rules); // DivineMC - lithium: collections.gamerules
this.enabledFeatures = enabledFeatures;
// Paper start - Perf: Use array for gamerule storage
diff --git a/net/minecraft/world/level/LocalMobCapCalculator.java b/net/minecraft/world/level/LocalMobCapCalculator.java
index 9641219c190261dea0db5f95f040a705ba0a3ff9..a3fccdeb2c076e12b611683da55d45e00a166417 100644
--- a/net/minecraft/world/level/LocalMobCapCalculator.java
+++ b/net/minecraft/world/level/LocalMobCapCalculator.java
@@ -13,16 +13,24 @@ import net.minecraft.world.entity.MobCategory;
public class LocalMobCapCalculator {
private final Long2ObjectMap<List<ServerPlayer>> playersNearChunk = new Long2ObjectOpenHashMap<>();
- private final Map<ServerPlayer, LocalMobCapCalculator.MobCounts> playerMobCounts = Maps.newHashMap();
+ private final Map<ServerPlayer, LocalMobCapCalculator.MobCounts> playerMobCounts = Maps.newConcurrentMap(); // DivineMC - Misc Optimizations
private final ChunkMap chunkMap;
public LocalMobCapCalculator(ChunkMap chunkMap) {
this.chunkMap = chunkMap;
}
- private List<ServerPlayer> getPlayersNear(ChunkPos pos) {
- return this.playersNearChunk.computeIfAbsent(pos.toLong(), key -> this.chunkMap.getPlayersCloseForSpawning(pos));
+ // DivineMC start - Some optimizations
+ private synchronized @org.jetbrains.annotations.NotNull List<ServerPlayer> getPlayersNear(ChunkPos pos) {
+ List<ServerPlayer> retVal = this.playersNearChunk.get(pos.toLong());
+ if (retVal == null) {
+ List<ServerPlayer> newVal = this.chunkMap.getPlayersCloseForSpawning(pos);
+ this.playersNearChunk.put(pos.toLong(), newVal);
+ return newVal;
+ }
+ return retVal;
}
+ // DivineMC end - Some optimizations
public void addMob(ChunkPos pos, MobCategory category) {
for (ServerPlayer serverPlayer : this.getPlayersNear(pos)) {
@@ -42,14 +50,14 @@ public class LocalMobCapCalculator {
}
static class MobCounts {
- private final Object2IntMap<MobCategory> counts = new Object2IntOpenHashMap<>(MobCategory.values().length);
+ private final int[] spawnGroupDensities = new int[MobCategory.values().length]; // DivineMC - Misc Optimizations
public void add(MobCategory category) {
- this.counts.computeInt(category, (key, value) -> value == null ? 1 : value + 1);
+ this.spawnGroupDensities[category.ordinal()] ++; // DivineMC - Misc Optimizations
}
public boolean canSpawn(MobCategory category) {
- return this.counts.getOrDefault(category, 0) < category.getMaxInstancesPerChunk();
+ return this.spawnGroupDensities[category.ordinal()] < category.getMaxInstancesPerChunk(); // DivineMC - Misc Optimizations
}
}
}
diff --git a/net/minecraft/world/level/levelgen/blending/Blender.java b/net/minecraft/world/level/levelgen/blending/Blender.java
index 01e5b29d6e9a5c53c0e23b61ed0c1d7be1a0fe08..d80df05e40f3941ade5ed320e12f8dcf47e6b247 100644
--- a/net/minecraft/world/level/levelgen/blending/Blender.java
+++ b/net/minecraft/world/level/levelgen/blending/Blender.java
@@ -144,7 +144,7 @@ public class Blender {
private static double heightToOffset(double height) {
double d = 1.0;
double d1 = height + 0.5;
- double d2 = Mth.positiveModulo(d1, 8.0);
+ double d2 = Mth.positiveModuloForPositiveIntegerDenominator(d1, 8.0); // DivineMC - Math optimizations
return 1.0 * (32.0 * (d1 - 128.0) - 3.0 * (d1 - 120.0) * d2 + 3.0 * d2 * d2) / (128.0 * (32.0 - 3.0 * d2));
}
diff --git a/net/minecraft/world/level/levelgen/feature/OreFeature.java b/net/minecraft/world/level/levelgen/feature/OreFeature.java
index c7b46efd4f08067e2c9c5c8b0e8b71a94a79823d..c7252c636fcea34a866dcc4862b60cef31071666 100644
--- a/net/minecraft/world/level/levelgen/feature/OreFeature.java
+++ b/net/minecraft/world/level/levelgen/feature/OreFeature.java
@@ -69,7 +69,7 @@ public class OreFeature extends Feature<OreConfiguration> {
int height
) {
int i = 0;
- BitSet bitSet = new BitSet(width * height * width);
+ BitSet bitSet = org.bxteam.divinemc.util.cache.CachedOrNewBitsGetter.getCachedOrNewBitSet(width * height * width); // DivineMC - Misc Optimizations
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
int i1 = config.size;
double[] doubles = new double[i1 * 4];
diff --git a/net/minecraft/world/level/storage/DimensionDataStorage.java b/net/minecraft/world/level/storage/DimensionDataStorage.java
index 1ff0b19a077333ad9da9cab7f5a891eeaa2109a9..b82be2c9576b7d41d104b0c44237a01e678811d5 100644
--- a/net/minecraft/world/level/storage/DimensionDataStorage.java
+++ b/net/minecraft/world/level/storage/DimensionDataStorage.java
@@ -39,7 +39,7 @@ import org.slf4j.Logger;
public class DimensionDataStorage implements AutoCloseable {
private static final Logger LOGGER = LogUtils.getLogger();
private final SavedData.Context context;
- public final Map<SavedDataType<?>, Optional<SavedData>> cache = new HashMap<>();
+ public final Map<SavedDataType<?>, Optional<SavedData>> cache = new java.util.concurrent.ConcurrentHashMap<>(); // DivineMC - Misc Optimizations
private final DataFixer fixerUpper;
private final HolderLookup.Provider registries;
private final Path dataFolder;
diff --git a/net/minecraft/world/phys/AABB.java b/net/minecraft/world/phys/AABB.java
index e53398996bbb278c6e06024d8ca945b364a44c10..f60c1ab58a2e9adfb01e9bd430b92cd1902e5dbe 100644
--- a/net/minecraft/world/phys/AABB.java
+++ b/net/minecraft/world/phys/AABB.java
@@ -190,13 +190,15 @@ public class AABB {
}
public AABB intersect(AABB other) {
- double max = Math.max(this.minX, other.minX);
- double max1 = Math.max(this.minY, other.minY);
- double max2 = Math.max(this.minZ, other.minZ);
- double min = Math.min(this.maxX, other.maxX);
- double min1 = Math.min(this.maxY, other.maxY);
- double min2 = Math.min(this.maxZ, other.maxZ);
- return new AABB(max, max1, max2, min, min1, min2);
+ // DivineMC start - Math Optimizations
+ return new AABB(
+ this.minX > other.minX ? this.minX : other.minX,
+ this.minY > other.minY ? this.minY : other.minY,
+ this.minZ > other.minZ ? this.minZ : other.minZ,
+ this.maxX < other.maxX ? this.maxX : other.maxX,
+ this.maxY < other.maxY ? this.maxY : other.maxY,
+ this.maxZ < other.maxZ ? this.maxZ : other.maxZ
+ );
}
public AABB minmax(AABB other) {
@@ -228,16 +230,37 @@ public class AABB {
}
public boolean intersects(AABB other) {
- return this.intersects(other.minX, other.minY, other.minZ, other.maxX, other.maxY, other.maxZ);
+ // DivineMC start - Math Optimizations
+ return this.minX < other.maxX &&
+ this.maxX > other.minX &&
+ this.minY < other.maxY &&
+ this.maxY > other.minY &&
+ this.minZ < other.maxZ &&
+ this.maxZ > other.minZ;
+ // DivineMC end - Math Optimizations
}
public boolean intersects(double x1, double y1, double z1, double x2, double y2, double z2) {
- return this.minX < x2 && this.maxX > x1 && this.minY < y2 && this.maxY > y1 && this.minZ < z2 && this.maxZ > z1;
+ // DivineMC start - Math Optimizations
+ return this.minX < x2 &&
+ this.maxX > x1 &&
+ this.minY < y2 &&
+ this.maxY > y1 &&
+ this.minZ < z2 &&
+ this.maxZ > z1;
+ // DivineMC end - Math Optimizations
}
public boolean intersects(Vec3 min, Vec3 max) {
return this.intersects(
- Math.min(min.x, max.x), Math.min(min.y, max.y), Math.min(min.z, max.z), Math.max(min.x, max.x), Math.max(min.y, max.y), Math.max(min.z, max.z)
+ // DivineMC start - Math Optimizations
+ min.x < max.x ? min.x : max.x,
+ min.y < max.y ? min.y : max.y,
+ min.z < max.z ? min.z : max.z,
+ min.x > max.x ? min.x : max.x,
+ min.y > max.y ? min.y : max.y,
+ min.z > max.z ? min.z : max.z
+ // DivineMC end - Math Optimizations
);
}

View File

@@ -5,22 +5,22 @@ Subject: [PATCH] Smooth teleport API
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
index cf4ab76f463836a8ed9aeedd09ae95e75b9e8dbc..f5a0c5a2f56376bf89b16a809d465bc45a80eb38 100644
index 890c295d2318767081580e9aabddedd2535388cc..8a8d72fa46f4eff31e06e8b1756d286f7f1b07a6 100644
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -431,6 +431,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
@@ -430,6 +430,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
private boolean tpsBar = false; // Purpur - Implement TPSBar
private boolean compassBar = false; // Purpur - Add compass command
private boolean ramBar = false; // Purpur - Implement rambar commands
public boolean hasTickedAtLeastOnceInNewWorld = false; // DivineMC - Parallel world ticking
+ public boolean smoothWorldTeleport; // DivineMC - Smooth teleport API
// Paper start - rewrite chunk system
private ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.PlayerChunkLoaderData chunkLoader;
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
index 04f82f77e1ad2b7105cbace2a4ef99590965ae4f..147535646319018ec5dfe42d12fdb19d9e1f7543 100644
index 0a2d1a89722094f7e51c33a364b6999143add0a1..fb1b9f75cffeb15875e6690a0e030f8a4fd8b276 100644
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -758,11 +758,11 @@ public abstract class PlayerList {
@@ -749,11 +749,11 @@ public abstract class PlayerList {
byte b = (byte)(keepInventory ? 1 : 0);
ServerLevel serverLevel = serverPlayer.level();
LevelData levelData = serverLevel.getLevelData();
@@ -34,7 +34,7 @@ index 04f82f77e1ad2b7105cbace2a4ef99590965ae4f..147535646319018ec5dfe42d12fdb19d
serverPlayer.connection.send(new ClientboundSetDefaultSpawnPositionPacket(level.getSharedSpawnPos(), level.getSharedSpawnAngle()));
serverPlayer.connection.send(new ClientboundChangeDifficultyPacket(levelData.getDifficulty(), levelData.isDifficultyLocked()));
serverPlayer.connection
@@ -849,6 +849,12 @@ public abstract class PlayerList {
@@ -840,6 +840,12 @@ public abstract class PlayerList {
return serverPlayer;
}

View File

@@ -27,7 +27,7 @@ index 63fd7b45750430b565d599337d3112cbaa7e7550..4275a2e1e29c15cdda75c29c46825563
public static Direction getApproximateNearest(double x, double y, double z) {
diff --git a/net/minecraft/world/phys/AABB.java b/net/minecraft/world/phys/AABB.java
index f60c1ab58a2e9adfb01e9bd430b92cd1902e5dbe..37ad60f2be694c22bfef402c38c8206348bf36a5 100644
index e53398996bbb278c6e06024d8ca945b364a44c10..13678a9c0f9056b4925e4de927ec3cbc01cb114e 100644
--- a/net/minecraft/world/phys/AABB.java
+++ b/net/minecraft/world/phys/AABB.java
@@ -19,6 +19,15 @@ public class AABB {

View File

@@ -0,0 +1,68 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sun, 6 Jul 2025 01:55:37 +0300
Subject: [PATCH] C2ME: Optimize world gen math
This patch is based on following mixins:
* "com/ishland/c2me/opts/math/mixin/MixinChunkPos.java"
* "com/ishland/c2me/opts/worldgen/vanilla/mixin/structure_weight_sampler/MixinStructureWeightSampler.java"
By: ishland <ishlandmc@yeah.net>
As part of: C2ME-fabric (https://github.com/RelativityMC/C2ME-fabric)
Licensed under: MIT
diff --git a/net/minecraft/world/level/ChunkPos.java b/net/minecraft/world/level/ChunkPos.java
index 55ce935a2fab7e32904d9ff599867269035d703f..7770e2aacaa7772a1710172f143452f076c6eef2 100644
--- a/net/minecraft/world/level/ChunkPos.java
+++ b/net/minecraft/world/level/ChunkPos.java
@@ -110,7 +110,12 @@ public class ChunkPos {
@Override
public boolean equals(Object other) {
- return this == other || other instanceof ChunkPos chunkPos && this.x == chunkPos.x && this.z == chunkPos.z;
+ // DivineMC start - C2ME: Optimize world gen math
+ if (other == this) return true;
+ if (other == null || other.getClass() != this.getClass()) return false;
+ ChunkPos thatPos = (ChunkPos) other;
+ return this.x == thatPos.x && this.z == thatPos.z;
+ // DivineMC end - C2ME: Optimize world gen math
}
public int getMiddleBlockX() {
diff --git a/net/minecraft/world/level/levelgen/Beardifier.java b/net/minecraft/world/level/levelgen/Beardifier.java
index 74d8202b5c9bb2a3ee832be70f95c0b5cbecb460..86c15d2d90e63d21cb83622a7b29e11151a4f64a 100644
--- a/net/minecraft/world/level/levelgen/Beardifier.java
+++ b/net/minecraft/world/level/levelgen/Beardifier.java
@@ -131,8 +131,14 @@ public class Beardifier implements DensityFunctions.BeardifierOrMarker {
}
private static double getBuryContribution(double x, double y, double z) {
- double len = Mth.length(x, y, z);
- return Mth.clampedMap(len, 0.0, 6.0, 1.0, 0.0);
+ // DivineMC start - C2ME: Optimize world gen math
+ double len = Math.sqrt(x * x + y * y + z * z);
+ if (len > 6.0) {
+ return 0.0;
+ } else {
+ return 1.0 - len / 6.0;
+ }
+ // DivineMC end - C2ME: Optimize world gen math
}
private static double getBeardContribution(int x, int y, int z, int height) {
diff --git a/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java b/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java
index 65728ef17e63d71833677fdcbd5bb90794b4822b..5716e80ba386f113d02f5d6a4848914d4bf9600f 100644
--- a/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java
+++ b/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java
@@ -68,8 +68,10 @@ public final class NoiseBasedChunkGenerator extends ChunkGenerator {
Aquifer.FluidStatus fluidStatus = new Aquifer.FluidStatus(-54, Blocks.LAVA.defaultBlockState());
int seaLevel = settings.seaLevel();
Aquifer.FluidStatus fluidStatus1 = new Aquifer.FluidStatus(seaLevel, settings.defaultFluid());
- Aquifer.FluidStatus fluidStatus2 = new Aquifer.FluidStatus(DimensionType.MIN_Y * 2, Blocks.AIR.defaultBlockState());
- return (x, y, z) -> y < Math.min(-54, seaLevel) ? fluidStatus : fluidStatus1;
+ // DivineMC start - C2ME: Optimize world gen math
+ final int min = Math.min(-54, seaLevel);
+ return (x, y, z) -> y < min ? fluidStatus : fluidStatus1;
+ // DivineMC end - C2ME: Optimize world gen math
}
@Override

View File

@@ -0,0 +1,216 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sun, 6 Jul 2025 02:23:03 +0300
Subject: [PATCH] lithium: faster chunk serialization
This patch is based on the following mixins and classes:
* "net/caffeinemc/mods/lithium/common/world/chunk/CompactingPackedIntegerArray.java"
* "net/caffeinemc/mods/lithium/common/world/chunk/LithiumHashPalette.java"
* "net/caffeinemc/mods/lithium/mixin/chunk/serialization/SimpleBitStorageMixin.java"
* "net/caffeinemc/mods/lithium/mixin/chunk/serialization/PalettedContainerMixin.java"
By: Angeline <jellysquid3@users.noreply.github.com>
As part of: Lithium (https://github.com/CaffeineMC/lithium-fabric)
Licensed under: LGPL-3.0 (https://www.gnu.org/licenses/lgpl-3.0.html)
diff --git a/net/minecraft/util/BitStorage.java b/net/minecraft/util/BitStorage.java
index 02502d50f0255f5bbcc0ecb965abb48cc1a112da..a0a0ec8747cf6477df8943d2268dece8e064cb33 100644
--- a/net/minecraft/util/BitStorage.java
+++ b/net/minecraft/util/BitStorage.java
@@ -38,4 +38,6 @@ public interface BitStorage extends ca.spottedleaf.moonrise.patches.block_counti
return ret;
}
// Paper end - block counting
+
+ <T> void compact(net.minecraft.world.level.chunk.Palette<T> srcPalette, net.minecraft.world.level.chunk.Palette<T> dstPalette, short[] out); // DivineMC - lithium: faster chunk serialization
}
diff --git a/net/minecraft/util/SimpleBitStorage.java b/net/minecraft/util/SimpleBitStorage.java
index e6306a68c8652d4c5d22d5ecb1416f5f931f76ee..1d8125e23e34a929da6fb4e361eae3ccbaeabce9 100644
--- a/net/minecraft/util/SimpleBitStorage.java
+++ b/net/minecraft/util/SimpleBitStorage.java
@@ -465,4 +465,44 @@ public class SimpleBitStorage implements BitStorage {
super(message);
}
}
+
+ // DivineMC start - lithium: faster chunk serialization
+ @Override
+ public <T> void compact(net.minecraft.world.level.chunk.Palette<T> srcPalette, net.minecraft.world.level.chunk.Palette<T> dstPalette, short[] out) {
+ if (this.size >= Short.MAX_VALUE) {
+ throw new IllegalStateException("Array too large");
+ }
+
+ if (this.size != out.length) {
+ throw new IllegalStateException("Array size mismatch");
+ }
+
+ short[] mappings = new short[(int) (this.mask + 1)];
+
+ int idx = 0;
+
+ for (long word : this.data) {
+ long bits = word;
+
+ for (int elementIdx = 0; elementIdx < this.valuesPerLong; ++elementIdx) {
+ int value = (int) (bits & this.mask);
+ int remappedId = mappings[value];
+
+ if (remappedId == 0) {
+ remappedId = dstPalette.idFor(srcPalette.valueFor(value)) + 1;
+ mappings[value] = (short) remappedId;
+ }
+
+ out[idx] = (short) (remappedId - 1);
+ bits >>= this.bits;
+
+ ++idx;
+
+ if (idx >= this.size) {
+ return;
+ }
+ }
+ }
+ }
+ // DivineMC end - lithium: faster chunk serialization
}
diff --git a/net/minecraft/util/ZeroBitStorage.java b/net/minecraft/util/ZeroBitStorage.java
index 09fd99c9cbd23b5f3c899bfb00c9b89651948ed8..6e264b311894f510112beb996190f5ff6943e5e8 100644
--- a/net/minecraft/util/ZeroBitStorage.java
+++ b/net/minecraft/util/ZeroBitStorage.java
@@ -80,4 +80,6 @@ public class ZeroBitStorage implements BitStorage {
return ret;
}
// Paper end - block counting
+
+ @Override public <T> void compact(net.minecraft.world.level.chunk.Palette<T> srcPalette, net.minecraft.world.level.chunk.Palette<T> dstPalette, short[] out) { } // DivineMC - lithium: faster chunk serialization
}
diff --git a/net/minecraft/world/level/chunk/PalettedContainer.java b/net/minecraft/world/level/chunk/PalettedContainer.java
index a251ba67644cd02a0b00d7c8b0e2c64aa5e26291..9d892c1c3890e0aaf13fd5cd7b7d138afeaad260 100644
--- a/net/minecraft/world/level/chunk/PalettedContainer.java
+++ b/net/minecraft/world/level/chunk/PalettedContainer.java
@@ -32,6 +32,23 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
private final PalettedContainer.Strategy strategy;
//private final ThreadingDetector threadingDetector = new ThreadingDetector("PalettedContainer"); // Paper - unused
+ // DivineMC start - lithium: faster chunk serialization
+ private static final ThreadLocal<short[]> CACHED_ARRAY_4096 = ThreadLocal.withInitial(() -> new short[4096]);
+ private static final ThreadLocal<short[]> CACHED_ARRAY_64 = ThreadLocal.withInitial(() -> new short[64]);
+
+ private Optional<LongStream> asOptional(long[] data) {
+ return Optional.of(Arrays.stream(data));
+ }
+
+ private short[] getOrCreate(int size) {
+ return switch (size) {
+ case 64 -> CACHED_ARRAY_64.get();
+ case 4096 -> CACHED_ARRAY_4096.get();
+ default -> new short[size];
+ };
+ }
+ // DivineMC end - lithium: faster chunk serialization
+
public void acquire() {
// this.threadingDetector.checkAndLock(); // Paper - disable this - use proper synchronization
}
@@ -343,28 +360,49 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
public synchronized PalettedContainerRO.PackedData<T> pack(IdMap<T> registry, PalettedContainer.Strategy strategy) { // Paper - synchronize
this.acquire();
- PalettedContainerRO.PackedData var12;
+ // DivineMC start - lithium: faster chunk serialization
+ Optional<LongStream> data = Optional.empty();
+ List<T> elements = null;
try {
- HashMapPalette<T> hashMapPalette = new HashMapPalette<>(registry, this.data.storage.getBits(), this.dummyPaletteResize);
- int size = strategy.size();
- int[] ints = new int[size];
- this.data.storage.unpack(ints);
- swapPalette(ints, id -> hashMapPalette.idFor(this.data.palette.valueFor(id)));
- int i = strategy.calculateBitsForSerialization(registry, hashMapPalette.getSize());
- Optional<LongStream> optional;
- if (i != 0) {
- SimpleBitStorage simpleBitStorage = new SimpleBitStorage(i, size, ints);
- optional = Optional.of(Arrays.stream(simpleBitStorage.getRaw()));
- } else {
- optional = Optional.empty();
+ net.caffeinemc.mods.lithium.common.world.chunk.LithiumHashPalette<T> hashPalette = null;
+
+ final Palette<T> palette = this.data.palette();
+ final BitStorage storage = this.data.storage();
+ if (storage instanceof ZeroBitStorage || palette.getSize() == 1) {
+ elements = List.of(palette.valueFor(0));
+ } else if (palette instanceof net.caffeinemc.mods.lithium.common.world.chunk.LithiumHashPalette<T> lithiumHashPalette) {
+ hashPalette = lithiumHashPalette;
}
- var12 = new PalettedContainerRO.PackedData<>(hashMapPalette.getEntries(), optional);
+ if (elements == null) {
+ net.caffeinemc.mods.lithium.common.world.chunk.LithiumHashPalette<T> compactedPalette = new net.caffeinemc.mods.lithium.common.world.chunk.LithiumHashPalette<>(registry, storage.getBits(), this.dummyPaletteResize);
+ short[] array = this.getOrCreate(strategy.size());
+
+ storage.compact(this.data.palette(), compactedPalette, array);
+
+ if (hashPalette != null && hashPalette.getSize() == compactedPalette.getSize() && storage.getBits() == strategy.calculateBitsForSerialization(registry, hashPalette.getSize())) { // paletteSize can de-sync from palette - see https://github.com/CaffeineMC/lithium-fabric/issues/279
+ data = this.asOptional(storage.getRaw().clone());
+ elements = hashPalette.getElements();
+ } else {
+ int bits = strategy.calculateBitsForSerialization(registry, compactedPalette.getSize());
+ if (bits != 0) {
+ SimpleBitStorage copy = new SimpleBitStorage(bits, array.length);
+ for (int i = 0; i < array.length; ++i) {
+ copy.set(i, array[i]);
+ }
+
+ data = this.asOptional(copy.getRaw());
+ }
+
+ elements = compactedPalette.getElements();
+ }
+ }
} finally {
this.release();
}
- return var12;
+ return new PalettedContainerRO.PackedData<>(elements, data);
+ // DivineMC end - lithium: faster chunk serialization
}
private static <T> void swapPalette(int[] bits, IntUnaryOperator operator) {
@@ -404,13 +442,31 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
@Override
public void count(PalettedContainer.CountConsumer<T> countConsumer) {
- if (this.data.palette.getSize() == 1) {
- countConsumer.accept(this.data.palette.valueFor(0), this.data.storage.getSize());
- } else {
- Int2IntOpenHashMap map = new Int2IntOpenHashMap();
- this.data.storage.getAll(id -> map.addTo(id, 1));
- map.int2IntEntrySet().forEach(idEntry -> countConsumer.accept(this.data.palette.valueFor(idEntry.getIntKey()), idEntry.getIntValue()));
+ // DivineMC start - lithium: faster chunk serialization
+ int len = this.data.palette().getSize();
+
+ if (len > 4096) {
+ if (this.data.palette.getSize() == 1) {
+ countConsumer.accept(this.data.palette.valueFor(0), this.data.storage.getSize());
+ } else {
+ Int2IntOpenHashMap map = new Int2IntOpenHashMap();
+ this.data.storage.getAll(id -> map.addTo(id, 1));
+ map.int2IntEntrySet().forEach(idEntry -> countConsumer.accept(this.data.palette.valueFor(idEntry.getIntKey()), idEntry.getIntValue()));
+ }
+ }
+
+ short[] counts = new short[len];
+
+ this.data.storage().getAll(i -> counts[i]++);
+
+ for (int i = 0; i < counts.length; i++) {
+ T obj = this.data.palette().valueFor(i);
+
+ if (obj != null) {
+ countConsumer.accept(obj, counts[i]);
+ }
}
+ // DivineMC end - lithium: faster chunk serialization
}
record Configuration<T>(Palette.Factory factory, int bits) {

View File

@@ -0,0 +1,245 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sun, 6 Jul 2025 02:38:39 +0300
Subject: [PATCH] C2ME: optimize noise generation
This patch is based on the following mixins:
* "com/ishland/c2me/opts/math/mixin/MixinOctavePerlinNoiseSampler.java"
* "com/ishland/c2me/opts/math/mixin/MixinPerlinNoiseSampler.java"
By: ishland <ishlandmc@yeah.net>
As part of: C2ME (https://github.com/RelativityMC/C2ME-fabric)
Licensed under: MIT (https://opensource.org/licenses/MIT)
diff --git a/net/minecraft/world/level/levelgen/synth/ImprovedNoise.java b/net/minecraft/world/level/levelgen/synth/ImprovedNoise.java
index fb11a2eea540d55e50eab59f9857ca5d99f556f8..c40f65c30b6422a27154295a2b3a63483496dcca 100644
--- a/net/minecraft/world/level/levelgen/synth/ImprovedNoise.java
+++ b/net/minecraft/world/level/levelgen/synth/ImprovedNoise.java
@@ -11,6 +11,27 @@ public final class ImprovedNoise {
public final double yo;
public final double zo;
+ // DivineMC start - C2ME: optimize noise generation
+ private static final double[] FLAT_SIMPLEX_GRAD = new double[]{
+ 1, 1, 0, 0,
+ -1, 1, 0, 0,
+ 1, -1, 0, 0,
+ -1, -1, 0, 0,
+ 1, 0, 1, 0,
+ -1, 0, 1, 0,
+ 1, 0, -1, 0,
+ -1, 0, -1, 0,
+ 0, 1, 1, 0,
+ 0, -1, 1, 0,
+ 0, 1, -1, 0,
+ 0, -1, -1, 0,
+ 1, 1, 0, 0,
+ 0, -1, 1, 0,
+ -1, 1, 0, 0,
+ 0, -1, -1, 0,
+ };
+ // DivineMC end - C2ME: optimize noise generation
+
public ImprovedNoise(RandomSource random) {
this.xo = random.nextDouble() * 256.0;
this.yo = random.nextDouble() * 256.0;
@@ -38,9 +59,11 @@ public final class ImprovedNoise {
double d = x + this.xo;
double d1 = y + this.yo;
double d2 = z + this.zo;
- int floor = Mth.floor(d);
- int floor1 = Mth.floor(d1);
- int floor2 = Mth.floor(d2);
+ // DivineMC start - C2ME: optimize noise generation
+ double floor = Math.floor(d);
+ double floor1 = Math.floor(d1);
+ double floor2 = Math.floor(d2);
+ // DivineMC end - C2ME: optimize noise generation
double d3 = d - floor;
double d4 = d1 - floor1;
double d5 = d2 - floor2;
@@ -53,25 +76,27 @@ public final class ImprovedNoise {
d6 = d4;
}
- d7 = Mth.floor(d6 / yScale + 1.0E-7F) * yScale;
+ d7 = Math.floor(d6 / yScale + 1.0E-7F) * yScale; // DivineMC - C2ME: optimize noise generation
} else {
d7 = 0.0;
}
- return this.sampleAndLerp(floor, floor1, floor2, d3, d4 - d7, d5, d4);
+ return this.sampleAndLerp((int) floor, (int) floor1, (int) floor2, d3, d4 - d7, d5, d4); // DivineMC - C2ME: optimize noise generation
}
public double noiseWithDerivative(double x, double y, double z, double[] values) {
double d = x + this.xo;
double d1 = y + this.yo;
double d2 = z + this.zo;
- int floor = Mth.floor(d);
- int floor1 = Mth.floor(d1);
- int floor2 = Mth.floor(d2);
+ // DivineMC start - C2ME: optimize noise generation
+ double floor = Math.floor(d);
+ double floor1 = Math.floor(d1);
+ double floor2 = Math.floor(d2);
+ // DivineMC end - C2ME: optimize noise generation
double d3 = d - floor;
double d4 = d1 - floor1;
double d5 = d2 - floor2;
- return this.sampleWithDerivative(floor, floor1, floor2, d3, d4, d5, values);
+ return this.sampleWithDerivative((int) floor, (int) floor1, (int) floor2, d3, d4, d5, values); // DivineMC - C2ME: optimize noise generation
}
private static double gradDot(int gradIndex, double xFactor, double yFactor, double zFactor) {
@@ -83,24 +108,69 @@ public final class ImprovedNoise {
}
private double sampleAndLerp(int gridX, int gridY, int gridZ, double deltaX, double weirdDeltaY, double deltaZ, double deltaY) {
- int i = this.p(gridX);
- int i1 = this.p(gridX + 1);
- int i2 = this.p(i + gridY);
- int i3 = this.p(i + gridY + 1);
- int i4 = this.p(i1 + gridY);
- int i5 = this.p(i1 + gridY + 1);
- double d = gradDot(this.p(i2 + gridZ), deltaX, weirdDeltaY, deltaZ);
- double d1 = gradDot(this.p(i4 + gridZ), deltaX - 1.0, weirdDeltaY, deltaZ);
- double d2 = gradDot(this.p(i3 + gridZ), deltaX, weirdDeltaY - 1.0, deltaZ);
- double d3 = gradDot(this.p(i5 + gridZ), deltaX - 1.0, weirdDeltaY - 1.0, deltaZ);
- double d4 = gradDot(this.p(i2 + gridZ + 1), deltaX, weirdDeltaY, deltaZ - 1.0);
- double d5 = gradDot(this.p(i4 + gridZ + 1), deltaX - 1.0, weirdDeltaY, deltaZ - 1.0);
- double d6 = gradDot(this.p(i3 + gridZ + 1), deltaX, weirdDeltaY - 1.0, deltaZ - 1.0);
- double d7 = gradDot(this.p(i5 + gridZ + 1), deltaX - 1.0, weirdDeltaY - 1.0, deltaZ - 1.0);
- double d8 = Mth.smoothstep(deltaX);
- double d9 = Mth.smoothstep(deltaY);
- double d10 = Mth.smoothstep(deltaZ);
- return Mth.lerp3(d8, d9, d10, d, d1, d2, d3, d4, d5, d6, d7);
+ // DivineMC start - C2ME: optimize noise generation
+ final int var0 = gridX & 0xFF;
+ final int var1 = (gridX + 1) & 0xFF;
+ final int var2 = this.p[var0] & 0xFF;
+ final int var3 = this.p[var1] & 0xFF;
+ final int var4 = (var2 + gridY) & 0xFF;
+ final int var5 = (var3 + gridY) & 0xFF;
+ final int var6 = (var2 + gridY + 1) & 0xFF;
+ final int var7 = (var3 + gridY + 1) & 0xFF;
+ final int var8 = this.p[var4] & 0xFF;
+ final int var9 = this.p[var5] & 0xFF;
+ final int var10 = this.p[var6] & 0xFF;
+ final int var11 = this.p[var7] & 0xFF;
+
+ final int var12 = (var8 + gridZ) & 0xFF;
+ final int var13 = (var9 + gridZ) & 0xFF;
+ final int var14 = (var10 + gridZ) & 0xFF;
+ final int var15 = (var11 + gridZ) & 0xFF;
+ final int var16 = (var8 + gridZ + 1) & 0xFF;
+ final int var17 = (var9 + gridZ + 1) & 0xFF;
+ final int var18 = (var10 + gridZ + 1) & 0xFF;
+ final int var19 = (var11 + gridZ + 1) & 0xFF;
+ final int var20 = (this.p[var12] & 15) << 2;
+ final int var21 = (this.p[var13] & 15) << 2;
+ final int var22 = (this.p[var14] & 15) << 2;
+ final int var23 = (this.p[var15] & 15) << 2;
+ final int var24 = (this.p[var16] & 15) << 2;
+ final int var25 = (this.p[var17] & 15) << 2;
+ final int var26 = (this.p[var18] & 15) << 2;
+ final int var27 = (this.p[var19] & 15) << 2;
+ final double var60 = deltaX - 1.0;
+ final double var61 = weirdDeltaY - 1.0;
+ final double var62 = deltaZ - 1.0;
+ final double var87 = FLAT_SIMPLEX_GRAD[(var20) | 0] * deltaX + FLAT_SIMPLEX_GRAD[(var20) | 1] * weirdDeltaY + FLAT_SIMPLEX_GRAD[(var20) | 2] * deltaZ;
+ final double var88 = FLAT_SIMPLEX_GRAD[(var21) | 0] * var60 + FLAT_SIMPLEX_GRAD[(var21) | 1] * weirdDeltaY + FLAT_SIMPLEX_GRAD[(var21) | 2] * deltaZ;
+ final double var89 = FLAT_SIMPLEX_GRAD[(var22) | 0] * deltaX + FLAT_SIMPLEX_GRAD[(var22) | 1] * var61 + FLAT_SIMPLEX_GRAD[(var22) | 2] * deltaZ;
+ final double var90 = FLAT_SIMPLEX_GRAD[(var23) | 0] * var60 + FLAT_SIMPLEX_GRAD[(var23) | 1] * var61 + FLAT_SIMPLEX_GRAD[(var23) | 2] * deltaZ;
+ final double var91 = FLAT_SIMPLEX_GRAD[(var24) | 0] * deltaX + FLAT_SIMPLEX_GRAD[(var24) | 1] * weirdDeltaY + FLAT_SIMPLEX_GRAD[(var24) | 2] * var62;
+ final double var92 = FLAT_SIMPLEX_GRAD[(var25) | 0] * var60 + FLAT_SIMPLEX_GRAD[(var25) | 1] * weirdDeltaY + FLAT_SIMPLEX_GRAD[(var25) | 2] * var62;
+ final double var93 = FLAT_SIMPLEX_GRAD[(var26) | 0] * deltaX + FLAT_SIMPLEX_GRAD[(var26) | 1] * var61 + FLAT_SIMPLEX_GRAD[(var26) | 2] * var62;
+ final double var94 = FLAT_SIMPLEX_GRAD[(var27) | 0] * var60 + FLAT_SIMPLEX_GRAD[(var27) | 1] * var61 + FLAT_SIMPLEX_GRAD[(var27) | 2] * var62;
+
+ final double var95 = deltaX * 6.0 - 15.0;
+ final double var96 = deltaY * 6.0 - 15.0;
+ final double var97 = deltaZ * 6.0 - 15.0;
+ final double var98 = deltaX * var95 + 10.0;
+ final double var99 = deltaY * var96 + 10.0;
+ final double var100 = deltaZ * var97 + 10.0;
+ final double var101 = deltaX * deltaX * deltaX * var98;
+ final double var102 = deltaY * deltaY * deltaY * var99;
+ final double var103 = deltaZ * deltaZ * deltaZ * var100;
+
+ final double var113 = var87 + var101 * (var88 - var87);
+ final double var114 = var93 + var101 * (var94 - var93);
+ final double var115 = var91 + var101 * (var92 - var91);
+ final double var116 = var89 + var101 * (var90 - var89);
+ final double var117 = var114 - var115;
+ final double var118 = var102 * (var116 - var113);
+ final double var119 = var102 * var117;
+ final double var120 = var113 + var118;
+ final double var121 = var115 + var119;
+ return var120 + (var103 * (var121 - var120));
+ // DivineMC end - C2ME: optimize noise generation
}
private double sampleWithDerivative(int gridX, int gridY, int gridZ, double deltaX, double deltaY, double deltaZ, double[] noiseValues) {
diff --git a/net/minecraft/world/level/levelgen/synth/PerlinNoise.java b/net/minecraft/world/level/levelgen/synth/PerlinNoise.java
index da3c26fbad32d75d71f7e59c8c3341316a754756..23e12c26e6035b429c89b98a796a048557e8c9b2 100644
--- a/net/minecraft/world/level/levelgen/synth/PerlinNoise.java
+++ b/net/minecraft/world/level/levelgen/synth/PerlinNoise.java
@@ -26,6 +26,10 @@ public class PerlinNoise {
private final double lowestFreqValueFactor;
private final double lowestFreqInputFactor;
private final double maxValue;
+ // DivineMC start - C2ME: optimize noise generation
+ private final int octaveSamplersCount;
+ private final double [] amplitudesArray;
+ // DivineMC end - C2ME: optimize noise generation
@Deprecated
public static PerlinNoise createLegacyForBlendedNoise(RandomSource random, IntStream octaves) {
@@ -127,6 +131,10 @@ public class PerlinNoise {
this.lowestFreqInputFactor = Math.pow(2.0, -i);
this.lowestFreqValueFactor = Math.pow(2.0, size - 1) / (Math.pow(2.0, size) - 1.0);
this.maxValue = this.edgeValue(2.0);
+ // DivineMC start - C2ME: optimize noise generation
+ this.octaveSamplersCount = this.noiseLevels.length;
+ this.amplitudesArray = this.amplitudes.toDoubleArray();
+ // DivineMC end - C2ME: optimize noise generation
}
protected double maxValue() {
@@ -138,7 +146,27 @@ public class PerlinNoise {
}
public double getValue(double x, double y, double z) {
- return this.getValue(x, y, z, 0.0, 0.0, false);
+ // DivineMC start - C2ME: optimize noise generation
+ double d = 0.0;
+ double e = this.lowestFreqInputFactor;
+ double f = this.lowestFreqValueFactor;
+
+ for (int i = 0; i < this.octaveSamplersCount; ++i) {
+ ImprovedNoise perlinNoiseSampler = this.noiseLevels[i];
+ if (perlinNoiseSampler != null) {
+ @SuppressWarnings("deprecation")
+ double g = perlinNoiseSampler.noise(
+ wrap(x * e), wrap(y * e), wrap(z * e), 0.0, 0.0
+ );
+ d += this.amplitudesArray[i] * g * f;
+ }
+
+ e *= 2.0;
+ f /= 2.0;
+ }
+
+ return d;
+ // DivineMC end - C2ME: optimize noise generation
}
@Deprecated
@@ -187,7 +215,7 @@ public class PerlinNoise {
}
public static double wrap(double value) {
- return value - Mth.lfloor(value / 3.3554432E7 + 0.5) * 3.3554432E7;
+ return value - Math.floor(value / 3.3554432E7 + 0.5) * 3.3554432E7; // DivineMC - C2ME: optimize noise generation
}
protected int firstOctave() {

View File

@@ -1,192 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sat, 1 Feb 2025 16:57:01 +0300
Subject: [PATCH] Optimize explosions
diff --git a/net/minecraft/world/level/ServerExplosion.java b/net/minecraft/world/level/ServerExplosion.java
index d0c4d63320fb5f58c43b38ebc333e9a7be487a5d..24648c6447774ac6aa8f76b078d923fface15c3f 100644
--- a/net/minecraft/world/level/ServerExplosion.java
+++ b/net/minecraft/world/level/ServerExplosion.java
@@ -375,6 +375,11 @@ public class ServerExplosion implements Explosion {
}
private List<BlockPos> calculateExplodedPositions() {
+ // DivineMC start - Optimize explosions
+ if (org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.enableFasterTntOptimization && !level.isClientSide && !(getIndirectSourceEntity() instanceof net.minecraft.world.entity.monster.breeze.Breeze)) {
+ return doExplosionA(this);
+ }
+ // DivineMC end - Optimize explosions
// Paper start - collision optimisations
final ObjectArrayList<BlockPos> ret = new ObjectArrayList<>();
@@ -473,6 +478,157 @@ public class ServerExplosion implements Explosion {
// Paper end - collision optimisations
}
+ // DivineMC start - Optimize explosions
+ private static final it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap<org.apache.commons.lang3.tuple.Pair<net.minecraft.world.phys.Vec3, net.minecraft.world.phys.AABB>> densityCache = new it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap<>();
+ private static final it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<net.minecraft.core.BlockPos, net.minecraft.world.level.block.state.BlockState> stateCache = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>();
+ private static final it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<net.minecraft.core.BlockPos, net.minecraft.world.level.material.FluidState> fluidCache = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>();
+ private static final BlockPos.MutableBlockPos posMutable = new BlockPos.MutableBlockPos(0, 0, 0);
+ private static final it.unimi.dsi.fastutil.objects.ObjectOpenHashSet<net.minecraft.core.BlockPos> affectedBlockPositionsSet = new it.unimi.dsi.fastutil.objects.ObjectOpenHashSet<>();
+ private static boolean firstRay;
+ private static boolean rayCalcDone;
+
+ public static @org.jetbrains.annotations.NotNull List<BlockPos> doExplosionA(ServerExplosion e) {
+ List<BlockPos> toBlow;
+
+ if (!org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.explosionNoBlockDamage && e.damageSource != null) {
+ rayCalcDone = false;
+ firstRay = true;
+ getAffectedPositionsOnPlaneY(e, 0, 0, 15, 0, 15); // bottom
+ getAffectedPositionsOnPlaneY(e, 15, 0, 15, 0, 15); // top
+ getAffectedPositionsOnPlaneX(e, 0, 1, 14, 0, 15); // west
+ getAffectedPositionsOnPlaneX(e, 15, 1, 14, 0, 15); // east
+ getAffectedPositionsOnPlaneZ(e, 0, 1, 14, 1, 14); // north
+ getAffectedPositionsOnPlaneZ(e, 15, 1, 14, 1, 14); // south
+ stateCache.clear();
+ fluidCache.clear();
+
+ toBlow = new ArrayList<>(affectedBlockPositionsSet);
+ affectedBlockPositionsSet.clear();
+ } else {
+ toBlow = java.util.Collections.emptyList();
+ }
+ densityCache.clear();
+
+ return toBlow;
+ }
+
+ private static void getAffectedPositionsOnPlaneX(Explosion e, int x, int yStart, int yEnd, int zStart, int zEnd) {
+ if (!rayCalcDone) {
+ final double xRel = (double) x / 15.0D * 2.0D - 1.0D;
+
+ for (int z = zStart; z <= zEnd; ++z) {
+ double zRel = (double) z / 15.0D * 2.0D - 1.0D;
+
+ for (int y = yStart; y <= yEnd; ++y) {
+ double yRel = (double) y / 15.0D * 2.0D - 1.0D;
+
+ if (checkAffectedPosition((ServerExplosion) e, xRel, yRel, zRel)) {
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ private static void getAffectedPositionsOnPlaneY(Explosion e, int y, int xStart, int xEnd, int zStart, int zEnd) {
+ if (!rayCalcDone) {
+ final double yRel = (double) y / 15.0D * 2.0D - 1.0D;
+
+ for (int z = zStart; z <= zEnd; ++z) {
+ double zRel = (double) z / 15.0D * 2.0D - 1.0D;
+
+ for (int x = xStart; x <= xEnd; ++x) {
+ double xRel = (double) x / 15.0D * 2.0D - 1.0D;
+
+ if (checkAffectedPosition((ServerExplosion) e, xRel, yRel, zRel)) {
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ private static void getAffectedPositionsOnPlaneZ(Explosion e, int z, int xStart, int xEnd, int yStart, int yEnd) {
+ if (!rayCalcDone) {
+ final double zRel = (double) z / 15.0D * 2.0D - 1.0D;
+
+ for (int x = xStart; x <= xEnd; ++x) {
+ double xRel = (double) x / 15.0D * 2.0D - 1.0D;
+
+ for (int y = yStart; y <= yEnd; ++y) {
+ double yRel = (double) y / 15.0D * 2.0D - 1.0D;
+
+ if (checkAffectedPosition((ServerExplosion) e, xRel, yRel, zRel)) {
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ private static boolean checkAffectedPosition(ServerExplosion e, double xRel, double yRel, double zRel) {
+ double len = Math.sqrt(xRel * xRel + yRel * yRel + zRel * zRel);
+ double xInc = (xRel / len) * 0.3;
+ double yInc = (yRel / len) * 0.3;
+ double zInc = (zRel / len) * 0.3;
+ float rand = e.level().random.nextFloat();
+ float sizeRand = (org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.tntRandomRange >= 0 ? (float) org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.tntRandomRange : rand);
+ float size = e.radius() * (0.7F + sizeRand * 0.6F);
+ Vec3 vec3 = e.center();
+ double posX = vec3.x;
+ double posY = vec3.y;
+ double posZ = vec3.z;
+
+ for (float f1 = 0.3F; size > 0.0F; size -= 0.22500001F) {
+ posMutable.set(posX, posY, posZ);
+
+ // Don't query already cached positions again from the world
+ BlockState state = stateCache.get(posMutable);
+ FluidState fluid = fluidCache.get(posMutable);
+ BlockPos posImmutable = null;
+
+ if (state == null) {
+ posImmutable = posMutable.immutable();
+ state = e.level().getBlockState(posImmutable);
+ stateCache.put(posImmutable, state);
+ fluid = e.level().getFluidState(posImmutable);
+ fluidCache.put(posImmutable, fluid);
+ }
+
+ if (!state.isAir()) {
+ float resistance = Math.max(state.getBlock().getExplosionResistance(), fluid.getExplosionResistance());
+
+ if (e.source != null) {
+ resistance = e.source.getBlockExplosionResistance(e, e.level(), posMutable, state, fluid, resistance);
+ }
+
+ size -= (resistance + 0.3F) * 0.3F;
+ }
+
+ if (size > 0.0F) {
+ if ((e.source == null || e.source.shouldBlockExplode(e, e.level(), posMutable, state, size)))
+ affectedBlockPositionsSet.add(posImmutable != null ? posImmutable : posMutable.immutable());
+ } else if (firstRay) {
+ rayCalcDone = true;
+ return true;
+ }
+
+ firstRay = false;
+
+ posX += xInc;
+ posY += yInc;
+ posZ += zInc;
+ }
+
+ return false;
+ }
+
+ private Optional<Float> noBlockCalcsWithNoBLockDamage(final ExplosionDamageCalculator instance, final Explosion explosion, final BlockGetter blockGetter, final BlockPos blockPos, final BlockState blockState, final FluidState fluidState) {
+ if (org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.explosionNoBlockDamage) return Optional.of(net.minecraft.world.level.block.Blocks.BEDROCK.getExplosionResistance());
+ return instance.getBlockExplosionResistance(explosion, blockGetter, blockPos, blockState, fluidState);
+ }
+ // DivineMC end - Optimize explosions
+
private void hurtEntities() {
float f = this.radius * 2.0F;
int floor = Mth.floor(this.center.x - f - 1.0);
@@ -562,6 +718,11 @@ public class ServerExplosion implements Explosion {
}
private void interactWithBlocks(List<BlockPos> blocks) {
+ // DivineMC start - Optimize explosions
+ if (org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.explosionNoBlockDamage) {
+ blocks.clear();
+ }
+ // DivineMC end - Optimize explosions
List<ServerExplosion.StackCollector> list = new ArrayList<>();
Util.shuffle(blocks, this.level.random);

View File

@@ -0,0 +1,65 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sun, 6 Jul 2025 02:59:37 +0300
Subject: [PATCH] Use Java's Math functions
diff --git a/net/minecraft/util/Mth.java b/net/minecraft/util/Mth.java
index e2602c6d817794616eb05a471077447804b835a1..c4d55514a44939c3e6006d9e23b6097b6360853e 100644
--- a/net/minecraft/util/Mth.java
+++ b/net/minecraft/util/Mth.java
@@ -58,18 +58,15 @@ public class Mth {
}
public static int floor(float value) {
- int i = (int)value;
- return value < i ? i - 1 : i;
+ return (int) Math.floor(value); // DivineMC - Use Java's Math functions
}
public static int floor(double value) {
- int i = (int)value;
- return value < i ? i - 1 : i;
+ return (int) Math.floor(value); // DivineMC - Use Java's Math functions
}
public static long lfloor(double value) {
- long l = (long)value;
- return value < l ? l - 1L : l;
+ return (long) Math.floor(value); // DivineMC - Use Java's Math functions
}
public static float abs(float value) {
@@ -81,13 +78,11 @@ public class Mth {
}
public static int ceil(float value) {
- int i = (int)value;
- return value > i ? i + 1 : i;
+ return (int) Math.ceil(value); // DivineMC - Use Java's Math functions
}
public static int ceil(double value) {
- int i = (int)value;
- return value > i ? i + 1 : i;
+ return (int) Math.ceil(value); // DivineMC - Use Java's Math functions
}
public static int clamp(int value, int min, int max) {
@@ -123,15 +118,7 @@ public class Mth {
}
public static double absMax(double x, double y) {
- if (x < 0.0) {
- x = -x;
- }
-
- if (y < 0.0) {
- y = -y;
- }
-
- return Math.max(x, y);
+ return Math.max(Math.abs(x), Math.abs(y)); // DivineMC - Use Java's Math functions
}
public static int floorDiv(int dividend, int divisor) {

View File

@@ -1,6 +1,14 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sun, 6 Jul 2025 03:03:04 +0300
Subject: [PATCH] Disable leaf decay
diff --git a/net/minecraft/world/level/block/LeavesBlock.java b/net/minecraft/world/level/block/LeavesBlock.java
index 010e9814490ffaa153df5b7865da17e2a84c7e82..f43dbc0fc05f549521490595fe594c424b2e8a87 100644
--- a/net/minecraft/world/level/block/LeavesBlock.java
+++ b/net/minecraft/world/level/block/LeavesBlock.java
@@ -70,12 +_,29 @@
@@ -70,12 +70,29 @@ public abstract class LeavesBlock extends Block implements SimpleWaterloggedBloc
}
protected boolean decaying(BlockState state) {
@@ -11,7 +19,7 @@
@Override
protected void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
- level.setBlock(pos, updateDistance(state, level, pos), 3);
+ // DivineMC start - Make leaves not suffocate the server
+ // DivineMC start - Disable leaf decay
+ if (org.bxteam.divinemc.config.DivineConfig.FixesCategory.disableLeafDecay) return; // DivineMC - Disable leaf decay
+ int newValue = 7;
+ int oldValue = state.getValue(DISTANCE);
@@ -28,7 +36,7 @@
+ if (newValue != oldValue) {
+ level.setBlock(pos, state.setValue(DISTANCE, newValue), 3);
+ }
+ // DivineMC end - Make leaves not suffocate the server
+ // DivineMC end - Disable leaf decay
}
@Override

View File

@@ -1,18 +1,18 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sat, 1 Feb 2025 16:05:57 +0300
Subject: [PATCH] Optimize entity stupid brain
Subject: [PATCH] Optimize entity brain
diff --git a/net/minecraft/world/entity/AgeableMob.java b/net/minecraft/world/entity/AgeableMob.java
index 04875840085541ebfc7014868beec49bb7ab9976..bd7e8fa315ca67fcf03d34added45b649d7aaebb 100644
index 04875840085541ebfc7014868beec49bb7ab9976..bbfb1de1a03c4208406feb803a2f378db9910556 100644
--- a/net/minecraft/world/entity/AgeableMob.java
+++ b/net/minecraft/world/entity/AgeableMob.java
@@ -125,6 +125,16 @@ public abstract class AgeableMob extends PathfinderMob {
public void onSyncedDataUpdated(EntityDataAccessor<?> key) {
if (DATA_BABY_ID.equals(key)) {
this.refreshDimensions();
+ // DivineMC start - Optimize entity stupid brain
+ // DivineMC start - Optimize entity brain
+ if (isBaby()) {
+ org.bxteam.divinemc.util.entity.SensorHelper.enableSensor(this, net.minecraft.world.entity.ai.sensing.SensorType.NEAREST_ADULT, true);
+ } else {
@@ -21,33 +21,34 @@ index 04875840085541ebfc7014868beec49bb7ab9976..bd7e8fa315ca67fcf03d34added45b64
+ this.getBrain().setMemory(net.minecraft.world.entity.ai.memory.MemoryModuleType.NEAREST_VISIBLE_ADULT, java.util.Optional.empty());
+ }
+ }
+ // DivineMC end - Optimize entity stupid brain
+ // DivineMC end - Optimize entity brain
}
super.onSyncedDataUpdated(key);
diff --git a/net/minecraft/world/entity/ai/Brain.java b/net/minecraft/world/entity/ai/Brain.java
index 99ced3cb7d3d4c7a80d890689d7585fa9acd17f6..572415b91152756a246eca242eeaca387289be7c 100644
index 99ced3cb7d3d4c7a80d890689d7585fa9acd17f6..9277b5da6065a5500e40727815083da25b9c9327 100644
--- a/net/minecraft/world/entity/ai/Brain.java
+++ b/net/minecraft/world/entity/ai/Brain.java
@@ -45,16 +45,73 @@ public class Brain<E extends LivingEntity> {
@@ -45,16 +45,75 @@ 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();
- public 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();
+ private Map<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memories = Maps.newConcurrentMap(); // DivineMC - concurrent map
+ public Map<SensorType<? extends Sensor<? super E>>, Sensor<? super E>> sensors = Maps.newLinkedHashMap(); // DivineMC - linked hash map
+ private final Map<Integer, Map<Activity, Set<BehaviorControl<? super E>>>> availableBehaviorsByPriority = Maps.newTreeMap(); // DivineMC - tree map
+ // DivineMC start - Optimize entity brain
+ private Map<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memories = Maps.newConcurrentMap();
+ public 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();
private Schedule schedule = Schedule.EMPTY;
- private final Map<Activity, Set<Pair<MemoryModuleType<?>, MemoryStatus>>> activityRequirements = Maps.newHashMap();
+ private Map<Activity, Set<Pair<MemoryModuleType<?>, MemoryStatus>>> activityRequirements = Maps.newHashMap(); // DivineMC - hash map
+ private Map<Activity, Set<Pair<MemoryModuleType<?>, MemoryStatus>>> activityRequirements = Maps.newHashMap();
+ // DivineMC end - Optimize entity brain
private final Map<Activity, Set<MemoryModuleType<?>>> activityMemoriesToEraseWhenStopped = Maps.newHashMap();
private Set<Activity> coreActivities = Sets.newHashSet();
private final Set<Activity> activeActivities = Sets.newHashSet();
private Activity defaultActivity = Activity.IDLE;
private long lastScheduleUpdate = -9999L;
+ // DivineMC start - Optimize entity stupid brain
+ // DivineMC start - Optimize entity brain
+ private java.util.ArrayList<net.minecraft.world.entity.ai.behavior.BehaviorControl<? super E>> possibleTasks;
+ private org.bxteam.divinemc.util.collections.MaskedList<net.minecraft.world.entity.ai.behavior.BehaviorControl<? super E>> runningTasks;
+
@@ -103,24 +104,24 @@ index 99ced3cb7d3d4c7a80d890689d7585fa9acd17f6..572415b91152756a246eca242eeaca38
+ }
+ this.runningTasks = list;
+ }
+ // DivineMC end - Optimize entity stupid brain
+ // DivineMC end - Optimize entity brain
public static <E extends LivingEntity> Brain.Provider<E> provider(
Collection<? extends MemoryModuleType<?>> memoryTypes, Collection<? extends SensorType<? extends Sensor<? super E>>> sensorTypes
@@ -146,6 +203,12 @@ public class Brain<E extends LivingEntity> {
@@ -146,6 +205,12 @@ public class Brain<E extends LivingEntity> {
for (Brain.MemoryValue<?> memoryValue : memoryValues) {
memoryValue.setMemoryInternal(this);
}
+ // DivineMC start - Optimize entity stupid brain
+ // DivineMC start - Optimize entity brain
+ this.onTasksChanged();
+ this.memories = new it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap<>(this.memories);
+ this.sensors = new it.unimi.dsi.fastutil.objects.Reference2ReferenceLinkedOpenHashMap<>(this.sensors);
+ this.activityRequirements = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>(this.activityRequirements);
+ // DivineMC end - Optimize entity stupid brain
+ // DivineMC end - Optimize entity brain
}
public <T> DataResult<T> serializeStart(DynamicOps<T> ops) {
@@ -165,6 +228,7 @@ public class Brain<E extends LivingEntity> {
@@ -165,6 +230,7 @@ public class Brain<E extends LivingEntity> {
}
public <U> void eraseMemory(MemoryModuleType<U> type) {
@@ -128,11 +129,11 @@ index 99ced3cb7d3d4c7a80d890689d7585fa9acd17f6..572415b91152756a246eca242eeaca38
this.setMemory(type, Optional.empty());
}
@@ -180,16 +244,33 @@ public class Brain<E extends LivingEntity> {
@@ -180,16 +246,33 @@ public class Brain<E extends LivingEntity> {
this.setMemoryInternal(memoryType, memory.map(ExpirableValue::of));
}
+ // DivineMC start - Optimize entity stupid brain
+ // DivineMC start - Optimize entity brain
<U> void setMemoryInternal(MemoryModuleType<U> memoryType, Optional<? extends ExpirableValue<?>> memory) {
+ if (memory.isPresent() && this.isEmptyCollection(memory.get().getValue())) {
+ this.eraseMemory(memoryType);
@@ -162,12 +163,12 @@ index 99ced3cb7d3d4c7a80d890689d7585fa9acd17f6..572415b91152756a246eca242eeaca38
+ }
+ return oldValue;
+ }
+ // DivineMC end - Optimize entity stupid brain
+ // DivineMC end - Optimize entity brain
+
public <U> Optional<U> getMemory(MemoryModuleType<U> type) {
Optional<? extends ExpirableValue<?>> optional = this.memories.get(type);
if (optional == null) {
@@ -251,19 +332,7 @@ public class Brain<E extends LivingEntity> {
@@ -251,19 +334,7 @@ public class Brain<E extends LivingEntity> {
@Deprecated
@VisibleForDebug
public List<BehaviorControl<? super E>> getRunningBehaviors() {
@@ -184,53 +185,53 @@ index 99ced3cb7d3d4c7a80d890689d7585fa9acd17f6..572415b91152756a246eca242eeaca38
- }
-
- return list;
+ return this.getCurrentlyRunningTasks(); // DivineMC - Optimize entity stupid brain
+ return this.getCurrentlyRunningTasks(); // DivineMC - Optimize entity brain
}
public void useDefaultActivity() {
@@ -294,6 +363,7 @@ public class Brain<E extends LivingEntity> {
@@ -294,6 +365,7 @@ public class Brain<E extends LivingEntity> {
this.activeActivities.clear();
this.activeActivities.addAll(this.coreActivities);
this.activeActivities.add(activity);
+ this.onPossibleActivitiesChanged(); // DivineMC - Optimize entity stupid brain
+ this.onPossibleActivitiesChanged(); // DivineMC - Optimize entity brain
}
}
@@ -383,11 +453,13 @@ public class Brain<E extends LivingEntity> {
@@ -383,11 +455,13 @@ public class Brain<E extends LivingEntity> {
.computeIfAbsent(activity, activity1 -> Sets.newLinkedHashSet())
.add((BehaviorControl<? super E>)pair.getSecond());
}
+ this.onTasksChanged(); // DivineMC - Optimize entity stupid brain
+ this.onTasksChanged(); // DivineMC - Optimize entity brain
}
@VisibleForTesting
public void removeAllBehaviors() {
this.availableBehaviorsByPriority.clear();
+ this.onTasksChanged(); // DivineMC - Optimize entity stupid brain
+ this.onTasksChanged(); // DivineMC - Optimize entity brain
}
public boolean isActive(Activity activity) {
@@ -404,6 +476,7 @@ public class Brain<E extends LivingEntity> {
@@ -404,6 +478,7 @@ public class Brain<E extends LivingEntity> {
}
}
+ brain.memoryModCount = this.memoryModCount + 1; // DivineMC - Optimize entity stupid brain
+ brain.memoryModCount = this.memoryModCount + 1; // DivineMC - Optimize entity brain
return brain;
}
@@ -438,31 +511,38 @@ public class Brain<E extends LivingEntity> {
@@ -438,31 +513,38 @@ public class Brain<E extends LivingEntity> {
for (BehaviorControl<? super E> behaviorControl : this.getRunningBehaviors()) {
behaviorControl.doStop(level, owner, gameTime);
+ // DivineMC start - Optimize entity stupid brain
+ // DivineMC start - Optimize entity brain
+ if (this.runningTasks != null) {
+ this.runningTasks.setVisible(behaviorControl, false);
+ }
+ // DivineMC end - Optimize entity stupid brain
+ // DivineMC end - Optimize entity brain
}
}
+ // DivineMC start - Optimize entity stupid brain
+ // DivineMC start - Optimize entity brain
private void startEachNonRunningBehavior(ServerLevel level, E entity) {
- long gameTime = level.getGameTime();
-
@@ -253,33 +254,33 @@ index 99ced3cb7d3d4c7a80d890689d7585fa9acd17f6..572415b91152756a246eca242eeaca38
}
}
}
+ // DivineMC end - Optimize entity stupid brain
+ // DivineMC end - Optimize entity brain
private void tickEachRunningBehavior(ServerLevel level, E entity) {
long gameTime = level.getGameTime();
for (BehaviorControl<? super E> behaviorControl : this.getRunningBehaviors()) {
behaviorControl.tickOrStop(level, entity, gameTime);
+ // DivineMC start - Optimize entity stupid brain
+ // DivineMC start - Optimize entity brain
+ if (this.runningTasks != null && behaviorControl.getStatus() != Behavior.Status.RUNNING) {
+ this.runningTasks.setVisible(behaviorControl, false);
+ }
+ // DivineMC end - Optimize entity stupid brain
+ // DivineMC end - Optimize entity brain
}
}
diff --git a/net/minecraft/world/entity/ai/behavior/Behavior.java b/net/minecraft/world/entity/ai/behavior/Behavior.java
index 5b0cadd2544fb2a627822e645ff32fec2e9cfda9..253b9ad671cf0932bb17d468f8b91a15a86ff77a 100644
index 5b0cadd2544fb2a627822e645ff32fec2e9cfda9..f367012ebcc4d06ac868bbc1733bee39ad2d67b1 100644
--- a/net/minecraft/world/entity/ai/behavior/Behavior.java
+++ b/net/minecraft/world/entity/ai/behavior/Behavior.java
@@ -14,6 +14,10 @@ public abstract class Behavior<E extends LivingEntity> implements BehaviorContro
private long endTimestamp;
private final int minDuration;
private final int maxDuration;
+ // DivineMC start - Optimize entity stupid brain
+ // DivineMC start - Optimize entity brain
+ private long cachedMemoryModCount = -1;
+ private boolean cachedHasRequiredMemoryState;
+ // DivineMC end - Optimize entity stupid brain
+ // DivineMC end - Optimize entity brain
private final String configKey; // Paper - configurable behavior tick rate and timings
public Behavior(Map<MemoryModuleType<?>, MemoryStatus> entryCondition) {
@@ -288,7 +289,7 @@ index 5b0cadd2544fb2a627822e645ff32fec2e9cfda9..253b9ad671cf0932bb17d468f8b91a15
this.minDuration = minDuration;
this.maxDuration = maxDuration;
- this.entryCondition = entryCondition;
+ this.entryCondition = new it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap<>(entryCondition); // DivineMC - Optimize entity stupid brain - Use fastutil
+ this.entryCondition = new it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap<>(entryCondition); // DivineMC - Optimize entity brain - Use fastutil
// Paper start - configurable behavior tick rate and timings
String key = io.papermc.paper.util.MappingEnvironment.reobf() ? io.papermc.paper.util.ObfHelper.INSTANCE.deobfClassName(this.getClass().getName()) : this.getClass().getName();
int lastSeparator = key.lastIndexOf('.');
@@ -302,7 +303,7 @@ index 5b0cadd2544fb2a627822e645ff32fec2e9cfda9..253b9ad671cf0932bb17d468f8b91a15
- MemoryStatus memoryStatus = entry.getValue();
- if (!owner.getBrain().checkMemory(memoryModuleType, memoryStatus)) {
- return false;
+ // DivineMC start - Optimize entity stupid brain
+ // DivineMC start - Optimize entity brain
+ public boolean hasRequiredMemories(E entity) {
+ net.minecraft.world.entity.ai.Brain<?> brain = entity.getBrain();
+ long modCount = brain.getMemoryModCount();
@@ -322,24 +323,24 @@ index 5b0cadd2544fb2a627822e645ff32fec2e9cfda9..253b9ad671cf0932bb17d468f8b91a15
- return true;
+ return this.cachedHasRequiredMemoryState = true;
}
+ // DivineMC end - Optimize entity stupid brain
+ // DivineMC end - Optimize entity brain
public static enum Status {
STOPPED,
diff --git a/net/minecraft/world/entity/ai/behavior/LongJumpToRandomPos.java b/net/minecraft/world/entity/ai/behavior/LongJumpToRandomPos.java
index 977afa268838304abdb34be253ca36ac1c22e99f..55a20253d139bc997d2b5d0c0d928fe67df2da32 100644
index 977afa268838304abdb34be253ca36ac1c22e99f..ff04ea295b70583137deb8babe5e75ebc755f697 100644
--- a/net/minecraft/world/entity/ai/behavior/LongJumpToRandomPos.java
+++ b/net/minecraft/world/entity/ai/behavior/LongJumpToRandomPos.java
@@ -119,6 +119,12 @@ public class LongJumpToRandomPos<E extends Mob> extends Behavior<E> {
int x = blockPos.getX();
int y = blockPos.getY();
int z = blockPos.getZ();
+ // DivineMC start - Optimize entity stupid brain
+ // DivineMC start - Optimize entity brain
+ if (this.maxLongJumpWidth < 128 && this.maxLongJumpHeight < 128) {
+ this.jumpCandidates = org.bxteam.divinemc.util.collections.LongJumpChoiceList.forCenter(blockPos, (byte) this.maxLongJumpWidth, (byte) this.maxLongJumpHeight);
+ return;
+ }
+ // DivineMC end - Optimize entity stupid brain
+ // DivineMC end - Optimize entity brain
this.jumpCandidates = BlockPos.betweenClosedStream(
x - this.maxLongJumpWidth,
y - this.maxLongJumpHeight,
@@ -347,7 +348,7 @@ index 977afa268838304abdb34be253ca36ac1c22e99f..55a20253d139bc997d2b5d0c0d928fe6
}
}
+ // DivineMC start - Optimize entity stupid brain
+ // DivineMC start - Optimize entity brain
protected Optional<LongJumpToRandomPos.PossibleJump> getJumpCandidate(ServerLevel level) {
- Optional<LongJumpToRandomPos.PossibleJump> randomItem = WeightedRandom.getRandomItem(
- level.random, this.jumpCandidates, LongJumpToRandomPos.PossibleJump::weight
@@ -403,20 +404,47 @@ index 24d1928445b5571e040a2b12d5c82e77a880d9bd..dac0a23aebf2dea1972c07d5c82079da
private boolean isVillagerBaby(LivingEntity livingEntity) {
return livingEntity.getType() == EntityType.VILLAGER && livingEntity.isBaby();
diff --git a/net/minecraft/world/entity/animal/goat/Goat.java b/net/minecraft/world/entity/animal/goat/Goat.java
index 70b32e0d06f9b8b7999df5fdfd773c09394e23fb..36fcc913385afec8bb66c1664b902e4d6868f11d 100644
index 70b32e0d06f9b8b7999df5fdfd773c09394e23fb..997cff138d5c99b1be9224cb3c96bdfeeb79915a 100644
--- a/net/minecraft/world/entity/animal/goat/Goat.java
+++ b/net/minecraft/world/entity/animal/goat/Goat.java
@@ -100,6 +100,13 @@ public class Goat extends Animal {
this.getNavigation().setCanFloat(true);
this.setPathfindingMalus(PathType.POWDER_SNOW, -1.0F);
this.setPathfindingMalus(PathType.DANGER_POWDER_SNOW, -1.0F);
+ // DivineMC start - Optimize entity stupid brain
+ // DivineMC start - Optimize entity brain
+ if (!this.getBrain().hasMemoryValue(MemoryModuleType.NEAREST_VISIBLE_WANTED_ITEM)) {
+ org.bxteam.divinemc.util.entity.SensorHelper.disableSensor(this, SensorType.NEAREST_ITEMS);
+ } else if (net.minecraft.SharedConstants.IS_RUNNING_IN_IDE) {
+ throw new IllegalStateException("Goat Entity has a nearest visible wanted item memory module! This patch(Optimize-Brain, Goat.java changes) should probably be removed permanently!");
+ }
+ // DivineMC end - Optimize entity stupid brain
+ // DivineMC end - Optimize entity brain
}
public ItemStack createHorn() {
diff --git a/net/minecraft/world/entity/schedule/Activity.java b/net/minecraft/world/entity/schedule/Activity.java
index 5a143bb6fabba3dc4e2272afb0be636d5722ea22..f17cc8135121f1a97f13bf83a0205e7fcb08b431 100644
--- a/net/minecraft/world/entity/schedule/Activity.java
+++ b/net/minecraft/world/entity/schedule/Activity.java
@@ -32,10 +32,12 @@ public class Activity {
public static final Activity DIG = register("dig");
private final String name;
private final int hashCode;
+ public final int id; // DivineMC - Cache registry ID
- private Activity(String name) {
+ private Activity(String name, int id) {
this.name = name;
this.hashCode = name.hashCode();
+ this.id = id; // DivineMC - Cache registry ID
}
public String getName() {
@@ -43,7 +45,7 @@ public class Activity {
}
private static Activity register(String key) {
- return Registry.register(BuiltInRegistries.ACTIVITY, key, new Activity(key));
+ return Registry.register(BuiltInRegistries.ACTIVITY, key, new Activity(key, BuiltInRegistries.ACTIVITY.size())); // DivineMC - Cache registry ID
}
@Override

View File

@@ -1,34 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sat, 1 Feb 2025 19:28:34 +0300
Subject: [PATCH] Block Log4Shell exploit
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index b0bd45b8f53d4b9617680d7fb92d324c3713d960..89eddabc1a01f78b6945f1b8b8d32cede7e3cd9d 100644
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -2525,6 +2525,7 @@ public class ServerGamePacketListenerImpl
}
private void tryHandleChat(String message, Runnable handler, boolean sync) { // CraftBukkit
+ if (ServerGamePacketListenerImpl.isLog4ShellExploit(message)) return; // DivineMC - Block Log4Shell exploit
if (isChatMessageIllegal(message)) {
this.disconnectAsync(Component.translatable("multiplayer.disconnect.illegal_characters"), org.bukkit.event.player.PlayerKickEvent.Cause.ILLEGAL_CHARACTERS); // Paper - add proper async disconnect
} else if (this.player.isRemoved() || this.player.getChatVisibility() == ChatVisiblity.HIDDEN) { // CraftBukkit - dead men tell no tales
@@ -2557,6 +2558,15 @@ public class ServerGamePacketListenerImpl
}
}
+ // DivineMC start - Block Log4Shell exploit
+ public static boolean isLog4ShellExploit(String message) {
+ java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(".*\\$\\{[^}]*}.*");
+ java.util.regex.Matcher matcher = pattern.matcher(message);
+
+ return matcher.find();
+ }
+ // DivineMC end - Block Log4Shell exploit
+
public static boolean isChatMessageIllegal(String message) {
for (int i = 0; i < message.length(); i++) {
if (!StringUtil.isAllowedChatCharacter(message.charAt(i))) {

View File

@@ -1,12 +1,18 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sat, 1 Feb 2025 19:50:02 +0300
Subject: [PATCH] Skip distanceToSqr call in ServerEntity#sendChanges if the
delta movement hasn't changed
Subject: [PATCH] SparklyPaper: Skip distanceToSqr call in
ServerEntity#sendChanges if the delta movement hasn't changed
Original project: https://github.com/SparklyPower/SparklyPaper
Patch description:
The "distanceToSqr" call is a bit expensive, so avoiding it is pretty nice, around ~15% calls are skipped with this check
We could also check if the x,y,z coordinates are equal, but for now, let's just keep the identity check, which also helps us since Minecraft's code does reuse the original delta movement Vec3 object
diff --git a/net/minecraft/server/level/ServerEntity.java b/net/minecraft/server/level/ServerEntity.java
index fa0fd2a7f15a076ac981f85f4f249a15a4ab512e..ff2f1e31633749da89cfc0779004ac1ef104470d 100644
index e96d4dee14c05f2fa329bfb1588ec795d4e3d730..0868189fee30d40dfb82ae39592a65b510e96b54 100644
--- a/net/minecraft/server/level/ServerEntity.java
+++ b/net/minecraft/server/level/ServerEntity.java
@@ -209,23 +209,27 @@ public class ServerEntity {

View File

@@ -0,0 +1,119 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sun, 6 Jul 2025 03:24:48 +0300
Subject: [PATCH] Carpet-Fixes: Optimized getBiome method
Original license: MIT
Original project: https://github.com/fxmorin/carpet-fixes
diff --git a/net/minecraft/world/level/biome/BiomeManager.java b/net/minecraft/world/level/biome/BiomeManager.java
index 73962e79a0f3d892e3155443a1b84508b0f4042e..c5fa1d7613410593f5b430968398c4ab1b40a98b 100644
--- a/net/minecraft/world/level/biome/BiomeManager.java
+++ b/net/minecraft/world/level/biome/BiomeManager.java
@@ -14,6 +14,7 @@ public class BiomeManager {
private static final int ZOOM_MASK = 3;
private final BiomeManager.NoiseBiomeSource noiseBiomeSource;
private final long biomeZoomSeed;
+ private static final double maxOffset = 0.4500000001D; // DivineMC - Carpet-Fixes: Optimized getBiome method
public BiomeManager(BiomeManager.NoiseBiomeSource noiseBiomeSource, long biomeZoomSeed) {
this.noiseBiomeSource = noiseBiomeSource;
@@ -29,39 +30,68 @@ public class BiomeManager {
}
public Holder<Biome> getBiome(BlockPos pos) {
- int i = pos.getX() - 2;
- int i1 = pos.getY() - 2;
- int i2 = pos.getZ() - 2;
- int i3 = i >> 2;
- int i4 = i1 >> 2;
- int i5 = i2 >> 2;
- double d = (i & 3) / 4.0;
- double d1 = (i1 & 3) / 4.0;
- double d2 = (i2 & 3) / 4.0;
- int i6 = 0;
- double d3 = Double.POSITIVE_INFINITY;
-
- for (int i7 = 0; i7 < 8; i7++) {
- boolean flag = (i7 & 4) == 0;
- boolean flag1 = (i7 & 2) == 0;
- boolean flag2 = (i7 & 1) == 0;
- int i8 = flag ? i3 : i3 + 1;
- int i9 = flag1 ? i4 : i4 + 1;
- int i10 = flag2 ? i5 : i5 + 1;
- double d4 = flag ? d : d - 1.0;
- double d5 = flag1 ? d1 : d1 - 1.0;
- double d6 = flag2 ? d2 : d2 - 1.0;
- double fiddledDistance = getFiddledDistance(this.biomeZoomSeed, i8, i9, i10, d4, d5, d6);
- if (d3 > fiddledDistance) {
- i6 = i7;
- d3 = fiddledDistance;
+ // DivineMC start - Carpet-Fixes: Optimized getBiome method
+ int xMinus2 = pos.getX() - 2;
+ int yMinus2 = pos.getY() - 2;
+ int zMinus2 = pos.getZ() - 2;
+ int x = xMinus2 >> 2;
+ int y = yMinus2 >> 2;
+ int z = zMinus2 >> 2;
+ double quartX = (double) (xMinus2 & 3) / 4.0;
+ double quartY = (double) (yMinus2 & 3) / 4.0;
+ double quartZ = (double) (zMinus2 & 3) / 4.0;
+ int smallestX = 0;
+ double smallestDist = Double.POSITIVE_INFINITY;
+
+ for (int biomeX = 0; biomeX < 8; ++biomeX) {
+ boolean everyOtherQuad = (biomeX & 4) == 0;
+ boolean everyOtherPair = (biomeX & 2) == 0;
+ boolean everyOther = (biomeX & 1) == 0;
+ double quartXX = everyOtherQuad ? quartX : quartX - 1.0;
+ double quartYY = everyOtherPair ? quartY : quartY - 1.0;
+ double quartZZ = everyOther ? quartZ : quartZ - 1.0;
+
+ double maxQuartYY = 0.0, maxQuartZZ = 0.0;
+ if (biomeX != 0) {
+ maxQuartYY = Mth.square(Math.max(quartYY + maxOffset, Math.abs(quartYY - maxOffset)));
+ maxQuartZZ = Mth.square(Math.max(quartZZ + maxOffset, Math.abs(quartZZ - maxOffset)));
+ double maxQuartXX = Mth.square(Math.max(quartXX + maxOffset, Math.abs(quartXX - maxOffset)));
+ if (smallestDist < maxQuartXX + maxQuartYY + maxQuartZZ) continue;
+ }
+
+ int xx = everyOtherQuad ? x : x + 1;
+ int yy = everyOtherPair ? y : y + 1;
+ int zz = everyOther ? z : z + 1;
+
+ long seed = LinearCongruentialGenerator.next(this.biomeZoomSeed, xx);
+ seed = LinearCongruentialGenerator.next(seed, yy);
+ seed = LinearCongruentialGenerator.next(seed, zz);
+ seed = LinearCongruentialGenerator.next(seed, xx);
+ seed = LinearCongruentialGenerator.next(seed, yy);
+ seed = LinearCongruentialGenerator.next(seed, zz);
+ double offsetX = getFiddle(seed);
+ double sqrX = Mth.square(quartXX + offsetX);
+ if (biomeX != 0 && smallestDist < sqrX + maxQuartYY + maxQuartZZ) continue;
+ seed = LinearCongruentialGenerator.next(seed, this.biomeZoomSeed);
+ double offsetY = getFiddle(seed);
+ double sqrY = Mth.square(quartYY + offsetY);
+ if (biomeX != 0 && smallestDist < sqrX + sqrY + maxQuartZZ) continue;
+ seed = LinearCongruentialGenerator.next(seed, this.biomeZoomSeed);
+ double offsetZ = getFiddle(seed);
+ double biomeDist = sqrX + sqrY + Mth.square(quartZZ + offsetZ);
+
+ if (smallestDist > biomeDist) {
+ smallestX = biomeX;
+ smallestDist = biomeDist;
}
}
- int i7x = (i6 & 4) == 0 ? i3 : i3 + 1;
- int i11 = (i6 & 2) == 0 ? i4 : i4 + 1;
- int i12 = (i6 & 1) == 0 ? i5 : i5 + 1;
- return this.noiseBiomeSource.getNoiseBiome(i7x, i11, i12);
+ return this.noiseBiomeSource.getNoiseBiome(
+ (smallestX & 4) == 0 ? x : x + 1,
+ (smallestX & 2) == 0 ? y : y + 1,
+ (smallestX & 1) == 0 ? z : z + 1
+ );
+ // DivineMC end - Carpet-Fixes: Optimized getBiome method
}
public Holder<Biome> getNoiseBiomeAtPosition(double x, double y, double z) {

View File

@@ -19,7 +19,7 @@ we used a prebaked list of all the possible colors and combinations, however thi
datapack to change it.
diff --git a/net/minecraft/world/item/DyeColor.java b/net/minecraft/world/item/DyeColor.java
index 6bac07817d2916c64f703586599a2cab226872e6..d8ad2d56d4f0d6e5a58ec0359cecdde384db93e8 100644
index c9cde255117b46690b2b6670d009a00b051af016..2c9f513e6ccd75959484f29a375671e21aab9590 100644
--- a/net/minecraft/world/item/DyeColor.java
+++ b/net/minecraft/world/item/DyeColor.java
@@ -112,6 +112,15 @@ public enum DyeColor implements StringRepresentable {

View File

@@ -3,6 +3,13 @@ From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Wed, 11 Jun 2025 19:33:13 +0300
Subject: [PATCH] Carpet-AMS-Addition: Optimized dragon respawn
This patch is based on the following mixins and classes:
* "club/mcams/carpet/mixin/rule/optimizedDragonRespawn/BlockPatternMixin.java"
* "club/mcams/carpet/mixin/rule/optimizedDragonRespawn/EnderDragonFightMixin.java"
* "club/mcams/carpet/helpers/rule/optimizedDragonRespawn/BlockPatternHelper.java"
By: 1024-byteeeee
As part of: Carpet-AMS-Addition (https://github.com/Minecraft-AMS/Carpet-AMS-Addition)
Licensed under: LGPL-3.0 (https://www.gnu.org/licenses/lgpl-3.0.html)
diff --git a/net/minecraft/world/level/block/state/pattern/BlockPattern.java b/net/minecraft/world/level/block/state/pattern/BlockPattern.java
index f7bb979f08634a7e1b77c59040f59fb5e11aafa5..e0eca73d9e8a77b2a4972db61001394c6bf1d2c4 100644

View File

@@ -1,38 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Wed, 5 Feb 2025 17:48:56 +0300
Subject: [PATCH] Verify Minecraft EULA earlier
diff --git a/net/minecraft/server/Main.java b/net/minecraft/server/Main.java
index b06c2c4aa77edafb374f7cf0406cf4d29c6e7f9f..a476b53e0c5b18d9b0abceb4ffeb5ab4c5d7d6d9 100644
--- a/net/minecraft/server/Main.java
+++ b/net/minecraft/server/Main.java
@@ -125,7 +125,6 @@ public class Main {
dedicatedServerSettings.forceSave();
RegionFileVersion.configure(dedicatedServerSettings.getProperties().regionFileComression);
Path path2 = Paths.get("eula.txt");
- Eula eula = new Eula(path2);
// Paper start - load config files early for access below if needed
org.bukkit.configuration.file.YamlConfiguration bukkitConfiguration = io.papermc.paper.configuration.PaperConfigurations.loadLegacyConfigFile((File) optionSet.valueOf("bukkit-settings"));
org.bukkit.configuration.file.YamlConfiguration spigotConfiguration = io.papermc.paper.configuration.PaperConfigurations.loadLegacyConfigFile((File) optionSet.valueOf("spigot-settings"));
@@ -148,19 +147,6 @@ public class Main {
return;
}
- // Spigot start
- boolean eulaAgreed = Boolean.getBoolean("com.mojang.eula.agree");
- if (eulaAgreed) {
- LOGGER.error("You have used the Spigot command line EULA agreement flag.");
- LOGGER.error("By using this setting you are indicating your agreement to Mojang's EULA (https://aka.ms/MinecraftEULA).");
- LOGGER.error("If you do not agree to the above EULA please stop your server and remove this flag immediately.");
- }
- if (!eula.hasAgreedToEULA() && !eulaAgreed) {
- // Spigot end
- LOGGER.info("You need to agree to the EULA in order to run the server. Go to eula.txt for more info.");
- return;
- }
-
// Paper start - Detect headless JRE
String awtException = io.papermc.paper.util.ServerEnvironment.awtDependencyCheck();
if (awtException != null) {

View File

@@ -10,10 +10,10 @@ As part of: ModernFix (https://github.com/embeddedt/ModernFix)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
diff --git a/net/minecraft/world/level/chunk/PalettedContainer.java b/net/minecraft/world/level/chunk/PalettedContainer.java
index ce41cd702a61d96552567b310cf59b22d9363eeb..4c02444001ce772cad0f9eb28ce147cd3cc08b8d 100644
index 9d892c1c3890e0aaf13fd5cd7b7d138afeaad260..ca3fab804e464a5db2b47495ecb588a96044265d 100644
--- a/net/minecraft/world/level/chunk/PalettedContainer.java
+++ b/net/minecraft/world/level/chunk/PalettedContainer.java
@@ -274,6 +274,28 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
@@ -291,6 +291,28 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
data.palette.read(buffer);
buffer.readFixedSizeLongArray(data.storage.getRaw());
this.data = data;

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Option to disable disconnect.spam
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index ad8a21401a54c3dc8c8a85a98b66a4822b817293..0163f6d69ae902ed50efefef3e98835c02e2c3e2 100644
index e269535609363528971268fdca9e6a6b70902608..637c5ca0c004e5de66bc3f84dba5fee47f729579 100644
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -853,7 +853,7 @@ public class ServerGamePacketListenerImpl
@@ -846,7 +846,7 @@ public class ServerGamePacketListenerImpl
public void handleCustomCommandSuggestions(ServerboundCommandSuggestionPacket packet) {
// PacketUtils.ensureRunningOnSameThread(packet, this, this.player.level()); // Paper - AsyncTabCompleteEvent; run this async
// CraftBukkit start
@@ -17,7 +17,7 @@ index ad8a21401a54c3dc8c8a85a98b66a4822b817293..0163f6d69ae902ed50efefef3e98835c
this.disconnectAsync(Component.translatable("disconnect.spam"), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM); // Paper - Kick event cause // Paper - add proper async disconnect
return;
}
@@ -865,7 +865,7 @@ public class ServerGamePacketListenerImpl
@@ -858,7 +858,7 @@ public class ServerGamePacketListenerImpl
// Paper end - Don't suggest if tab-complete is disabled
// Paper start
final int index;
@@ -26,7 +26,7 @@ index ad8a21401a54c3dc8c8a85a98b66a4822b817293..0163f6d69ae902ed50efefef3e98835c
this.disconnectAsync(Component.translatable("disconnect.spam"), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM); // Paper - add proper async disconnect
return;
}
@@ -925,6 +925,7 @@ public class ServerGamePacketListenerImpl
@@ -918,6 +918,7 @@ public class ServerGamePacketListenerImpl
ParseResults<CommandSourceStack> parseResults = this.server.getCommands().getDispatcher().parse(stringReader, this.player.createCommandSourceStack());
// Paper start - Handle non-recoverable exceptions
if (!parseResults.getExceptions().isEmpty()
@@ -34,7 +34,7 @@ index ad8a21401a54c3dc8c8a85a98b66a4822b817293..0163f6d69ae902ed50efefef3e98835c
&& parseResults.getExceptions().values().stream().anyMatch(e -> e instanceof io.papermc.paper.brigadier.TagParseCommandSyntaxException)) {
this.disconnect(Component.translatable("disconnect.spam"), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM);
return;
@@ -2652,6 +2653,7 @@ public class ServerGamePacketListenerImpl
@@ -2631,6 +2632,7 @@ public class ServerGamePacketListenerImpl
// this.chatSpamThrottler.increment();
if (!this.chatSpamThrottler.isIncrementAndUnderThreshold()
// CraftBukkit end
@@ -42,7 +42,7 @@ index ad8a21401a54c3dc8c8a85a98b66a4822b817293..0163f6d69ae902ed50efefef3e98835c
&& !this.server.getPlayerList().isOp(this.player.getGameProfile())
&& !this.server.isSingleplayerOwner(this.player.getGameProfile())) {
this.disconnectAsync(Component.translatable("disconnect.spam"), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM); // Paper - kick event cause & add proper async disconnect
@@ -3351,7 +3353,7 @@ public class ServerGamePacketListenerImpl
@@ -3330,7 +3332,7 @@ public class ServerGamePacketListenerImpl
public void handlePlaceRecipe(ServerboundPlaceRecipePacket packet) {
// Paper start - auto recipe limit
if (!org.bukkit.Bukkit.isPrimaryThread()) {

View File

@@ -24,10 +24,10 @@ index d8dc196ef92e97f831cf97cd1536a46f81f9d5d1..ed8c50f67f5a6deda74845e4bce9fd9a
+ // DivineMC end - Option to disable saving firework
}
diff --git a/net/minecraft/world/entity/projectile/Snowball.java b/net/minecraft/world/entity/projectile/Snowball.java
index 86e75722b37eaa02858fa4313d8bcc2a72c0f7f6..0f611169a4ed2a059b9231bedf94a903600b73f0 100644
index d8f9fb603fd2e3e5c1dfc05face7f42b4844daf4..42b2be469972e02671fa5a02aeecfb4e5be405c3 100644
--- a/net/minecraft/world/entity/projectile/Snowball.java
+++ b/net/minecraft/world/entity/projectile/Snowball.java
@@ -100,4 +100,14 @@ public class Snowball extends ThrowableItemProjectile {
@@ -94,4 +94,14 @@ public class Snowball extends ThrowableItemProjectile {
this.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.HIT); // CraftBukkit - add Bukkit remove cause
}
}

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Snowball and Egg knockback
diff --git a/net/minecraft/world/entity/projectile/Snowball.java b/net/minecraft/world/entity/projectile/Snowball.java
index d8f9fb603fd2e3e5c1dfc05face7f42b4844daf4..86e75722b37eaa02858fa4313d8bcc2a72c0f7f6 100644
index 42b2be469972e02671fa5a02aeecfb4e5be405c3..0f611169a4ed2a059b9231bedf94a903600b73f0 100644
--- a/net/minecraft/world/entity/projectile/Snowball.java
+++ b/net/minecraft/world/entity/projectile/Snowball.java
@@ -54,6 +54,12 @@ public class Snowball extends ThrowableItemProjectile {

View File

@@ -7,7 +7,7 @@ Original license: GPL v3
Original project: https://github.com/pufferfish-gg/Pufferfish
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
index 16a3cd813997456ca67a382a8277eca02dc6662f..3cf377f87e8b7f672ea247728365eb61f47bc3ac 100644
index 8df6ceea1536b12d87755c8a69e1b652d280600c..33f33a51a7016e214bca1aec8e6cc3910ec3bb42 100644
--- a/net/minecraft/world/entity/LivingEntity.java
+++ b/net/minecraft/world/entity/LivingEntity.java
@@ -420,6 +420,12 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin

View File

@@ -1,87 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Mon, 3 Mar 2025 19:29:13 +0300
Subject: [PATCH] Async Chunk Sending
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
index 636ba1c5fef58aabd5b8d6c6a8d183584b9c8be1..998f8f0bd173ff370e947c16c28b9b01f89da1eb 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
@@ -53,6 +53,8 @@ public final class RegionizedPlayerChunkLoader {
public static final int LOADED_TICKET_LEVEL = ChunkTaskScheduler.getTicketLevel(ChunkStatus.EMPTY);
public static final int TICK_TICKET_LEVEL = ChunkHolderManager.ENTITY_TICKING_TICKET_LEVEL;
+ private static final org.apache.logging.log4j.Logger LOGGER = org.apache.logging.log4j.LogManager.getLogger("RegionizedPlayerChunkLoader"); // DivineMC - Async Chunk Sending
+
public static void setUnloadDelay(final long ticks) {
((ChunkSystemTicketType)(Object)PLAYER_TICKET_DELAYED).moonrise$setTimeout(Math.max(1, ticks));
}
@@ -421,17 +423,61 @@ public final class RegionizedPlayerChunkLoader {
}
private void sendChunk(final int chunkX, final int chunkZ) {
- if (this.sentChunks.add(CoordinateUtils.getChunkKey(chunkX, chunkZ))) {
- ((ChunkSystemChunkHolder)((ChunkSystemServerLevel)this.world).moonrise$getChunkTaskScheduler().chunkHolderManager
- .getChunkHolder(chunkX, chunkZ).vanillaChunkHolder).moonrise$addReceivedChunk(this.player);
+ // DivineMC start - Async Chunk Sending
+ final long chunkKey = CoordinateUtils.getChunkKey(chunkX, chunkZ);
+
+ if (!this.sentChunks.add(chunkKey)) return;
- final LevelChunk chunk = ((ChunkSystemLevel)this.world).moonrise$getFullChunkIfLoaded(chunkX, chunkZ);
+ final LevelChunk chunk = ((ChunkSystemLevel) this.world).moonrise$getFullChunkIfLoaded(chunkX, chunkZ);
+ if (chunk == null) {
+ this.sentChunks.remove(chunkKey);
+ return;
+ }
+ try {
+ ((ChunkSystemServerLevel) this.world).moonrise$getChunkTaskScheduler().chunkHolderManager.getChunkHolder(chunkX, chunkZ).vanillaChunkHolder.moonrise$addReceivedChunk(this.player);
PlatformHooks.get().onChunkWatch(this.world, chunk, this.player);
- PlayerChunkSender.sendChunk(this.player.connection, this.world, chunk);
+ } catch (IllegalStateException e) {
+ this.sentChunks.remove(chunkKey);
return;
}
- throw new IllegalStateException();
+
+ if (org.bxteam.divinemc.config.DivineConfig.AsyncCategory.asyncChunkSendingEnabled) {
+ net.minecraft.Util.backgroundExecutor().execute(() -> {
+ try {
+ // Modified from PlayerChunkSender#sendChunk
+ final net.minecraft.server.network.ServerGamePacketListenerImpl connection = this.player.connection;
+ final ServerLevel serverLevel = this.world;
+
+ final net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket packet = new net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket(
+ chunk, serverLevel.getLightEngine(), null, null,
+ serverLevel.chunkPacketBlockController.shouldModify(this.player, chunk)
+ );
+
+ serverLevel.getServer().execute(() -> {
+ if (this.removed || !this.sentChunks.contains(chunkKey)) return;
+
+ connection.send(packet);
+
+ if (io.papermc.paper.event.packet.PlayerChunkLoadEvent.getHandlerList().getRegisteredListeners().length > 0) {
+ new io.papermc.paper.event.packet.PlayerChunkLoadEvent(
+ new org.bukkit.craftbukkit.CraftChunk(chunk),
+ this.player.getBukkitEntity()
+ ).callEvent();
+ }
+
+ net.minecraft.network.protocol.game.DebugPackets.sendPoiPacketsForChunk(serverLevel, chunk.getPos());
+ });
+ } catch (Exception e) {
+ LOGGER.error("Failed to send chunk asynchronously!", e);
+
+ if (!this.removed) this.sentChunks.remove(chunkKey);
+ }
+ });
+ } else {
+ PlayerChunkSender.sendChunk(this.player.connection, this.world, chunk);
+ }
+ // DivineMC end - Async Chunk Sending
}
private void sendUnloadChunk(final int chunkX, final int chunkZ) {

View File

@@ -1,18 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sun, 23 Feb 2025 01:03:59 +0300
Subject: [PATCH] Configurable MC-67
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index ddc8095dfb6acce493e66034e47ee9a1f3497e5d..dfb6391533009a2030710046ade3ac569e3de8ec 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -4170,6 +4170,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
public boolean canTeleport(Level fromLevel, Level toLevel) {
+ if (!fromLevel.divineConfig.allowEntityPortalWithPassenger && (this.isPassenger() || this.isVehicle())) return false; // DivineMC - Allow entity teleport with passenger
if (!this.isAlive() || !this.valid) return false; // Paper - Fix item duplication and teleport issues
if (fromLevel.dimension() == Level.END && toLevel.dimension() == Level.OVERWORLD) {
for (Entity entity : this.getPassengers()) {

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Configurable movement speed for entities
diff --git a/net/minecraft/world/entity/monster/Drowned.java b/net/minecraft/world/entity/monster/Drowned.java
index edcb20935f58e78fa4ef2c11a7dcc6a7857341c2..d4e7fc0a5bda4f44bcfed3d1adae7cdaf815784b 100644
index 2e6d0f035a01277aa28bbe912d5df8dc4cf04547..2a13332ebabf2e63a8f51a5d794fab3d66c7a1db 100644
--- a/net/minecraft/world/entity/monster/Drowned.java
+++ b/net/minecraft/world/entity/monster/Drowned.java
@@ -98,6 +98,7 @@ public class Drowned extends Zombie implements RangedAttackMob {

View File

@@ -3,15 +3,18 @@ From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Wed, 26 Mar 2025 01:46:49 +0300
Subject: [PATCH] Leaf: Improve BlockEntity ticking isRemoved check
Original project: https://github.com/Winds-Studio/Leaf
This should help for massive hopper chains or hopper matrix.
diff --git a/net/minecraft/world/level/chunk/LevelChunk.java b/net/minecraft/world/level/chunk/LevelChunk.java
index df086a2580ee41f88a00fb78b50b87f22539b833..868881e2b8567d1a03eee4f4a9f611bbc36c66d0 100644
index dbb4142ea38cdf484e74c81103cebb024ae8813d..32f17328b7980a9dc382c90af76cca04b74c639a 100644
--- a/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/net/minecraft/world/level/chunk/LevelChunk.java
@@ -999,13 +999,26 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
@@ -982,13 +982,26 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
public static class RebindableTickingBlockEntityWrapper implements TickingBlockEntity {
public TickingBlockEntity ticker;
static class RebindableTickingBlockEntityWrapper implements TickingBlockEntity {
private TickingBlockEntity ticker;
+ private @Nullable BlockEntity blockEntityReference = null; // DivineMC - Improve BlockEntity ticking isRemoved check
RebindableTickingBlockEntityWrapper(TickingBlockEntity ticker) {
@@ -23,7 +26,7 @@ index df086a2580ee41f88a00fb78b50b87f22539b833..868881e2b8567d1a03eee4f4a9f611bb
+ // DivineMC end - Improve BlockEntity ticking isRemoved check
}
public void rebind(TickingBlockEntity ticker) {
void rebind(TickingBlockEntity ticker) {
this.ticker = ticker;
+ // DivineMC start - Improve BlockEntity ticking isRemoved check
+ if (ticker instanceof BoundTickingBlockEntity<?> boundTicker) {
@@ -35,7 +38,7 @@ index df086a2580ee41f88a00fb78b50b87f22539b833..868881e2b8567d1a03eee4f4a9f611bb
}
@Override
@@ -1015,6 +1028,12 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
@@ -998,6 +1011,12 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
@Override
public boolean isRemoved() {

View File

@@ -6,10 +6,10 @@ Subject: [PATCH] Option to allow weird movement and disable teleporting
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 649b01c00ec01eea1514676e424d88acbfa26184..b0bd45b8f53d4b9617680d7fb92d324c3713d960 100644
index 637c5ca0c004e5de66bc3f84dba5fee47f729579..1bd6368704665f90eaa621366b4dec21bc937a96 100644
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -607,7 +607,7 @@ public class ServerGamePacketListenerImpl
@@ -609,7 +609,7 @@ public class ServerGamePacketListenerImpl
return;
}
// Paper end - Prevent moving into unloaded chunks
@@ -18,7 +18,7 @@ index 649b01c00ec01eea1514676e424d88acbfa26184..b0bd45b8f53d4b9617680d7fb92d324c
// CraftBukkit end
LOGGER.warn(
"{} (vehicle of {}) moved too quickly! {},{},{}", rootVehicle.getName().getString(), this.player.getName().getString(), d3, d4, d5
@@ -637,7 +637,7 @@ public class ServerGamePacketListenerImpl
@@ -639,7 +639,7 @@ public class ServerGamePacketListenerImpl
d5 = d2 - rootVehicle.getZ();
d7 = d3 * d3 + d4 * d4 + d5 * d5;
boolean flag1 = false;
@@ -27,7 +27,7 @@ index 649b01c00ec01eea1514676e424d88acbfa26184..b0bd45b8f53d4b9617680d7fb92d324c
flag1 = true; // Paper - diff on change, this should be moved wrongly
LOGGER.warn("{} (vehicle of {}) moved wrongly! {}", rootVehicle.getName().getString(), this.player.getName().getString(), Math.sqrt(d7));
}
@@ -1560,20 +1560,24 @@ public class ServerGamePacketListenerImpl
@@ -1557,20 +1557,24 @@ public class ServerGamePacketListenerImpl
if (this.shouldCheckPlayerMovement(isFallFlying)) {
float f2 = isFallFlying ? 300.0F : 100.0F;
if (d7 - d6 > Math.max(f2, Mth.square(org.spigotmc.SpigotConfig.movedTooQuicklyMultiplier * (float) i * speed))) {
@@ -63,7 +63,7 @@ index 649b01c00ec01eea1514676e424d88acbfa26184..b0bd45b8f53d4b9617680d7fb92d324c
}
}
}
@@ -1634,6 +1638,7 @@ public class ServerGamePacketListenerImpl
@@ -1631,6 +1635,7 @@ public class ServerGamePacketListenerImpl
d7 = d3 * d3 + d4 * d4 + d5 * d5;
boolean movedWrongly = false; // Paper - Add fail move event; rename
if (!this.player.isChangingDimension()

View File

@@ -5,20 +5,20 @@ Subject: [PATCH] Optimize Raids
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
index adac2dd1530c21c610f6dced12a80ab726fe3a98..d39d15dcb6964aed0bf9c2f64952d229d64cff62 100644
index 5f2c27800f047f128857044493a6d9325ffd759b..4a2cace22512fe06c1713bc8735e775e3012f3bc 100644
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -218,6 +218,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -215,6 +215,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
public boolean hasEntityMoveEvent; // Paper - Add EntityMoveEvent
private final alternate.current.wire.WireHandler wireHandler = new alternate.current.wire.WireHandler(this); // Paper - optimize redstone (Alternate Current)
public boolean hasRidableMoveEvent = false; // Purpur - Ridables
public org.bxteam.divinemc.util.tps.TPSCalculator tpsCalculator = new org.bxteam.divinemc.util.tps.TPSCalculator(); // DivineMC - Lag Compensation
+ public net.minecraft.world.item.ItemStack ominousBanner; // DivineMC - Optimize Raids
@Override
public @Nullable LevelChunk getChunkIfLoaded(int x, int z) {
@@ -706,6 +707,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -694,6 +695,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
// Paper end - rewrite chunk system
this.getCraftServer().addWorld(this.getWorld()); // CraftBukkit
this.tickExecutor = java.util.concurrent.Executors.newSingleThreadExecutor(new org.bxteam.divinemc.server.ServerLevelTickExecutorThreadFactory(getWorld().getName())); // DivineMC - Parallel world ticking
this.preciseTime = this.serverLevelData.getDayTime(); // Purpur - Configurable daylight cycle
+ this.ominousBanner = Objects.requireNonNullElse(this.registryAccess(), net.minecraft.core.RegistryAccess.EMPTY).lookup(Registries.BANNER_PATTERN).map(Raid::getOminousBannerInstance).orElse(null); // DivineMC - Optimize Raids
}

View File

@@ -0,0 +1,63 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Mon, 7 Jul 2025 04:21:38 +0300
Subject: [PATCH] Small optimization to LinearPalette
diff --git a/net/minecraft/world/level/chunk/LinearPalette.java b/net/minecraft/world/level/chunk/LinearPalette.java
index 2073f6ff41aa570102621d183ee890b076267d54..93cb815032fada7b8abc7301a7005114eea8384d 100644
--- a/net/minecraft/world/level/chunk/LinearPalette.java
+++ b/net/minecraft/world/level/chunk/LinearPalette.java
@@ -12,7 +12,7 @@ public class LinearPalette<T> implements Palette<T>, ca.spottedleaf.moonrise.pat
private final T[] values;
private final PaletteResize<T> resizeHandler;
private final int bits;
- private int size;
+ private volatile int size; // DivineMC - Small optimization to LinearPalette
// Paper start - optimise palette reads
@Override
@@ -49,11 +49,14 @@ public class LinearPalette<T> implements Palette<T>, ca.spottedleaf.moonrise.pat
@Override
public int idFor(T state) {
- for (int i = 0; i < this.size; i++) {
- if (this.values[i] == state) {
+ // DivineMC start - Small optimization to LinearPalette
+ final T[] values = this.values;
+ for (int i = 0; i < values.length; i++) {
+ if (values[i] == state) {
return i;
}
}
+ // DivineMC end - Small optimization to LinearPalette
int ix = this.size;
if (ix < this.values.length) {
@@ -67,17 +70,23 @@ public class LinearPalette<T> implements Palette<T>, ca.spottedleaf.moonrise.pat
@Override
public boolean maybeHas(Predicate<T> filter) {
- for (int i = 0; i < this.size; i++) {
- if (filter.test(this.values[i])) {
+ // DivineMC start - Small optimization to LinearPalette
+ final T[] values = this.values;
+ final int currentSize = this.size;
+
+ for (int i = 0; i < currentSize; i++) {
+ T value = values[i];
+ if (value != null && filter.test(value)) {
return true;
}
}
+ // DivineMC end - Small optimization to LinearPalette
return false;
}
@Override
- public T valueFor(int id) {
+ public synchronized T valueFor(int id) { // DivineMC - Small optimization to LinearPalette
if (id >= 0 && id < this.size) {
return this.values[id];
} else {

View File

@@ -0,0 +1,213 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Wed, 9 Jul 2025 02:08:35 +0300
Subject: [PATCH] Optimize VarInt and VarLong write
This patch is based on the following commit:
"Reapply "Optimize varint writing""
By: Andrew Steinborn <git@steinborn.me>
As part of: Velocity (https://github.com/PaperMC/Velocity)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
diff --git a/net/minecraft/network/VarInt.java b/net/minecraft/network/VarInt.java
index 4897ff4648083ebe737ae5b32bae344af27357e4..e138b64c4b09d83e5f38d7421fc23e9cc5e5d5a7 100644
--- a/net/minecraft/network/VarInt.java
+++ b/net/minecraft/network/VarInt.java
@@ -50,28 +50,45 @@ public class VarInt {
return i;
}
- public static ByteBuf write(ByteBuf buffer, int value) {
- // Paper start - Optimize VarInts
- // Peel the one and two byte count cases explicitly as they are the most common VarInt sizes
- // that the proxy will write, to improve inlining.
- if ((value & (0xFFFFFFFF << 7)) == 0) {
- buffer.writeByte(value);
- } else if ((value & (0xFFFFFFFF << 14)) == 0) {
- int w = (value & 0x7F | 0x80) << 8 | (value >>> 7);
- buffer.writeShort(w);
- } else {
- writeOld(buffer, value);
- }
- return buffer;
- }
- public static ByteBuf writeOld(ByteBuf buffer, int value) {
- // Paper end - Optimize VarInts
- while ((value & -128) != 0) {
- buffer.writeByte(value & 127 | 128);
- value >>>= 7;
+ // DivineMC start - Optimize VarInt
+ public static ByteBuf write(ByteBuf buffer, int value) {
+ int bytesNeeded = getByteSize(value);
+
+ switch (bytesNeeded) {
+ case 1:
+ buffer.writeByte(value);
+ break;
+ case 2:
+ int w2 = ((value & 0x7F) << 8) | (value >>> 7) | 0x00008000;
+ buffer.writeShort(w2);
+ break;
+ case 3:
+ int w3 = (value & 0x7F) << 16
+ | (value & 0x3F80) << 1
+ | (value >>> 14)
+ | 0x00808000;
+ buffer.writeMedium(w3);
+ break;
+ case 4:
+ int w4 = (value & 0x7F) << 24
+ | ((value & 0x3F80) << 9)
+ | (value & 0x1FC000) >> 6
+ | (value >>> 21)
+ | 0x80808000;
+ buffer.writeInt(w4);
+ break;
+ case 5:
+ int w5 = (value & 0x7F) << 24
+ | (value & 0x3F80) << 9
+ | (value & 0x1FC000) >> 6
+ | ((value >>> 21) & 0x7F)
+ | 0x80808080;
+ buffer.writeInt(w5);
+ buffer.writeByte(value >>> 28);
+ break;
}
- buffer.writeByte(value);
return buffer;
}
+ // DivineMC end - Optimize VarInt
}
diff --git a/net/minecraft/network/VarLong.java b/net/minecraft/network/VarLong.java
index df9a85b19a9767c85f02837af6835f7ddb6c7dc3..77f090bc1b9225dd5a61d8c57c902fcdea8ed7cd 100644
--- a/net/minecraft/network/VarLong.java
+++ b/net/minecraft/network/VarLong.java
@@ -38,13 +38,122 @@ public class VarLong {
return l;
}
+ // DivineMC start - Optimize VarLong
public static ByteBuf write(ByteBuf buffer, long value) {
- while ((value & -128L) != 0L) {
- buffer.writeByte((int)(value & 127L) | 128);
- value >>>= 7;
+ if ((value & 0xFFFFFFFFFFFFFF80L) == 0) {
+ buffer.writeByte((int) value);
+ } else if (value < 0) {
+ int least7bits = (int) (value & 0xFFFFFFFL);
+ int w = (least7bits & 0x7F) << 24
+ | (least7bits & 0x3F80) << 9
+ | (least7bits & 0x1FC000) >> 6
+ | ((least7bits >>> 21) & 0x7F)
+ | 0x80808080;
+ long nonLeast7Bits = value >>> 28;
+ int secondLeast7bits = (int) (nonLeast7Bits & 0xFFFFFFFL);
+ int w2 = (secondLeast7bits & 0x7F) << 24
+ | ((secondLeast7bits & 0x3F80) << 9)
+ | (secondLeast7bits & 0x1FC000) >> 6
+ | (secondLeast7bits >>> 21)
+ | 0x80808080;
+ int thirdLeast7Bits = (int) (nonLeast7Bits >>> 28);
+ int w3 = (thirdLeast7Bits & 0x7F) << 8
+ | (thirdLeast7Bits >>> 7)
+ | 0x00008000;
+ buffer.writeInt(w);
+ buffer.writeInt(w2);
+ buffer.writeShort(w3);
+ } else if ((value & 0xFFFFFFFFFFFFC000L) == 0) {
+ int least7bits = (int) value;
+ int w = (least7bits & 0x7F) << 8
+ | (least7bits >>> 7)
+ | 0x00008000;
+ buffer.writeShort(w);
+ } else if ((value & 0xFFFFFFFFFFE00000L) == 0) {
+ int least7bits = (int) value;
+ int w = (least7bits & 0x7F) << 16
+ | (least7bits & 0x3F80) << 1
+ | (least7bits >>> 14)
+ | 0x00808000;
+ buffer.writeMedium(w);
+ } else if ((value & 0xFFFFFFFFF0000000L) == 0) {
+ int least7bits = (int) value;
+ int w = (least7bits & 0x7F) << 24
+ | ((least7bits & 0x3F80) << 9)
+ | (least7bits & 0x1FC000) >> 6
+ | (least7bits >>> 21)
+ | 0x80808000;
+ buffer.writeInt(w);
+ } else if ((value & 0xFFFFFFF800000000L) == 0) {
+ int least7bits = (int) (value & 0xFFFFFFFL);
+ int w = (least7bits & 0x7F) << 24
+ | (least7bits & 0x3F80) << 9
+ | (least7bits & 0x1FC000) >> 6
+ | ((least7bits >>> 21) & 0x7F)
+ | 0x80808080;
+ buffer.writeInt(w);
+ buffer.writeByte((int) (value >>> 28));
+ } else if ((value & 0xFFFFFC0000000000L) == 0) {
+ int least7bits = (int) (value & 0xFFFFFFFL);
+ int w = (least7bits & 0x7F) << 24
+ | (least7bits & 0x3F80) << 9
+ | (least7bits & 0x1FC000) >> 6
+ | ((least7bits >>> 21) & 0x7F)
+ | 0x80808080;
+ int secondLeast7bits = (int) (value >>> 28);
+ int w2 = (secondLeast7bits & 0x7F) << 8
+ | (secondLeast7bits >>> 7)
+ | 0x00008000;
+ buffer.writeInt(w);
+ buffer.writeShort(w2);
+ } else if ((value & 0xFFFE000000000000L) == 0) {
+ int least7bits = (int) (value & 0xFFFFFFFL);
+ int w = (least7bits & 0x7F) << 24
+ | (least7bits & 0x3F80) << 9
+ | (least7bits & 0x1FC000) >> 6
+ | ((least7bits >>> 21) & 0x7F)
+ | 0x80808080;
+ int secondLeast7bits = (int) (value >>> 28);
+ int w2 = (secondLeast7bits & 0x7F) << 16
+ | (secondLeast7bits & 0x3F80) << 1
+ | (secondLeast7bits >>> 14)
+ | 0x00808000;
+ buffer.writeInt(w);
+ buffer.writeMedium(w2);
+ } else if ((value & 0xFF00000000000000L) == 0) {
+ int least7bits = (int) (value & 0xFFFFFFFL);
+ int w = (least7bits & 0x7F) << 24
+ | (least7bits & 0x3F80) << 9
+ | (least7bits & 0x1FC000) >> 6
+ | ((least7bits >>> 21) & 0x7F)
+ | 0x80808080;
+ int secondLeast7bits = (int) (value >>> 28);
+ int w2 = (secondLeast7bits & 0x7F) << 24
+ | ((secondLeast7bits & 0x3F80) << 9)
+ | (secondLeast7bits & 0x1FC000) >> 6
+ | (secondLeast7bits >>> 21)
+ | 0x80808000;
+ buffer.writeInt(w);
+ buffer.writeInt(w2);
+ } else {
+ int least7bits = (int) (value & 0xFFFFFFFL);
+ int w = (least7bits & 0x7F) << 24
+ | (least7bits & 0x3F80) << 9
+ | (least7bits & 0x1FC000) >> 6
+ | ((least7bits >>> 21) & 0x7F)
+ | 0x80808080;
+ long nonLeast7Bits = value >>> 28;
+ int secondLeast7bits = (int) (nonLeast7Bits & 0xFFFFFFFL);
+ int w2 = (secondLeast7bits & 0x7F) << 24
+ | ((secondLeast7bits & 0x3F80) << 9)
+ | (secondLeast7bits & 0x1FC000) >> 6
+ | (secondLeast7bits >>> 21)
+ | 0x80808080;
+ buffer.writeInt(w);
+ buffer.writeInt(w2);
+ buffer.writeByte((int) (nonLeast7Bits >>> 28));
}
-
- buffer.writeByte((int)value);
return buffer;
}
+ // DivineMC end - Optimize VarLong
}

View File

@@ -3,9 +3,11 @@ From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Tue, 4 Feb 2025 19:52:24 +0300
Subject: [PATCH] Optimize Structure Generation
Original project: https://github.com/TelepathicGrunt/StructureLayoutOptimizer
Original license: MIT
diff --git a/net/minecraft/world/level/levelgen/structure/pools/JigsawPlacement.java b/net/minecraft/world/level/levelgen/structure/pools/JigsawPlacement.java
index 86a54586112b84b7c2026a4cbdad99cdf1c6ef81..e4ca880b5d16ae30676ec25c39c3d5b5f6cb3c24 100644
index 1cfa0fcd28685736fcdce4aef817e4d4cc4061cb..cd3b24a760053dcd650a1a263b3c0093a0cbb175 100644
--- a/net/minecraft/world/level/levelgen/structure/pools/JigsawPlacement.java
+++ b/net/minecraft/world/level/levelgen/structure/pools/JigsawPlacement.java
@@ -4,6 +4,8 @@ import com.google.common.collect.Lists;
@@ -17,7 +19,7 @@ index 86a54586112b84b7c2026a4cbdad99cdf1c6ef81..e4ca880b5d16ae30676ec25c39c3d5b5
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
@@ -292,6 +294,108 @@ public class JigsawPlacement {
@@ -288,6 +290,108 @@ public class JigsawPlacement {
this.random = random;
}
@@ -126,7 +128,7 @@ index 86a54586112b84b7c2026a4cbdad99cdf1c6ef81..e4ca880b5d16ae30676ec25c39c3d5b5
void tryPlacingChildren(
PoolElementStructurePiece piece,
MutableObject<VoxelShape> free,
@@ -349,9 +453,9 @@ public class JigsawPlacement {
@@ -345,9 +449,9 @@ public class JigsawPlacement {
mutableObject1 = free;
}
@@ -138,7 +140,7 @@ index 86a54586112b84b7c2026a4cbdad99cdf1c6ef81..e4ca880b5d16ae30676ec25c39c3d5b5
}
list.addAll(fallback.value().getShuffledTemplates(this.random));
@@ -362,10 +466,14 @@ public class JigsawPlacement {
@@ -358,10 +462,14 @@ public class JigsawPlacement {
break;
}
@@ -155,7 +157,7 @@ index 86a54586112b84b7c2026a4cbdad99cdf1c6ef81..e4ca880b5d16ae30676ec25c39c3d5b5
BoundingBox boundingBox1 = structurePoolElement.getBoundingBox(this.structureTemplateManager, BlockPos.ZERO, rotation1);
int i2;
if (useExpansionHack && boundingBox1.getYSpan() <= 16) {
@@ -398,7 +506,7 @@ public class JigsawPlacement {
@@ -394,7 +502,7 @@ public class JigsawPlacement {
}
for (StructureTemplate.JigsawBlockInfo jigsawBlockInfo1 : shuffledJigsawBlocks) {
@@ -164,7 +166,7 @@ index 86a54586112b84b7c2026a4cbdad99cdf1c6ef81..e4ca880b5d16ae30676ec25c39c3d5b5
BlockPos blockPos2 = jigsawBlockInfo1.info().pos();
BlockPos blockPos3 = blockPos1.subtract(blockPos2);
BoundingBox boundingBox2 = structurePoolElement.getBoundingBox(this.structureTemplateManager, blockPos3, rotation1);
@@ -427,9 +535,26 @@ public class JigsawPlacement {
@@ -423,9 +531,26 @@ public class JigsawPlacement {
boundingBox3.encapsulate(new BlockPos(boundingBox3.minX(), boundingBox3.minY() + max, boundingBox3.minZ()));
}
@@ -231,7 +233,7 @@ index 5c081a5b3d10f713e4e82fe1a43758f553fe50e0..85e84603a19964f05d9d5e62eb096ca7
+ // DivineMC end - Optimize Structure Generation
}
diff --git a/net/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate.java b/net/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate.java
index 5a05536e474bec574aa637f86bfc51f566d76ebf..e0f4500099c582653a81e6679be859e3d669bb88 100644
index f21e612a35d6ac4482dbf5d14e506959659e371a..c02c3b1fddd513cb477cbb7400c30a9ad57f80a6 100644
--- a/net/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate.java
+++ b/net/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate.java
@@ -255,6 +255,12 @@ public class StructureTemplate {

View File

@@ -206,10 +206,10 @@ index a491be4250de3199c3e1aa9e5482b568692bd2f5..c88826db76c28c536e6c36c5592d69c1
private static final String PREFIX = "data:image/png;base64,";
public static final Codec<ServerStatus.Favicon> CODEC = Codec.STRING.comapFlatMap(string -> {
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
index 7ac82a49e3c64d1a41a2870c5cf9900812329a57..978934f81ba023d7565d2e66c51f6ca249510702 100644
index ac35fc08574a72be356c48fb6e1cfafe36cd0860..dcd004749846aa9e650be438b0f097e414c2ec76 100644
--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -629,6 +629,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@@ -623,6 +623,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@Override
public boolean enforceSecureProfile() {
@@ -287,7 +287,7 @@ index 667ef5b2ab50eeb0491f7fe0bc8913ec29a4603a..a7c4fad2b1cb0cbac742a18d37d688bb
if (packet == null || this.processedDisconnect) { // Spigot
return;
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
index 8a67672f1175769ac213099331453fbae59442fa..5ebbb4e37469beef11bdfd1531b0d10f3d01c826 100644
index 2db120cd68447a4adc6f4ed6334fa52b8b55effc..84250c9786f4886fe4ab2e42808f8162da3f45d8 100644
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -276,7 +276,7 @@ public abstract class PlayerList {
@@ -299,7 +299,7 @@ index 8a67672f1175769ac213099331453fbae59442fa..5ebbb4e37469beef11bdfd1531b0d10f
)
);
player.getBukkitEntity().sendSupportedChannels(); // CraftBukkit
@@ -1318,6 +1318,7 @@ public abstract class PlayerList {
@@ -1333,6 +1333,7 @@ public abstract class PlayerList {
}
public boolean verifyChatTrusted(PlayerChatMessage message) {

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Lag compensation
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index abfecaf4467092f7baa02e0f5bbfd23d087f2aa3..77a693f42d90b5d17bf56d86b1676247c1ad505d 100644
index 824f9200b66639ad1e3e821c8ae2ea4c66fe0b30..dd88e4d0f72a482e4feea38bc194fc16799adf02 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -288,6 +288,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -16,7 +16,7 @@ index abfecaf4467092f7baa02e0f5bbfd23d087f2aa3..77a693f42d90b5d17bf56d86b1676247
public static <S extends MinecraftServer> S spin(Function<Thread, S> threadFunction) {
ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry.init(); // Paper - rewrite data converter system
@@ -1534,6 +1535,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1535,6 +1536,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
this.server.spark.tickStart(); // Paper - spark
@@ -25,18 +25,18 @@ index abfecaf4467092f7baa02e0f5bbfd23d087f2aa3..77a693f42d90b5d17bf56d86b1676247
this.tickCount++;
this.tickRateManager.tick();
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
index efda5818ac05cbf06b93a1c983d6e3b18412ca86..ebd4b7c36e1cece8730782764c476756feebc211 100644
index 4a2cace22512fe06c1713bc8735e775e3012f3bc..85c4d709b6d04e8f43baf7b900ee59eae5d98fe0 100644
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -216,6 +216,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
public boolean hasEntityMoveEvent; // Paper - Add EntityMoveEvent
private final alternate.current.wire.WireHandler wireHandler = new alternate.current.wire.WireHandler(this); // Paper - optimize redstone (Alternate Current)
public boolean hasRidableMoveEvent = false; // Purpur - Ridables
public net.minecraft.world.item.ItemStack ominousBanner; // DivineMC - Optimize Raids
+ public org.bxteam.divinemc.util.tps.TPSCalculator tpsCalculator = new org.bxteam.divinemc.util.tps.TPSCalculator(); // DivineMC - Lag Compensation
@Override
public @Nullable LevelChunk getChunkIfLoaded(int x, int z) {
@@ -764,6 +765,8 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -763,6 +764,8 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
}
}
@@ -66,10 +66,10 @@ index efda5818ac05cbf06b93a1c983d6e3b18412ca86..ebd4b7c36e1cece8730782764c476756
this.serverLevelData.setDayTime(time);
// Purpur start - Configurable daylight cycle
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
index b8bd792293cb5985db5e5dfa5644930971a34632..a24829b705945fbda1058d9848b829500e727304 100644
index 33f33a51a7016e214bca1aec8e6cc3910ec3bb42..327b3b1463caafc69e6a5dc0eee577f4af49d202 100644
--- a/net/minecraft/world/entity/LivingEntity.java
+++ b/net/minecraft/world/entity/LivingEntity.java
@@ -517,6 +517,7 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
@@ -523,6 +523,7 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
}
}
@@ -77,7 +77,7 @@ index b8bd792293cb5985db5e5dfa5644930971a34632..a24829b705945fbda1058d9848b82950
this.tickEffects();
this.yHeadRotO = this.yHeadRot;
this.yBodyRotO = this.yBodyRot;
@@ -524,6 +525,17 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
@@ -530,6 +531,17 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
this.xRotO = this.getXRot();
}
@@ -183,7 +183,7 @@ index 40cb5e6bbcf9dbdb400f1503e86c0804b60e07be..d5352cbb4a64631a0a831de880efa21e
BlocksAttacks blocksAttacks = stack.get(DataComponents.BLOCKS_ATTACKS);
return blocksAttacks != null ? 72000 : 0;
diff --git a/net/minecraft/world/level/GameRules.java b/net/minecraft/world/level/GameRules.java
index 2d9bf302b779602d733187c6f86e52467f0dc540..69196d7e43054955137569b22c4ca40adff3b1d8 100644
index d510503a8ad272255aeba20a916642828023fd19..2def087994cb6676b6346e7062fd050e7e346c05 100644
--- a/net/minecraft/world/level/GameRules.java
+++ b/net/minecraft/world/level/GameRules.java
@@ -366,8 +366,31 @@ public class GameRules {
@@ -248,7 +248,7 @@ index 8db95b74f88f8096de93115ae8d3fb2e6184ad3b..e044830439fe9821ab3f62695d318a63
}
diff --git a/net/minecraft/world/level/chunk/LevelChunk.java b/net/minecraft/world/level/chunk/LevelChunk.java
index 53c77efe2f86c5dfb5f02fa0b1886e8cda2e3862..f534f7983424ff3a72809a4f6c20bbed83a54b42 100644
index 32f17328b7980a9dc382c90af76cca04b74c639a..6f25be39103cd0bb26bc365d9599b9846c6fe133 100644
--- a/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/net/minecraft/world/level/chunk/LevelChunk.java
@@ -917,6 +917,19 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p

View File

@@ -36,10 +36,10 @@ index 758ce439d2e10e6ef42a58d147a77093667e0acd..de622982f864d96a5b76efcd69f1836e
new java.util.concurrent.LinkedBlockingQueue<>(),
new com.google.common.util.concurrent.ThreadFactoryBuilder()
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 23144971acc04bbeacd719dafe2363d1618153b9..7dbefd83d164a7d97a56b02862fef3b2f17d5aab 100644
index dd88e4d0f72a482e4feea38bc194fc16799adf02..2baa4dc93bcc448ce65bae50ca39d41e562e2211 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -2639,8 +2639,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -2640,8 +2640,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
}
@@ -54,10 +54,10 @@ index 23144971acc04bbeacd719dafe2363d1618153b9..7dbefd83d164a7d97a56b02862fef3b2
public ChatDecorator getChatDecorator() {
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index ff34cc2007e274dd3067ebb75ed39efa7dda041e..ad8a21401a54c3dc8c8a85a98b66a4822b817293 100644
index 1bd6368704665f90eaa621366b4dec21bc937a96..7b10fe7cf66757ed68f9e39e03259700dfabf184 100644
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -842,8 +842,11 @@ public class ServerGamePacketListenerImpl
@@ -838,8 +838,11 @@ public class ServerGamePacketListenerImpl
}
// Paper start - AsyncTabCompleteEvent
@@ -71,23 +71,6 @@ index ff34cc2007e274dd3067ebb75ed39efa7dda041e..ad8a21401a54c3dc8c8a85a98b66a482
// Paper end - AsyncTabCompleteEvent
@Override
diff --git a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
index 20ba45054c243fbb85e50cf0bdf75648730cb0bc..10aecbb88a9a3dae3ecdf28aa449f1a1475a1905 100644
--- a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
@@ -53,7 +53,11 @@ import org.bukkit.event.player.PlayerPreLoginEvent;
public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener, TickablePacketListener {
private static final AtomicInteger UNIQUE_THREAD_ID = new AtomicInteger(0);
static final Logger LOGGER = LogUtils.getLogger();
- private static final java.util.concurrent.ExecutorService authenticatorPool = java.util.concurrent.Executors.newCachedThreadPool(new com.google.common.util.concurrent.ThreadFactoryBuilder().setNameFormat("User Authenticator #%d").setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER)).build()); // Paper - Cache authenticator threads
+ // DivineMC start - Virtual Threads
+ private static final java.util.concurrent.ExecutorService authenticatorPool = org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.virtualThreadsEnabled && org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.virtualAuthenticatorScheduler
+ ? java.util.concurrent.Executors.newVirtualThreadPerTaskExecutor()
+ : java.util.concurrent.Executors.newCachedThreadPool(new com.google.common.util.concurrent.ThreadFactoryBuilder().setNameFormat("User Authenticator #%d").setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER)).build()); // Paper - Cache authenticator threads
+ // DivineMC end - Virtual Threads
private static final int MAX_TICKS_BEFORE_LOGIN = 600;
private final byte[] challenge;
final MinecraftServer server;
diff --git a/net/minecraft/server/network/ServerTextFilter.java b/net/minecraft/server/network/ServerTextFilter.java
index b3d46e7687c572d9847124eb58e4a6011a78066c..9d2e2b1cff68383cd19b42e24559e3009ef1df54 100644
--- a/net/minecraft/server/network/ServerTextFilter.java

View File

@@ -0,0 +1,185 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Mon, 3 Mar 2025 19:29:13 +0300
Subject: [PATCH] Async Chunk Sending
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
index 1ed2ae41e47b2446bf1835efc8bad369408d52da..c4a1e3908cf8e1b0614ff6c3a0f5f6708a7667e5 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
@@ -441,7 +441,13 @@ public final class RegionizedPlayerChunkLoader {
// Note: drop isAlive() check so that chunks properly unload client-side when the player dies
((ChunkSystemChunkHolder)((ChunkSystemServerLevel)this.world).moonrise$getChunkTaskScheduler().chunkHolderManager
.getChunkHolder(chunkX, chunkZ).vanillaChunkHolder).moonrise$removeReceivedChunk(this.player);
- this.player.connection.send(new ClientboundForgetLevelChunkPacket(new ChunkPos(chunkX, chunkZ)));
+ // DivineMC start - Async Chunk Sending
+ if (org.bxteam.divinemc.config.DivineConfig.AsyncCategory.asyncChunkSendingEnabled) {
+ org.bxteam.divinemc.async.AsyncChunkSend.POOL.execute(() -> this.player.connection.send(new ClientboundForgetLevelChunkPacket(new ChunkPos(chunkX, chunkZ))));
+ } else {
+ this.player.connection.send(new ClientboundForgetLevelChunkPacket(new ChunkPos(chunkX, chunkZ)));
+ }
+ // DivineMC end - Async Chunk Sending
// Paper start - PlayerChunkUnloadEvent
if (io.papermc.paper.event.packet.PlayerChunkUnloadEvent.getHandlerList().getRegisteredListeners().length > 0) {
new io.papermc.paper.event.packet.PlayerChunkUnloadEvent(player.getBukkitEntity().getWorld().getChunkAt(new ChunkPos(chunkX, chunkZ).longKey), player.getBukkitEntity()).callEvent();
diff --git a/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java b/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
index 9f6d7c5dc0e591488a8a3763d8a1f1b3671d5299..4983a34e42ef972f2d5ad8a12dfad99ca88d7032 100644
--- a/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
+++ b/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
@@ -75,6 +75,52 @@ public class ClientboundLevelChunkPacketData {
}
}
+ // DivineMC start - Async Chunk Sending
+ public ClientboundLevelChunkPacketData(LevelChunk levelChunk, io.papermc.paper.antixray.ChunkPacketInfo<net.minecraft.world.level.block.state.BlockState> chunkPacketInfo, BlockEntity[] blockEntities, Map<Heightmap.Types, long[]> heightmaps) {
+ this.heightmaps = heightmaps;
+
+ if (Thread.currentThread() instanceof org.bxteam.divinemc.async.AsyncChunkSend.AsyncChunkSendThread) {
+ int size = calculateChunkSize(levelChunk);
+ ByteBuf buffer = Unpooled.buffer(size);
+ extractChunkData(new FriendlyByteBuf(buffer), levelChunk, chunkPacketInfo);
+ // make sure all sections is latest
+ while (size != buffer.writerIndex()) {
+ buffer.writerIndex(0);
+ size = calculateChunkSize(levelChunk);
+ extractChunkData(new FriendlyByteBuf(buffer), levelChunk, chunkPacketInfo);
+ }
+ byte[] array = it.unimi.dsi.fastutil.bytes.ByteArrays.setLength(buffer.array(), buffer.writerIndex());
+ if (chunkPacketInfo != null) {
+ chunkPacketInfo.setBuffer(array);
+ }
+ this.buffer = array;
+ } else {
+ this.buffer = new byte[calculateChunkSize(levelChunk)];
+ // Paper start - Anti-Xray - Add chunk packet info
+ if (chunkPacketInfo != null) {
+ chunkPacketInfo.setBuffer(this.buffer);
+ }
+ extractChunkData(new FriendlyByteBuf(this.getWriteBuffer()), levelChunk, chunkPacketInfo);
+ }
+
+ this.blockEntitiesData = Lists.newArrayList();
+ int totalTileEntities = 0; // Paper - Handle oversized block entities in chunks
+
+ for (BlockEntity blockEntity : blockEntities) {
+ // Paper start - Handle oversized block entities in chunks
+ if (++totalTileEntities > BLOCK_ENTITY_LIMIT) {
+ net.minecraft.network.protocol.Packet<ClientGamePacketListener> packet = blockEntity.getUpdatePacket();
+ if (packet != null) {
+ this.extraPackets.add(packet);
+ continue;
+ }
+ }
+ // Paper end - Handle oversized block entities in chunks
+ this.blockEntitiesData.add(ClientboundLevelChunkPacketData.BlockEntityInfo.create(blockEntity));
+ }
+ }
+ // DivineMC end - Async Chunk Sending
+
public ClientboundLevelChunkPacketData(RegistryFriendlyByteBuf buffer, int x, int z) {
this.heightmaps = HEIGHTMAPS_STREAM_CODEC.decode(buffer);
int varInt = buffer.readVarInt();
@@ -123,6 +169,8 @@ public class ClientboundLevelChunkPacketData {
// Paper end - Anti-Xray - Add chunk packet info
}
+ if (Thread.currentThread() instanceof org.bxteam.divinemc.async.AsyncChunkSend.AsyncChunkSendThread) return; // DivineMC - Async Chunk Sending
+
if (buffer.writerIndex() != buffer.capacity()) {
throw new IllegalStateException("Didn't fill chunk buffer: expected " + buffer.capacity() + " bytes, got " + buffer.writerIndex());
}
diff --git a/net/minecraft/network/protocol/game/ClientboundLevelChunkWithLightPacket.java b/net/minecraft/network/protocol/game/ClientboundLevelChunkWithLightPacket.java
index 8578d1f78ddd1bb75f3230f04bfaa35af9f5f822..7c55fabd264e4e813d68798433dfccfb170537a2 100644
--- a/net/minecraft/network/protocol/game/ClientboundLevelChunkWithLightPacket.java
+++ b/net/minecraft/network/protocol/game/ClientboundLevelChunkWithLightPacket.java
@@ -45,6 +45,18 @@ public class ClientboundLevelChunkWithLightPacket implements Packet<ClientGamePa
chunk.getLevel().chunkPacketBlockController.modifyBlocks(this, chunkPacketInfo); // Paper - Anti-Xray - Modify blocks
}
+ // DivineMC start - Async Chunk Sending
+ public ClientboundLevelChunkWithLightPacket(LevelChunk chunk, LevelLightEngine lightEngine, @Nullable BitSet skyLight, @Nullable BitSet blockLight, boolean modifyBlocks, net.minecraft.world.level.block.entity.BlockEntity[] blockEntities, java.util.Map<net.minecraft.world.level.levelgen.Heightmap.Types, long[]> heightmaps) {
+ ChunkPos pos = chunk.getPos();
+ this.x = pos.x;
+ this.z = pos.z;
+ io.papermc.paper.antixray.ChunkPacketInfo<net.minecraft.world.level.block.state.BlockState> chunkPacketInfo = modifyBlocks ? chunk.getLevel().chunkPacketBlockController.getChunkPacketInfo(this, chunk) : null; // Paper - Ant-Xray
+ this.chunkData = new ClientboundLevelChunkPacketData(chunk, chunkPacketInfo, blockEntities, heightmaps); // Paper - Anti-Xray
+ this.lightData = new ClientboundLightUpdatePacketData(pos, lightEngine, skyLight, blockLight);
+ chunk.getLevel().chunkPacketBlockController.modifyBlocks(this, chunkPacketInfo); // Paper - Anti-Xray - Modify blocks
+ }
+ // DivineMC end - Async Chunk Sending
+
private ClientboundLevelChunkWithLightPacket(RegistryFriendlyByteBuf buffer) {
this.x = buffer.readInt();
this.z = buffer.readInt();
diff --git a/net/minecraft/server/network/PlayerChunkSender.java b/net/minecraft/server/network/PlayerChunkSender.java
index 0376a10ee0544b13e8fd629a7b13f78811e57a30..68c34ebf4dcf280aca6be27f3e34a5a74934ff45 100644
--- a/net/minecraft/server/network/PlayerChunkSender.java
+++ b/net/minecraft/server/network/PlayerChunkSender.java
@@ -64,13 +64,25 @@ public class PlayerChunkSender {
if (!list.isEmpty()) {
ServerGamePacketListenerImpl serverGamePacketListenerImpl = player.connection;
this.unacknowledgedBatches++;
- serverGamePacketListenerImpl.send(ClientboundChunkBatchStartPacket.INSTANCE);
+ // DivineMC start - Async Chunk Sending
+ if (org.bxteam.divinemc.config.DivineConfig.AsyncCategory.asyncChunkSendingEnabled) {
+ org.bxteam.divinemc.async.AsyncChunkSend.POOL.execute(() -> serverGamePacketListenerImpl.send(ClientboundChunkBatchStartPacket.INSTANCE));
+ } else {
+ serverGamePacketListenerImpl.send(ClientboundChunkBatchStartPacket.INSTANCE);
+ }
+ // DivineMC end - Async Chunk Sending
for (LevelChunk levelChunk : list) {
sendChunk(serverGamePacketListenerImpl, serverLevel, levelChunk);
}
- serverGamePacketListenerImpl.send(new ClientboundChunkBatchFinishedPacket(list.size()));
+ // DivineMC start - Async Chunk Sending
+ if (org.bxteam.divinemc.config.DivineConfig.AsyncCategory.asyncChunkSendingEnabled) {
+ org.bxteam.divinemc.async.AsyncChunkSend.POOL.execute(() -> serverGamePacketListenerImpl.send(new ClientboundChunkBatchFinishedPacket(list.size())));
+ } else {
+ serverGamePacketListenerImpl.send(new ClientboundChunkBatchFinishedPacket(list.size()));
+ }
+ // DivineMC end - Async Chunk Sending
this.batchQuota = this.batchQuota - list.size();
}
}
@@ -81,7 +93,24 @@ public class PlayerChunkSender {
// Paper start - Anti-Xray
public static void sendChunk(ServerGamePacketListenerImpl packetListener, ServerLevel level, LevelChunk chunk) {
final boolean shouldModify = level.chunkPacketBlockController.shouldModify(packetListener.player, chunk);
- packetListener.send(new ClientboundLevelChunkWithLightPacket(chunk, level.getLightEngine(), null, null, shouldModify));
+
+ // DivineMC start - Async Chunk Sending
+ if (org.bxteam.divinemc.config.DivineConfig.AsyncCategory.asyncChunkSendingEnabled) {
+ var blockEntities = chunk.blockEntities.values().toArray(new net.minecraft.world.level.block.entity.BlockEntity[0]);
+ java.util.Map<net.minecraft.world.level.levelgen.Heightmap.Types, long[]> heightmaps = new java.util.concurrent.ConcurrentHashMap<>();
+
+ for (var entry : chunk.getHeightmaps()) {
+ if (entry.getKey().sendToClient()) {
+ heightmaps.put(entry.getKey(), entry.getValue().getRawData());
+ }
+ }
+
+ org.bxteam.divinemc.async.AsyncChunkSend.POOL.execute(() -> packetListener.send(new ClientboundLevelChunkWithLightPacket(chunk, level.getLightEngine(), null, null, shouldModify, blockEntities, heightmaps)));
+ } else {
+ packetListener.send(new ClientboundLevelChunkWithLightPacket(chunk, level.getLightEngine(), null, null, shouldModify));
+ }
+ // DivineMC end - Async Chunk Sending
+
// Paper end - Anti-Xray
// Paper start - PlayerChunkLoadEvent
if (io.papermc.paper.event.packet.PlayerChunkLoadEvent.getHandlerList().getRegisteredListeners().length > 0) {
diff --git a/net/minecraft/world/level/chunk/LevelChunkSection.java b/net/minecraft/world/level/chunk/LevelChunkSection.java
index df717c545472006b99532280c38c1fbef12bcf82..ba4c20df405f41a526273a6216d2aedf4e5c435e 100644
--- a/net/minecraft/world/level/chunk/LevelChunkSection.java
+++ b/net/minecraft/world/level/chunk/LevelChunkSection.java
@@ -18,7 +18,7 @@ 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
+ volatile short nonEmptyBlockCount; // Paper - package private // DivineMC - Async Chunk Sending
private short tickingBlockCount;
private short tickingFluidCount;
public final PalettedContainer<BlockState> states;

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Command block parse results caching
diff --git a/net/minecraft/world/level/BaseCommandBlock.java b/net/minecraft/world/level/BaseCommandBlock.java
index 625fffa596e1067d3f0e3402ea8c739f84298730..17a5cee6b06e6b3efff4c690a116f9001eabde00 100644
index 13950339598f4ec705c54275342fa17ff2e74ca9..5791910babe010d3bdc00a5dd4486f00358df14f 100644
--- a/net/minecraft/world/level/BaseCommandBlock.java
+++ b/net/minecraft/world/level/BaseCommandBlock.java
@@ -34,6 +34,10 @@ public abstract class BaseCommandBlock implements CommandSource {

View File

@@ -5,22 +5,22 @@ Subject: [PATCH] Player ProfileResult caching
diff --git a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
index 10aecbb88a9a3dae3ecdf28aa449f1a1475a1905..13b468d4d3b92bf71fdfa112dfe56464c4f9dbed 100644
index 20ba45054c243fbb85e50cf0bdf75648730cb0bc..443aebb71b2a55ee9dcd2dd4bf9a30fbb8da9e49 100644
--- a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
@@ -75,6 +75,11 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
@@ -71,6 +71,11 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
public @Nullable java.util.UUID requestedUuid; // Paper
private final io.papermc.paper.connection.PaperPlayerLoginConnection paperLoginConnection; // Paper - Config API
private volatile boolean disconnecting = false; // Paper - Fix disconnect still ticking login
+ // DivineMC start - Player ProfileResult caching
+ private static final com.google.common.cache.Cache<String, ProfileResult> playerProfileResultCache = com.google.common.cache.CacheBuilder.newBuilder()
+ .expireAfterWrite(1, java.util.concurrent.TimeUnit.MINUTES)
+ .expireAfterWrite(org.bxteam.divinemc.config.DivineConfig.NetworkCategory.playerProfileResultCachingTimeout, java.util.concurrent.TimeUnit.MINUTES)
+ .build();
+ // DivineMC end - Player ProfileResult caching
public ServerLoginPacketListenerImpl(MinecraftServer server, Connection connection, boolean transferred) {
this.server = server;
@@ -260,9 +265,23 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
@@ -256,9 +261,23 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
String string1 = Objects.requireNonNull(ServerLoginPacketListenerImpl.this.requestedUsername, "Player name not initialized");
try {

View File

@@ -64,10 +64,10 @@ index 25150731bb3f3d04b248ebc47fc9b453e49a705e..75c8ce32e68f92e20201e9c243f46f2b
}
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
index 5f2c27800f047f128857044493a6d9325ffd759b..9dcb9e5ecc31fcc3fc7547a47ec98d2689698769 100644
index 85c4d709b6d04e8f43baf7b900ee59eae5d98fe0..421b59b24bda3d03dea8fd0fc6237a71900e1cdc 100644
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -627,6 +627,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -629,6 +629,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
chunkGenerator = new org.bukkit.craftbukkit.generator.CustomChunkGenerator(this, chunkGenerator, gen);
}
// CraftBukkit end
@@ -93,7 +93,7 @@ index b299fc08fe900b4d48ce3e6986bcea000253053e..4dc68a03f607cacbf7f1bf9c08a4cbc1
final double maxHeightSlimeChunk = level.getMinecraftWorld().paperConfig().entities.spawning.slimeSpawnHeight.slimeChunk.maximum;
if (random.nextInt(10) == 0 && flag && pos.getY() < maxHeightSlimeChunk) {
diff --git a/net/minecraft/world/level/chunk/ChunkAccess.java b/net/minecraft/world/level/chunk/ChunkAccess.java
index 182c14b660f8860bed627eed4e01fd4002153e9a..5e9f3856c384dbb2bd462121b903cd2b326e4376 100644
index 81511de113c292549fe5fe720a15bf3e0497ca84..19f74518923783d8d5560b526a1f267dabd23156 100644
--- a/net/minecraft/world/level/chunk/ChunkAccess.java
+++ b/net/minecraft/world/level/chunk/ChunkAccess.java
@@ -83,6 +83,10 @@ public abstract class ChunkAccess implements BiomeManager.NoiseBiomeSource, Ligh
@@ -107,7 +107,7 @@ index 182c14b660f8860bed627eed4e01fd4002153e9a..5e9f3856c384dbb2bd462121b903cd2b
// CraftBukkit start - SPIGOT-6814: move to IChunkAccess to account for 1.17 to 1.18 chunk upgrading.
private static final org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry();
public org.bukkit.craftbukkit.persistence.DirtyCraftPersistentDataContainer persistentDataContainer = new org.bukkit.craftbukkit.persistence.DirtyCraftPersistentDataContainer(ChunkAccess.DATA_TYPE_REGISTRY);
@@ -192,6 +196,17 @@ public abstract class ChunkAccess implements BiomeManager.NoiseBiomeSource, Ligh
@@ -193,6 +197,17 @@ public abstract class ChunkAccess implements BiomeManager.NoiseBiomeSource, Ligh
return GameEventListenerRegistry.NOOP;
}
@@ -412,10 +412,10 @@ index 1f939b325ec5291b3c4aabc4735c863f9436a6f8..0a544577922bef471d2f07544ad45ce2
}
diff --git a/net/minecraft/world/level/levelgen/structure/pools/JigsawPlacement.java b/net/minecraft/world/level/levelgen/structure/pools/JigsawPlacement.java
index 1cfa0fcd28685736fcdce4aef817e4d4cc4061cb..86a54586112b84b7c2026a4cbdad99cdf1c6ef81 100644
index cd3b24a760053dcd650a1a263b3c0093a0cbb175..e4ca880b5d16ae30676ec25c39c3d5b5f6cb3c24 100644
--- a/net/minecraft/world/level/levelgen/structure/pools/JigsawPlacement.java
+++ b/net/minecraft/world/level/levelgen/structure/pools/JigsawPlacement.java
@@ -64,7 +64,11 @@ public class JigsawPlacement {
@@ -66,7 +66,11 @@ public class JigsawPlacement {
ChunkGenerator chunkGenerator = context.chunkGenerator();
StructureTemplateManager structureTemplateManager = context.structureTemplateManager();
LevelHeightAccessor levelHeightAccessor = context.heightAccessor();

View File

@@ -31,7 +31,7 @@ index ca21597263cb430e2a5ae07e8cecfb0d53a270d2..226088405c019922085285ba5d04d7c1
}
}
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
index ebd4b7c36e1cece8730782764c476756feebc211..324c573899965b204cec17458b6cb9733d83a868 100644
index 421b59b24bda3d03dea8fd0fc6237a71900e1cdc..78bf3365b426e7090182af84630111d410a2460e 100644
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -802,6 +802,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -43,7 +43,7 @@ index ebd4b7c36e1cece8730782764c476756feebc211..324c573899965b204cec17458b6cb973
if (!tickRateManager.isEntityFrozen(entity)) {
entity.checkDespawn();
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 9971c034391c13237dc403cdc9f8806b3bfc69f4..1e201ff091bdf33c96e2cfa333030ae105ab7bc9 100644
index 5bc7f37290eb99145a2ea3e40d31180f3494979b..bdf9899f960b6cca3529af97ebff738761208439 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -365,6 +365,8 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -210,7 +210,7 @@ index 6931bc84594362579a1832cb8ccda501e9fb0631..4e84f2faef81ba596ff1017a666c34cd
public static AttributeSupplier.Builder createAttributes() {
diff --git a/net/minecraft/world/entity/animal/frog/Frog.java b/net/minecraft/world/entity/animal/frog/Frog.java
index 81f0e444ccb6962d675e3a097341683d504d0889..1c9f3f0b2a344c026532c89c0db377ab8183c912 100644
index c6e4966d3e4fdb7c91577fc1693fb66930b4f3dc..85963b74a533beb7883ea417ceb3c21d834aebe0 100644
--- a/net/minecraft/world/entity/animal/frog/Frog.java
+++ b/net/minecraft/world/entity/animal/frog/Frog.java
@@ -106,6 +106,7 @@ public class Frog extends Animal {
@@ -239,7 +239,7 @@ index 81f0e444ccb6962d675e3a097341683d504d0889..1c9f3f0b2a344c026532c89c0db377ab
@Override
diff --git a/net/minecraft/world/entity/animal/frog/Tadpole.java b/net/minecraft/world/entity/animal/frog/Tadpole.java
index c0e12a6e5dd2b7e12e4cc40f6795228de6b470cc..d8eb93431f4ef8720ccfd58cf5e7942ccb1184c2 100644
index f85626b690b02908fac3979d277b293ec48aa451..30eeb222753d6c715a2d3066e74ef3fa148c904f 100644
--- a/net/minecraft/world/entity/animal/frog/Tadpole.java
+++ b/net/minecraft/world/entity/animal/frog/Tadpole.java
@@ -65,6 +65,7 @@ public class Tadpole extends AbstractFish {
@@ -268,7 +268,7 @@ index c0e12a6e5dd2b7e12e4cc40f6795228de6b470cc..d8eb93431f4ef8720ccfd58cf5e7942c
public static AttributeSupplier.Builder createAttributes() {
diff --git a/net/minecraft/world/entity/animal/goat/Goat.java b/net/minecraft/world/entity/animal/goat/Goat.java
index 36fcc913385afec8bb66c1664b902e4d6868f11d..ec72612cb69a2483349e29eb88063ed717a60029 100644
index 997cff138d5c99b1be9224cb3c96bdfeeb79915a..217cd170041807b9eb520ec1f7363fb75e0b6b55 100644
--- a/net/minecraft/world/entity/animal/goat/Goat.java
+++ b/net/minecraft/world/entity/animal/goat/Goat.java
@@ -94,6 +94,7 @@ public class Goat extends Animal {
@@ -369,7 +369,7 @@ index 94c1e65a4d7d59e967f31c2692e9b448faf67a55..472f48965dc7806ca751a397cbe1b048
@Override
diff --git a/net/minecraft/world/entity/monster/warden/Warden.java b/net/minecraft/world/entity/monster/warden/Warden.java
index 0440cbbc0d6657f32dc37a1dbbe9ee78f8e229cf..4944b6d389c65511eed75d580779f912b8ff076d 100644
index 021aa51da04bea01b0e827390ce1690af7092b8f..7bfc597655cc55c46b65c9726a6e9de9f3f5afc8 100644
--- a/net/minecraft/world/entity/monster/warden/Warden.java
+++ b/net/minecraft/world/entity/monster/warden/Warden.java
@@ -108,6 +108,7 @@ public class Warden extends Monster implements VibrationSystem {

View File

@@ -1,7 +1,7 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Tue, 28 Jan 2025 01:04:55 +0300
Subject: [PATCH] Async Pathfinding
Subject: [PATCH] Petal: Async Pathfinding
Original code by Bloom-host, licensed under GPL v3
You can find the original code on https://github.com/Bloom-host/Petal
@@ -9,7 +9,7 @@ You can find the original code on https://github.com/Bloom-host/Petal
Makes most pathfinding-related work happen asynchronously
diff --git a/net/minecraft/world/entity/ai/behavior/AcquirePoi.java b/net/minecraft/world/entity/ai/behavior/AcquirePoi.java
index 67cbf9f5760fae5db6f31e64095cd1b6be6ade8e..327a0414c8723420ffe34597464c1772768e8fa3 100644
index 67cbf9f5760fae5db6f31e64095cd1b6be6ade8e..3e7db8ef9ba48d42e8373296031301308573b154 100644
--- a/net/minecraft/world/entity/ai/behavior/AcquirePoi.java
+++ b/net/minecraft/world/entity/ai/behavior/AcquirePoi.java
@@ -94,21 +94,18 @@ public class AcquirePoi {
@@ -29,7 +29,7 @@ index 67cbf9f5760fae5db6f31e64095cd1b6be6ade8e..327a0414c8723420ffe34597464c1772
+ if (org.bxteam.divinemc.config.DivineConfig.AsyncCategory.asyncPathfinding) {
+ Path possiblePath = findPathToPois(mob, set);
+
+ org.bxteam.divinemc.entity.pathfinding.AsyncPathProcessor.awaitProcessing(possiblePath, path -> {
+ org.bxteam.divinemc.async.pathfinding.AsyncPathProcessor.awaitProcessing(possiblePath, path -> {
+ processPath(acquirablePois, entityEventId, (Long2ObjectMap<JitteredLinearRetry>) map, memoryAccessor, level, mob, time, poiManager, set, path);
});
} else {
@@ -222,7 +222,7 @@ index 621ba76784f2b92790eca62be4d0688834335ab6..92d8899ff7d42ecc987a7bf2035cc724
private boolean tryComputePath(Mob mob, WalkTarget target, long time) {
BlockPos blockPos = target.getTarget().currentBlockPosition();
diff --git a/net/minecraft/world/entity/ai/behavior/SetClosestHomeAsWalkTarget.java b/net/minecraft/world/entity/ai/behavior/SetClosestHomeAsWalkTarget.java
index 4f9f3367b1ca3903df03a80fa2b01a3d24e6e77d..87f218cbeda68d2996a354afabb8be70f513920e 100644
index 4f9f3367b1ca3903df03a80fa2b01a3d24e6e77d..48b7e91191192266d57f4d4692d1865cbddae5c0 100644
--- a/net/minecraft/world/entity/ai/behavior/SetClosestHomeAsWalkTarget.java
+++ b/net/minecraft/world/entity/ai/behavior/SetClosestHomeAsWalkTarget.java
@@ -60,17 +60,18 @@ public class SetClosestHomeAsWalkTarget {
@@ -243,7 +243,7 @@ index 4f9f3367b1ca3903df03a80fa2b01a3d24e6e77d..87f218cbeda68d2996a354afabb8be70
+ if (org.bxteam.divinemc.config.DivineConfig.AsyncCategory.asyncPathfinding) {
+ Path possiblePath = AcquirePoi.findPathToPois(mob, set);
+
+ org.bxteam.divinemc.entity.pathfinding.AsyncPathProcessor.awaitProcessing(possiblePath, path -> {
+ org.bxteam.divinemc.async.pathfinding.AsyncPathProcessor.awaitProcessing(possiblePath, path -> {
+ processPath(speedModifier, map, mutableLong, walkTarget, level, poiManager, mutableInt, path);
+ });
+ } else {
@@ -295,7 +295,7 @@ index 73bba480f3f017a8aed14562bd82ba33db04391c..b31976b68eec3cd0ab0620a487e99ecd
Node node = path.getNode(i);
this.doorPos = new BlockPos(node.x, node.y + 1, node.z);
diff --git a/net/minecraft/world/entity/ai/navigation/AmphibiousPathNavigation.java b/net/minecraft/world/entity/ai/navigation/AmphibiousPathNavigation.java
index 458ceec68ca138b0aa9b70d6c934473c01d468f4..62e385f40294c2343ce0a3deb95229057539503b 100644
index 458ceec68ca138b0aa9b70d6c934473c01d468f4..ff06ba3ede2f2e40aae8f9a0b997150cfaaeecb7 100644
--- a/net/minecraft/world/entity/ai/navigation/AmphibiousPathNavigation.java
+++ b/net/minecraft/world/entity/ai/navigation/AmphibiousPathNavigation.java
@@ -12,9 +12,25 @@ public class AmphibiousPathNavigation extends PathNavigation {
@@ -303,7 +303,7 @@ index 458ceec68ca138b0aa9b70d6c934473c01d468f4..62e385f40294c2343ce0a3deb9522905
}
+ // DivineMC start - async path processing
+ private static final org.bxteam.divinemc.entity.pathfinding.NodeEvaluatorGenerator nodeEvaluatorGenerator = (org.bxteam.divinemc.entity.pathfinding.NodeEvaluatorFeatures nodeEvaluatorFeatures) -> {
+ private static final org.bxteam.divinemc.async.pathfinding.NodeEvaluatorGenerator nodeEvaluatorGenerator = (org.bxteam.divinemc.async.pathfinding.NodeEvaluatorFeatures nodeEvaluatorFeatures) -> {
+ AmphibiousNodeEvaluator nodeEvaluator = new AmphibiousNodeEvaluator(false);
+ nodeEvaluator.setCanPassDoors(nodeEvaluatorFeatures.canPassDoors());
+ nodeEvaluator.setCanFloat(nodeEvaluatorFeatures.canFloat());
@@ -325,7 +325,7 @@ index 458ceec68ca138b0aa9b70d6c934473c01d468f4..62e385f40294c2343ce0a3deb9522905
}
diff --git a/net/minecraft/world/entity/ai/navigation/FlyingPathNavigation.java b/net/minecraft/world/entity/ai/navigation/FlyingPathNavigation.java
index 077863b758fbc3e51f25bcf842d00a2cc07c6a2f..4b2cc7fa8848b6cb15cc82090bf37bcdd16f098a 100644
index 077863b758fbc3e51f25bcf842d00a2cc07c6a2f..b544685d191af2dcf3742abe45693b1eab0507e8 100644
--- a/net/minecraft/world/entity/ai/navigation/FlyingPathNavigation.java
+++ b/net/minecraft/world/entity/ai/navigation/FlyingPathNavigation.java
@@ -16,9 +16,25 @@ public class FlyingPathNavigation extends PathNavigation {
@@ -333,7 +333,7 @@ index 077863b758fbc3e51f25bcf842d00a2cc07c6a2f..4b2cc7fa8848b6cb15cc82090bf37bcd
}
+ // DivineMC start - async path processing
+ private static final org.bxteam.divinemc.entity.pathfinding.NodeEvaluatorGenerator nodeEvaluatorGenerator = (org.bxteam.divinemc.entity.pathfinding.NodeEvaluatorFeatures nodeEvaluatorFeatures) -> {
+ private static final org.bxteam.divinemc.async.pathfinding.NodeEvaluatorGenerator nodeEvaluatorGenerator = (org.bxteam.divinemc.async.pathfinding.NodeEvaluatorFeatures nodeEvaluatorFeatures) -> {
+ FlyNodeEvaluator nodeEvaluator = new FlyNodeEvaluator();
+ nodeEvaluator.setCanPassDoors(nodeEvaluatorFeatures.canPassDoors());
+ nodeEvaluator.setCanFloat(nodeEvaluatorFeatures.canFloat());
@@ -363,7 +363,7 @@ index 077863b758fbc3e51f25bcf842d00a2cc07c6a2f..4b2cc7fa8848b6cb15cc82090bf37bcd
if (!this.isDone()) {
if (this.canUpdatePath()) {
diff --git a/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java b/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java
index 86fccf3617a32f3791b03d8067e2eaf6b8d8bebb..2c26d30a7373c6ac8ead22894b63a8d6529ba1f2 100644
index 86fccf3617a32f3791b03d8067e2eaf6b8d8bebb..348fe5b7f8f3d7c87891704115d911a271e8882a 100644
--- a/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java
+++ b/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java
@@ -24,9 +24,25 @@ public class GroundPathNavigation extends PathNavigation {
@@ -371,7 +371,7 @@ index 86fccf3617a32f3791b03d8067e2eaf6b8d8bebb..2c26d30a7373c6ac8ead22894b63a8d6
}
+ // DivineMC start - async path processing
+ protected static final org.bxteam.divinemc.entity.pathfinding.NodeEvaluatorGenerator nodeEvaluatorGenerator = (org.bxteam.divinemc.entity.pathfinding.NodeEvaluatorFeatures nodeEvaluatorFeatures) -> {
+ protected static final org.bxteam.divinemc.async.pathfinding.NodeEvaluatorGenerator nodeEvaluatorGenerator = (org.bxteam.divinemc.async.pathfinding.NodeEvaluatorFeatures nodeEvaluatorFeatures) -> {
+ WalkNodeEvaluator nodeEvaluator = new WalkNodeEvaluator();
+ nodeEvaluator.setCanPassDoors(nodeEvaluatorFeatures.canPassDoors());
+ nodeEvaluator.setCanFloat(nodeEvaluatorFeatures.canFloat());
@@ -393,7 +393,7 @@ index 86fccf3617a32f3791b03d8067e2eaf6b8d8bebb..2c26d30a7373c6ac8ead22894b63a8d6
}
diff --git a/net/minecraft/world/entity/ai/navigation/PathNavigation.java b/net/minecraft/world/entity/ai/navigation/PathNavigation.java
index c8e4ccb96a0f162c780066cf4f61b970b49b7703..0b5f1f1e24c8c0468875d709c6b81798882600a0 100644
index 24dd92449f70144c79f25bf24942ebd666655ed2..90035d61f705094507e1738a77bd624bcab3d235 100644
--- a/net/minecraft/world/entity/ai/navigation/PathNavigation.java
+++ b/net/minecraft/world/entity/ai/navigation/PathNavigation.java
@@ -167,6 +167,10 @@ public abstract class PathNavigation {
@@ -401,7 +401,7 @@ index c8e4ccb96a0f162c780066cf4f61b970b49b7703..0b5f1f1e24c8c0468875d709c6b81798
} else if (!this.canUpdatePath()) {
return null;
+ // DivineMC start - catch early if it's still processing these positions let it keep processing
+ } else if (this.path instanceof org.bxteam.divinemc.entity.pathfinding.AsyncPath asyncPath && !asyncPath.isProcessed() && asyncPath.hasSameProcessingPositions(targets)) {
+ } else if (this.path instanceof org.bxteam.divinemc.async.pathfinding.AsyncPath asyncPath && !asyncPath.isProcessed() && asyncPath.hasSameProcessingPositions(targets)) {
+ return this.path;
+ // DivineMC end - catch early if it's still processing these positions let it keep processing
} else if (this.path != null && !this.path.isDone() && targets.contains(this.targetPos)) {
@@ -420,7 +420,7 @@ index c8e4ccb96a0f162c780066cf4f61b970b49b7703..0b5f1f1e24c8c0468875d709c6b81798
+ // assign early a target position. most calls will only have 1 position
+ if (!targets.isEmpty()) this.targetPos = targets.iterator().next();
+
+ org.bxteam.divinemc.entity.pathfinding.AsyncPathProcessor.awaitProcessing(path, processedPath -> {
+ org.bxteam.divinemc.async.pathfinding.AsyncPathProcessor.awaitProcessing(path, processedPath -> {
+ // check that processing didn't take so long that we calculated a new path
+ if (processedPath != this.path) return;
+
@@ -478,7 +478,7 @@ index c8e4ccb96a0f162c780066cf4f61b970b49b7703..0b5f1f1e24c8c0468875d709c6b81798
Vec3 vec3 = new Vec3((endNode.x + this.mob.getX()) / 2.0, (endNode.y + this.mob.getY()) / 2.0, (endNode.z + this.mob.getZ()) / 2.0);
return pos.closerToCenterThan(vec3, this.path.getNodeCount() - this.path.getNextNodeIndex());
diff --git a/net/minecraft/world/entity/ai/navigation/WaterBoundPathNavigation.java b/net/minecraft/world/entity/ai/navigation/WaterBoundPathNavigation.java
index ea0f6a19e4a79538e68917ba86cbc98be4dbca8d..2c9c16d30ae55e86e00d3b97447c870a66ac8f6e 100644
index ea0f6a19e4a79538e68917ba86cbc98be4dbca8d..030d90f93dbbc07e94d4776198c368650539bf91 100644
--- a/net/minecraft/world/entity/ai/navigation/WaterBoundPathNavigation.java
+++ b/net/minecraft/world/entity/ai/navigation/WaterBoundPathNavigation.java
@@ -15,11 +15,27 @@ public class WaterBoundPathNavigation extends PathNavigation {
@@ -486,7 +486,7 @@ index ea0f6a19e4a79538e68917ba86cbc98be4dbca8d..2c9c16d30ae55e86e00d3b97447c870a
}
+ // DivineMC start - async path processing
+ private static final org.bxteam.divinemc.entity.pathfinding.NodeEvaluatorGenerator nodeEvaluatorGenerator = (org.bxteam.divinemc.entity.pathfinding.NodeEvaluatorFeatures nodeEvaluatorFeatures) -> {
+ private static final org.bxteam.divinemc.async.pathfinding.NodeEvaluatorGenerator nodeEvaluatorGenerator = (org.bxteam.divinemc.async.pathfinding.NodeEvaluatorFeatures nodeEvaluatorFeatures) -> {
+ SwimNodeEvaluator nodeEvaluator = new SwimNodeEvaluator(nodeEvaluatorFeatures.allowBreaching());
+ nodeEvaluator.setCanPassDoors(nodeEvaluatorFeatures.canPassDoors());
+ nodeEvaluator.setCanFloat(nodeEvaluatorFeatures.canFloat());
@@ -510,7 +510,7 @@ index ea0f6a19e4a79538e68917ba86cbc98be4dbca8d..2c9c16d30ae55e86e00d3b97447c870a
}
diff --git a/net/minecraft/world/entity/ai/sensing/NearestBedSensor.java b/net/minecraft/world/entity/ai/sensing/NearestBedSensor.java
index 1f96fd5085bacb4c584576c7cb9f51e7898e9b03..e56869b8c700bfd9fa25f7b7db8663c4b8bad006 100644
index 1f96fd5085bacb4c584576c7cb9f51e7898e9b03..d975b89c7bb57562852596751a4ff881d3ecf193 100644
--- a/net/minecraft/world/entity/ai/sensing/NearestBedSensor.java
+++ b/net/minecraft/world/entity/ai/sensing/NearestBedSensor.java
@@ -57,17 +57,32 @@ public class NearestBedSensor extends Sensor<Mob> {
@@ -530,7 +530,7 @@ index 1f96fd5085bacb4c584576c7cb9f51e7898e9b03..e56869b8c700bfd9fa25f7b7db8663c4
+ // DivineMC start - async pathfinding
+ if (org.bxteam.divinemc.config.DivineConfig.AsyncCategory.asyncPathfinding) {
+ Path possiblePath = AcquirePoi.findPathToPois(entity, new java.util.HashSet<>(poiposes));
+ org.bxteam.divinemc.entity.pathfinding.AsyncPathProcessor.awaitProcessing(possiblePath, path -> {
+ org.bxteam.divinemc.async.pathfinding.AsyncPathProcessor.awaitProcessing(possiblePath, path -> {
+ processPath(entity, poiManager, path);
+ });
+ } else {
@@ -579,15 +579,15 @@ index ca5651f15552f91fba650747d28a75c00fa11442..c5883758d11e91f96b4139b3bd8586a8
}
}
diff --git a/net/minecraft/world/entity/animal/frog/Frog.java b/net/minecraft/world/entity/animal/frog/Frog.java
index c6e4966d3e4fdb7c91577fc1693fb66930b4f3dc..81f0e444ccb6962d675e3a097341683d504d0889 100644
index 85963b74a533beb7883ea417ceb3c21d834aebe0..dd2874406ad224393ccf1b45aef88c396597e633 100644
--- a/net/minecraft/world/entity/animal/frog/Frog.java
+++ b/net/minecraft/world/entity/animal/frog/Frog.java
@@ -483,6 +483,17 @@ public class Frog extends Animal {
@@ -488,6 +488,17 @@ public class Frog extends Animal {
super(mob, level);
}
+ // DivineMC start - async path processing
+ private static final org.bxteam.divinemc.entity.pathfinding.NodeEvaluatorGenerator nodeEvaluatorGenerator = (org.bxteam.divinemc.entity.pathfinding.NodeEvaluatorFeatures nodeEvaluatorFeatures) -> {
+ private static final org.bxteam.divinemc.async.pathfinding.NodeEvaluatorGenerator nodeEvaluatorGenerator = (org.bxteam.divinemc.async.pathfinding.NodeEvaluatorFeatures nodeEvaluatorFeatures) -> {
+ Frog.FrogNodeEvaluator nodeEvaluator = new Frog.FrogNodeEvaluator(true);
+ nodeEvaluator.setCanPassDoors(nodeEvaluatorFeatures.canPassDoors());
+ nodeEvaluator.setCanFloat(nodeEvaluatorFeatures.canFloat());
@@ -600,7 +600,7 @@ index c6e4966d3e4fdb7c91577fc1693fb66930b4f3dc..81f0e444ccb6962d675e3a097341683d
@Override
public boolean canCutCorner(PathType pathType) {
return pathType != PathType.WATER_BORDER && super.canCutCorner(pathType);
@@ -491,6 +502,11 @@ public class Frog extends Animal {
@@ -496,6 +507,11 @@ public class Frog extends Animal {
@Override
protected PathFinder createPathFinder(int maxVisitedNodes) {
this.nodeEvaluator = new Frog.FrogNodeEvaluator(true);
@@ -613,10 +613,10 @@ index c6e4966d3e4fdb7c91577fc1693fb66930b4f3dc..81f0e444ccb6962d675e3a097341683d
}
}
diff --git a/net/minecraft/world/entity/monster/Drowned.java b/net/minecraft/world/entity/monster/Drowned.java
index 2e6d0f035a01277aa28bbe912d5df8dc4cf04547..edcb20935f58e78fa4ef2c11a7dcc6a7857341c2 100644
index 2a13332ebabf2e63a8f51a5d794fab3d66c7a1db..d4e7fc0a5bda4f44bcfed3d1adae7cdaf815784b 100644
--- a/net/minecraft/world/entity/monster/Drowned.java
+++ b/net/minecraft/world/entity/monster/Drowned.java
@@ -308,7 +308,7 @@ public class Drowned extends Zombie implements RangedAttackMob {
@@ -309,7 +309,7 @@ public class Drowned extends Zombie implements RangedAttackMob {
protected boolean closeToNextPos() {
Path path = this.getNavigation().getPath();
@@ -626,7 +626,7 @@ index 2e6d0f035a01277aa28bbe912d5df8dc4cf04547..edcb20935f58e78fa4ef2c11a7dcc6a7
if (target != null) {
double d = this.distanceToSqr(target.getX(), target.getY(), target.getZ());
diff --git a/net/minecraft/world/entity/monster/Strider.java b/net/minecraft/world/entity/monster/Strider.java
index fe31c4a45afd61be8b74efe9d0858ccd0aced075..859c41c3c81b3d3ac05eebdc83c959d196bd5b3e 100644
index fe31c4a45afd61be8b74efe9d0858ccd0aced075..e2e42bbdba1daf6783d10a62aa4c4b1bcf138fe6 100644
--- a/net/minecraft/world/entity/monster/Strider.java
+++ b/net/minecraft/world/entity/monster/Strider.java
@@ -560,9 +560,25 @@ public class Strider extends Animal implements ItemSteerable {
@@ -634,7 +634,7 @@ index fe31c4a45afd61be8b74efe9d0858ccd0aced075..859c41c3c81b3d3ac05eebdc83c959d1
}
+ // DivineMC start - async path processing
+ private static final org.bxteam.divinemc.entity.pathfinding.NodeEvaluatorGenerator nodeEvaluatorGenerator = (org.bxteam.divinemc.entity.pathfinding.NodeEvaluatorFeatures nodeEvaluatorFeatures) -> {
+ private static final org.bxteam.divinemc.async.pathfinding.NodeEvaluatorGenerator nodeEvaluatorGenerator = (org.bxteam.divinemc.async.pathfinding.NodeEvaluatorFeatures nodeEvaluatorFeatures) -> {
+ WalkNodeEvaluator nodeEvaluator = new WalkNodeEvaluator();
+ nodeEvaluator.setCanPassDoors(nodeEvaluatorFeatures.canPassDoors());
+ nodeEvaluator.setCanFloat(nodeEvaluatorFeatures.canFloat());
@@ -656,10 +656,10 @@ index fe31c4a45afd61be8b74efe9d0858ccd0aced075..859c41c3c81b3d3ac05eebdc83c959d1
}
diff --git a/net/minecraft/world/entity/monster/warden/Warden.java b/net/minecraft/world/entity/monster/warden/Warden.java
index 021aa51da04bea01b0e827390ce1690af7092b8f..0440cbbc0d6657f32dc37a1dbbe9ee78f8e229cf 100644
index 7bfc597655cc55c46b65c9726a6e9de9f3f5afc8..4944b6d389c65511eed75d580779f912b8ff076d 100644
--- a/net/minecraft/world/entity/monster/warden/Warden.java
+++ b/net/minecraft/world/entity/monster/warden/Warden.java
@@ -574,6 +574,16 @@ public class Warden extends Monster implements VibrationSystem {
@@ -579,6 +579,16 @@ public class Warden extends Monster implements VibrationSystem {
@Override
protected PathFinder createPathFinder(int maxVisitedNodes) {
this.nodeEvaluator = new WalkNodeEvaluator();
@@ -707,18 +707,18 @@ index d6d3c8f5e5dd4a8cab0d3fcc131c3a59f06130c6..839653a997f1e10970fa2956fadaf493
return false;
} else if (pathentity.nodes.size() != this.nodes.size()) {
diff --git a/net/minecraft/world/level/pathfinder/PathFinder.java b/net/minecraft/world/level/pathfinder/PathFinder.java
index c2baadcdceb1df6a881d6f73aa4eb4dd264bcdfe..8997908508c1dbe839aab25e4f546b9aa664047e 100644
index c2baadcdceb1df6a881d6f73aa4eb4dd264bcdfe..38c8019f3cdfa351c120e80e312219416b157e6d 100644
--- a/net/minecraft/world/level/pathfinder/PathFinder.java
+++ b/net/minecraft/world/level/pathfinder/PathFinder.java
@@ -22,11 +22,19 @@ public class PathFinder {
public final NodeEvaluator nodeEvaluator;
private static final boolean DEBUG = false;
private final BinaryHeap openSet = new BinaryHeap();
+ private final @Nullable org.bxteam.divinemc.entity.pathfinding.NodeEvaluatorGenerator nodeEvaluatorGenerator; // DivineMC - we use this later to generate an evaluator
+ private final @Nullable org.bxteam.divinemc.async.pathfinding.NodeEvaluatorGenerator nodeEvaluatorGenerator; // DivineMC - we use this later to generate an evaluator
- public PathFinder(NodeEvaluator nodeEvaluator, int maxVisitedNodes) {
+ // DivineMC start - support nodeEvaluatorgenerators
+ public PathFinder(NodeEvaluator nodeEvaluator, int maxVisitedNodes, @Nullable org.bxteam.divinemc.entity.pathfinding.NodeEvaluatorGenerator nodeEvaluatorGenerator) { // DivineMC - add nodeEvaluatorGenerator
+ public PathFinder(NodeEvaluator nodeEvaluator, int maxVisitedNodes, @Nullable org.bxteam.divinemc.async.pathfinding.NodeEvaluatorGenerator nodeEvaluatorGenerator) { // DivineMC - add nodeEvaluatorGenerator
this.nodeEvaluator = nodeEvaluator;
this.maxVisitedNodes = maxVisitedNodes;
+ this.nodeEvaluatorGenerator = nodeEvaluatorGenerator;
@@ -743,12 +743,12 @@ index c2baadcdceb1df6a881d6f73aa4eb4dd264bcdfe..8997908508c1dbe839aab25e4f546b9a
+ this.openSet.clear(); // it's always cleared in processPath
+ NodeEvaluator nodeEvaluator = this.nodeEvaluatorGenerator == null
+ ? this.nodeEvaluator
+ : org.bxteam.divinemc.entity.pathfinding.NodeEvaluatorCache.takeNodeEvaluator(this.nodeEvaluatorGenerator, this.nodeEvaluator);
+ : org.bxteam.divinemc.async.pathfinding.NodeEvaluatorCache.takeNodeEvaluator(this.nodeEvaluatorGenerator, this.nodeEvaluator);
+ nodeEvaluator.prepare(region, mob);
+ Node start = nodeEvaluator.getStart();
+ // DivineMC end - use a generated evaluator if we have one otherwise run sync
if (start == null) {
+ org.bxteam.divinemc.entity.pathfinding.NodeEvaluatorCache.removeNodeEvaluator(nodeEvaluator); // DivineMC - handle nodeEvaluatorGenerator
+ org.bxteam.divinemc.async.pathfinding.NodeEvaluatorCache.removeNodeEvaluator(nodeEvaluator); // DivineMC - handle nodeEvaluatorGenerator
return null;
} else {
// Paper start - Perf: remove streams and optimize collection
@@ -764,11 +764,11 @@ index c2baadcdceb1df6a881d6f73aa4eb4dd264bcdfe..8997908508c1dbe839aab25e4f546b9a
+ // DivineMC start - async path processing
+ if (this.nodeEvaluatorGenerator == null) {
+ // run sync :(
+ org.bxteam.divinemc.entity.pathfinding.NodeEvaluatorCache.removeNodeEvaluator(nodeEvaluator);
+ org.bxteam.divinemc.async.pathfinding.NodeEvaluatorCache.removeNodeEvaluator(nodeEvaluator);
+ return this.findPath(start, map, maxRange, accuracy, searchDepthMultiplier);
+ }
+
+ return new org.bxteam.divinemc.entity.pathfinding.AsyncPath(Lists.newArrayList(), targetPositions, () -> {
+ return new org.bxteam.divinemc.async.pathfinding.AsyncPath(Lists.newArrayList(), targetPositions, () -> {
+ try {
+ return this.processPath(nodeEvaluator, start, map, maxRange, accuracy, searchDepthMultiplier);
+ } catch (Exception e) {
@@ -776,7 +776,7 @@ index c2baadcdceb1df6a881d6f73aa4eb4dd264bcdfe..8997908508c1dbe839aab25e4f546b9a
+ return null;
+ } finally {
+ nodeEvaluator.done();
+ org.bxteam.divinemc.entity.pathfinding.NodeEvaluatorCache.returnNodeEvaluator(nodeEvaluator);
+ org.bxteam.divinemc.async.pathfinding.NodeEvaluatorCache.returnNodeEvaluator(nodeEvaluator);
+ }
+ });
+ // DivineMC end - async path processing

View File

@@ -1,8 +1,18 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Tue, 28 Jan 2025 01:18:49 +0300
Subject: [PATCH] Multithreaded Tracker
Subject: [PATCH] Petal: Multithreaded Tracker
Original project: https://github.com/Bloom-host/Petal
Original license: GPL v3
Patch description:
We made much of tracking logic asynchronously, and fixed visible issue
for the case of some NPC plugins which using real entity type, e.g. Citizens.
But it is still recommending to use those packet based, virtual entity
based NPC plugins, e.g. ZNPC Plus, Adyeshach, Fancy NPC, etc.
diff --git a/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java b/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java
index 1b8193587814225c2ef2c5d9e667436eb50ff6c5..93272808d94e81d31af728ebe85df9a2bc7aedab 100644
@@ -27,10 +37,10 @@ index 1b8193587814225c2ef2c5d9e667436eb50ff6c5..93272808d94e81d31af728ebe85df9a2
{
for (int i = 0; i < this.directByChunk.length; ++i) {
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
index bdc1200ef5317fdaf58973bf580b0a672aee800f..dc2b3ccf7810731c0e2c90e5a476c1c8203a1fb7 100644
index c4a1e3908cf8e1b0614ff6c3a0f5f6708a7667e5..fef167837e05d6e80246d4fccd037cc1c9500f97 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
@@ -344,7 +344,11 @@ public final class RegionizedPlayerChunkLoader {
@@ -345,7 +345,11 @@ public final class RegionizedPlayerChunkLoader {
private boolean canGenerateChunks = true;
private final ArrayDeque<ChunkHolderManager.TicketOperation<?, ?>> delayedTicketOps = new ArrayDeque<>();
@@ -56,7 +66,7 @@ index 9c0c99b936b4a82ebfe924866e53ec71f7bbe9ad..01ed1e3572e9c2ccfd19df117cda0d5c
.add(
new ClientboundUpdateAttributesPacket.AttributeSnapshot(
diff --git a/net/minecraft/server/level/ChunkMap.java b/net/minecraft/server/level/ChunkMap.java
index edda52a8430386238be4963e8ea2406f0c2d4df3..2c5104b9ae1d2ea902eeac5a1c9d49bc1af67c43 100644
index c0d996fb99f053863ce623889add3feb70d7137d..7ca147cf9da67c399806056e5092841f7ca32321 100644
--- a/net/minecraft/server/level/ChunkMap.java
+++ b/net/minecraft/server/level/ChunkMap.java
@@ -255,9 +255,19 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
@@ -88,7 +98,7 @@ index edda52a8430386238be4963e8ea2406f0c2d4df3..2c5104b9ae1d2ea902eeac5a1c9d49bc
+ // DivineMC start - Multithreaded tracker
+ if (org.bxteam.divinemc.config.DivineConfig.AsyncCategory.multithreadedEnabled) {
+ final ServerLevel level = this.level;
+ org.bxteam.divinemc.entity.tracking.MultithreadedTracker.tick(level);
+ org.bxteam.divinemc.async.tracking.MultithreadedTracker.tick(level);
+ return;
+ }
+ // DivineMC end - Multithreaded tracker
@@ -346,7 +356,7 @@ index f106373ef3ac4a8685c2939c9e8361688a285913..b844b6dd89bc53b74c0d1bdbf4657c11
public boolean visible = true;
diff --git a/net/minecraft/server/level/ServerEntity.java b/net/minecraft/server/level/ServerEntity.java
index e96d4dee14c05f2fa329bfb1588ec795d4e3d730..917029d96afb5843276f4fa4ee37292327aea626 100644
index 0868189fee30d40dfb82ae39592a65b510e96b54..39e28ad0cbb4617a80d7f197723233d4bdc1eed5 100644
--- a/net/minecraft/server/level/ServerEntity.java
+++ b/net/minecraft/server/level/ServerEntity.java
@@ -134,7 +134,7 @@ public class ServerEntity {
@@ -358,7 +368,7 @@ index e96d4dee14c05f2fa329bfb1588ec795d4e3d730..917029d96afb5843276f4fa4ee372923
final ServerPlayer serverPlayer = connection.getPlayer(); // Paper
savedData.tickCarriedBy(serverPlayer, item);
Packet<?> updatePacket = savedData.getUpdatePacket(mapId, serverPlayer);
@@ -424,8 +424,6 @@ public class ServerEntity {
@@ -428,8 +428,6 @@ public class ServerEntity {
// CraftBukkit end
this.broadcastAndSend(new ClientboundUpdateAttributesPacket(this.entity.getId(), attributesToSync));
}
@@ -368,10 +378,10 @@ index e96d4dee14c05f2fa329bfb1588ec795d4e3d730..917029d96afb5843276f4fa4ee372923
}
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
index 9dcb9e5ecc31fcc3fc7547a47ec98d2689698769..2560799fe6ec006916a2bc9915355a358ab6c8bb 100644
index 78bf3365b426e7090182af84630111d410a2460e..3c1795eb56900cd80cfec38bd1d922d566463ecb 100644
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -2504,7 +2504,6 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -2517,7 +2517,6 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@Override
public LevelEntityGetter<Entity> getEntities() {
@@ -379,7 +389,7 @@ index 9dcb9e5ecc31fcc3fc7547a47ec98d2689698769..2560799fe6ec006916a2bc9915355a35
return this.moonrise$getEntityLookup(); // Paper - rewrite chunk system
}
@@ -2771,7 +2770,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -2784,7 +2783,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
}
map.carriedByPlayers.remove(player);
@@ -389,10 +399,10 @@ index 9dcb9e5ecc31fcc3fc7547a47ec98d2689698769..2560799fe6ec006916a2bc9915355a35
}
}
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index f36e042b36b94a0de2524d01ed44558900ba2a99..649b01c00ec01eea1514676e424d88acbfa26184 100644
index 7b10fe7cf66757ed68f9e39e03259700dfabf184..c537d22fd97225c1b6d58bed61add83a20d9be24 100644
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1931,7 +1931,6 @@ public class ServerGamePacketListenerImpl
@@ -1936,7 +1936,6 @@ public class ServerGamePacketListenerImpl
}
public void internalTeleport(PositionMoveRotation posMoveRotation, Set<Relative> relatives) {
@@ -401,10 +411,10 @@ index f36e042b36b94a0de2524d01ed44558900ba2a99..649b01c00ec01eea1514676e424d88ac
if (this.player.isRemoved()) {
LOGGER.info("Attempt to teleport removed player {} restricted", player.getScoreboardName());
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
index d382a9760c0379f3d1c3bc65303d1de250858343..f5a036cfde9ced6ed8f0e548db3b69b1a46a0d2d 100644
index 327b3b1463caafc69e6a5dc0eee577f4af49d202..683a8913ef4e71ae3072b520d0e0a6a73c96a13c 100644
--- a/net/minecraft/world/entity/LivingEntity.java
+++ b/net/minecraft/world/entity/LivingEntity.java
@@ -1335,13 +1335,13 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
@@ -1353,13 +1353,13 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
}
private void refreshDirtyAttributes() {
@@ -638,10 +648,10 @@ index 325ec57df2885f5e81b8a6b61e3a9fed9484b30f..1796f0a6f647c94b0943a6003a130779
@Override
diff --git a/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java b/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
index 7bbeed6c998c91e68376d3f17a510d68e3cd0b27..de7b3a8a7c841360310a88005da02a0733b46714 100644
index ebb0b7e5047efa65e8b6986f12dd5a7d6c0e9613..a77665abefdf653e65393cc6908506a5812b5596 100644
--- a/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
+++ b/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
@@ -211,6 +211,7 @@ public class MapItemSavedData extends SavedData {
@@ -212,6 +212,7 @@ public class MapItemSavedData extends SavedData {
for (int i = 0; i < this.carriedBy.size(); i++) {
MapItemSavedData.HoldingPlayer holdingPlayer1 = this.carriedBy.get(i);

View File

@@ -1,74 +1,93 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Wed, 19 Mar 2025 23:24:32 +0300
Subject: [PATCH] Async mob spawning
Subject: [PATCH] Pufferfish: Optimize mob spawning
Original license: GPL v3
Original project: https://github.com/pufferfish-gg/Pufferfish
This patch reduces the main-thread impact of mob spawning by moving spawning work to other threads
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 1a36a7c071c9f203d32f524008cf031fb1a4d6a6..c067f46935753794b49f29358262273fcd15d707 100644
index 2baa4dc93bcc448ce65bae50ca39d41e562e2211..a0cad0bdb8245b19f4ff983245d61d7b237a4042 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -289,6 +289,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
public boolean lagging = false; // Purpur - Lagging threshold
protected boolean upnp = false; // Purpur - UPnP Port Forwarding
public final org.bxteam.divinemc.util.tps.TPSCalculator tpsCalculator = new org.bxteam.divinemc.util.tps.TPSCalculator(); // DivineMC - Lag compensation
+ public org.bxteam.divinemc.util.AsyncProcessor mobSpawnExecutor = new org.bxteam.divinemc.util.AsyncProcessor("mob_spawning"); // DivineMC - Async mob spawning
+ public gg.pufferfish.pufferfish.util.AsyncExecutor mobSpawnExecutor = new gg.pufferfish.pufferfish.util.AsyncExecutor("Mob Spawning"); // DivineMC - Pufferfish: Optimize mob spawning
public static <S extends MinecraftServer> S spin(Function<Thread, S> threadFunction) {
ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry.init(); // Paper - rewrite data converter system
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
index 6de832e7aec630914e70fb0f11223907ab28298c..7205fc8d3b17863c262d4c4c3cb956c852468c6f 100644
index 75c8ce32e68f92e20201e9c243f46f2be716eac8..bf680624bc6c618dfa0eeeb74c103ff6716fd27e 100644
--- a/net/minecraft/server/level/ServerChunkCache.java
+++ b/net/minecraft/server/level/ServerChunkCache.java
@@ -182,6 +182,10 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
}
// Paper end - chunk tick iteration optimisations
+ // DivineMC start - Async mob spawning
+ // DivineMC start - Pufferfish: Optimize mob spawning
+ public boolean firstRunSpawnCounts = true;
+ public final java.util.concurrent.atomic.AtomicBoolean spawnCountsReady = new java.util.concurrent.atomic.AtomicBoolean(false);
+ // DivineMC end - Async mob spawning
+ // DivineMC end - Pufferfish: Optimize mob spawning
public ServerChunkCache(
ServerLevel level,
@@ -505,6 +509,32 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
@@ -506,6 +510,47 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
this.broadcastChangedChunks();
}
+
+ // DivineMC start - Async mob spawning
+ // DivineMC start - Pufferfish: Optimize mob spawning
+ if (org.bxteam.divinemc.config.DivineConfig.AsyncCategory.enableAsyncSpawning) {
+ for (ServerPlayer player : this.level.players) {
+ for (int ii = 0; ii < ServerPlayer.MOBCATEGORY_TOTAL_ENUMS; ii++) {
+ player.mobCounts[ii] = 0;
+
+ int newBackoff = Math.max(0, player.mobBackoffCounts[ii] - 1); // DivineMC - Async mob spawning
+ int newBackoff = Math.max(0, player.mobBackoffCounts[ii] - 1);
+ player.mobBackoffCounts[ii] = newBackoff;
+ }
+ }
+
+ if (firstRunSpawnCounts) {
+ firstRunSpawnCounts = false;
+ spawnCountsReady.set(true);
+ }
+
+ if (spawnCountsReady.getAndSet(false)) {
+ MinecraftServer.getServer().mobSpawnExecutor.submit(() -> {
+ net.minecraft.server.MinecraftServer.getServer().mobSpawnExecutor.submit(() -> {
+ int mapped = distanceManager.getNaturalSpawnChunkCount();
+ ca.spottedleaf.moonrise.common.list.IteratorSafeOrderedReferenceSet.Iterator<Entity> objectiterator = level.entityTickList.entities.iterator(ca.spottedleaf.moonrise.common.list.IteratorSafeOrderedReferenceSet.ITERATOR_FLAG_SEE_ADDITIONS);
+
+ try {
+ lastSpawnState = NaturalSpawner.createState(mapped, new java.util.ArrayList<>(level.entityTickList.entities), this::getFullChunk, new LocalMobCapCalculator(this.chunkMap), true);
+ } finally { }
+ gg.pufferfish.pufferfish.util.IterableWrapper<Entity> wrappedIterator = new gg.pufferfish.pufferfish.util.IterableWrapper<>(objectiterator);
+ LocalMobCapCalculator mobCapCalculator = !level.paperConfig().entities.spawning.perPlayerMobSpawns ? new LocalMobCapCalculator(chunkMap) : null;
+
+ lastSpawnState = NaturalSpawner.createState(
+ mapped,
+ wrappedIterator,
+ ServerChunkCache.this::getFullChunk,
+ mobCapCalculator,
+ level.paperConfig().entities.spawning.perPlayerMobSpawns
+ );
+ } finally {
+ objectiterator.finishedIterating();
+ }
+ spawnCountsReady.set(true);
+ });
+ }
+ }
+ // DivineMC end - Async mob spawning
+ // DivineMC end - Pufferfish: Optimize mob spawning
}
private void broadcastChangedChunks() {
@@ -522,27 +552,31 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
@@ -523,27 +568,31 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
int naturalSpawnChunkCount = this.distanceManager.getNaturalSpawnChunkCount();
// Paper start - Optional per player mob spawns
NaturalSpawner.SpawnState spawnState;
+ // DivineMC start - Async mob spawning
+ // DivineMC start - Pufferfish: Optimize mob spawning
if ((this.spawnFriendlies || this.spawnEnemies) && this.level.paperConfig().entities.spawning.perPlayerMobSpawns) { // don't count mobs when animals and monsters are disabled
- // re-set mob counts
- for (ServerPlayer player : this.level.players) {
@@ -104,31 +123,31 @@ index 6de832e7aec630914e70fb0f11223907ab28298c..7205fc8d3b17863c262d4c4c3cb956c8
+ lastSpawnState = NaturalSpawner.createState(naturalSpawnChunkCount, this.level.getAllEntities(), this::getFullChunk, new LocalMobCapCalculator(this.chunkMap), false);
+ spawnCountsReady.set(true);
}
+ // DivineMC end - Async mob spawning
+ // DivineMC end - Pufferfish: Optimize mob spawning
// Paper end - Optional per player mob spawns
- this.lastSpawnState = spawnState;
boolean _boolean = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !this.level.players().isEmpty(); // CraftBukkit
int _int = this.level.getGameRules().getInt(GameRules.RULE_RANDOMTICKING);
List<MobCategory> filteredSpawningCategories;
@@ -556,7 +590,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
@@ -557,7 +606,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
}
// Paper end - PlayerNaturallySpawnCreaturesEvent
boolean flag = this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) != 0L && this.level.getLevelData().getGameTime() % this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) == 0L; // CraftBukkit
- filteredSpawningCategories = NaturalSpawner.getFilteredSpawningCategories(spawnState, this.spawnFriendlies, this.spawnEnemies, flag, this.level); // CraftBukkit
+ filteredSpawningCategories = NaturalSpawner.getFilteredSpawningCategories(lastSpawnState, this.spawnFriendlies, this.spawnEnemies, flag, this.level); // CraftBukkit // DivineMC - Async mob spawning
+ filteredSpawningCategories = NaturalSpawner.getFilteredSpawningCategories(lastSpawnState, this.spawnFriendlies, this.spawnEnemies, flag, this.level); // CraftBukkit // DivineMC - Pufferfish: Optimize mob spawning
} else {
filteredSpawningCategories = List.of();
}
@@ -573,7 +607,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
@@ -572,7 +621,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
// Paper end - chunk tick iteration optimisation
for (LevelChunk levelChunk : list) {
- this.tickSpawningChunk(levelChunk, timeInhabited, filteredSpawningCategories, spawnState);
+ this.tickSpawningChunk(levelChunk, timeInhabited, filteredSpawningCategories, lastSpawnState); // DivineMC - Async mob spawning
+ this.tickSpawningChunk(levelChunk, timeInhabited, filteredSpawningCategories, lastSpawnState); // DivineMC - Pufferfish: Optimize mob spawning
}
} finally {
list.clear();
@@ -592,11 +626,11 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
@@ -591,11 +640,11 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
this.level.tickThunder(chunk);
}
@@ -136,77 +155,11 @@ index 6de832e7aec630914e70fb0f11223907ab28298c..7205fc8d3b17863c262d4c4c3cb956c8
- if (this.level.getWorldBorder().isWithinBounds(pos)) { // Paper - rewrite chunk system
- NaturalSpawner.spawnForChunk(this.level, chunk, spawnState, spawnCategories);
- }
+ // DivineMC start - Async mob spawning
+ // DivineMC start - Pufferfish: Optimize mob spawning
+ if (!spawnCategories.isEmpty() && this.level.getWorldBorder().isWithinBounds(pos) && (!org.bxteam.divinemc.config.DivineConfig.AsyncCategory.enableAsyncSpawning || spawnCountsReady.get())) { // Paper - rewrite chunk system
+ NaturalSpawner.spawnForChunk(this.level, chunk, spawnState, spawnCategories);
}
+ // DivineMC end - Async mob spawning
+ // DivineMC end - Pufferfish: Optimize mob spawning
}
private void getFullChunk(long chunkPos, Consumer<LevelChunk> fullChunkGetter) {
diff --git a/net/minecraft/world/level/NaturalSpawner.java b/net/minecraft/world/level/NaturalSpawner.java
index 68a074a1eb11b158af773a2c44aa49d5d8462080..a5f6f50ad1e276a908347d9c21527fb583734538 100644
--- a/net/minecraft/world/level/NaturalSpawner.java
+++ b/net/minecraft/world/level/NaturalSpawner.java
@@ -149,7 +149,18 @@ public final class NaturalSpawner {
return list;
}
+ private static int maxCapPerPlayer = -1; // DivineMC - Async mob spawning
+
public static void spawnForChunk(ServerLevel level, LevelChunk chunk, NaturalSpawner.SpawnState spawnState, List<MobCategory> categories) {
+ // DivineMC start - Async mob spawning
+ if (maxCapPerPlayer < 0) {
+ maxCapPerPlayer = 0;
+ for (final MobCategory value : MobCategory.values()) {
+ maxCapPerPlayer += value.getMaxInstancesPerChunk();
+ }
+ }
+ // DivineMC end - Async mob spawning
+
for (MobCategory mobCategory : categories) {
// Paper start - Optional per player mob spawns
final boolean canSpawn;
@@ -680,6 +691,13 @@ public final class NaturalSpawner {
}
boolean canSpawnForCategoryLocal(MobCategory category, ChunkPos chunkPos) {
+ // DivineMC start - Async mob spawning
+ if (this.localMobCapCalculator == null) {
+ LOGGER.warn("Local mob cap calculator was null! Report to DivineMC!");
+ return false;
+ }
+ // DivineMC end - Async mob spawning
+
return this.localMobCapCalculator.canSpawn(category, chunkPos);
}
}
diff --git a/net/minecraft/world/level/entity/EntityTickList.java b/net/minecraft/world/level/entity/EntityTickList.java
index c89701d7bdc9b889038d3c52f2232fb17624b113..9e75320e51886e0f93c23683d8614128f44a613e 100644
--- a/net/minecraft/world/level/entity/EntityTickList.java
+++ b/net/minecraft/world/level/entity/EntityTickList.java
@@ -9,7 +9,7 @@ import javax.annotation.Nullable;
import net.minecraft.world.entity.Entity;
public class EntityTickList {
- public final ca.spottedleaf.moonrise.common.list.IteratorSafeOrderedReferenceSet<net.minecraft.world.entity.Entity> entities = new ca.spottedleaf.moonrise.common.list.IteratorSafeOrderedReferenceSet<>(); // Paper - rewrite chunk system
+ public final java.util.concurrent.ConcurrentLinkedQueue<Entity> entities = new java.util.concurrent.ConcurrentLinkedQueue<>(); // Paper - rewrite chunk system // DivineMC - Async mob spawning
private void ensureActiveIsNotIterated() {
// Paper - rewrite chunk system
@@ -33,13 +33,13 @@ public class EntityTickList {
// Paper start - rewrite chunk system
// To ensure nothing weird happens with dimension travelling, do not iterate over new entries...
// (by dfl iterator() is configured to not iterate over new entries)
- final ca.spottedleaf.moonrise.common.list.IteratorSafeOrderedReferenceSet.Iterator<Entity> iterator = this.entities.iterator();
+ final java.util.Iterator<Entity> iterator = this.entities.iterator(); // DivineMC - Async mob spawning
try {
while (iterator.hasNext()) {
entity.accept(iterator.next());
}
} finally {
- iterator.finishedIterating();
+ //iterator.finishedIterating(); // DivineMC - Async mob spawning
}
// Paper end - rewrite chunk system
}

View File

@@ -0,0 +1,68 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Wed, 9 Jul 2025 03:06:02 +0300
Subject: [PATCH] Pufferfish: Simpler ShapelessRecipes comparison for Vanilla
Original license: GPL v3
Original project: https://github.com/pufferfish-gg/Pufferfish
Patch description:
Paper added a fancy sorting comparison due to Bukkit recipes breaking
the vanilla one, however this is far more advanced than what you need
for all the vanilla recipes.
diff --git a/net/minecraft/world/item/crafting/ShapelessRecipe.java b/net/minecraft/world/item/crafting/ShapelessRecipe.java
index d601b54b1de2f2ae44fe2b20c8116c71a6340e45..658c950e18a5a4ff992c8720e60f505a11ab2efd 100644
--- a/net/minecraft/world/item/crafting/ShapelessRecipe.java
+++ b/net/minecraft/world/item/crafting/ShapelessRecipe.java
@@ -23,13 +23,21 @@ public class ShapelessRecipe implements CraftingRecipe {
final List<Ingredient> ingredients;
@Nullable
private PlacementInfo placementInfo;
+ // DivineMC start - Pufferfish: Simpler ShapelessRecipes comparison for Vanilla
+ private final boolean isBukkit;
public ShapelessRecipe(String group, CraftingBookCategory category, ItemStack result, List<Ingredient> ingredients) {
+ this(group, category, result, ingredients, false);
+ }
+
+ public ShapelessRecipe(String group, CraftingBookCategory category, ItemStack result, List<Ingredient> ingredients, boolean isBukkit) {
this.group = group;
this.category = category;
this.result = result;
this.ingredients = ingredients;
+ this.isBukkit = isBukkit;
}
+ // DivineMC end - Pufferfish: Simpler ShapelessRecipes comparison for Vanilla
// CraftBukkit start
@Override
@@ -72,6 +80,27 @@ public class ShapelessRecipe implements CraftingRecipe {
@Override
public boolean matches(CraftingInput input, Level level) {
+ // DivineMC start - Pufferfish: Simpler ShapelessRecipes comparison for Vanilla
+ if (!this.isBukkit) {
+ java.util.List<Ingredient> ingredients = com.google.common.collect.Lists.newArrayList(this.ingredients.toArray(new Ingredient[0]));
+
+ inventory: for (int index = 0; index < input.size(); index++) {
+ ItemStack itemStack = input.getItem(index);
+
+ if (!itemStack.isEmpty()) {
+ for (int i = 0; i < ingredients.size(); i++) {
+ if (ingredients.get(i).test(itemStack)) {
+ ingredients.remove(i);
+ continue inventory;
+ }
+ }
+ return false;
+ }
+ }
+
+ return ingredients.isEmpty();
+ }
+ // DivineMC end - Pufferfish: Simpler ShapelessRecipes comparison for Vanilla
// Paper start - Improve exact choice recipe ingredients & unwrap ternary
if (input.ingredientCount() != this.ingredients.size()) {
return false;

View File

@@ -1,17 +1,15 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Wed, 12 Feb 2025 01:05:50 +0300
Subject: [PATCH] Density Function Compiler
Implements density function compiler to accelerate world generation from C2ME
Density function: https://minecraft.wiki/w/Density_function
Subject: [PATCH] C2ME: Density Function Compiler
This functionality compiles density functions from world generation
datapacks (including vanilla generation) to JVM bytecode to increase
performance by allowing JVM JIT to better optimize the code.
All functions provided by vanilla are implemented.
About Density function: https://minecraft.wiki/w/Density_function
diff --git a/net/minecraft/util/CubicSpline.java b/net/minecraft/util/CubicSpline.java
index f36f8f2d49d4eba5c80eb243883749d6f831eb8a..b43b7e242ea0a4f87704853c03201144ce355565 100644
--- a/net/minecraft/util/CubicSpline.java
@@ -113,7 +111,7 @@ index f36f8f2d49d4eba5c80eb243883749d6f831eb8a..b43b7e242ea0a4f87704853c03201144
}
}
diff --git a/net/minecraft/world/level/levelgen/DensityFunctions.java b/net/minecraft/world/level/levelgen/DensityFunctions.java
index 4c53031cf8f6198825b190955d96f20bbcccd77e..fb3c3c3e837056e2762cf32050440ed7a4142ddc 100644
index 4c53031cf8f6198825b190955d96f20bbcccd77e..2b65f922f802a9dbea56f1bae0d243af1080501f 100644
--- a/net/minecraft/world/level/levelgen/DensityFunctions.java
+++ b/net/minecraft/world/level/levelgen/DensityFunctions.java
@@ -275,38 +275,66 @@ public final class DensityFunctions {
@@ -184,7 +182,7 @@ index 4c53031cf8f6198825b190955d96f20bbcccd77e..fb3c3c3e837056e2762cf32050440ed7
- break;
- case MAX:
- d1 = this.argument2.maxValue();
+ org.bxteam.divinemc.dfc.common.util.ArrayCache arrayCache = contextProvider instanceof org.bxteam.divinemc.dfc.common.ducks.IArrayCacheCapable arrayCacheCapable ? arrayCacheCapable.c2me$getArrayCache() : null;
+ com.ishland.c2me.opts.dfc.common.util.ArrayCache arrayCache = contextProvider instanceof com.ishland.c2me.opts.dfc.common.ducks.IArrayCacheCapable arrayCacheCapable ? arrayCacheCapable.c2me$getArrayCache() : null;
- for (int i2 = 0; i2 < array.length; i2++) {
- double d2 = array[i2];
@@ -218,7 +216,7 @@ index 4c53031cf8f6198825b190955d96f20bbcccd77e..fb3c3c3e837056e2762cf32050440ed7
- protected record Marker(@Override DensityFunctions.Marker.Type type, @Override DensityFunction wrapped) implements DensityFunctions.MarkerOrMarked {
+ // DivineMC start - Density Function Compiler
+ public static final class Marker implements org.bxteam.divinemc.dfc.common.ducks.IFastCacheLike, org.bxteam.divinemc.dfc.common.ducks.IEqualityOverriding, MarkerOrMarked {
+ public static final class Marker implements com.ishland.c2me.opts.dfc.common.ducks.IFastCacheLike, com.ishland.c2me.opts.dfc.common.ducks.IEqualityOverriding, MarkerOrMarked {
+ private final Type type;
+ private final DensityFunction wrapped;
+ private Object c2me$optionalEquality;
@@ -236,7 +234,7 @@ index 4c53031cf8f6198825b190955d96f20bbcccd77e..fb3c3c3e837056e2762cf32050440ed7
+ return original.apply(that);
+ }
+ Object a = this.c2me$getOverriddenEquality();
+ Object b = that instanceof org.bxteam.divinemc.dfc.common.ducks.IEqualityOverriding equalityOverriding ? equalityOverriding.c2me$getOverriddenEquality() : null;
+ Object b = that instanceof com.ishland.c2me.opts.dfc.common.ducks.IEqualityOverriding equalityOverriding ? equalityOverriding.c2me$getOverriddenEquality() : null;
+ if (a == null) {
+ return original.apply(b != null ? b : that);
+ } else {
@@ -261,22 +259,22 @@ index 4c53031cf8f6198825b190955d96f20bbcccd77e..fb3c3c3e837056e2762cf32050440ed7
+ }
+
+ @Override
+ public double c2me$getCached(int x, int y, int z, org.bxteam.divinemc.dfc.common.ast.EvalType evalType) {
+ public double c2me$getCached(int x, int y, int z, com.ishland.c2me.opts.dfc.common.ast.EvalType evalType) {
+ return Double.longBitsToDouble(CACHE_MISS_NAN_BITS);
+ }
+
+ @Override
+ public boolean c2me$getCached(double[] res, int[] x, int[] y, int[] z, org.bxteam.divinemc.dfc.common.ast.EvalType evalType) {
+ public boolean c2me$getCached(double[] res, int[] x, int[] y, int[] z, com.ishland.c2me.opts.dfc.common.ast.EvalType evalType) {
+ return false;
+ }
+
+ @Override
+ public void c2me$cache(int x, int y, int z, org.bxteam.divinemc.dfc.common.ast.EvalType evalType, double cached) {
+ public void c2me$cache(int x, int y, int z, com.ishland.c2me.opts.dfc.common.ast.EvalType evalType, double cached) {
+ // nop
+ }
+
+ @Override
+ public void c2me$cache(double[] res, int[] x, int[] y, int[] z, org.bxteam.divinemc.dfc.common.ast.EvalType evalType) {
+ public void c2me$cache(double[] res, int[] x, int[] y, int[] z, com.ishland.c2me.opts.dfc.common.ast.EvalType evalType) {
+ // nop
+ }
+
@@ -288,7 +286,7 @@ index 4c53031cf8f6198825b190955d96f20bbcccd77e..fb3c3c3e837056e2762cf32050440ed7
+ @Override
+ public DensityFunction c2me$withDelegate(DensityFunction delegate) {
+ DensityFunctions.Marker wrapping = new DensityFunctions.Marker(this.type(), delegate);
+ ((org.bxteam.divinemc.dfc.common.ducks.IEqualityOverriding) (Object) wrapping).c2me$overrideEquality(this);
+ ((com.ishland.c2me.opts.dfc.common.ducks.IEqualityOverriding) (Object) wrapping).c2me$overrideEquality(this);
+ return wrapping;
+ }
+
@@ -296,7 +294,7 @@ index 4c53031cf8f6198825b190955d96f20bbcccd77e..fb3c3c3e837056e2762cf32050440ed7
+ public void c2me$overrideEquality(Object object) {
+ Object inner = object;
+ while (true) {
+ Object inner1 = inner instanceof org.bxteam.divinemc.dfc.common.ducks.IEqualityOverriding e1 ? e1.c2me$getOverriddenEquality() : null;
+ Object inner1 = inner instanceof com.ishland.c2me.opts.dfc.common.ducks.IEqualityOverriding e1 ? e1.c2me$getOverriddenEquality() : null;
+ if (inner1 == null) {
+ this.c2me$optionalEquality = inner;
+ break;
@@ -341,7 +339,7 @@ index 4c53031cf8f6198825b190955d96f20bbcccd77e..fb3c3c3e837056e2762cf32050440ed7
FlatCache("flat_cache"),
Cache2D("cache_2d"),
diff --git a/net/minecraft/world/level/levelgen/NoiseChunk.java b/net/minecraft/world/level/levelgen/NoiseChunk.java
index 977b0d595e5637c80e7d4bb20da8896a0b64b844..840c15e4e2613c20b6d4fbcb44cb096997958bd3 100644
index 977b0d595e5637c80e7d4bb20da8896a0b64b844..1a3da40d668054c92027cfe83d2ddbd803e0a1dd 100644
--- a/net/minecraft/world/level/levelgen/NoiseChunk.java
+++ b/net/minecraft/world/level/levelgen/NoiseChunk.java
@@ -4,9 +4,11 @@ import com.google.common.collect.Lists;
@@ -362,14 +360,14 @@ index 977b0d595e5637c80e7d4bb20da8896a0b64b844..840c15e4e2613c20b6d4fbcb44cb0969
-public class NoiseChunk implements DensityFunction.ContextProvider, DensityFunction.FunctionContext {
+// DivineMC start - Density Function Compiler
+import org.bxteam.divinemc.dfc.common.ast.EvalType;
+import org.bxteam.divinemc.dfc.common.ducks.IArrayCacheCapable;
+import org.bxteam.divinemc.dfc.common.ducks.ICoordinatesFilling;
+import org.bxteam.divinemc.dfc.common.ducks.IFastCacheLike;
+import org.bxteam.divinemc.dfc.common.gen.DelegatingBlendingAwareVisitor;
+import org.bxteam.divinemc.dfc.common.util.ArrayCache;
+import org.bxteam.divinemc.dfc.common.vif.EachApplierVanillaInterface;
+import org.bxteam.divinemc.dfc.common.vif.NoisePosVanillaInterface;
+import com.ishland.c2me.opts.dfc.common.ast.EvalType;
+import com.ishland.c2me.opts.dfc.common.ducks.IArrayCacheCapable;
+import com.ishland.c2me.opts.dfc.common.ducks.ICoordinatesFilling;
+import com.ishland.c2me.opts.dfc.common.ducks.IFastCacheLike;
+import com.ishland.c2me.opts.dfc.common.gen.DelegatingBlendingAwareVisitor;
+import com.ishland.c2me.opts.dfc.common.util.ArrayCache;
+import com.ishland.c2me.opts.dfc.common.vif.EachApplierVanillaInterface;
+import com.ishland.c2me.opts.dfc.common.vif.NoisePosVanillaInterface;
+// DivineMC end - Density Function Compiler
+
+public class NoiseChunk implements DensityFunction.ContextProvider, DensityFunction.FunctionContext, IArrayCacheCapable, ICoordinatesFilling {
@@ -1155,7 +1153,7 @@ index 977b0d595e5637c80e7d4bb20da8896a0b64b844..840c15e4e2613c20b6d4fbcb44cb0969
@Override
diff --git a/net/minecraft/world/level/levelgen/RandomState.java b/net/minecraft/world/level/levelgen/RandomState.java
index f1e089ecfffa40cd794c49db30fcedf138d3fee9..b28221ca337ce8d76bbccdd736a4c5b2c7cd08da 100644
index f1e089ecfffa40cd794c49db30fcedf138d3fee9..3d8bdd7e40c7457c0ad7729162b43cba2043b8b5 100644
--- a/net/minecraft/world/level/levelgen/RandomState.java
+++ b/net/minecraft/world/level/levelgen/RandomState.java
@@ -122,6 +122,41 @@ public final class RandomState {
@@ -1168,29 +1166,29 @@ index f1e089ecfffa40cd794c49db30fcedf138d3fee9..b28221ca337ce8d76bbccdd736a4c5b2
+ com.google.common.base.Stopwatch stopwatch = com.google.common.base.Stopwatch.createStarted();
+ it.unimi.dsi.fastutil.objects.Reference2ReferenceMap<DensityFunction, DensityFunction> tempCache = new it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap<>();
+ this.router = new NoiseRouter(
+ org.bxteam.divinemc.dfc.common.gen.BytecodeGen.compile(this.router.barrierNoise(), tempCache),
+ org.bxteam.divinemc.dfc.common.gen.BytecodeGen.compile(this.router.fluidLevelFloodednessNoise(), tempCache),
+ org.bxteam.divinemc.dfc.common.gen.BytecodeGen.compile(this.router.fluidLevelSpreadNoise(), tempCache),
+ org.bxteam.divinemc.dfc.common.gen.BytecodeGen.compile(this.router.lavaNoise(), tempCache),
+ org.bxteam.divinemc.dfc.common.gen.BytecodeGen.compile(this.router.temperature(), tempCache),
+ org.bxteam.divinemc.dfc.common.gen.BytecodeGen.compile(this.router.vegetation(), tempCache),
+ org.bxteam.divinemc.dfc.common.gen.BytecodeGen.compile(this.router.continents(), tempCache),
+ org.bxteam.divinemc.dfc.common.gen.BytecodeGen.compile(this.router.erosion(), tempCache),
+ org.bxteam.divinemc.dfc.common.gen.BytecodeGen.compile(this.router.depth(), tempCache),
+ org.bxteam.divinemc.dfc.common.gen.BytecodeGen.compile(this.router.ridges(), tempCache),
+ org.bxteam.divinemc.dfc.common.gen.BytecodeGen.compile(this.router.initialDensityWithoutJaggedness(), tempCache),
+ org.bxteam.divinemc.dfc.common.gen.BytecodeGen.compile(this.router.finalDensity(), tempCache),
+ org.bxteam.divinemc.dfc.common.gen.BytecodeGen.compile(this.router.veinToggle(), tempCache),
+ org.bxteam.divinemc.dfc.common.gen.BytecodeGen.compile(this.router.veinRidged(), tempCache),
+ org.bxteam.divinemc.dfc.common.gen.BytecodeGen.compile(this.router.veinGap(), tempCache)
+ com.ishland.c2me.opts.dfc.common.gen.BytecodeGen.compile(this.router.barrierNoise(), tempCache),
+ com.ishland.c2me.opts.dfc.common.gen.BytecodeGen.compile(this.router.fluidLevelFloodednessNoise(), tempCache),
+ com.ishland.c2me.opts.dfc.common.gen.BytecodeGen.compile(this.router.fluidLevelSpreadNoise(), tempCache),
+ com.ishland.c2me.opts.dfc.common.gen.BytecodeGen.compile(this.router.lavaNoise(), tempCache),
+ com.ishland.c2me.opts.dfc.common.gen.BytecodeGen.compile(this.router.temperature(), tempCache),
+ com.ishland.c2me.opts.dfc.common.gen.BytecodeGen.compile(this.router.vegetation(), tempCache),
+ com.ishland.c2me.opts.dfc.common.gen.BytecodeGen.compile(this.router.continents(), tempCache),
+ com.ishland.c2me.opts.dfc.common.gen.BytecodeGen.compile(this.router.erosion(), tempCache),
+ com.ishland.c2me.opts.dfc.common.gen.BytecodeGen.compile(this.router.depth(), tempCache),
+ com.ishland.c2me.opts.dfc.common.gen.BytecodeGen.compile(this.router.ridges(), tempCache),
+ com.ishland.c2me.opts.dfc.common.gen.BytecodeGen.compile(this.router.initialDensityWithoutJaggedness(), tempCache),
+ com.ishland.c2me.opts.dfc.common.gen.BytecodeGen.compile(this.router.finalDensity(), tempCache),
+ com.ishland.c2me.opts.dfc.common.gen.BytecodeGen.compile(this.router.veinToggle(), tempCache),
+ com.ishland.c2me.opts.dfc.common.gen.BytecodeGen.compile(this.router.veinRidged(), tempCache),
+ com.ishland.c2me.opts.dfc.common.gen.BytecodeGen.compile(this.router.veinGap(), tempCache)
+ );
+ this.sampler = new Climate.Sampler(
+ org.bxteam.divinemc.dfc.common.gen.BytecodeGen.compile(this.sampler.temperature(), tempCache),
+ org.bxteam.divinemc.dfc.common.gen.BytecodeGen.compile(this.sampler.humidity(), tempCache),
+ org.bxteam.divinemc.dfc.common.gen.BytecodeGen.compile(this.sampler.continentalness(), tempCache),
+ org.bxteam.divinemc.dfc.common.gen.BytecodeGen.compile(this.sampler.erosion(), tempCache),
+ org.bxteam.divinemc.dfc.common.gen.BytecodeGen.compile(this.sampler.depth(), tempCache),
+ org.bxteam.divinemc.dfc.common.gen.BytecodeGen.compile(this.sampler.weirdness(), tempCache),
+ com.ishland.c2me.opts.dfc.common.gen.BytecodeGen.compile(this.sampler.temperature(), tempCache),
+ com.ishland.c2me.opts.dfc.common.gen.BytecodeGen.compile(this.sampler.humidity(), tempCache),
+ com.ishland.c2me.opts.dfc.common.gen.BytecodeGen.compile(this.sampler.continentalness(), tempCache),
+ com.ishland.c2me.opts.dfc.common.gen.BytecodeGen.compile(this.sampler.erosion(), tempCache),
+ com.ishland.c2me.opts.dfc.common.gen.BytecodeGen.compile(this.sampler.depth(), tempCache),
+ com.ishland.c2me.opts.dfc.common.gen.BytecodeGen.compile(this.sampler.weirdness(), tempCache),
+ this.sampler.spawnTarget()
+ );
+ stopwatch.stop();

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Clump experience orbs
diff --git a/net/minecraft/world/entity/ExperienceOrb.java b/net/minecraft/world/entity/ExperienceOrb.java
index 382ef2dad5e995bc01f6492218b8c8f7a930d6ac..598d46010877cf31c8b6f23deecb91ce61c832b2 100644
index c8354d46ed909090f7c15f396863bf7d73afcefa..96d22f93fc07de0fecf3249081a997c280b8fde2 100644
--- a/net/minecraft/world/entity/ExperienceOrb.java
+++ b/net/minecraft/world/entity/ExperienceOrb.java
@@ -50,6 +50,10 @@ public class ExperienceOrb extends Entity {
@@ -19,7 +19,7 @@ index 382ef2dad5e995bc01f6492218b8c8f7a930d6ac..598d46010877cf31c8b6f23deecb91ce
private void loadPaperNBT(ValueInput input) {
input.read("Paper.ExpData", net.minecraft.nbt.CompoundTag.CODEC).ifPresent(expData -> {
@@ -273,6 +277,28 @@ public class ExperienceOrb extends Entity {
@@ -272,6 +276,28 @@ public class ExperienceOrb extends Entity {
}
private static boolean tryMergeToExisting(ServerLevel level, Vec3 pos, int amount) {
@@ -48,7 +48,7 @@ index 382ef2dad5e995bc01f6492218b8c8f7a930d6ac..598d46010877cf31c8b6f23deecb91ce
// Paper - TODO some other event for this kind of merge
AABB aabb = AABB.ofSize(pos, 1.0, 1.0, 1.0);
int randomInt = level.getRandom().nextInt(io.papermc.paper.configuration.GlobalConfiguration.get().misc.xpOrbGroupsPerArea.or(ORB_GROUPS_PER_AREA)); // Paper - Configure how many orb groups per area
@@ -290,11 +316,11 @@ public class ExperienceOrb extends Entity {
@@ -289,11 +315,11 @@ public class ExperienceOrb extends Entity {
}
private boolean canMerge(ExperienceOrb orb) {
@@ -62,7 +62,7 @@ index 382ef2dad5e995bc01f6492218b8c8f7a930d6ac..598d46010877cf31c8b6f23deecb91ce
}
private void merge(ExperienceOrb orb) {
@@ -303,6 +329,18 @@ public class ExperienceOrb extends Entity {
@@ -302,6 +328,18 @@ public class ExperienceOrb extends Entity {
return;
}
// Paper end - call orb merge event
@@ -81,7 +81,7 @@ index 382ef2dad5e995bc01f6492218b8c8f7a930d6ac..598d46010877cf31c8b6f23deecb91ce
this.count = this.count + orb.count;
this.age = Math.min(this.age, orb.age);
orb.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.MERGE); // CraftBukkit - add Bukkit remove cause
@@ -344,6 +382,13 @@ public class ExperienceOrb extends Entity {
@@ -343,6 +381,13 @@ public class ExperienceOrb extends Entity {
output.putInt("Value", this.getValue()); // Paper - save as Integer
output.putInt("Count", this.count);
this.savePaperNBT(output); // Paper
@@ -95,7 +95,7 @@ index 382ef2dad5e995bc01f6492218b8c8f7a930d6ac..598d46010877cf31c8b6f23deecb91ce
}
@Override
@@ -353,10 +398,52 @@ public class ExperienceOrb extends Entity {
@@ -352,10 +397,52 @@ public class ExperienceOrb extends Entity {
this.setValue(input.getIntOr("Value", 0)); // Paper - load as Integer
this.count = input.read("Count", ExtraCodecs.POSITIVE_INT).orElse(1);
this.loadPaperNBT(input); // Paper
@@ -148,7 +148,7 @@ index 382ef2dad5e995bc01f6492218b8c8f7a930d6ac..598d46010877cf31c8b6f23deecb91ce
if (entity instanceof ServerPlayer serverPlayer) {
if (entity.takeXpDelay == 0 && new com.destroystokyo.paper.event.player.PlayerPickupExperienceEvent(serverPlayer.getBukkitEntity(), (org.bukkit.entity.ExperienceOrb) this.getBukkitEntity()).callEvent()) { // Paper - PlayerPickupExperienceEvent
entity.takeXpDelay = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerXpCooldownEvent(entity, this.level().purpurConfig.playerExpPickupDelay, org.bukkit.event.player.PlayerExpCooldownChangeEvent.ChangeReason.PICKUP_ORB).getNewCooldown(); // CraftBukkit - entityhuman.takeXpDelay = 2; // Purpur - Configurable player pickup exp delay
@@ -374,10 +461,60 @@ public class ExperienceOrb extends Entity {
@@ -373,10 +460,60 @@ public class ExperienceOrb extends Entity {
}
}

View File

@@ -1,16 +1,15 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Wed, 29 Jan 2025 00:59:03 +0300
Subject: [PATCH] Parallel world ticking
Subject: [PATCH] SparklyPaper: Parallel world ticking
Original project: https://github.com/SparklyPower/SparklyPaper
TODO: find the crash problem and fix it (Attempting to remove entity ... from entity slices (.., ..) that is receiving status updates)
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java
index c10e31017e7dfab348e9cc45c28d3858863ac0b1..97bdfe92f32368427bff4960b8f5e39f298c00ab 100644
index 6ce4a98e4d3b633e3c87944c23b6b3f0ff58f159..57fec1f9a210d2ecb74ff7b05cec790ae77f9178 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java
@@ -1155,7 +1155,7 @@ public final class ChunkHolderManager {
@@ -1142,7 +1142,7 @@ public final class ChunkHolderManager {
if (changedFullStatus.isEmpty()) {
return;
}
@@ -18,8 +17,8 @@ index c10e31017e7dfab348e9cc45c28d3858863ac0b1..97bdfe92f32368427bff4960b8f5e39f
+ if (org.bxteam.divinemc.config.DivineConfig.AsyncCategory.enableParallelWorldTicking && !TickThread.isTickThreadFor(world) || !TickThread.isTickThread()) { // DivineMC - Parallel world ticking
// These will be handled on the next ServerChunkCache$MainThreadExecutor#pollTask, as it runs the distance manager update
// which will invoke processTicketUpdates
this.getData().offThreadPendingFullLoadUpdate.addAll(changedFullStatus); // DivineMC - Chunk System optimization
@@ -1176,7 +1176,13 @@ public final class ChunkHolderManager {
this.offThreadPendingFullLoadUpdate.addAll(changedFullStatus);
@@ -1163,7 +1163,13 @@ public final class ChunkHolderManager {
// note: never call while inside the chunk system, this will absolutely break everything
public void processUnloads() {
@@ -34,7 +33,7 @@ index c10e31017e7dfab348e9cc45c28d3858863ac0b1..97bdfe92f32368427bff4960b8f5e39f
if (BLOCK_TICKET_UPDATES.get() == Boolean.TRUE) {
throw new IllegalStateException("Cannot unload chunks recursively");
@@ -1463,7 +1469,7 @@ public final class ChunkHolderManager {
@@ -1429,7 +1435,7 @@ public final class ChunkHolderManager {
if (BLOCK_TICKET_UPDATES.get() == Boolean.TRUE) {
throw new IllegalStateException("Cannot update ticket level while unloading chunks or updating entity manager");
}
@@ -83,13 +82,13 @@ index ac27ff24f018d8798921c5152e679ceed1e88d8d..ec7d1353b19e55b00c558df8981323ef
List<org.bukkit.block.BlockState> states = new java.util.ArrayList<>(level.capturedBlockStates.values());
level.capturedBlockStates.clear();
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index aa8c2a3fc3a9a6318a3e757c6e51249ff11bd633..7bf2449141270c8ed924e38fdd8f9c1830ac2d99 100644
index a0cad0bdb8245b19f4ff983245d61d7b237a4042..c56fa00f9443b6a3a44f0b89da9dcfb6a4faf1c8 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -290,6 +290,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
protected boolean upnp = false; // Purpur - UPnP Port Forwarding
public final org.bxteam.divinemc.util.tps.TPSCalculator tpsCalculator = new org.bxteam.divinemc.util.tps.TPSCalculator(); // DivineMC - Lag compensation
public org.bxteam.divinemc.util.AsyncProcessor mobSpawnExecutor = new org.bxteam.divinemc.util.AsyncProcessor("mob_spawning"); // DivineMC - Async mob spawning
public gg.pufferfish.pufferfish.util.AsyncExecutor mobSpawnExecutor = new gg.pufferfish.pufferfish.util.AsyncExecutor("Mob Spawning"); // DivineMC - Pufferfish: Optimize mob spawning
+ public java.util.concurrent.Semaphore serverLevelTickingSemaphore = null; // DivineMC - Parallel world ticking
public static <S extends MinecraftServer> S spin(Function<Thread, S> threadFunction) {
@@ -144,7 +143,7 @@ index aa8c2a3fc3a9a6318a3e757c6e51249ff11bd633..7bf2449141270c8ed924e38fdd8f9c18
}
@Override
@@ -1660,6 +1673,18 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1661,6 +1674,18 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
public final io.papermc.paper.threadedregions.EntityScheduler.EntitySchedulerTickList entitySchedulerTickList = new io.papermc.paper.threadedregions.EntityScheduler.EntitySchedulerTickList(); // Paper - optimise Folia entity scheduler
@@ -163,7 +162,7 @@ index aa8c2a3fc3a9a6318a3e757c6e51249ff11bd633..7bf2449141270c8ed924e38fdd8f9c18
protected void tickChildren(BooleanSupplier hasTimeLeft) {
this.getPlayerList().getPlayers().forEach(serverPlayer1 -> serverPlayer1.connection.suspendFlushing());
this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit
@@ -1705,28 +1730,43 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1706,28 +1731,43 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
this.isIteratingOverLevels = true; // Paper - Throw exception on world create while being ticked
@@ -225,7 +224,7 @@ index aa8c2a3fc3a9a6318a3e757c6e51249ff11bd633..7bf2449141270c8ed924e38fdd8f9c18
this.isIteratingOverLevels = false; // Paper - Throw exception on world create while being ticked
this.tickConnection();
@@ -1804,6 +1844,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1805,6 +1845,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
Map<ResourceKey<Level>, ServerLevel> oldLevels = this.levels;
Map<ResourceKey<Level>, ServerLevel> newLevels = Maps.newLinkedHashMap(oldLevels);
newLevels.remove(level.dimension());
@@ -234,7 +233,7 @@ index aa8c2a3fc3a9a6318a3e757c6e51249ff11bd633..7bf2449141270c8ed924e38fdd8f9c18
}
// CraftBukkit end
diff --git a/net/minecraft/server/PlayerAdvancements.java b/net/minecraft/server/PlayerAdvancements.java
index 10e5469df1800bcdfb3f8cb4045ee25a4bafc58c..8efed0ffdc906b6c1ba054831e481f53c11f102d 100644
index 3836d60ce84fb26f30a609486a5755d3fd1c94f1..1aab02441e4dfa7703963855d77bb918dee7a6fc 100644
--- a/net/minecraft/server/PlayerAdvancements.java
+++ b/net/minecraft/server/PlayerAdvancements.java
@@ -54,6 +54,7 @@ public class PlayerAdvancements {
@@ -334,12 +333,12 @@ index 10e5469df1800bcdfb3f8cb4045ee25a4bafc58c..8efed0ffdc906b6c1ba054831e481f53
}
} else if (this.visible.remove(advancementHolder)) {
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
index 978934f81ba023d7565d2e66c51f6ca249510702..13d85eb366a070bfd6723088412f51af07892362 100644
index 46adbe6ccf1e4291e33a52a6612f624558c18f96..374abd7e1502edefb78cd6451a36c3b8ad6d8f8f 100644
--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -224,6 +224,13 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@@ -218,6 +218,13 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
}
// DivineMC end - Pufferfish SIMD
// DivineMC end - Pufferfish: SIMD Support
+ // DivineMC start - Parallel world ticking
+ if (org.bxteam.divinemc.config.DivineConfig.AsyncCategory.enableParallelWorldTicking) {
@@ -352,7 +351,7 @@ index 978934f81ba023d7565d2e66c51f6ca249510702..13d85eb366a070bfd6723088412f51af
this.setFlightAllowed(properties.allowFlight);
this.setMotd(properties.motd);
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
index 7205fc8d3b17863c262d4c4c3cb956c852468c6f..3cf54630d36f821a232fa03f9094c4c1f70902a1 100644
index bf680624bc6c618dfa0eeeb74c103ff6716fd27e..654d03368f06ab9870c11745b0994ea6722fa7bf 100644
--- a/net/minecraft/server/level/ServerChunkCache.java
+++ b/net/minecraft/server/level/ServerChunkCache.java
@@ -175,7 +175,6 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
@@ -364,26 +363,26 @@ index 7205fc8d3b17863c262d4c4c3cb956c852468c6f..3cf54630d36f821a232fa03f9094c4c1
}
}
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
index 324c573899965b204cec17458b6cb9733d83a868..2348a3ec6afb2618033b8f40257f7c9c58448397 100644
index 3c1795eb56900cd80cfec38bd1d922d566463ecb..b752bcc03b558a26f9c592c829efb44a299be8de 100644
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -181,7 +181,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -180,7 +180,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
private final MinecraftServer server;
public final net.minecraft.world.level.storage.PrimaryLevelData serverLevelData; // CraftBukkit - type
public final ca.spottedleaf.moonrise.patches.chunk_system.scheduling.ChunkHolderManager.LevelHolderData chunkHolderData; // DivineMC - Chunk System optimization
private int lastSpawnChunkRadius;
- final EntityTickList entityTickList = new EntityTickList();
+ final EntityTickList entityTickList = new EntityTickList(this); // DivineMC - Parallel world ticking
private final ServerWaypointManager waypointManager;
// Paper - rewrite chunk system
private final GameEventDispatcher gameEventDispatcher;
@@ -208,6 +208,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
private double preciseTime; // Purpur - Configurable daylight cycle
private boolean forceTime; // Purpur - Configurable daylight cycle
private final RandomSequences randomSequences;
@@ -217,6 +217,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
public boolean hasRidableMoveEvent = false; // Purpur - Ridables
public net.minecraft.world.item.ItemStack ominousBanner; // DivineMC - Optimize Raids
public org.bxteam.divinemc.util.tps.TPSCalculator tpsCalculator = new org.bxteam.divinemc.util.tps.TPSCalculator(); // DivineMC - Lag Compensation
+ public java.util.concurrent.ExecutorService tickExecutor; // DivineMC - Parallel world ticking
// CraftBukkit start
public final LevelStorageSource.LevelStorageAccess levelStorageAccess;
@Override
public @Nullable LevelChunk getChunkIfLoaded(int x, int z) {
@@ -680,7 +681,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
this.sleepStatus = new SleepStatus();
this.gameEventDispatcher = new GameEventDispatcher(this);
@@ -393,15 +392,15 @@ index 324c573899965b204cec17458b6cb9733d83a868..2348a3ec6afb2618033b8f40257f7c9c
// Paper start - rewrite chunk system
this.moonrise$setEntityLookup(new ca.spottedleaf.moonrise.patches.chunk_system.level.entity.server.ServerEntityLookup((ServerLevel)(Object)this, ((ServerLevel)(Object)this).new EntityCallbacks()));
this.chunkTaskScheduler = new ca.spottedleaf.moonrise.patches.chunk_system.scheduling.ChunkTaskScheduler((ServerLevel)(Object)this);
@@ -697,6 +698,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
this.chunkDataController = new ca.spottedleaf.moonrise.patches.chunk_system.io.datacontroller.ChunkDataController((ServerLevel)(Object)this, this.chunkTaskScheduler);
// Paper end - rewrite chunk system
@@ -698,6 +699,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
this.getCraftServer().addWorld(this.getWorld()); // CraftBukkit
+ this.tickExecutor = java.util.concurrent.Executors.newSingleThreadExecutor(new org.bxteam.divinemc.server.ServerLevelTickExecutorThreadFactory(getWorld().getName())); // DivineMC - Parallel world ticking
this.preciseTime = this.serverLevelData.getDayTime(); // Purpur - Configurable daylight cycle
this.ominousBanner = Objects.requireNonNullElse(this.registryAccess(), net.minecraft.core.RegistryAccess.EMPTY).lookup(Registries.BANNER_PATTERN).map(Raid::getOminousBannerInstance).orElse(null); // DivineMC - Optimize Raids
+ this.tickExecutor = java.util.concurrent.Executors.newSingleThreadExecutor(new org.bxteam.divinemc.async.world.ServerLevelTickThreadFactory(getWorld().getName())); // DivineMC - Parallel world ticking
}
@@ -1298,12 +1300,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
// Paper start
@@ -1300,12 +1302,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
if (fluidState.is(fluid)) {
fluidState.tick(this, pos, blockState);
}
@@ -419,7 +418,7 @@ index 324c573899965b204cec17458b6cb9733d83a868..2348a3ec6afb2618033b8f40257f7c9c
}
private void tickBlock(BlockPos pos, Block block) {
@@ -1311,12 +1313,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -1313,12 +1315,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
if (blockState.is(block)) {
blockState.tick(this, pos, this.random);
}
@@ -437,7 +436,7 @@ index 324c573899965b204cec17458b6cb9733d83a868..2348a3ec6afb2618033b8f40257f7c9c
}
// Paper start - log detailed entity tick information
@@ -1566,6 +1568,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -1581,6 +1583,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
}
private void addPlayer(ServerPlayer player) {
@@ -445,7 +444,7 @@ index 324c573899965b204cec17458b6cb9733d83a868..2348a3ec6afb2618033b8f40257f7c9c
Entity entity = this.getEntity(player.getUUID());
if (entity != null) {
LOGGER.warn("Force-added player with duplicate UUID {}", player.getUUID());
@@ -1578,7 +1581,13 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -1593,7 +1596,13 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
// CraftBukkit start
private boolean addEntity(Entity entity, @Nullable org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) {
@@ -461,18 +460,18 @@ index 324c573899965b204cec17458b6cb9733d83a868..2348a3ec6afb2618033b8f40257f7c9c
// Paper start - extra debug info
if (entity.valid) {
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
index b4bbacdd5061f45c619211bbed40a5f9dc1b0ae0..ca7eeb696c777d6299be49c1e3b2f033b83da5ba 100644
index 1431a2e386bee22ec10365a38ead349a398d551f..77d1cab278a13e08ba8096af2c683b5042cc1574 100644
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -430,6 +430,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
private boolean tpsBar = false; // Purpur - Implement TPSBar
@@ -431,6 +431,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
private boolean compassBar = false; // Purpur - Add compass command
private boolean ramBar = false; // Purpur - Implement rambar commands
public boolean smoothWorldTeleport; // DivineMC - Smooth teleport API
+ public boolean hasTickedAtLeastOnceInNewWorld = false; // DivineMC - Parallel world ticking
// Paper start - rewrite chunk system
private ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.PlayerChunkLoaderData chunkLoader;
@@ -747,6 +748,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
@@ -748,6 +749,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
@Override
public void tick() {
@@ -480,7 +479,7 @@ index b4bbacdd5061f45c619211bbed40a5f9dc1b0ae0..ca7eeb696c777d6299be49c1e3b2f033
// CraftBukkit start
if (this.joining) {
this.joining = false;
@@ -1433,6 +1435,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
@@ -1434,6 +1436,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
return this;
} else {
// CraftBukkit start
@@ -488,7 +487,7 @@ index b4bbacdd5061f45c619211bbed40a5f9dc1b0ae0..ca7eeb696c777d6299be49c1e3b2f033
/*
this.isChangingDimension = true;
LevelData levelData = level.getLevelData();
@@ -1778,6 +1781,12 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
@@ -1779,6 +1782,12 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
return OptionalInt.empty();
} else {
// CraftBukkit start
@@ -501,7 +500,7 @@ index b4bbacdd5061f45c619211bbed40a5f9dc1b0ae0..ca7eeb696c777d6299be49c1e3b2f033
this.containerMenu = abstractContainerMenu; // Moved up
if (!this.isImmobile())
this.connection
@@ -1842,6 +1851,11 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
@@ -1843,6 +1852,11 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
}
@Override
public void closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
@@ -514,7 +513,7 @@ index b4bbacdd5061f45c619211bbed40a5f9dc1b0ae0..ca7eeb696c777d6299be49c1e3b2f033
// Paper end - Inventory close reason
this.connection.send(new ClientboundContainerClosePacket(this.containerMenu.containerId));
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
index 5ebbb4e37469beef11bdfd1531b0d10f3d01c826..ef9b99bc76876e7348b418b4a66339c2b8b33f50 100644
index 84250c9786f4886fe4ab2e42808f8162da3f45d8..cfe2bbc46046f144044d8cba67cda978f231d354 100644
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -149,6 +149,7 @@ public abstract class PlayerList {
@@ -525,7 +524,7 @@ index 5ebbb4e37469beef11bdfd1531b0d10f3d01c826..ef9b99bc76876e7348b418b4a66339c2
player.isRealPlayer = true; // Paper
player.loginTime = System.currentTimeMillis(); // Paper - Replace OfflinePlayer#getLastPlayed
GameProfile gameProfile = player.getGameProfile();
@@ -678,6 +679,14 @@ public abstract class PlayerList {
@@ -685,6 +686,14 @@ public abstract class PlayerList {
}
public ServerPlayer respawn(ServerPlayer player, boolean keepInventory, Entity.RemovalReason reason, @Nullable org.bukkit.event.player.PlayerRespawnEvent.RespawnReason eventReason, @Nullable org.bukkit.Location location) {
@@ -537,10 +536,10 @@ index 5ebbb4e37469beef11bdfd1531b0d10f3d01c826..ef9b99bc76876e7348b418b4a66339c2
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureOnlyTickThread("Cannot respawn player off-main, respawning in world " + player.level().getWorld().getName());
+ }
+ // DivineMC end - Parallel world ticking
player.stopRiding(); // CraftBukkit
this.players.remove(player);
this.playersByName.remove(player.getScoreboardName().toLowerCase(java.util.Locale.ROOT)); // Spigot
player.level().removePlayerImmediately(player, reason);
@@ -687,6 +696,7 @@ public abstract class PlayerList {
@@ -695,6 +704,7 @@ public abstract class PlayerList {
ServerPlayer serverPlayer = player;
Level fromWorld = player.level();
player.wonGame = false;
@@ -634,10 +633,10 @@ index f9e7532f86122a379692561a639a209a126e8bba..839f6b7696ef85314da185bedba7cfc5
if (isLocatorBarEnabledFor(player)) {
if (!connection.isBroken()) {
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index ece35e552888f2a2afb5f19f90d5700ee04e836a..9ccc7ae83cc51013c74e47e0a12b629f8b93c407 100644
index bdf9899f960b6cca3529af97ebff738761208439..adea48cfde04df3107341075f414133ae37d986e 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -3431,14 +3431,34 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -3459,14 +3459,34 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
if (this.portalProcess != null) {
if (this.portalProcess.processPortalTeleportation(serverLevel, this, this.canUsePortal(false))) {
this.setPortalCooldown();
@@ -678,7 +677,7 @@ index ece35e552888f2a2afb5f19f90d5700ee04e836a..9ccc7ae83cc51013c74e47e0a12b629f
} else if (this.portalProcess.hasExpired()) {
this.portalProcess = null;
}
@@ -4015,6 +4035,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4043,6 +4063,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
private Entity teleportCrossDimension(ServerLevel oldLevel, ServerLevel newLevel, TeleportTransition teleportTransition) {
@@ -687,14 +686,14 @@ index ece35e552888f2a2afb5f19f90d5700ee04e836a..9ccc7ae83cc51013c74e47e0a12b629f
List<Entity> list = new ArrayList<>(passengers.size());
this.ejectPassengers();
diff --git a/net/minecraft/world/entity/PortalProcessor.java b/net/minecraft/world/entity/PortalProcessor.java
index 91f6d43b3785ddad7db8eb529ba3293c45f3588d..fc3ab0881bf9b275beb9b32ca5a7475d50789401 100644
index 91f6d43b3785ddad7db8eb529ba3293c45f3588d..7fd5f40ee928330769bbe0c5e8da17fa65b30db6 100644
--- a/net/minecraft/world/entity/PortalProcessor.java
+++ b/net/minecraft/world/entity/PortalProcessor.java
@@ -11,6 +11,7 @@ public class PortalProcessor {
private BlockPos entryPosition;
private int portalTime;
private boolean insidePortalThisTick;
+ private org.bxteam.divinemc.util.PWTTeleportState teleportState = org.bxteam.divinemc.util.PWTTeleportState.INACTIVE; // DivineMC - Parallel world ticking
+ private org.bxteam.divinemc.async.world.TeleportState teleportState = org.bxteam.divinemc.async.world.TeleportState.INACTIVE; // DivineMC - Parallel world ticking
public PortalProcessor(Portal portal, BlockPos entryPosition) {
this.portal = portal;
@@ -722,27 +721,27 @@ index 91f6d43b3785ddad7db8eb529ba3293c45f3588d..fc3ab0881bf9b275beb9b32ca5a7475d
+
+ // DivineMC start - Parallel world ticking
+ public boolean isParallelTeleportPending() {
+ return this.teleportState == org.bxteam.divinemc.util.PWTTeleportState.PENDING;
+ return this.teleportState == org.bxteam.divinemc.async.world.TeleportState.PENDING;
+ }
+
+ public boolean isParallelTeleportScheduled() {
+ return this.teleportState != org.bxteam.divinemc.util.PWTTeleportState.INACTIVE;
+ return this.teleportState != org.bxteam.divinemc.async.world.TeleportState.INACTIVE;
+ }
+
+ public boolean isParallelCancelledByPlugin() {
+ return this.teleportState == org.bxteam.divinemc.util.PWTTeleportState.CANCELLED;
+ return this.teleportState == org.bxteam.divinemc.async.world.TeleportState.CANCELLED;
+ }
+
+ public void setParallelAsScheduled() {
+ this.teleportState = org.bxteam.divinemc.util.PWTTeleportState.PENDING;
+ this.teleportState = org.bxteam.divinemc.async.world.TeleportState.PENDING;
+ }
+
+ public void confirmParallelAsHandled() {
+ this.teleportState = org.bxteam.divinemc.util.PWTTeleportState.INACTIVE;
+ this.teleportState = org.bxteam.divinemc.async.world.TeleportState.INACTIVE;
+ }
+
+ public void setParallelAsCancelled() {
+ this.teleportState = org.bxteam.divinemc.util.PWTTeleportState.CANCELLED;
+ this.teleportState = org.bxteam.divinemc.async.world.TeleportState.CANCELLED;
+ }
+ // DivineMC end - Parallel world ticking
}
@@ -1344,7 +1343,7 @@ index d23f255de9208f42125fa358a9e8194c984fe4d3..92e9bc9ba577474ca1108b8d06157395
// CraftBukkit end
}
diff --git a/net/minecraft/world/level/chunk/LevelChunk.java b/net/minecraft/world/level/chunk/LevelChunk.java
index 010c7204bfa772ff9a2187a5db76d7c65ea34f66..6de61b3e75edee87562e3aab01c7020cd91133b3 100644
index 6f25be39103cd0bb26bc365d9599b9846c6fe133..24f13e2b0b694ff4dd01aeea876ef874f1828304 100644
--- a/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/net/minecraft/world/level/chunk/LevelChunk.java
@@ -365,6 +365,7 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
@@ -1356,13 +1355,13 @@ index 010c7204bfa772ff9a2187a5db76d7c65ea34f66..6de61b3e75edee87562e3aab01c7020c
LevelChunkSection section = this.getSection(this.getSectionIndex(y));
boolean hasOnlyAir = section.hasOnlyAir();
diff --git a/net/minecraft/world/level/entity/EntityTickList.java b/net/minecraft/world/level/entity/EntityTickList.java
index 9e75320e51886e0f93c23683d8614128f44a613e..d8b3e0901922016a22ca2801c2c4e0afd28e1c0a 100644
index c89701d7bdc9b889038d3c52f2232fb17624b113..f2ba43b92b0d0356a97069fd427f9fa446d6c007 100644
--- a/net/minecraft/world/level/entity/EntityTickList.java
+++ b/net/minecraft/world/level/entity/EntityTickList.java
@@ -10,17 +10,31 @@ import net.minecraft.world.entity.Entity;
@@ -11,16 +11,31 @@ import net.minecraft.world.entity.Entity;
public class EntityTickList {
public final java.util.concurrent.ConcurrentLinkedQueue<Entity> entities = new java.util.concurrent.ConcurrentLinkedQueue<>(); // Paper - rewrite chunk system // DivineMC - Async mob spawning
public final ca.spottedleaf.moonrise.common.list.IteratorSafeOrderedReferenceSet<net.minecraft.world.entity.Entity> entities = new ca.spottedleaf.moonrise.common.list.IteratorSafeOrderedReferenceSet<>(); // Paper - rewrite chunk system
+ // DivineMC start - Parallel world ticking
+ @Nullable
+ private final net.minecraft.server.level.ServerLevel serverLevel;
@@ -1375,7 +1374,7 @@ index 9e75320e51886e0f93c23683d8614128f44a613e..d8b3e0901922016a22ca2801c2c4e0af
+ this.serverLevel = serverLevel;
+ }
+ // DivineMC end - Parallel world ticking
+
private void ensureActiveIsNotIterated() {
// Paper - rewrite chunk system
}
@@ -1391,7 +1390,7 @@ index 9e75320e51886e0f93c23683d8614128f44a613e..d8b3e0901922016a22ca2801c2c4e0af
this.ensureActiveIsNotIterated();
this.entities.remove(entity); // Paper - rewrite chunk system
}
@@ -30,6 +44,7 @@ public class EntityTickList {
@@ -30,6 +45,7 @@ public class EntityTickList {
}
public void forEach(Consumer<Entity> entity) {

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] MSPT Tracking for each world
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index cbeb56539f00a3139f7c19d29cce92fae49dab2f..59642de7b2d3064c59bb1d8d2fc436cb9e2c2914 100644
index c56fa00f9443b6a3a44f0b89da9dcfb6a4faf1c8..57d401aa7801c8cd37921086c3349414d9f7af4f 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1676,7 +1676,15 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1677,7 +1677,15 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// DivineMC start - Parallel world ticking
private void tickLevel(ServerLevel serverLevel, BooleanSupplier hasTimeLeft) {
try {
@@ -25,7 +25,7 @@ index cbeb56539f00a3139f7c19d29cce92fae49dab2f..59642de7b2d3064c59bb1d8d2fc436cb
CrashReport crashReport = CrashReport.forThrowable(levelTickingException, "Exception ticking world");
serverLevel.fillReportDetails(crashReport);
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
index 2348a3ec6afb2618033b8f40257f7c9c58448397..adac2dd1530c21c610f6dced12a80ab726fe3a98 100644
index b752bcc03b558a26f9c592c829efb44a299be8de..f9091b2daf735fd0788f8d6d60e3c812fd6dd4f2 100644
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -569,6 +569,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Catch update suppressors
diff --git a/net/minecraft/network/protocol/PacketUtils.java b/net/minecraft/network/protocol/PacketUtils.java
index e65c62dbe4c1560ae153e4c4344e9194c783a2f4..e3d3b062e273fee4a9d3ba3cadc212787096dc54 100644
index 4535858701b2bb232b9d2feb2af6551526232ddc..aa4dd7517e8be167aef1eaf7aa907e3ce7cc0e62 100644
--- a/net/minecraft/network/protocol/PacketUtils.java
+++ b/net/minecraft/network/protocol/PacketUtils.java
@@ -25,6 +25,10 @@ public class PacketUtils {
@@ -27,6 +27,10 @@ public class PacketUtils {
if (processor.shouldHandleMessage(packet)) {
try {
packet.handle(processor);
@@ -20,10 +20,10 @@ index e65c62dbe4c1560ae153e4c4344e9194c783a2f4..e3d3b062e273fee4a9d3ba3cadc21278
if (var4 instanceof ReportedException reportedException && reportedException.getCause() instanceof OutOfMemoryError) {
throw makeReportedException(var4, packet, processor);
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 59642de7b2d3064c59bb1d8d2fc436cb9e2c2914..2f9463cbef40dabd8769ba8fe9c18f1ac8487298 100644
index 57d401aa7801c8cd37921086c3349414d9f7af4f..008530bf0f09180ba365fc514b51d22630564de2 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1685,6 +1685,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1686,6 +1686,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
serverLevel.tickTimes10s.add(this.tickCount, j);
serverLevel.tickTimes60s.add(this.tickCount, j);
// DivineMC end - MSPT Tracking for each world

View File

@@ -8,7 +8,7 @@ This patch adds regionized chunk ticking feature, by grouping adjacent chunks in
Original idea by Dueris, modified by NONPLAYT and heavily optimized by dan28000
diff --git a/net/minecraft/network/Connection.java b/net/minecraft/network/Connection.java
index cdacbfa64bda461d4f24c2a85db9feae7766b597..07370cb7bc0bb5a8abfd0062df999ed24c936113 100644
index e72eda830644851656fae3118c513d7bd701be45..4ab30d291de7db5ad7d5684662f41348270802b9 100644
--- a/net/minecraft/network/Connection.java
+++ b/net/minecraft/network/Connection.java
@@ -326,7 +326,7 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
@@ -21,7 +21,7 @@ index cdacbfa64bda461d4f24c2a85db9feae7766b597..07370cb7bc0bb5a8abfd0062df999ed2
if (var2 instanceof ClosedChannelException) {
LOGGER.info("Connection closed during protocol change");
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
index 3cf54630d36f821a232fa03f9094c4c1f70902a1..5f62eee8a60d7fcadb1f9efb7473bc5c20c47263 100644
index 654d03368f06ab9870c11745b0994ea6722fa7bf..7fcf9761c3af761e6d3e402fce2f9cbcc219d3b0 100644
--- a/net/minecraft/server/level/ServerChunkCache.java
+++ b/net/minecraft/server/level/ServerChunkCache.java
@@ -57,6 +57,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
@@ -45,7 +45,7 @@ index 3cf54630d36f821a232fa03f9094c4c1f70902a1..5f62eee8a60d7fcadb1f9efb7473bc5c
@Nullable
@VisibleForDebug
private NaturalSpawner.SpawnState lastSpawnState;
@@ -153,31 +156,240 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
@@ -153,31 +156,246 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
return load ? this.syncLoad(chunkX, chunkZ, toStatus) : null;
}
// Paper end - rewrite chunk system
@@ -128,15 +128,21 @@ index 3cf54630d36f821a232fa03f9094c4c1f70902a1..5f62eee8a60d7fcadb1f9efb7473bc5c
+
+ final Set<Entity> firstTick = java.util.Collections.newSetFromMap(new java.util.concurrent.ConcurrentHashMap<>());
+
+ level.entityTickList.entities.parallelStream().forEach(entity -> {
+ long chunkKey = entity.chunkPosition().longKey;
+ int regionIndex = chunkToRegion.get(chunkKey);
+ if (regionIndex != -1) {
+ regions.get(regionIndex).entities().add(entity);
+ } else {
+ firstTick.add(entity);
+ final ca.spottedleaf.moonrise.common.list.IteratorSafeOrderedReferenceSet.Iterator<Entity> iterator = level.entityTickList.entities.iterator();
+ try {
+ while (iterator.hasNext()) {
+ Entity entity = iterator.next();
+ long chunkKey = entity.chunkPosition().longKey;
+ int regionIndex = chunkToRegion.get(chunkKey);
+ if (regionIndex != -1) {
+ regions.get(regionIndex).entities().add(entity);
+ } else {
+ firstTick.add(entity);
+ }
+ }
+ });
+ } finally {
+ iterator.finishedIterating();
+ }
+
+ return new Output(regions.toArray(new RegionData[0]), firstTick);
+ }
@@ -268,7 +274,10 @@ index 3cf54630d36f821a232fa03f9094c4c1f70902a1..5f62eee8a60d7fcadb1f9efb7473bc5c
+ latch.await();
+ return true;
+ }
+
- // call mid-tick tasks for chunk system
- if ((i & 7) == 0) {
- continue;
+ @Override
+ public boolean isReleasable() {
+ return latch.getCount() == 0;
@@ -281,10 +290,7 @@ index 3cf54630d36f821a232fa03f9094c4c1f70902a1..5f62eee8a60d7fcadb1f9efb7473bc5c
+ java.util.Objects.checkFromToIndex(0, size, raw.length);
+ for (int i = 0; i < size; ++i) {
+ world.tickChunk(raw[i], randomTickSpeed);
- // call mid-tick tasks for chunk system
- if ((i & 7) == 0) {
- continue;
+
+ // call mid-tick tasks for chunk system
+ if ((i & 7) == 0) {
+ continue;
@@ -295,7 +301,7 @@ index 3cf54630d36f821a232fa03f9094c4c1f70902a1..5f62eee8a60d7fcadb1f9efb7473bc5c
}
// Paper end - chunk tick iteration optimisations
@@ -501,14 +713,21 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
@@ -502,14 +720,21 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
long gameTime = this.level.getGameTime();
long l = gameTime - this.lastInhabitedUpdate;
this.lastInhabitedUpdate = gameTime;
@@ -318,10 +324,10 @@ index 3cf54630d36f821a232fa03f9094c4c1f70902a1..5f62eee8a60d7fcadb1f9efb7473bc5c
+ this.broadcastChangedChunks();
+ // DivineMC end - Regionized Chunk Ticking
+
// DivineMC start - Async mob spawning
// DivineMC start - Pufferfish: Optimize mob spawning
if (org.bxteam.divinemc.config.DivineConfig.AsyncCategory.enableAsyncSpawning) {
for (ServerPlayer player : this.level.players) {
@@ -537,14 +756,18 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
@@ -553,14 +778,18 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
}
private void broadcastChangedChunks() {
@@ -346,36 +352,34 @@ index 3cf54630d36f821a232fa03f9094c4c1f70902a1..5f62eee8a60d7fcadb1f9efb7473bc5c
}
private void tickChunks(long timeInhabited) {
@@ -594,25 +817,28 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
@@ -610,23 +839,28 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
filteredSpawningCategories = List.of();
}
- List<LevelChunk> list = this.spawningChunks;
-
- try {
- this.chunkMap.collectSpawningChunks(list);
- // Paper start - chunk tick iteration optimisation
- if (!this.level.paperConfig().entities.spawning.perPlayerMobSpawns) {
- this.shuffleRandom.setSeed(this.level.random.nextLong()); // DivineMC - Misc Optimizations
- Util.shuffle(list, this.shuffleRandom); // Paper - Optional per player mob spawns; do not need this when per-player is enabled
- }
- // Paper end - chunk tick iteration optimisation
+ // DivineMC start - Regionized Chunk Ticking
+ final java.util.concurrent.CompletableFuture<Void> spawns = java.util.concurrent.CompletableFuture.runAsync(() -> {
+ List<LevelChunk> list = this.spawningChunks;
- try {
- this.chunkMap.collectSpawningChunks(list);
- // Paper start - chunk tick iteration optimisation
- this.shuffleRandom.setSeed(this.level.random.nextLong());
- if (!this.level.paperConfig().entities.spawning.perPlayerMobSpawns) Util.shuffle(list, this.shuffleRandom); // Paper - Optional per player mob spawns; do not need this when per-player is enabled
- // Paper end - chunk tick iteration optimisation
-
- for (LevelChunk levelChunk : list) {
- this.tickSpawningChunk(levelChunk, timeInhabited, filteredSpawningCategories, lastSpawnState); // DivineMC - Pufferfish: Optimize mob spawning
+ try {
+ this.chunkMap.collectSpawningChunks(list);
+ // Paper start - chunk tick iteration optimisation
+ if (!this.level.paperConfig().entities.spawning.perPlayerMobSpawns) {
+ this.shuffleRandom.setSeed(this.level.random.nextLong()); // DivineMC - Misc Optimizations
+ this.shuffleRandom.setSeed(this.level.random.nextLong());
+ if (!this.level.paperConfig().entities.spawning.perPlayerMobSpawns)
+ Util.shuffle(list, this.shuffleRandom); // Paper - Optional per player mob spawns; do not need this when per-player is enabled
+ }
+ // Paper end - chunk tick iteration optimisation
- for (LevelChunk levelChunk : list) {
- this.tickSpawningChunk(levelChunk, timeInhabited, filteredSpawningCategories, lastSpawnState); // DivineMC - Async mob spawning
+
+ for (LevelChunk levelChunk : list) {
+ this.tickSpawningChunk(levelChunk, timeInhabited, filteredSpawningCategories, lastSpawnState); // DivineMC - Async mob spawning
+ this.tickSpawningChunk(levelChunk, timeInhabited, filteredSpawningCategories, lastSpawnState); // DivineMC - Pufferfish: Optimize mob spawning
+ }
+ } finally {
+ list.clear();
@@ -392,10 +396,10 @@ index 3cf54630d36f821a232fa03f9094c4c1f70902a1..5f62eee8a60d7fcadb1f9efb7473bc5c
this.level.tickCustomSpawners(this.spawnEnemies, this.spawnFriendlies);
}
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
index d39d15dcb6964aed0bf9c2f64952d229d64cff62..69b2ce6647edacabdff5079114e067a69d485e96 100644
index f9091b2daf735fd0788f8d6d60e3c812fd6dd4f2..0ad18866c323308ad9b87322932e03a283f740b1 100644
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -192,7 +192,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -191,7 +191,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
private final LevelTicks<Block> blockTicks = new LevelTicks<>(this::isPositionTickingWithEntitiesLoaded);
private final LevelTicks<Fluid> fluidTicks = new LevelTicks<>(this::isPositionTickingWithEntitiesLoaded);
private final PathTypeCache pathTypesByPosCache = new PathTypeCache();
@@ -404,7 +408,7 @@ index d39d15dcb6964aed0bf9c2f64952d229d64cff62..69b2ce6647edacabdff5079114e067a6
volatile boolean isUpdatingNavigations;
protected final Raids raids;
private final ObjectLinkedOpenHashSet<BlockEventData> blockEvents = new ObjectLinkedOpenHashSet<>();
@@ -808,6 +808,13 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -806,6 +806,13 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
this.dragonFight.tick();
}
@@ -418,7 +422,7 @@ index d39d15dcb6964aed0bf9c2f64952d229d64cff62..69b2ce6647edacabdff5079114e067a6
io.papermc.paper.entity.activation.ActivationRange.activateEntities(this); // Paper - EAR
this.entityTickList
.forEach(
@@ -1815,22 +1822,16 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -1828,22 +1835,16 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
if (Shapes.joinIsNotEmpty(collisionShape, collisionShape1, BooleanOp.NOT_SAME)) {
List<PathNavigation> list = new ObjectArrayList<>();

View File

@@ -0,0 +1,54 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Wed, 9 Jul 2025 04:37:59 +0300
Subject: [PATCH] C2ME: Limit NBT cache
This patch is based on the following mixins:
* "com/ishland/c2me/opts/chunkio/mixin/limit_nbt_cache/MixinStorageIoWorker.java"
By: ishland <ishlandmc@yeah.net>
As part of: C2ME (https://github.com/RelativityMC/C2ME-fabric)
Licensed under: MIT (https://opensource.org/licenses/MIT)
diff --git a/net/minecraft/world/level/chunk/storage/IOWorker.java b/net/minecraft/world/level/chunk/storage/IOWorker.java
index 27e1edbd8d8ffd80c1a3df17bc47f4a6936619f7..c3326e753ecf8a0ba1930d8c7573ebd2c594cf45 100644
--- a/net/minecraft/world/level/chunk/storage/IOWorker.java
+++ b/net/minecraft/world/level/chunk/storage/IOWorker.java
@@ -212,7 +212,38 @@ public class IOWorker implements ChunkScanAccess, AutoCloseable {
});
}
+ // DivineMC start - C2ME: Limit NBT cache
+ private void checkHardLimit() {
+ if (this.pendingWrites.size() >= org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.chunkDataCacheLimit) {
+ LOGGER.warn("Chunk data cache size exceeded hard limit ({} >= {}), forcing writes to disk (you can increase chunkDataCacheLimit in divinemc.yml)", this.pendingWrites.size(), org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.chunkDataCacheLimit);
+ while (this.pendingWrites.size() >= org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.chunkDataCacheSoftLimit * 0.75) {
+ writeResult0();
+ }
+ }
+ }
+
+ private void writeResult0() {
+ java.util.Iterator<java.util.Map.Entry<net.minecraft.world.level.ChunkPos, net.minecraft.world.level.chunk.storage.IOWorker.PendingStore>> iterator = this.pendingWrites.entrySet().iterator();
+ if (iterator.hasNext()) {
+ java.util.Map.Entry<ChunkPos, IOWorker.PendingStore> entry = iterator.next();
+ iterator.remove();
+ this.runStore(entry.getKey(), entry.getValue());
+ }
+ }
+ // DivineMC end - C2ME: Limit NBT cache
+
private void storePendingChunk() {
+ // DivineMC start - C2ME: Limit NBT cache
+ if (!this.pendingWrites.isEmpty()) {
+ checkHardLimit();
+ if (this.pendingWrites.size() >= org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.chunkDataCacheSoftLimit) {
+ int writeFrequency = Math.min(1, (this.pendingWrites.size() - (int) org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.chunkDataCacheSoftLimit) / 16);
+ for (int i = 0; i < writeFrequency; i++) {
+ writeResult0();
+ }
+ }
+ }
+ // DivineMC end - C2ME: Limit NBT cache
Entry<ChunkPos, IOWorker.PendingStore> entry = this.pendingWrites.pollFirstEntry();
if (entry != null) {
this.runStore(entry.getKey(), entry.getValue());

View File

@@ -0,0 +1,705 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Thu, 10 Jul 2025 03:48:14 +0300
Subject: [PATCH] C2ME: Optimize Aquifer and Beardifier
This patch is based on the following mixins:
* "com/ishland/c2me/opts/worldgen/vanilla/mixin/aquifer/MixinAquiferSamplerImpl.java"
* "com/ishland/c2me/opts/worldgen/general/common/random_instances/RandomUtils.java"
By: ishland <ishlandmc@yeah.net>
As part of: C2ME (https://github.com/RelativityMC/C2ME-fabric)
Licensed under: MIT (https://opensource.org/licenses/MIT)
diff --git a/net/minecraft/world/level/levelgen/Aquifer.java b/net/minecraft/world/level/levelgen/Aquifer.java
index c62a15ea4a1bb22e7bcc2fc544acf8a601892029..06419ac3b18365b27b522baba24736c1add5bd9a 100644
--- a/net/minecraft/world/level/levelgen/Aquifer.java
+++ b/net/minecraft/world/level/levelgen/Aquifer.java
@@ -85,6 +85,15 @@ public interface Aquifer {
private final int minGridZ;
private final int gridSizeX;
private final int gridSizeZ;
+ // DivineMC start - C2ME: Optimize Aquifer
+ private int c2me$dist1;
+ private int c2me$dist2;
+ private int c2me$dist3;
+ private long c2me$pos1;
+ private long c2me$pos2;
+ private long c2me$pos3;
+ private double c2me$mutableDoubleThingy;
+ // DivineMC end - C2ME: Optimize Aquifer
private static final int[][] SURFACE_SAMPLING_OFFSETS_IN_CHUNKS = new int[][]{
{0, 0}, {-2, -1}, {-1, -1}, {0, -1}, {1, -1}, {-3, 0}, {-2, 0}, {-1, 0}, {1, 0}, {-2, 1}, {-1, 1}, {0, 1}, {1, 1}
};
@@ -120,6 +129,36 @@ public interface Aquifer {
this.aquiferCache = new Aquifer.FluidStatus[i4];
this.aquiferLocationCache = new long[i4];
Arrays.fill(this.aquiferLocationCache, Long.MAX_VALUE);
+ // DivineMC start - C2ME: Optimize Aquifer
+ if (this.aquiferLocationCache.length % (this.gridSizeX * this.gridSizeZ) != 0) {
+ throw new AssertionError("Array length");
+ }
+
+ int sizeY = this.aquiferLocationCache.length / (this.gridSizeX * this.gridSizeZ);
+
+ final RandomSource random = com.ishland.c2me.opts.worldgen.general.common.random_instances.RandomUtils.getRandom(this.positionalRandomFactory);
+ // index: y, z, x
+ for (int y = 0; y < sizeY; y++) {
+ for (int z = 0; z < this.gridSizeZ; z++) {
+ for (int x = 0; x < this.gridSizeX; x++) {
+ final int x1 = x + this.minGridX;
+ final int y1 = y + this.minGridY;
+ final int z1 = z + this.minGridZ;
+ com.ishland.c2me.opts.worldgen.general.common.random_instances.RandomUtils.derive(this.positionalRandomFactory, random, x1, y1, z1);
+ int x2 = x1 * 16 + random.nextInt(10);
+ int y2 = y1 * 12 + random.nextInt(9);
+ int z2 = z1 * 16 + random.nextInt(10);
+ int index = this.getIndex(x1, y1, z1);
+ this.aquiferLocationCache[index] = BlockPos.asLong(x2, y2, z2);
+ }
+ }
+ }
+ for (long blockPosition : this.aquiferLocationCache) {
+ if (blockPosition == Long.MAX_VALUE) {
+ throw new AssertionError("Array initialization");
+ }
+ }
+ // DivineMC end - C2ME: Optimize Aquifer
}
private int getIndex(int gridX, int gridY, int gridZ) {
@@ -132,140 +171,24 @@ public interface Aquifer {
@Nullable
@Override
public BlockState computeSubstance(DensityFunction.FunctionContext context, double substance) {
+ // DivineMC start - C2ME: Optimize Aquifer
int i = context.blockX();
- int i1 = context.blockY();
- int i2 = context.blockZ();
+ int j = context.blockY();
+ int k = context.blockZ();
if (substance > 0.0) {
this.shouldScheduleFluidUpdate = false;
return null;
} else {
- Aquifer.FluidStatus fluidStatus = this.globalFluidPicker.computeFluid(i, i1, i2);
- if (fluidStatus.at(i1).is(Blocks.LAVA)) {
+ Aquifer.FluidStatus fluidLevel = this.globalFluidPicker.computeFluid(i, j, k);
+ if (fluidLevel.at(j).is(Blocks.LAVA)) {
this.shouldScheduleFluidUpdate = false;
return Blocks.LAVA.defaultBlockState();
} else {
- int i3 = Math.floorDiv(i - 5, 16);
- int i4 = Math.floorDiv(i1 + 1, 12);
- int i5 = Math.floorDiv(i2 - 5, 16);
- int i6 = Integer.MAX_VALUE;
- int i7 = Integer.MAX_VALUE;
- int i8 = Integer.MAX_VALUE;
- int i9 = Integer.MAX_VALUE;
- long l = 0L;
- long l1 = 0L;
- long l2 = 0L;
- long l3 = 0L;
-
- for (int i10 = 0; i10 <= 1; i10++) {
- for (int i11 = -1; i11 <= 1; i11++) {
- for (int i12 = 0; i12 <= 1; i12++) {
- int i13 = i3 + i10;
- int i14 = i4 + i11;
- int i15 = i5 + i12;
- int index = this.getIndex(i13, i14, i15);
- long l4 = this.aquiferLocationCache[index];
- long l5;
- if (l4 != Long.MAX_VALUE) {
- l5 = l4;
- } else {
- RandomSource randomSource = this.positionalRandomFactory.at(i13, i14, i15);
- l5 = BlockPos.asLong(
- i13 * 16 + randomSource.nextInt(10), i14 * 12 + randomSource.nextInt(9), i15 * 16 + randomSource.nextInt(10)
- );
- this.aquiferLocationCache[index] = l5;
- }
-
- int i16 = BlockPos.getX(l5) - i;
- int i17 = BlockPos.getY(l5) - i1;
- int i18 = BlockPos.getZ(l5) - i2;
- int i19 = i16 * i16 + i17 * i17 + i18 * i18;
- if (i6 >= i19) {
- l3 = l2;
- l2 = l1;
- l1 = l;
- l = l5;
- i9 = i8;
- i8 = i7;
- i7 = i6;
- i6 = i19;
- } else if (i7 >= i19) {
- l3 = l2;
- l2 = l1;
- l1 = l5;
- i9 = i8;
- i8 = i7;
- i7 = i19;
- } else if (i8 >= i19) {
- l3 = l2;
- l2 = l5;
- i9 = i8;
- i8 = i19;
- } else if (i9 >= i19) {
- l3 = l5;
- i9 = i19;
- }
- }
- }
- }
-
- Aquifer.FluidStatus aquiferStatus = this.getAquiferStatus(l);
- double d = similarity(i6, i7);
- BlockState blockState = aquiferStatus.at(i1);
- if (d <= 0.0) {
- if (d >= FLOWING_UPDATE_SIMULARITY) {
- Aquifer.FluidStatus aquiferStatus1 = this.getAquiferStatus(l1);
- this.shouldScheduleFluidUpdate = !aquiferStatus.equals(aquiferStatus1);
- } else {
- this.shouldScheduleFluidUpdate = false;
- }
-
- return blockState;
- } else if (blockState.is(Blocks.WATER) && this.globalFluidPicker.computeFluid(i, i1 - 1, i2).at(i1 - 1).is(Blocks.LAVA)) {
- this.shouldScheduleFluidUpdate = true;
- return blockState;
- } else {
- MutableDouble mutableDouble = new MutableDouble(Double.NaN);
- Aquifer.FluidStatus aquiferStatus2 = this.getAquiferStatus(l1);
- double d1 = d * this.calculatePressure(context, mutableDouble, aquiferStatus, aquiferStatus2);
- if (substance + d1 > 0.0) {
- this.shouldScheduleFluidUpdate = false;
- return null;
- } else {
- Aquifer.FluidStatus aquiferStatus3 = this.getAquiferStatus(l2);
- double d2 = similarity(i6, i8);
- if (d2 > 0.0) {
- double d3 = d * d2 * this.calculatePressure(context, mutableDouble, aquiferStatus, aquiferStatus3);
- if (substance + d3 > 0.0) {
- this.shouldScheduleFluidUpdate = false;
- return null;
- }
- }
-
- double d3 = similarity(i7, i8);
- if (d3 > 0.0) {
- double d4 = d * d3 * this.calculatePressure(context, mutableDouble, aquiferStatus2, aquiferStatus3);
- if (substance + d4 > 0.0) {
- this.shouldScheduleFluidUpdate = false;
- return null;
- }
- }
-
- boolean flag = !aquiferStatus.equals(aquiferStatus2);
- boolean flag1 = d3 >= FLOWING_UPDATE_SIMULARITY && !aquiferStatus2.equals(aquiferStatus3);
- boolean flag2 = d2 >= FLOWING_UPDATE_SIMULARITY && !aquiferStatus.equals(aquiferStatus3);
- if (!flag && !flag1 && !flag2) {
- this.shouldScheduleFluidUpdate = d2 >= FLOWING_UPDATE_SIMULARITY
- && similarity(i6, i9) >= FLOWING_UPDATE_SIMULARITY
- && !aquiferStatus.equals(this.getAquiferStatus(l3));
- } else {
- this.shouldScheduleFluidUpdate = true;
- }
-
- return blockState;
- }
- }
+ aquiferExtracted$refreshDistPosIdx(i, j, k);
+ return aquiferExtracted$applyPost(context, substance, j, i, k);
}
}
+ // DivineMC end - C2ME: Optimize Aquifer
}
@Override
@@ -278,65 +201,28 @@ public interface Aquifer {
return 1.0 - Math.abs(secondDistance - firstDistance) / 25.0;
}
+ // DivineMC start - C2ME: Optimize Aquifer
private double calculatePressure(
- DensityFunction.FunctionContext context, MutableDouble substance, Aquifer.FluidStatus firstFluid, Aquifer.FluidStatus secondFluid
+ DensityFunction.FunctionContext context, MutableDouble substance, Aquifer.FluidStatus fluidLevel, Aquifer.FluidStatus fluidLevel2 // DivineMC - rename args
) {
int i = context.blockY();
- BlockState blockState = firstFluid.at(i);
- BlockState blockState1 = secondFluid.at(i);
- if ((!blockState.is(Blocks.LAVA) || !blockState1.is(Blocks.WATER)) && (!blockState.is(Blocks.WATER) || !blockState1.is(Blocks.LAVA))) {
- int abs = Math.abs(firstFluid.fluidLevel - secondFluid.fluidLevel);
+ BlockState blockState = fluidLevel.at(i);
+ BlockState blockState2 = fluidLevel2.at(i);
+ if ((!blockState.is(Blocks.LAVA) || !blockState2.is(Blocks.WATER)) && (!blockState.is(Blocks.WATER) || !blockState2.is(Blocks.LAVA))) {
+ int abs = Math.abs(fluidLevel.fluidLevel - fluidLevel2.fluidLevel);
if (abs == 0) {
return 0.0;
} else {
- double d = 0.5 * (firstFluid.fluidLevel + secondFluid.fluidLevel);
- double d1 = i + 0.5 - d;
- double d2 = abs / 2.0;
- double d3 = 0.0;
- double d4 = 2.5;
- double d5 = 1.5;
- double d6 = 3.0;
- double d7 = 10.0;
- double d8 = 3.0;
- double d9 = d2 - Math.abs(d1);
- double d11;
- if (d1 > 0.0) {
- double d10 = 0.0 + d9;
- if (d10 > 0.0) {
- d11 = d10 / 1.5;
- } else {
- d11 = d10 / 2.5;
- }
- } else {
- double d10 = 3.0 + d9;
- if (d10 > 0.0) {
- d11 = d10 / 3.0;
- } else {
- d11 = d10 / 10.0;
- }
- }
-
- double d10x = 2.0;
- double d12;
- if (!(d11 < -2.0) && !(d11 > 2.0)) {
- double value = substance.getValue();
- if (Double.isNaN(value)) {
- double d13 = this.barrierNoise.compute(context);
- substance.setValue(d13);
- d12 = d13;
- } else {
- d12 = value;
- }
- } else {
- d12 = 0.0;
- }
+ double d = 0.5 * (double)(fluidLevel.fluidLevel + fluidLevel2.fluidLevel);
+ final double q = aquiferExtracted$getQ(i, d, abs);
- return 2.0 * (d12 + d11);
+ return aquiferExtracted$postCalculateDensity(context, substance, q);
}
} else {
return 2.0;
}
}
+ // DivineMC end - C2ME: Optimize Aquifer
private int gridX(int x) {
return Math.floorDiv(x, 16);
@@ -350,23 +236,25 @@ public interface Aquifer {
return Math.floorDiv(z, 16);
}
- private Aquifer.FluidStatus getAquiferStatus(long packedPos) {
- int x = BlockPos.getX(packedPos);
- int y = BlockPos.getY(packedPos);
- int z = BlockPos.getZ(packedPos);
- int i = this.gridX(x);
- int i1 = this.gridY(y);
- int i2 = this.gridZ(z);
- int index = this.getIndex(i, i1, i2);
- Aquifer.FluidStatus fluidStatus = this.aquiferCache[index];
- if (fluidStatus != null) {
- return fluidStatus;
+ // DivineMC start - C2ME: Optimize Aquifer
+ private Aquifer.FluidStatus getAquiferStatus(long pos) {
+ int i = BlockPos.getX(pos);
+ int j = BlockPos.getY(pos);
+ int k = BlockPos.getZ(pos);
+ int l = i >> 4; // C2ME - inline: floorDiv(i, 16)
+ int m = Math.floorDiv(j, 12); // C2ME - inline
+ int n = k >> 4; // C2ME - inline: floorDiv(k, 16)
+ int o = this.getIndex(l, m, n);
+ Aquifer.FluidStatus fluidLevel = this.aquiferCache[o];
+ if (fluidLevel != null) {
+ return fluidLevel;
} else {
- Aquifer.FluidStatus fluidStatus1 = this.computeFluid(x, y, z);
- this.aquiferCache[index] = fluidStatus1;
- return fluidStatus1;
+ Aquifer.FluidStatus fluidLevel2 = this.computeFluid(i, j, k);
+ this.aquiferCache[o] = fluidLevel2;
+ return fluidLevel2;
}
}
+ // DivineMC end - C2ME: Optimize Aquifer
private Aquifer.FluidStatus computeFluid(int x, int y, int z) {
Aquifer.FluidStatus fluidStatus = this.globalFluidPicker.computeFluid(x, y, z);
@@ -407,22 +295,21 @@ public interface Aquifer {
}
private int computeSurfaceLevel(int x, int y, int z, Aquifer.FluidStatus fluidStatus, int maxSurfaceLevel, boolean fluidPresent) {
- DensityFunction.SinglePointContext singlePointContext = new DensityFunction.SinglePointContext(x, y, z);
+ // DivineMC start - C2ME: Optimize Aquifer
+ DensityFunction.SinglePointContext unblendedNoisePos = new DensityFunction.SinglePointContext(x, y, z);
double d;
double d1;
- if (OverworldBiomeBuilder.isDeepDarkRegion(this.erosion, this.depth, singlePointContext)) {
+ if (OverworldBiomeBuilder.isDeepDarkRegion(this.erosion, this.depth, unblendedNoisePos)) {
d = -1.0;
d1 = -1.0;
} else {
int i = maxSurfaceLevel + 8 - y;
- int i1 = 64;
- double d2 = fluidPresent ? Mth.clampedMap((double)i, 0.0, 64.0, 1.0, 0.0) : 0.0;
- double d3 = Mth.clamp(this.fluidLevelFloodednessNoise.compute(singlePointContext), -1.0, 1.0);
- double d4 = Mth.map(d2, 1.0, 0.0, -0.3, 0.8);
- double d5 = Mth.map(d2, 1.0, 0.0, -0.8, 0.4);
- d = d3 - d5;
- d1 = d3 - d4;
+ double f = fluidPresent ? Mth.clampedLerp(1.0, 0.0, ((double) i) / 64.0) : 0.0; // inline
+ double g = Mth.clamp(this.fluidLevelFloodednessNoise.compute(unblendedNoisePos), -1.0, 1.0);
+ d = g + 0.8 + (f - 1.0) * 1.2; // inline
+ d1 = g + 0.3 + (f - 1.0) * 1.1; // inline
}
+ // DivineMC end - C2ME: Optimize Aquifer
int i;
if (d1 > 0.0) {
@@ -453,12 +340,12 @@ public interface Aquifer {
private BlockState computeFluidType(int x, int y, int z, Aquifer.FluidStatus fluidStatus, int surfaceLevel) {
BlockState blockState = fluidStatus.fluidType;
if (surfaceLevel <= -10 && surfaceLevel != DimensionType.WAY_BELOW_MIN_Y && fluidStatus.fluidType != Blocks.LAVA.defaultBlockState()) {
- int i = 64;
- int i1 = 40;
- int i2 = Math.floorDiv(x, 64);
- int i3 = Math.floorDiv(y, 40);
- int i4 = Math.floorDiv(z, 64);
- double d = this.lavaNoise.compute(new DensityFunction.SinglePointContext(i2, i3, i4));
+ // DivineMC start - C2ME: Optimize Aquifer
+ int k = x >> 6;
+ int l = Math.floorDiv(y, 40);
+ int m = z >> 6;
+ double d = this.lavaNoise.compute(new DensityFunction.SinglePointContext(k, l, m));
+ // DivineMC end - C2ME: Optimize Aquifer
if (Math.abs(d) > 0.3) {
blockState = Blocks.LAVA.defaultBlockState();
}
@@ -466,5 +353,183 @@ public interface Aquifer {
return blockState;
}
+
+ // DivineMC start - C2ME: Optimize Aquifer
+ private @org.jetbrains.annotations.Nullable BlockState aquiferExtracted$applyPost(DensityFunction.FunctionContext pos, double density, int j, int i, int k) {
+ Aquifer.FluidStatus fluidLevel2 = this.getAquiferStatus(this.c2me$pos1);
+ double d = similarity(this.c2me$dist1, this.c2me$dist2);
+ BlockState blockState = fluidLevel2.at(j);
+ if (d <= 0.0) {
+ this.shouldScheduleFluidUpdate = d >= FLOWING_UPDATE_SIMULARITY;
+ return blockState;
+ } else if (blockState.is(Blocks.WATER) && this.globalFluidPicker.computeFluid(i, j - 1, k).at(j - 1).is(Blocks.LAVA)) {
+ this.shouldScheduleFluidUpdate = true;
+ return blockState;
+ } else {
+ this.c2me$mutableDoubleThingy = Double.NaN;
+ Aquifer.FluidStatus fluidLevel3 = this.getAquiferStatus(this.c2me$pos2);
+ double e = d * this.c2me$calculateDensityModified(pos, fluidLevel2, fluidLevel3);
+ if (density + e > 0.0) {
+ this.shouldScheduleFluidUpdate = false;
+ return null;
+ } else {
+ return aquiferExtracted$getFinalBlockState(pos, density, d, fluidLevel2, fluidLevel3, blockState);
+ }
+ }
+ }
+
+ private BlockState aquiferExtracted$getFinalBlockState(DensityFunction.FunctionContext pos, double density, double d, Aquifer.FluidStatus fluidLevel2, Aquifer.FluidStatus fluidLevel3, BlockState blockState) {
+ Aquifer.FluidStatus fluidLevel4 = this.getAquiferStatus(this.c2me$pos3);
+ double f = similarity(this.c2me$dist1, this.c2me$dist3);
+ if (aquiferExtracted$extractedCheckFG(pos, density, d, fluidLevel2, f, fluidLevel4)) return null;
+
+ double g = similarity(this.c2me$dist2, this.c2me$dist3);
+ if (aquiferExtracted$extractedCheckFG(pos, density, d, fluidLevel3, g, fluidLevel4)) return null;
+
+ this.shouldScheduleFluidUpdate = true;
+ return blockState;
+ }
+
+ private boolean aquiferExtracted$extractedCheckFG(DensityFunction.FunctionContext pos, double density, double d, Aquifer.FluidStatus fluidLevel2, double f, Aquifer.FluidStatus fluidLevel4) {
+ if (f > 0.0) {
+ double g = d * f * this.c2me$calculateDensityModified(pos, fluidLevel2, fluidLevel4);
+ if (density + g > 0.0) {
+ this.shouldScheduleFluidUpdate = false;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private void aquiferExtracted$refreshDistPosIdx(int x, int y, int z) {
+ int gx = (x - 5) >> 4;
+ int gy = Math.floorDiv(y + 1, 12);
+ int gz = (z - 5) >> 4;
+ int dist1 = Integer.MAX_VALUE;
+ int dist2 = Integer.MAX_VALUE;
+ int dist3 = Integer.MAX_VALUE;
+ long pos1 = 0;
+ long pos2 = 0;
+ long pos3 = 0;
+
+ for (int offY = -1; offY <= 1; ++offY) {
+ for (int offZ = 0; offZ <= 1; ++offZ) {
+ for (int offX = 0; offX <= 1; ++offX) {
+ int posIdx = this.getIndex(gx + offX, gy + offY, gz + offZ);
+
+ long position = this.aquiferLocationCache[posIdx];
+
+ int dx = BlockPos.getX(position) - x;
+ int dy = BlockPos.getY(position) - y;
+ int dz = BlockPos.getZ(position) - z;
+ int dist = dx * dx + dy * dy + dz * dz;
+
+ if (dist3 >= dist) {
+ pos3 = position;
+ dist3 = dist;
+ }
+ if (dist2 >= dist) {
+ pos3 = pos2;
+ dist3 = dist2;
+ pos2 = position;
+ dist2 = dist;
+ }
+ if (dist1 >= dist) {
+ pos2 = pos1;
+ dist2 = dist1;
+ pos1 = position;
+ dist1 = dist;
+ }
+ }
+ }
+ }
+
+ this.c2me$dist1 = dist1;
+ this.c2me$dist2 = dist2;
+ this.c2me$dist3 = dist3;
+ this.c2me$pos1 = pos1;
+ this.c2me$pos2 = pos2;
+ this.c2me$pos3 = pos3;
+ }
+
+ private double c2me$calculateDensityModified(
+ DensityFunction.FunctionContext pos, Aquifer.FluidStatus fluidLevel, Aquifer.FluidStatus fluidLevel2
+ ) {
+ int i = pos.blockY();
+ BlockState blockState = fluidLevel.at(i);
+ BlockState blockState2 = fluidLevel2.at(i);
+ if ((!blockState.is(Blocks.LAVA) || !blockState2.is(Blocks.WATER)) && (!blockState.is(Blocks.WATER) || !blockState2.is(Blocks.LAVA))) {
+ int j = Math.abs(fluidLevel.fluidLevel - fluidLevel2.fluidLevel);
+ if (j == 0) {
+ return 0.0;
+ } else {
+ double d = 0.5 * (double)(fluidLevel.fluidLevel + fluidLevel2.fluidLevel);
+ final double q = aquiferExtracted$getQ(i, d, j);
+
+ return aquiferExtracted$postCalculateDensityModified(pos, q);
+ }
+ } else {
+ return 2.0;
+ }
+ }
+
+ private double aquiferExtracted$postCalculateDensity(DensityFunction.FunctionContext pos, MutableDouble mutableDouble, double q) {
+ double r;
+ if (!(q < -2.0) && !(q > 2.0)) {
+ double s = mutableDouble.getValue();
+ if (Double.isNaN(s)) {
+ double t = this.barrierNoise.compute(pos);
+ mutableDouble.setValue(t);
+ r = t;
+ } else {
+ r = s;
+ }
+ } else {
+ r = 0.0;
+ }
+
+ return 2.0 * (r + q);
+ }
+
+ private double aquiferExtracted$postCalculateDensityModified(DensityFunction.FunctionContext pos, double q) {
+ double r;
+ if (!(q < -2.0) && !(q > 2.0)) {
+ double s = this.c2me$mutableDoubleThingy;
+ if (Double.isNaN(s)) {
+ double t = this.barrierNoise.compute(pos);
+ this.c2me$mutableDoubleThingy = t;
+ r = t;
+ } else {
+ r = s;
+ }
+ } else {
+ r = 0.0;
+ }
+
+ return 2.0 * (r + q);
+ }
+
+ private static double aquiferExtracted$getQ(double i, double d, double j) {
+ double e = i + 0.5 - d;
+ double f = j / 2.0;
+ double o = f - Math.abs(e);
+ double q;
+ if (e > 0.0) {
+ if (o > 0.0) {
+ q = o / 1.5;
+ } else {
+ q = o / 2.5;
+ }
+ } else {
+ double p = 3.0 + o;
+ if (p > 0.0) {
+ q = p / 3.0;
+ } else {
+ q = p / 10.0;
+ }
+ }
+ return q;
+ }
+ // DivineMC end - C2ME: Optimize Aquifer
}
}
diff --git a/net/minecraft/world/level/levelgen/Beardifier.java b/net/minecraft/world/level/levelgen/Beardifier.java
index 86c15d2d90e63d21cb83622a7b29e11151a4f64a..2c0c0546046857056b8445f59828fdf9821ea001 100644
--- a/net/minecraft/world/level/levelgen/Beardifier.java
+++ b/net/minecraft/world/level/levelgen/Beardifier.java
@@ -29,6 +29,17 @@ public class Beardifier implements DensityFunctions.BeardifierOrMarker {
});
private final ObjectListIterator<Beardifier.Rigid> pieceIterator;
private final ObjectListIterator<JigsawJunction> junctionIterator;
+ // DivineMC start - C2ME: Optimize Beardifier
+ private Beardifier.Rigid[] c2me$pieceArray;
+ private JigsawJunction[] c2me$junctionArray;
+
+ private void c2me$initArrays() {
+ this.c2me$pieceArray = com.google.common.collect.Iterators.toArray(this.pieceIterator, Beardifier.Rigid.class);
+ this.pieceIterator.back(Integer.MAX_VALUE);
+ this.c2me$junctionArray = com.google.common.collect.Iterators.toArray(this.junctionIterator, JigsawJunction.class);
+ this.junctionIterator.back(Integer.MAX_VALUE);
+ }
+ // DivineMC end - C2ME: Optimize Beardifier
public static Beardifier forStructuresInChunk(StructureManager structureManager, ChunkPos chunkPos) {
int minBlockX = chunkPos.getMinBlockX();
@@ -75,50 +86,44 @@ public class Beardifier implements DensityFunctions.BeardifierOrMarker {
this.junctionIterator = junctionIterator;
}
+ // DivineMC start - C2ME: Optimize Beardifier
@Override
public double compute(DensityFunction.FunctionContext context) {
+ if (this.c2me$pieceArray == null || this.c2me$junctionArray == null) {
+ this.c2me$initArrays();
+ }
int i = context.blockX();
- int i1 = context.blockY();
- int i2 = context.blockZ();
+ int j = context.blockY();
+ int k = context.blockZ();
double d = 0.0;
- while (this.pieceIterator.hasNext()) {
- Beardifier.Rigid rigid = this.pieceIterator.next();
- BoundingBox boundingBox = rigid.box();
- int groundLevelDelta = rigid.groundLevelDelta();
- int max = Math.max(0, Math.max(boundingBox.minX() - i, i - boundingBox.maxX()));
- int max1 = Math.max(0, Math.max(boundingBox.minZ() - i2, i2 - boundingBox.maxZ()));
- int i3 = boundingBox.minY() + groundLevelDelta;
- int i4 = i1 - i3;
-
- int i5 = switch (rigid.terrainAdjustment()) {
- case NONE -> 0;
- case BURY, BEARD_THIN -> i4;
- case BEARD_BOX -> Math.max(0, Math.max(i3 - i1, i1 - boundingBox.maxY()));
- case ENCAPSULATE -> Math.max(0, Math.max(boundingBox.minY() - i1, i1 - boundingBox.maxY()));
- };
+ for (Beardifier.Rigid piece : this.c2me$pieceArray) {
+ BoundingBox blockBox = piece.box();
+ int l = piece.groundLevelDelta();
+ int m = Math.max(0, Math.max(blockBox.minX() - i, i - blockBox.maxX()));
+ int n = Math.max(0, Math.max(blockBox.minZ() - k, k - blockBox.maxZ()));
+ int o = blockBox.minY() + l;
+ int p = j - o;
- d += switch (rigid.terrainAdjustment()) {
+ d += switch (piece.terrainAdjustment()) { // 2 switch statement merged
case NONE -> 0.0;
- case BURY -> getBuryContribution(max, i5 / 2.0, max1);
- case BEARD_THIN, BEARD_BOX -> getBeardContribution(max, i5, max1, i4) * 0.8;
- case ENCAPSULATE -> getBuryContribution(max / 2.0, i5 / 2.0, max1 / 2.0) * 0.8;
+ case BURY -> getBuryContribution(m, (double)p / 2.0, n);
+ case BEARD_THIN -> getBeardContribution(m, p, n, p) * 0.8;
+ case BEARD_BOX -> getBeardContribution(m, Math.max(0, Math.max(o - j, j - blockBox.maxY())), n, p) * 0.8;
+ case ENCAPSULATE -> getBuryContribution((double)m / 2.0, (double)Math.max(0, Math.max(blockBox.minY() - j, j - blockBox.maxY())) / 2.0, (double)n / 2.0) * 0.8;
};
}
- this.pieceIterator.back(Integer.MAX_VALUE);
-
- while (this.junctionIterator.hasNext()) {
- JigsawJunction jigsawJunction = this.junctionIterator.next();
- int i6 = i - jigsawJunction.getSourceX();
- int groundLevelDelta = i1 - jigsawJunction.getSourceGroundY();
- int max = i2 - jigsawJunction.getSourceZ();
- d += getBeardContribution(i6, groundLevelDelta, max, groundLevelDelta) * 0.4;
+ for (JigsawJunction jigsawJunction : this.c2me$junctionArray) {
+ int r = i - jigsawJunction.getSourceX();
+ int l = j - jigsawJunction.getSourceGroundY();
+ int m = k - jigsawJunction.getSourceZ();
+ d += getBeardContribution(r, l, m, l) * 0.4;
}
- this.junctionIterator.back(Integer.MAX_VALUE);
return d;
}
+ // DivineMC end - C2ME: Optimize Beardifier
@Override
public double minValue() {
diff --git a/net/minecraft/world/level/levelgen/LegacyRandomSource.java b/net/minecraft/world/level/levelgen/LegacyRandomSource.java
index c67168517774a0ad9ca43422a79ef14a8ea0c2e8..026dfbbb6c3fd5cd274dcbf721e5cf3af889e3d9 100644
--- a/net/minecraft/world/level/levelgen/LegacyRandomSource.java
+++ b/net/minecraft/world/level/levelgen/LegacyRandomSource.java
@@ -53,13 +53,7 @@ public class LegacyRandomSource implements BitRandomSource {
return this.gaussianSource.nextGaussian();
}
- public static class LegacyPositionalRandomFactory implements PositionalRandomFactory {
- private final long seed;
-
- public LegacyPositionalRandomFactory(long seed) {
- this.seed = seed;
- }
-
+ public record LegacyPositionalRandomFactory(long seed) implements PositionalRandomFactory { // DivineMC - make record
@Override
public RandomSource at(int x, int y, int z) {
long seed = Mth.getSeed(x, y, z);
diff --git a/net/minecraft/world/level/levelgen/XoroshiroRandomSource.java b/net/minecraft/world/level/levelgen/XoroshiroRandomSource.java
index 9d3a9ca1e13cd80f468f1352bbb74345f03903dd..d97b9b43686bda0a95fc02f6ca31b2d07d603a32 100644
--- a/net/minecraft/world/level/levelgen/XoroshiroRandomSource.java
+++ b/net/minecraft/world/level/levelgen/XoroshiroRandomSource.java
@@ -106,15 +106,7 @@ public class XoroshiroRandomSource implements RandomSource {
return this.randomNumberGenerator.nextLong() >>> 64 - bits;
}
- public static class XoroshiroPositionalRandomFactory implements PositionalRandomFactory {
- private final long seedLo;
- private final long seedHi;
-
- public XoroshiroPositionalRandomFactory(long seedLo, long seedHi) {
- this.seedLo = seedLo;
- this.seedHi = seedHi;
- }
-
+ public record XoroshiroPositionalRandomFactory(long seedLo, long seedHi) implements PositionalRandomFactory { // DivineMC - make record
@Override
public RandomSource at(int x, int y, int z) {
long seed = Mth.getSeed(x, y, z);

View File

@@ -0,0 +1,49 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Thu, 10 Jul 2025 04:30:21 +0300
Subject: [PATCH] Copper Bulb 1gt delay
diff --git a/net/minecraft/world/level/block/CopperBulbBlock.java b/net/minecraft/world/level/block/CopperBulbBlock.java
index 25caeb117d9a49fa00f46ec895a35dee8242aacd..3a2b751b150e7930817fd07d50a3baeecb44f7d1 100644
--- a/net/minecraft/world/level/block/CopperBulbBlock.java
+++ b/net/minecraft/world/level/block/CopperBulbBlock.java
@@ -32,16 +32,36 @@ public class CopperBulbBlock extends Block {
@Override
protected void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldState, boolean movedByPiston) {
if (oldState.getBlock() != state.getBlock() && level instanceof ServerLevel serverLevel) {
- this.checkAndFlip(state, serverLevel, pos);
+ // DivineMC start - Copper Bulb 1gt delay
+ if (!org.bxteam.divinemc.config.DivineConfig.MiscCategory.copperBulb1gt) {
+ this.checkAndFlip(state, serverLevel, pos);
+ } else {
+ level.scheduleTick(pos, this, 1);
+ }
+ // DivineMC end - Copper Bulb 1gt delay
}
}
@Override
protected void neighborChanged(BlockState state, Level level, BlockPos pos, Block neighborBlock, @Nullable Orientation orientation, boolean movedByPiston) {
if (level instanceof ServerLevel serverLevel) {
- this.checkAndFlip(state, serverLevel, pos);
+ // DivineMC start - Copper Bulb 1gt delay
+ if (!org.bxteam.divinemc.config.DivineConfig.MiscCategory.copperBulb1gt) {
+ this.checkAndFlip(state, serverLevel, pos);
+ } else {
+ level.scheduleTick(pos, this, 1);
+ }
+ }
+ }
+
+ // DivineMC start - Copper Bulb 1gt delay
+ @Override
+ public void tick(BlockState state, ServerLevel level, BlockPos pos, net.minecraft.util.RandomSource random) {
+ if (org.bxteam.divinemc.config.DivineConfig.MiscCategory.copperBulb1gt) {
+ checkAndFlip(state, level, pos);
}
}
+ // DivineMC end - Copper Bulb 1gt delay
public void checkAndFlip(BlockState state, ServerLevel level, BlockPos pos) {
boolean hasNeighborSignal = level.hasNeighborSignal(pos);

View File

@@ -0,0 +1,28 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Thu, 10 Jul 2025 04:31:46 +0300
Subject: [PATCH] Crafter 1gt delay
diff --git a/net/minecraft/world/level/block/CrafterBlock.java b/net/minecraft/world/level/block/CrafterBlock.java
index 38b03c7b02bdfc579e5e126c12de3d878e26d188..c3e68a63f6f7d669dca8a08625a04bd7c8ef0327 100644
--- a/net/minecraft/world/level/block/CrafterBlock.java
+++ b/net/minecraft/world/level/block/CrafterBlock.java
@@ -75,7 +75,7 @@ public class CrafterBlock extends BaseEntityBlock {
boolean triggeredValue = state.getValue(TRIGGERED);
BlockEntity blockEntity = level.getBlockEntity(pos);
if (hasNeighborSignal && !triggeredValue) {
- level.scheduleTick(pos, this, 4);
+ level.scheduleTick(pos, this, !org.bxteam.divinemc.config.DivineConfig.MiscCategory.copperBulb1gt ? 4 : 1); // DivineMC - Crafter 1gt delay
level.setBlock(pos, state.setValue(TRIGGERED, true), 2);
this.setBlockEntityTriggered(blockEntity, true);
} else if (!hasNeighborSignal && triggeredValue) {
@@ -125,7 +125,7 @@ public class CrafterBlock extends BaseEntityBlock {
@Override
public void setPlacedBy(Level level, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
if (state.getValue(TRIGGERED)) {
- level.scheduleTick(pos, this, 4);
+ level.scheduleTick(pos, this, !org.bxteam.divinemc.config.DivineConfig.MiscCategory.copperBulb1gt ? 4 : 1); // DivineMC - Crafter 1gt delay
}
}

View File

@@ -0,0 +1,169 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Thu, 10 Jul 2025 04:51:08 +0300
Subject: [PATCH] Raytrace Entity Tracker
Original project: https://github.com/tr7zw/EntityCulling
Original license: Custom License
Original project: https://github.com/LogisticsCraft/OcclusionCulling
Original license: MIT
diff --git a/net/minecraft/server/level/ChunkMap.java b/net/minecraft/server/level/ChunkMap.java
index 7ca147cf9da67c399806056e5092841f7ca32321..a6bf257ca93e4b3819b65b4ef4ba71d9e2b40933 100644
--- a/net/minecraft/server/level/ChunkMap.java
+++ b/net/minecraft/server/level/ChunkMap.java
@@ -1421,7 +1421,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
double d1 = vec3_dx * vec3_dx + vec3_dz * vec3_dz; // Paper
double d2 = d * d;
// Paper start - Configurable entity tracking range by Y
- boolean flag = d1 <= d2;
+ boolean flag = d1 <= d2 && !entity.isCulled(); // DivineMC - Raytrace Entity Tracker
if (flag && level.paperConfig().entities.trackingRangeY.enabled) {
double rangeY = level.paperConfig().entities.trackingRangeY.get(this.entity, -1);
if (rangeY != -1) {
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index adea48cfde04df3107341075f414133ae37d986e..c1c8e235b9c096cd36c3e83b0831af7cb722cad2 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -145,7 +145,7 @@ import net.minecraft.world.waypoints.WaypointTransmitter;
import org.jetbrains.annotations.Contract;
import org.slf4j.Logger;
-public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess, ScoreHolder, DataComponentGetter, ca.spottedleaf.moonrise.patches.chunk_system.entity.ChunkSystemEntity, ca.spottedleaf.moonrise.patches.entity_tracker.EntityTrackerEntity { // Paper - rewrite chunk system // Paper - optimise entity tracker
+public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess, ScoreHolder, DataComponentGetter, ca.spottedleaf.moonrise.patches.chunk_system.entity.ChunkSystemEntity, ca.spottedleaf.moonrise.patches.entity_tracker.EntityTrackerEntity, dev.tr7zw.entityculling.versionless.access.Cullable { // Paper - rewrite chunk system // Paper - optimise entity tracker // DivineMC - Raytrace Entity Tracker
public static javax.script.ScriptEngine scriptEngine = new javax.script.ScriptEngineManager().getEngineByName("rhino"); // Purpur - Configurable entity base attributes
// CraftBukkit start
private static final int CURRENT_LEVEL = 2;
@@ -5474,4 +5474,47 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return false;
}
// Purpur end - Ridables
+
+ // DivineMC start - Raytrace Entity Tracker
+ private long lasttime = 0;
+ private boolean culled = false;
+ private boolean outOfCamera = false;
+
+ @Override
+ public void setTimeout() {
+ this.lasttime = System.currentTimeMillis() + 1000;
+ }
+
+ @Override
+ public boolean isForcedVisible() {
+ return this.lasttime > System.currentTimeMillis();
+ }
+
+ @Override
+ public void setCulled(boolean value) {
+ this.culled = value;
+ if (!value) {
+ setTimeout();
+ }
+ }
+
+ @Override
+ public boolean isCulled() {
+ if (!org.bxteam.divinemc.config.DivineConfig.MiscCategory.retEnabled) return false;
+
+ return this.culled;
+ }
+
+ @Override
+ public void setOutOfCamera(boolean value) {
+ this.outOfCamera = value;
+ }
+
+ @Override
+ public boolean isOutOfCamera() {
+ if (!org.bxteam.divinemc.config.DivineConfig.MiscCategory.retEnabled) return false;
+
+ return this.outOfCamera;
+ }
+ // DivineMC end - Raytrace Entity Tracker
}
diff --git a/net/minecraft/world/entity/EntityType.java b/net/minecraft/world/entity/EntityType.java
index 0159627e2c9a540d062073faf9018f5215e10866..26f6941dfbe0453ed5b091e408d8422901f4ca32 100644
--- a/net/minecraft/world/entity/EntityType.java
+++ b/net/minecraft/world/entity/EntityType.java
@@ -1093,6 +1093,7 @@ public class EntityType<T extends Entity> implements FeatureElement, EntityTypeT
public EntityDimensions dimensions;
private final float spawnDimensionsScale;
private final FeatureFlagSet requiredFeatures;
+ public boolean skipRaytracingCheck = false; // DivineMC - Raytrace Entity Tracker
private static <T extends Entity> EntityType<T> register(ResourceKey<EntityType<?>> key, EntityType.Builder<T> builder) {
return Registry.register(BuiltInRegistries.ENTITY_TYPE, key, builder.build(key));
diff --git a/net/minecraft/world/entity/player/Player.java b/net/minecraft/world/entity/player/Player.java
index 05634e09200fa613b69aafe9b2505dbc9b5c54eb..80ce59b79896ff415cf3a93eb6ea3272f42c3d02 100644
--- a/net/minecraft/world/entity/player/Player.java
+++ b/net/minecraft/world/entity/player/Player.java
@@ -122,7 +122,6 @@ import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.scores.PlayerTeam;
import net.minecraft.world.scores.Scoreboard;
-import net.minecraft.world.scores.Team;
import org.slf4j.Logger;
public abstract class Player extends LivingEntity {
@@ -222,6 +221,25 @@ public abstract class Player extends LivingEntity {
public int burpDelay = 0; // Purpur - Burp delay
public boolean canPortalInstant = false; // Purpur - Add portal permission bypass
public int sixRowEnderchestSlotCount = -1; // Purpur - Barrels and enderchests 6 rows
+ // DivineMC start - Raytrace Entity Tracker
+ public dev.tr7zw.entityculling.CullTask cullTask;
+ {
+ if (!org.bxteam.divinemc.config.DivineConfig.MiscCategory.retEnabled) {
+ this.cullTask = null;
+ } else {
+ final com.logisticscraft.occlusionculling.OcclusionCullingInstance culling = new com.logisticscraft.occlusionculling.OcclusionCullingInstance(
+ org.bxteam.divinemc.config.DivineConfig.MiscCategory.retTracingDistance,
+ new dev.tr7zw.entityculling.DefaultChunkDataProvider(this.level())
+ );
+
+ this.cullTask = new dev.tr7zw.entityculling.CullTask(
+ culling, this,
+ org.bxteam.divinemc.config.DivineConfig.MiscCategory.retHitboxLimit,
+ org.bxteam.divinemc.config.DivineConfig.MiscCategory.retCheckIntervalMs
+ );
+ }
+ }
+ // DivineMC end - Raytrace Entity Tracker
// CraftBukkit start
public boolean fauxSleeping;
@@ -310,6 +328,25 @@ public abstract class Player extends LivingEntity {
@Override
public void tick() {
+ // DivineMC start - Raytrace Entity Tracker
+ if (!org.bxteam.divinemc.config.DivineConfig.MiscCategory.retEnabled) {
+ if (this.cullTask != null) this.cullTask.signalStop();
+ this.cullTask = null;
+ } else {
+ final com.logisticscraft.occlusionculling.OcclusionCullingInstance culling = new com.logisticscraft.occlusionculling.OcclusionCullingInstance(
+ org.bxteam.divinemc.config.DivineConfig.MiscCategory.retTracingDistance,
+ new dev.tr7zw.entityculling.DefaultChunkDataProvider(this.level())
+ );
+
+ this.cullTask = new dev.tr7zw.entityculling.CullTask(
+ culling, this,
+ org.bxteam.divinemc.config.DivineConfig.MiscCategory.retHitboxLimit,
+ org.bxteam.divinemc.config.DivineConfig.MiscCategory.retCheckIntervalMs
+ );
+ }
+ if (this.cullTask != null) this.cullTask.setup();
+ if (this.cullTask != null) this.cullTask.requestCullSignal();
+ // DivineMC end - Raytrace Entity Tracker
// Purpur start - Burp delay
if (this.burpDelay > 0 && --this.burpDelay == 0) {
this.level().playSound(null, getX(), getY(), getZ(), SoundEvents.PLAYER_BURP, SoundSource.PLAYERS, 1.0F, this.level().random.nextFloat() * 0.1F + 0.9F);
@@ -1466,6 +1503,7 @@ public abstract class Player extends LivingEntity {
if (this.containerMenu != null && this.hasContainerOpen()) {
this.doCloseContainer();
}
+ if (this.cullTask != null) this.cullTask.signalStop(); // DivineMC - Raytrace Entity Tracker
}
@Override

View File

@@ -0,0 +1,86 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Wed, 11 Jun 2025 20:15:37 +0300
Subject: [PATCH] Async Join Thread
diff --git a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
index 443aebb71b2a55ee9dcd2dd4bf9a30fbb8da9e49..6cec77e483d51771c602bbdb537c62c893043c08 100644
--- a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
@@ -53,7 +53,6 @@ import org.bukkit.event.player.PlayerPreLoginEvent;
public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener, TickablePacketListener {
private static final AtomicInteger UNIQUE_THREAD_ID = new AtomicInteger(0);
static final Logger LOGGER = LogUtils.getLogger();
- private static final java.util.concurrent.ExecutorService authenticatorPool = java.util.concurrent.Executors.newCachedThreadPool(new com.google.common.util.concurrent.ThreadFactoryBuilder().setNameFormat("User Authenticator #%d").setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER)).build()); // Paper - Cache authenticator threads
private static final int MAX_TICKS_BEFORE_LOGIN = 600;
private final byte[] challenge;
final MinecraftServer server;
@@ -182,22 +181,25 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
return;
}
// Paper end - Add Velocity IP Forwarding Support
- // CraftBukkit start
- // Paper start - Cache authenticator threads
- authenticatorPool.execute(() -> {
+ // DivineMC start - Async Join Thread
+ org.bxteam.divinemc.async.AsyncJoinHandler.runAsync(() -> {
try {
GameProfile gameprofile = ServerLoginPacketListenerImpl.this.createOfflineProfile(ServerLoginPacketListenerImpl.this.requestedUsername); // Spigot
gameprofile = ServerLoginPacketListenerImpl.this.callPlayerPreLoginEvents(gameprofile); // Paper - Add more fields to AsyncPlayerPreLoginEvent
ServerLoginPacketListenerImpl.LOGGER.info("UUID of player {} is {}", gameprofile.getName(), gameprofile.getId());
- ServerLoginPacketListenerImpl.this.startClientVerification(gameprofile);
+ return gameprofile;
} catch (Exception ex) {
ServerLoginPacketListenerImpl.this.disconnect("Failed to verify username!");
ServerLoginPacketListenerImpl.this.server.server.getLogger().log(java.util.logging.Level.WARNING, "Exception verifying " + ServerLoginPacketListenerImpl.this.requestedUsername, ex);
+ return null;
+ }
+ }, (gameprofile) -> {
+ if (gameprofile != null) {
+ ServerLoginPacketListenerImpl.this.startClientVerification(gameprofile);
}
});
- // Paper end - Cache authenticator threads
- // CraftBukkit end
+ // DivineMC end - Async Join Thread
}
}
}
@@ -255,7 +257,8 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
}
// Paper start - Cache authenticator threads
- authenticatorPool.execute(new Runnable() {
+ // DivineMC start - Async Join Thread
+ org.bxteam.divinemc.async.AsyncJoinHandler.runAsync(new Runnable() {
@Override
public void run() {
String string1 = Objects.requireNonNull(ServerLoginPacketListenerImpl.this.requestedUsername, "Player name not initialized");
@@ -406,16 +409,23 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
//TODO Update handling for lazy sessions, might not even have to do anything?
// Proceed with login
- authenticatorPool.execute(() -> {
+ // DivineMC start - Async Join Thread
+ org.bxteam.divinemc.async.AsyncJoinHandler.runAsync(() -> {
try {
final GameProfile gameprofile = this.callPlayerPreLoginEvents(this.authenticatedProfile);
ServerLoginPacketListenerImpl.LOGGER.info("UUID of player {} is {}", gameprofile.getName(), gameprofile.getId());
- ServerLoginPacketListenerImpl.this.startClientVerification(gameprofile);
+ return gameprofile;
} catch (Exception ex) {
disconnect("Failed to verify username!");
server.server.getLogger().log(java.util.logging.Level.WARNING, "Exception verifying " + this.authenticatedProfile.getName(), ex);
+ return null;
+ }
+ }, (gameprofile) -> {
+ if (gameprofile != null) {
+ ServerLoginPacketListenerImpl.this.startClientVerification(gameprofile);
}
});
+ // DivineMC end - Async Join Thread
return;
}
// Paper end - Add Velocity IP Forwarding Support

View File

@@ -0,0 +1,146 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Thu, 10 Jul 2025 22:11:47 +0300
Subject: [PATCH] Leaves: Protocol Core
Original project: https://github.com/LeavesMC/Leaves
Original license: GPLv3
diff --git a/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java b/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java
index fb263fa1f30a7dfcb7ec2656abfb38e5fe88eac9..c3be4c2fd4a544967322a45d3b8c0fe78a0684a5 100644
--- a/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java
+++ b/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java
@@ -40,13 +40,22 @@ public interface CustomPacketPayload {
@Override
public void encode(B buffer, CustomPacketPayload value) {
+ // DivineMC start - Leaves Protocol Core
+ if (value instanceof org.leavesmc.leaves.protocol.core.LeavesCustomPayload payload) {
+ org.leavesmc.leaves.protocol.core.LeavesProtocolManager.encode(buffer, payload);
+ return;
+ }
+ // DivineMC end - Leaves Protocol Core
this.writeCap(buffer, value.type(), value);
}
@Override
public CustomPacketPayload decode(B buffer) {
ResourceLocation resourceLocation = buffer.readResourceLocation();
- return (CustomPacketPayload)this.findCodec(resourceLocation).decode(buffer);
+ // DivineMC start - Leaves Protocol Core
+ var payload = org.leavesmc.leaves.protocol.core.LeavesProtocolManager.decode(resourceLocation, buffer);
+ return java.util.Objects.requireNonNullElseGet(payload, () -> this.findCodec(resourceLocation).decode(buffer));
+ // DivineMC end - Leaves Protocol Core
}
};
}
diff --git a/net/minecraft/network/protocol/common/custom/DiscardedPayload.java b/net/minecraft/network/protocol/common/custom/DiscardedPayload.java
index 62b9d9486c15a1ec6527f786df4e9fc483390bcb..36d8b93182cc44e3bea245800ea9e2719333ac65 100644
--- a/net/minecraft/network/protocol/common/custom/DiscardedPayload.java
+++ b/net/minecraft/network/protocol/common/custom/DiscardedPayload.java
@@ -4,12 +4,12 @@ import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
-public record DiscardedPayload(ResourceLocation id, byte[] data) implements CustomPacketPayload { // Paper - store data
+public record DiscardedPayload(ResourceLocation id, byte @org.jetbrains.annotations.Nullable [] data) implements CustomPacketPayload { // Paper - store data // DivineMC - Leaves Protocol Core
public static <T extends FriendlyByteBuf> StreamCodec<T, DiscardedPayload> codec(ResourceLocation id, int maxSize) {
return CustomPacketPayload.codec((value, output) -> {
// Paper start
// Always write data
- output.writeBytes(value.data);
+ if (value.data != null) output.writeBytes(value.data); // DivineMC - Leaves Protocol Core
}, buffer -> {
int i = buffer.readableBytes();
if (i >= 0 && i <= maxSize) {
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 008530bf0f09180ba365fc514b51d22630564de2..7bc07d120ca3b8cffa6b1147f1687b5a4023b709 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1788,6 +1788,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
GameTestTicker.SINGLETON.tick();
}
+ org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handleTick(tickCount); // DivineMC - Leaves Protocol Core
+
for (int i = 0; i < this.tickables.size(); i++) {
this.tickables.get(i).run();
}
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
index 77d1cab278a13e08ba8096af2c683b5042cc1574..74b639bec2243800077a4fe579fcfeadc514e30d 100644
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -432,6 +432,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
private boolean ramBar = false; // Purpur - Implement rambar commands
public boolean smoothWorldTeleport; // DivineMC - Smooth teleport API
public boolean hasTickedAtLeastOnceInNewWorld = false; // DivineMC - Parallel world ticking
+ public net.minecraft.network.Connection internalConnection; // DivineMC - Leaves Protocol Core
// Paper start - rewrite chunk system
private ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.PlayerChunkLoaderData chunkLoader;
diff --git a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
index a7c4fad2b1cb0cbac742a18d37d688bb2663944e..b94243d293e805743453adf7b4fc8d852184f460 100644
--- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
@@ -230,6 +230,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
final String channel = new String(data, from, length, java.nio.charset.StandardCharsets.US_ASCII);
if (register) {
bridge.addChannel(channel);
+ org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handleMinecraftRegister(channel, bridge); // DivineMC - Leaves Protocol Core
} else {
bridge.removeChannel(channel);
}
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index c537d22fd97225c1b6d58bed61add83a20d9be24..75d9d06066c750ac9a176adc021410f1265cd36f 100644
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -3678,6 +3678,17 @@ public class ServerGamePacketListenerImpl
@Override
public void handleCustomPayload(ServerboundCustomPayloadPacket packet) {
+ // DivineMC start - Leaves Protocol Core
+ if (packet.payload() instanceof org.leavesmc.leaves.protocol.core.LeavesCustomPayload leavesPayload) {
+ org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handlePayload(player, leavesPayload);
+ return;
+ }
+ if (packet.payload() instanceof net.minecraft.network.protocol.common.custom.DiscardedPayload(net.minecraft.resources.ResourceLocation id, byte[] data)) {
+ if (org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handleBytebuf(player, id, io.netty.buffer.Unpooled.wrappedBuffer(data))) {
+ return;
+ }
+ }
+ // DivineMC end - Leaves Protocol Core
super.handleCustomPayload(packet); // Paper
}
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
index cfe2bbc46046f144044d8cba67cda978f231d354..96af2c75b526c59510965665da0b2ca00bf657b3 100644
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -343,6 +343,11 @@ public abstract class PlayerList {
return;
}
+ // DivineMC start - Leaves Protocol Core
+ if (player.internalConnection == null) player.internalConnection = connection;
+ org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handlePlayerJoin(player);
+ // DivineMC end - Leaves Protocol Core
+
final net.kyori.adventure.text.Component jm = playerJoinEvent.joinMessage();
if (jm != null && !jm.equals(net.kyori.adventure.text.Component.empty())) { // Paper - Adventure
@@ -516,6 +521,7 @@ public abstract class PlayerList {
return this.remove(player, net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, io.papermc.paper.configuration.GlobalConfiguration.get().messages.useDisplayNameInQuitMessage ? player.getBukkitEntity().displayName() : io.papermc.paper.adventure.PaperAdventure.asAdventure(player.getDisplayName())));
}
public @Nullable net.kyori.adventure.text.Component remove(ServerPlayer player, net.kyori.adventure.text.Component leaveMessage) {
+ org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handlePlayerLeave(player); // DivineMC - Leaves Protocol Core
// Paper end - Fix kick event leave message not being sent
org.purpurmc.purpur.task.BossBarTask.removeFromAll(player.getBukkitEntity()); // Purpur - Implement TPSBar
ServerLevel serverLevel = player.level();
@@ -1461,6 +1467,7 @@ public abstract class PlayerList {
serverPlayer.connection.send(clientboundUpdateRecipesPacket);
serverPlayer.getRecipeBook().sendInitialRecipeBook(serverPlayer);
}
+ org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handleDataPackReload(); // DivineMC - Leaves Protocol Core
}
public boolean isAllowCommandsForAllPlayers() {

View File

@@ -0,0 +1,60 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Fri, 11 Jul 2025 20:39:54 +0300
Subject: [PATCH] Paper PR: Optimise non-flush packet sending
Original project: https://github.com/PaperMC/Paper
Original license: GPLv3
Paper pull request: https://github.com/PaperMC/Paper/pull/10172
Places like entity tracking make heavy use of packet sending,
and internally netty will use some very expensive thread wakeup
calls when scheduling.
Thanks to various hacks in ProtocolLib as well as other
plugins, we cannot simply use a queue of packets to group
send on execute. We have to call execute for each packet.
Tux's suggestion here is exactly what was needed - tag
the Runnable indicating it should not make a wakeup call.
Big thanks to Tux for making this possible as I had given
up on this optimisation before he came along.
Locally this patch drops the entity tracker tick by a full 1.5x.
diff --git a/net/minecraft/network/Connection.java b/net/minecraft/network/Connection.java
index 4ab30d291de7db5ad7d5684662f41348270802b9..8bb7d9f2bce06880164f0ae36e1674e9dc380809 100644
--- a/net/minecraft/network/Connection.java
+++ b/net/minecraft/network/Connection.java
@@ -149,6 +149,7 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
// Paper start - Optimize network
public boolean isPending = true;
public boolean queueImmunity;
+ private io.netty.channel.SingleThreadEventLoop eventLoop; // Paper - Optimise non-flush packet sending
// Paper end - Optimize network
public Connection(PacketFlow receiving) {
@@ -159,6 +160,7 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
public void channelActive(ChannelHandlerContext context) throws Exception {
super.channelActive(context);
this.channel = context.channel();
+ this.eventLoop = (io.netty.channel.SingleThreadEventLoop) this.channel.eventLoop(); // Paper - Optimise non-flush packet sending
this.address = this.channel.remoteAddress();
this.preparing = false; // Spigot
if (this.delayedDisconnect != null) {
@@ -473,7 +475,13 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
if (this.channel.eventLoop().inEventLoop()) {
this.doSendPacket(packet, channelFutureListener, flag);
} else {
- this.channel.eventLoop().execute(() -> this.doSendPacket(packet, channelFutureListener, flag));
+ // Paper start - Optimise non-flush packet sending
+ if (!flag && org.bxteam.divinemc.config.DivineConfig.NetworkCategory.optimizeNonFlushPacketSending) {
+ this.eventLoop.lazyExecute(() -> this.doSendPacket(packet, channelFutureListener, flag));
+ } else {
+ this.channel.eventLoop().execute(() -> this.doSendPacket(packet, channelFutureListener, flag));
+ }
+ // Paper end - Optimise non-flush packet sending
}
}

View File

@@ -1,11 +1,11 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sun, 16 Mar 2025 21:16:55 +0300
Date: Fri, 11 Jul 2025 21:47:45 +0300
Subject: [PATCH] Linear region file format
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/io/ChunkSystemRegionFileStorage.java b/ca/spottedleaf/moonrise/patches/chunk_system/io/ChunkSystemRegionFileStorage.java
index a814512fcfb85312474ae2c2c21443843bf57831..fdccc27c528b01b16a72e614ffd96523aa6f50d2 100644
index a814512fcfb85312474ae2c2c21443843bf57831..215d4444fbd9821811fbd4724de088dbb589f179 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/io/ChunkSystemRegionFileStorage.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/io/ChunkSystemRegionFileStorage.java
@@ -8,9 +8,9 @@ public interface ChunkSystemRegionFileStorage {
@@ -13,15 +13,15 @@ index a814512fcfb85312474ae2c2c21443843bf57831..fdccc27c528b01b16a72e614ffd96523
public boolean moonrise$doesRegionFileNotExistNoIO(final int chunkX, final int chunkZ);
- public RegionFile moonrise$getRegionFileIfLoaded(final int chunkX, final int chunkZ);
+ public org.bxteam.divinemc.region.IRegionFile moonrise$getRegionFileIfLoaded(final int chunkX, final int chunkZ); // DivineMC - Linear region file format
+ public org.bxteam.divinemc.region.IRegionFile moonrise$getRegionFileIfLoaded(final int chunkX, final int chunkZ); // DivineMC - Buffered Linear region format
- public RegionFile moonrise$getRegionFileIfExists(final int chunkX, final int chunkZ) throws IOException;
+ public org.bxteam.divinemc.region.IRegionFile moonrise$getRegionFileIfExists(final int chunkX, final int chunkZ) throws IOException; // DivineMC - Linear region file format
+ public org.bxteam.divinemc.region.IRegionFile moonrise$getRegionFileIfExists(final int chunkX, final int chunkZ) throws IOException; // DivineMC - Buffered Linear region format
public MoonriseRegionFileIO.RegionDataController.WriteData moonrise$startWrite(
final int chunkX, final int chunkZ, final CompoundTag compound
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/io/MoonriseRegionFileIO.java b/ca/spottedleaf/moonrise/patches/chunk_system/io/MoonriseRegionFileIO.java
index f5ed467c0880e4bcdf1b9ae773a5aac21c4381c3..95fb49f7b9ee3d132cf2405d99b2d63ee295d76d 100644
index f5ed467c0880e4bcdf1b9ae773a5aac21c4381c3..64c157252f2288b507025ea96bfe4f76c635f1d9 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/io/MoonriseRegionFileIO.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/io/MoonriseRegionFileIO.java
@@ -1260,7 +1260,7 @@ public final class MoonriseRegionFileIO {
@@ -29,7 +29,7 @@ index f5ed467c0880e4bcdf1b9ae773a5aac21c4381c3..95fb49f7b9ee3d132cf2405d99b2d63e
// Paper start - flush regionfiles on save
if (this.world.paperConfig().chunks.flushRegionsOnSave) {
- final RegionFile regionFile = this.regionDataController.getCache().moonrise$getRegionFileIfLoaded(this.chunkX, this.chunkZ);
+ final org.bxteam.divinemc.region.IRegionFile regionFile = this.regionDataController.getCache().moonrise$getRegionFileIfLoaded(this.chunkX, this.chunkZ); // DivineMC - Linear region file format
+ final org.bxteam.divinemc.region.IRegionFile regionFile = this.regionDataController.getCache().moonrise$getRegionFileIfLoaded(this.chunkX, this.chunkZ); // DivineMC - Buffered Linear region format
if (regionFile != null) {
regionFile.flush();
} // else: evicted from cache, which should have called flush
@@ -38,40 +38,46 @@ index f5ed467c0880e4bcdf1b9ae773a5aac21c4381c3..95fb49f7b9ee3d132cf2405d99b2d63e
public static interface IORunnable {
- public void run(final RegionFile regionFile) throws IOException;
+ public void run(final org.bxteam.divinemc.region.IRegionFile regionFile) throws IOException; // DivineMC - Linear region file format
+ public void run(final org.bxteam.divinemc.region.IRegionFile regionFile) throws IOException; // DivineMC - Buffered Linear region format
}
}
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/storage/ChunkSystemChunkBuffer.java b/ca/spottedleaf/moonrise/patches/chunk_system/storage/ChunkSystemChunkBuffer.java
index 51c126735ace8fdde89ad97b5cab62f244212db0..8713d00d767c9225a0823d2fdbb0b479005738d7 100644
index 51c126735ace8fdde89ad97b5cab62f244212db0..23f6ed26b531ea570fdf2ae48c1e2710e0ed22ed 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/storage/ChunkSystemChunkBuffer.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/storage/ChunkSystemChunkBuffer.java
@@ -8,5 +8,5 @@ public interface ChunkSystemChunkBuffer {
@@ -3,10 +3,10 @@ package ca.spottedleaf.moonrise.patches.chunk_system.storage;
import net.minecraft.world.level.chunk.storage.RegionFile;
import java.io.IOException;
-public interface ChunkSystemChunkBuffer {
+public interface ChunkSystemChunkBuffer {
public boolean moonrise$getWriteOnClose();
public void moonrise$setWriteOnClose(final boolean value);
- public void moonrise$write(final RegionFile regionFile) throws IOException;
+ public void moonrise$write(final org.bxteam.divinemc.region.IRegionFile regionFile) throws IOException; // DivineMC - Linear region file format
+ public void moonrise$write(final org.bxteam.divinemc.region.IRegionFile regionFile) throws IOException; // DivineMC - Buffered Linear region format
}
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 5c05a41e6f64f37fc365cde6333ed5a684f167f2..1a36a7c071c9f203d32f524008cf031fb1a4d6a6 100644
index 7bc07d120ca3b8cffa6b1147f1687b5a4023b709..97f097eff051690ea0bc24b851153c7deafdc008 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -928,10 +928,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -942,10 +942,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// CraftBukkit end
if (flush) {
for (ServerLevel serverLevel2 : this.getAllLevels()) {
- LOGGER.info("ThreadedAnvilChunkStorage ({}): All chunks are saved", serverLevel2.getChunkSource().chunkMap.getStorageName());
+ LOGGER.info("ThreadedChunkStorage ({}): All chunks are saved", serverLevel2.getChunkSource().chunkMap.getStorageName()); // DivineMC - Linear region file format
+ LOGGER.info("ThreadedChunkStorage ({}): All chunks are saved", serverLevel2.getChunkSource().chunkMap.getStorageName()); // DivineMC - Buffered Linear region format
}
- LOGGER.info("ThreadedAnvilChunkStorage: All dimensions are saved");
+ LOGGER.info("ThreadedChunkStorage: All dimensions are saved"); // DivineMC - Linear region file format
+ LOGGER.info("ThreadedChunkStorage: All dimensions are saved"); // DivineMC - Buffered Linear region format
}
return flag;
diff --git a/net/minecraft/util/worldupdate/WorldUpgrader.java b/net/minecraft/util/worldupdate/WorldUpgrader.java
index 79d57ca8a7870a02e95562d89cbd4341d8282660..b5711b348a2e1480b041587c220af5872ead2c56 100644
index 79d57ca8a7870a02e95562d89cbd4341d8282660..1156772217b139d54266f470b18d4a98dc960a79 100644
--- a/net/minecraft/util/worldupdate/WorldUpgrader.java
+++ b/net/minecraft/util/worldupdate/WorldUpgrader.java
@@ -75,7 +75,7 @@ public class WorldUpgrader implements AutoCloseable {
@@ -79,7 +85,7 @@ index 79d57ca8a7870a02e95562d89cbd4341d8282660..b5711b348a2e1480b041587c220af587
final Reference2FloatMap<ResourceKey<Level>> progressMap = Reference2FloatMaps.synchronize(new Reference2FloatOpenHashMap<>());
volatile Component status = Component.translatable("optimizeWorld.stage.counting");
- static final Pattern REGEX = Pattern.compile("^r\\.(-?[0-9]+)\\.(-?[0-9]+)\\.mca$");
+ static final Pattern REGEX = Pattern.compile("^r\\.(-?[0-9]+)\\.(-?[0-9]+)\\.(linear | mca)$"); // DivineMC - Linear region file format
+ static final Pattern REGEX = Pattern.compile("^r\\.(-?[0-9]+)\\.(-?[0-9]+)\\\\"+ net.minecraft.world.level.chunk.storage.RegionFileStorage.getExtensionName() +"$"); // DivineMC - Buffered Linear region format
final DimensionDataStorage overworldDataStorage;
public WorldUpgrader(
@@ -88,7 +94,7 @@ index 79d57ca8a7870a02e95562d89cbd4341d8282660..b5711b348a2e1480b041587c220af587
private static List<WorldUpgrader.FileToUpgrade> getAllChunkPositions(RegionStorageInfo regionStorageInfo, Path path) {
- File[] files = path.toFile().listFiles((directory, filename) -> filename.endsWith(".mca"));
+ File[] files = path.toFile().listFiles((directory, filename) -> filename.endsWith(".linear") || filename.endsWith(".mca")); // DivineMC - Linear region file format
+ File[] files = path.toFile().listFiles((directory, filename) -> filename.endsWith(net.minecraft.world.level.chunk.storage.RegionFileStorage.getExtensionName())); // DivineMC - Buffered Linear region format
if (files == null) {
return List.of();
} else {
@@ -97,7 +103,7 @@ index 79d57ca8a7870a02e95562d89cbd4341d8282660..b5711b348a2e1480b041587c220af587
List<ChunkPos> list1 = Lists.newArrayList();
- try (RegionFile regionFile = new RegionFile(regionStorageInfo, file.toPath(), path, true)) {
+ try (org.bxteam.divinemc.region.IRegionFile regionFile = org.bxteam.divinemc.region.RegionFileFactory.getAbstractRegionFile(regionStorageInfo, file.toPath(), path, true)) { // DivineMC - Linear region file format
+ try (org.bxteam.divinemc.region.IRegionFile regionFile = net.minecraft.world.level.chunk.storage.RegionFileStorage.createNew(regionStorageInfo, file.toPath(), path, true)) { // DivineMC - Buffered Linear region format
for (int i2 = 0; i2 < 32; i2++) {
for (int i3 = 0; i3 < 32; i3++) {
ChunkPos chunkPos = new ChunkPos(i2 + i, i3 + i1);
@@ -106,7 +112,7 @@ index 79d57ca8a7870a02e95562d89cbd4341d8282660..b5711b348a2e1480b041587c220af587
protected abstract boolean tryProcessOnePosition(T chunkStorage, ChunkPos chunkPos, ResourceKey<Level> dimension);
- private void onFileFinished(RegionFile regionFile) {
+ private void onFileFinished(org.bxteam.divinemc.region.IRegionFile regionFile) { // DivineMC - Linear region file format
+ private void onFileFinished(org.bxteam.divinemc.region.IRegionFile regionFile) { // DivineMC - Buffered Linear region format
if (WorldUpgrader.this.recreateRegionFiles) {
if (this.previousWriteFuture != null) {
this.previousWriteFuture.join();
@@ -115,12 +121,12 @@ index 79d57ca8a7870a02e95562d89cbd4341d8282660..b5711b348a2e1480b041587c220af587
}
- record FileToUpgrade(RegionFile file, List<ChunkPos> chunksToUpgrade) {
+ record FileToUpgrade(org.bxteam.divinemc.region.IRegionFile file, List<ChunkPos> chunksToUpgrade) { // DivineMC - Linear region file format
+ record FileToUpgrade(org.bxteam.divinemc.region.IRegionFile file, List<ChunkPos> chunksToUpgrade) { // DivineMC - Buffered Linear region format
}
class PoiUpgrader extends WorldUpgrader.SimpleRegionStorageUpgrader {
diff --git a/net/minecraft/world/level/chunk/storage/RegionFile.java b/net/minecraft/world/level/chunk/storage/RegionFile.java
index ae0a893498d0bfe90c14508f15b431d4885e06ff..6fba4d36377359dbcf8c804b194c4aefdde53b01 100644
index ae0a893498d0bfe90c14508f15b431d4885e06ff..00656cf8634e06f7ce1067ef7ba44edfb4519be3 100644
--- a/net/minecraft/world/level/chunk/storage/RegionFile.java
+++ b/net/minecraft/world/level/chunk/storage/RegionFile.java
@@ -22,7 +22,7 @@ import net.minecraft.util.profiling.jfr.JvmProfiler;
@@ -128,7 +134,7 @@ index ae0a893498d0bfe90c14508f15b431d4885e06ff..6fba4d36377359dbcf8c804b194c4aef
import org.slf4j.Logger;
-public class RegionFile implements AutoCloseable, ca.spottedleaf.moonrise.patches.chunk_system.storage.ChunkSystemRegionFile { // Paper - rewrite chunk system
+public class RegionFile implements AutoCloseable, ca.spottedleaf.moonrise.patches.chunk_system.storage.ChunkSystemRegionFile, org.bxteam.divinemc.region.IRegionFile { // Paper - rewrite chunk system // DivineMC - Linear region file format
+public class RegionFile implements AutoCloseable, ca.spottedleaf.moonrise.patches.chunk_system.storage.ChunkSystemRegionFile, org.bxteam.divinemc.region.IRegionFile { // Paper - rewrite chunk system // DivineMC - Buffered Linear region format
private static final Logger LOGGER = LogUtils.getLogger();
public static final int MAX_CHUNK_SIZE = 500 * 1024 * 1024; // Paper - don't write garbage data to disk if writing serialization fails
private static final int SECTOR_BYTES = 4096;
@@ -137,12 +143,12 @@ index ae0a893498d0bfe90c14508f15b431d4885e06ff..6fba4d36377359dbcf8c804b194c4aef
@Override
- public final void moonrise$write(final RegionFile regionFile) throws IOException {
+ public final void moonrise$write(final org.bxteam.divinemc.region.IRegionFile regionFile) throws IOException { // DivineMC - Linear region file format
+ public final void moonrise$write(final org.bxteam.divinemc.region.IRegionFile regionFile) throws IOException { // DivineMC - Buffered Linear region format
regionFile.write(this.pos, ByteBuffer.wrap(this.buf, 0, this.count));
}
// Paper end - rewrite chunk system
diff --git a/net/minecraft/world/level/chunk/storage/RegionFileStorage.java b/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
index c98cb390bda4b536f97445f228e06aaebcd84609..4e90366c5cea27ca2a38983c5de7b8eb68d72603 100644
index 8d1174f25e0e90d0533970f4ddd8448442024936..ee797d6b3cd898cba1abd3422cb54b17eb4a639f 100644
--- a/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
+++ b/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
@@ -18,7 +18,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -150,188 +156,192 @@ index c98cb390bda4b536f97445f228e06aaebcd84609..4e90366c5cea27ca2a38983c5de7b8eb
public static final String ANVIL_EXTENSION = ".mca";
private static final int MAX_CACHE_SIZE = 256;
- public final Long2ObjectLinkedOpenHashMap<RegionFile> regionCache = new Long2ObjectLinkedOpenHashMap<>();
+ public final Long2ObjectLinkedOpenHashMap<org.bxteam.divinemc.region.IRegionFile> regionCache = new Long2ObjectLinkedOpenHashMap<>(); // DivineMC - Linear region file format
+ public final Long2ObjectLinkedOpenHashMap<org.bxteam.divinemc.region.IRegionFile> regionCache = new Long2ObjectLinkedOpenHashMap<>(); // DivineMC - Buffered Linear region format
private final RegionStorageInfo info;
private final Path folder;
private final boolean sync;
@@ -33,7 +33,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@Nullable
public static ChunkPos getRegionFileCoordinates(Path file) {
String fileName = file.getFileName().toString();
- if (!fileName.startsWith("r.") || !fileName.endsWith(".mca")) {
+ if (!fileName.startsWith("r.") || !fileName.endsWith(".mca") || !fileName.endsWith(".linear")) { // DivineMC - Linear region file format
return null;
}
@@ -58,6 +58,12 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -58,9 +58,29 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
private static final int MAX_NON_EXISTING_CACHE = 1024 * 4;
private final it.unimi.dsi.fastutil.longs.LongLinkedOpenHashSet nonExistingRegionFiles = new it.unimi.dsi.fastutil.longs.LongLinkedOpenHashSet();
private static String getRegionFileName(final int chunkX, final int chunkZ) {
+ // DivineMC start - Linear region file format
+ if (org.bxteam.divinemc.config.DivineConfig.MiscCategory.regionFormatTypeName == org.bxteam.divinemc.region.RegionFileFormat.LINEAR) {
+ return "r." + (chunkX >> REGION_SHIFT) + "." + (chunkZ >> REGION_SHIFT) + ".linear";
+ }
+ // DivineMC end - Linear region file format
+
return "r." + (chunkX >> REGION_SHIFT) + "." + (chunkZ >> REGION_SHIFT) + ".mca";
- return "r." + (chunkX >> REGION_SHIFT) + "." + (chunkZ >> REGION_SHIFT) + ".mca";
+ return "r." + (chunkX >> REGION_SHIFT) + "." + (chunkZ >> REGION_SHIFT) + getExtensionName(); // DivineMC - Buffered Linear region format
}
@@ -93,15 +99,15 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
+ // DivineMC start - Buffered Linear region format
+ public static org.bxteam.divinemc.region.IRegionFile createNew(RegionStorageInfo info, Path filePath, Path folder, boolean sync) throws IOException{
+ final org.bxteam.divinemc.region.EnumRegionFileExtension regionFormat = org.bxteam.divinemc.config.DivineConfig.MiscCategory.regionFileType;
+ final String fullFileName = filePath.getFileName().toString();
+ final String[] fullNameSplit = fullFileName.split("\\.");
+ final String extensionName = fullNameSplit[fullNameSplit.length - 1];
+
+ if (!regionFormat.getArgument().equalsIgnoreCase(extensionName)) {
+ net.minecraft.server.MinecraftServer.setFatalException(new RuntimeException("Invalid region file format: " + extensionName + " expected " + regionFormat.getArgument()));
+ throw new IOException("Invalid region file format: " + extensionName + " expected " + regionFormat.getArgument());
+ }
+
+ return regionFormat.getCreator().create(new org.bxteam.divinemc.region.RegionFileInfo(info, filePath, folder, sync));
+ }
+
+ public static String getExtensionName() {
+ return "." + org.bxteam.divinemc.config.DivineConfig.MiscCategory.regionFileType.getArgument();
+ }
+ // DivineMC end - Buffered Linear region format
+
private boolean doesRegionFilePossiblyExist(final long position) {
synchronized (this.nonExistingRegionFiles) {
if (this.nonExistingRegionFiles.contains(position)) {
@@ -93,15 +113,15 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
}
@Override
- public synchronized final RegionFile moonrise$getRegionFileIfLoaded(final int chunkX, final int chunkZ) {
+ public synchronized final org.bxteam.divinemc.region.IRegionFile moonrise$getRegionFileIfLoaded(final int chunkX, final int chunkZ) { // DivineMC - Linear region file format
+ public synchronized final org.bxteam.divinemc.region.IRegionFile moonrise$getRegionFileIfLoaded(final int chunkX, final int chunkZ) { // DivineMC - Buffered Linear region format
return this.regionCache.getAndMoveToFirst(ChunkPos.asLong(chunkX >> REGION_SHIFT, chunkZ >> REGION_SHIFT));
}
@Override
- public synchronized final RegionFile moonrise$getRegionFileIfExists(final int chunkX, final int chunkZ) throws IOException {
+ public synchronized final org.bxteam.divinemc.region.IRegionFile moonrise$getRegionFileIfExists(final int chunkX, final int chunkZ) throws IOException { // DivineMC - Linear region file format
+ public synchronized final org.bxteam.divinemc.region.IRegionFile moonrise$getRegionFileIfExists(final int chunkX, final int chunkZ) throws IOException { // DivineMC - Buffered Linear region format
final long key = ChunkPos.asLong(chunkX >> REGION_SHIFT, chunkZ >> REGION_SHIFT);
- RegionFile ret = this.regionCache.getAndMoveToFirst(key);
+ org.bxteam.divinemc.region.IRegionFile ret = this.regionCache.getAndMoveToFirst(key); // DivineMC - Linear region file format
+ org.bxteam.divinemc.region.IRegionFile ret = this.regionCache.getAndMoveToFirst(key); // DivineMC - Buffered Linear region format
if (ret != null) {
return ret;
}
@@ -125,7 +131,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -125,7 +145,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
FileUtil.createDirectoriesSafe(this.folder);
- ret = new RegionFile(this.info, regionPath, this.folder, this.sync);
+ ret = org.bxteam.divinemc.region.RegionFileFactory.getAbstractRegionFile(this.info, regionPath, this.folder, this.sync); // DivineMC - Linear region file format
+ ret = this.createNew(this.info, regionPath, this.folder, this.sync); // DivineMC - Buffered Linear region format
this.regionCache.putAndMoveToFirst(key, ret);
@@ -144,11 +150,11 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -144,7 +164,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
}
final ChunkPos pos = new ChunkPos(chunkX, chunkZ);
- final RegionFile regionFile = this.getRegionFile(pos);
+ final org.bxteam.divinemc.region.IRegionFile regionFile = this.getRegionFile(pos); // DivineMC - Linear region file format
+ final org.bxteam.divinemc.region.IRegionFile regionFile = this.getRegionFile(pos); // DivineMC - Buffered Linear region format
// note: not required to keep regionfile loaded after this call, as the write param takes a regionfile as input
// (and, the regionfile parameter is unused for writing until the write call)
- final ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.RegionDataController.WriteData writeData = ((ca.spottedleaf.moonrise.patches.chunk_system.storage.ChunkSystemRegionFile)regionFile).moonrise$startWrite(compound, pos);
+ final ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.RegionDataController.WriteData writeData = regionFile.moonrise$startWrite(compound, pos); // DivineMC - Linear region file format
try { // Paper - implement RegionFileSizeException
try {
@@ -178,7 +184,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -178,7 +198,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
) throws IOException {
final ChunkPos pos = new ChunkPos(chunkX, chunkZ);
if (writeData.result() == ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.RegionDataController.WriteData.WriteResult.DELETE) {
- final RegionFile regionFile = this.moonrise$getRegionFileIfExists(chunkX, chunkZ);
+ final org.bxteam.divinemc.region.IRegionFile regionFile = this.moonrise$getRegionFileIfExists(chunkX, chunkZ); // DivineMC - Linear region file format
+ final org.bxteam.divinemc.region.IRegionFile regionFile = this.moonrise$getRegionFileIfExists(chunkX, chunkZ); // DivineMC - Buffered Linear region format
if (regionFile != null) {
regionFile.clear(pos);
} // else: didn't exist
@@ -193,7 +199,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -193,7 +213,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
public final ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.RegionDataController.ReadData moonrise$readData(
final int chunkX, final int chunkZ
) throws IOException {
- final RegionFile regionFile = this.moonrise$getRegionFileIfExists(chunkX, chunkZ);
+ final org.bxteam.divinemc.region.IRegionFile regionFile = this.moonrise$getRegionFileIfExists(chunkX, chunkZ); // DivineMC - Linear region file format
+ final org.bxteam.divinemc.region.IRegionFile regionFile = this.moonrise$getRegionFileIfExists(chunkX, chunkZ); // DivineMC - Buffered Linear region format
final DataInputStream input = regionFile == null ? null : regionFile.getChunkDataInputStream(new ChunkPos(chunkX, chunkZ));
@@ -238,7 +244,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -238,7 +258,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
final ChunkPos pos = new ChunkPos(chunkX, chunkZ);
final ChunkPos headerChunkPos = SerializableChunkData.getChunkCoordinate(ret);
- final RegionFile regionFile = this.getRegionFile(pos);
+ final org.bxteam.divinemc.region.IRegionFile regionFile = this.getRegionFile(pos); // DivineMC - Linear region file format
+ final org.bxteam.divinemc.region.IRegionFile regionFile = this.getRegionFile(pos); // DivineMC - Buffered Linear region format
if (regionFile.getRecalculateCount() != readData.recalculateCount()) {
return null;
@@ -262,7 +268,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -262,7 +282,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
}
// Paper end - rewrite chunk system
// Paper start - rewrite chunk system
- public RegionFile getRegionFile(ChunkPos chunkcoordintpair) throws IOException {
+ public org.bxteam.divinemc.region.IRegionFile getRegionFile(ChunkPos chunkcoordintpair) throws IOException { // DivineMC - Linear region file format
+ public org.bxteam.divinemc.region.IRegionFile getRegionFile(ChunkPos chunkcoordintpair) throws IOException { // DivineMC - Buffered Linear region format
return this.getRegionFile(chunkcoordintpair, false);
}
// Paper end - rewrite chunk system
@@ -274,7 +280,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -274,7 +294,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
this.isChunkData = isChunkDataFolder(this.folder); // Paper - recalculate region file headers
}
- @org.jetbrains.annotations.Contract("_, false -> !null") @Nullable private RegionFile getRegionFile(ChunkPos chunkPos, boolean existingOnly) throws IOException { // CraftBukkit
+ @org.jetbrains.annotations.Contract("_, false -> !null") @Nullable private org.bxteam.divinemc.region.IRegionFile getRegionFile(ChunkPos chunkPos, boolean existingOnly) throws IOException { // CraftBukkit // DivineMC - Linear region file format
+ @org.jetbrains.annotations.Contract("_, false -> !null") @Nullable private org.bxteam.divinemc.region.IRegionFile getRegionFile(ChunkPos chunkPos, boolean existingOnly) throws IOException { // CraftBukkit // DivineMC - Buffered Linear region format
// Paper start - rewrite chunk system
if (existingOnly) {
return this.moonrise$getRegionFileIfExists(chunkPos.x, chunkPos.z);
@@ -282,7 +288,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -282,7 +302,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
synchronized (this) {
final long key = ChunkPos.asLong(chunkPos.x >> REGION_SHIFT, chunkPos.z >> REGION_SHIFT);
- RegionFile ret = this.regionCache.getAndMoveToFirst(key);
+ org.bxteam.divinemc.region.IRegionFile ret = this.regionCache.getAndMoveToFirst(key); // DivineMC - Linear region file format
+ org.bxteam.divinemc.region.IRegionFile ret = this.regionCache.getAndMoveToFirst(key); // DivineMC - Buffered Linear region format
if (ret != null) {
return ret;
}
@@ -297,7 +303,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -297,7 +317,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
FileUtil.createDirectoriesSafe(this.folder);
- ret = new RegionFile(this.info, regionPath, this.folder, this.sync);
+ ret = org.bxteam.divinemc.region.RegionFileFactory.getAbstractRegionFile(this.info, regionPath, this.folder, this.sync); // DivineMC - Linear region file format
+ ret = this.createNew(this.info, regionPath, this.folder, this.sync); // DivineMC - Buffered Linear region format
this.regionCache.putAndMoveToFirst(key, ret);
@@ -311,7 +317,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -311,7 +331,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
org.apache.logging.log4j.LogManager.getLogger().fatal(msg + " (" + file.toString().replaceAll(".+[\\\\/]", "") + " - " + x + "," + z + ") Go clean it up to remove this message. /minecraft:tp " + (x<<4)+" 128 "+(z<<4) + " - DO NOT REPORT THIS TO DIVINEMC - You may ask for help on Discord, but do not file an issue. These error messages can not be removed."); // DivineMC - Rebrand
}
- private static CompoundTag readOversizedChunk(RegionFile regionfile, ChunkPos chunkCoordinate) throws IOException {
+ private static CompoundTag readOversizedChunk(org.bxteam.divinemc.region.IRegionFile regionfile, ChunkPos chunkCoordinate) throws IOException { // DivineMC - Linear region file format
+ private static CompoundTag readOversizedChunk(org.bxteam.divinemc.region.IRegionFile regionfile, ChunkPos chunkCoordinate) throws IOException { // DivineMC - Buffered Linear region format
synchronized (regionfile) {
try (DataInputStream datainputstream = regionfile.getChunkDataInputStream(chunkCoordinate)) {
CompoundTag oversizedData = regionfile.getOversizedData(chunkCoordinate.x, chunkCoordinate.z);
@@ -346,7 +352,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -346,7 +366,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@Nullable
public CompoundTag read(ChunkPos chunkPos) throws IOException {
// CraftBukkit start - SPIGOT-5680: There's no good reason to preemptively create files on read, save that for writing
- RegionFile regionFile = this.getRegionFile(chunkPos, true);
+ org.bxteam.divinemc.region.IRegionFile regionFile = this.getRegionFile(chunkPos, true); // DivineMC - Linear region file format
+ org.bxteam.divinemc.region.IRegionFile regionFile = this.getRegionFile(chunkPos, true); // DivineMC - Buffered Linear region format
if (regionFile == null) {
return null;
}
@@ -385,7 +391,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -385,7 +405,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
public void scanChunk(ChunkPos chunkPos, StreamTagVisitor visitor) throws IOException {
// CraftBukkit start - SPIGOT-5680: There's no good reason to preemptively create files on read, save that for writing
- RegionFile regionFile = this.getRegionFile(chunkPos, true);
+ org.bxteam.divinemc.region.IRegionFile regionFile = this.getRegionFile(chunkPos, true); // DivineMC - Linear region file format
+ org.bxteam.divinemc.region.IRegionFile regionFile = this.getRegionFile(chunkPos, true); // DivineMC - Buffered Linear region format
if (regionFile == null) {
return;
}
@@ -399,7 +405,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -399,7 +419,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
}
public void write(ChunkPos chunkPos, @Nullable CompoundTag chunkData) throws IOException { // Paper - rewrite chunk system - public
- RegionFile regionFile = this.getRegionFile(chunkPos, chunkData == null); // CraftBukkit // Paper - rewrite chunk system
+ org.bxteam.divinemc.region.IRegionFile regionFile = this.getRegionFile(chunkPos, chunkData == null); // CraftBukkit // Paper - rewrite chunk system // DivineMC - Linear region file format
+ org.bxteam.divinemc.region.IRegionFile regionFile = this.getRegionFile(chunkPos, chunkData == null); // CraftBukkit // Paper - rewrite chunk system // DivineMC - Buffered Linear region format
// Paper start - rewrite chunk system
if (regionFile == null) {
// if the RegionFile doesn't exist, no point in deleting from it
@@ -429,7 +435,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -429,7 +449,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
// Paper start - rewrite chunk system
synchronized (this) {
final ExceptionCollector<IOException> exceptionCollector = new ExceptionCollector<>();
- for (final RegionFile regionFile : this.regionCache.values()) {
+ for (final org.bxteam.divinemc.region.IRegionFile regionFile : this.regionCache.values()) { // DivineMC - Linear region file format
+ for (final org.bxteam.divinemc.region.IRegionFile regionFile : this.regionCache.values()) { // DivineMC - Buffered Linear region format
try {
regionFile.close();
} catch (final IOException ex) {
@@ -445,7 +451,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@@ -445,7 +465,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
// Paper start - rewrite chunk system
synchronized (this) {
final ExceptionCollector<IOException> exceptionCollector = new ExceptionCollector<>();
- for (final RegionFile regionFile : this.regionCache.values()) {
+ for (final org.bxteam.divinemc.region.IRegionFile regionFile : this.regionCache.values()) { // DivineMC - Linear region file format
+ for (final org.bxteam.divinemc.region.IRegionFile regionFile : this.regionCache.values()) { // DivineMC - Buffered Linear region format
try {
regionFile.flush();
} catch (final IOException ex) {

View File

@@ -0,0 +1,174 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sun, 13 Jul 2025 20:03:51 +0300
Subject: [PATCH] Cleanup dead code from Paper
diff --git a/net/minecraft/network/Connection.java b/net/minecraft/network/Connection.java
index 8bb7d9f2bce06880164f0ae36e1674e9dc380809..04d47ef66f17daf3dfc9223c9f382e058d09a10b 100644
--- a/net/minecraft/network/Connection.java
+++ b/net/minecraft/network/Connection.java
@@ -609,13 +609,7 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
if (!(this.packetListener instanceof net.minecraft.server.network.ServerLoginPacketListenerImpl loginPacketListener)
|| loginPacketListener.state != net.minecraft.server.network.ServerLoginPacketListenerImpl.State.VERIFYING
|| Connection.joinAttemptsThisTick++ < MAX_PER_TICK) {
- // Paper start - detailed watchdog information
- net.minecraft.network.protocol.PacketUtils.packetProcessing.push(this.packetListener);
- try {
- tickablePacketListener.tick();
- } finally {
- net.minecraft.network.protocol.PacketUtils.packetProcessing.pop();
- } // Paper end - detailed watchdog information
+ tickablePacketListener.tick();
} // Paper end - Buffer joins to world
}
diff --git a/net/minecraft/network/protocol/PacketUtils.java b/net/minecraft/network/protocol/PacketUtils.java
index aa4dd7517e8be167aef1eaf7aa907e3ce7cc0e62..e3d3b062e273fee4a9d3ba3cadc212787096dc54 100644
--- a/net/minecraft/network/protocol/PacketUtils.java
+++ b/net/minecraft/network/protocol/PacketUtils.java
@@ -21,8 +21,6 @@ public class PacketUtils {
public static <T extends PacketListener> void ensureRunningOnSameThread(Packet<T> packet, T processor, BlockableEventLoop<?> executor) throws RunningOnDifferentThreadException {
if (!executor.isSameThread()) {
executor.executeIfPossible(() -> {
- packetProcessing.push(processor); // Paper - detailed watchdog information
- try { // Paper - detailed watchdog information
if (processor instanceof net.minecraft.server.network.ServerCommonPacketListenerImpl serverCommonPacketListener && serverCommonPacketListener.processedDisconnect) return; // Paper - Don't handle sync packets for kicked players
if (processor.shouldHandleMessage(packet)) {
try {
@@ -41,12 +39,6 @@ public class PacketUtils {
} else {
LOGGER.debug("Ignoring packet due to disconnection: {}", packet);
}
- // Paper start - detailed watchdog information
- } finally {
- totalMainThreadPacketsProcessed.getAndIncrement();
- packetProcessing.pop();
- }
- // Paper end - detailed watchdog information
});
throw RunningOnDifferentThreadException.RUNNING_ON_DIFFERENT_THREAD;
}
@@ -73,22 +65,4 @@ public class PacketUtils {
packetListener.fillCrashReport(crashReport);
}
-
- // Paper start - detailed watchdog information
- public static final java.util.concurrent.ConcurrentLinkedDeque<PacketListener> packetProcessing = new java.util.concurrent.ConcurrentLinkedDeque<>();
- static final java.util.concurrent.atomic.AtomicLong totalMainThreadPacketsProcessed = new java.util.concurrent.atomic.AtomicLong();
-
- public static long getTotalProcessedPackets() {
- return totalMainThreadPacketsProcessed.get();
- }
-
- public static java.util.List<PacketListener> getCurrentPacketProcessors() {
- java.util.List<PacketListener> listeners = new java.util.ArrayList<>(4);
- for (PacketListener listener : packetProcessing) {
- listeners.add(listener);
- }
-
- return listeners;
- }
- // Paper end - detailed watchdog information
}
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
index 0ad18866c323308ad9b87322932e03a283f740b1..386fdc23b35675a7db66d16bf2a8a6dd5b44059a 100644
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -1349,13 +1349,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
// Paper end - log detailed entity tick information
public void tickNonPassenger(Entity entity) {
- // Paper start - log detailed entity tick information
ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread("Cannot tick an entity off-main");
- try {
- if (currentlyTickingEntity.get() == null) {
- currentlyTickingEntity.lazySet(entity);
- }
- // Paper end - log detailed entity tick information
entity.setOldPosAndRot();
entity.tickCount++;
entity.totalEntityAge++; // Paper - age-like counter for all entities
@@ -1368,13 +1362,6 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
for (Entity entity1 : entity.getPassengers()) {
this.tickPassenger(entity, entity1, isActive); // Paper - EAR 2
}
- // Paper start - log detailed entity tick information
- } finally {
- if (currentlyTickingEntity.get() == entity) {
- currentlyTickingEntity.lazySet(null);
- }
- }
- // Paper end - log detailed entity tick information
}
private void tickPassenger(Entity ridingEntity, Entity passengerEntity, final boolean isActive) { // Paper - EAR 2
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index c1c8e235b9c096cd36c3e83b0831af7cb722cad2..7e6e5d5962de14d064321ed7e4f5254046c15d0b 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -1111,29 +1111,10 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return this.onGround;
}
- // Paper start - detailed watchdog information
- public final Object posLock = new Object(); // Paper - log detailed entity tick information
-
- @Nullable
- private Vec3 moveVector;
- private double moveStartX;
- private double moveStartY;
- private double moveStartZ;
- // Paper end - detailed watchdog information
-
public void move(MoverType type, Vec3 movement) {
if (!this.boundingBoxChanged && movement.equals(Vec3.ZERO)) return; // DivineMC - VMP: skip entity move if movement is zero
final Vec3 originalMovement = movement; // Paper - Expose pre-collision velocity
- // Paper start - detailed watchdog information
ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread("Cannot move an entity off-main");
- synchronized (this.posLock) {
- this.moveStartX = this.getX();
- this.moveStartY = this.getY();
- this.moveStartZ = this.getZ();
- this.moveVector = movement;
- }
- try {
- // Paper end - detailed watchdog information
if (this.noPhysics) {
this.setPos(this.getX() + movement.x, this.getY() + movement.y, this.getZ() + movement.z);
} else {
@@ -1248,13 +1229,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
this.setDeltaMovement(this.getDeltaMovement().multiply(blockSpeedFactor, 1.0, blockSpeedFactor));
}
}
- // Paper start - detailed watchdog information
- } finally {
- synchronized (this.posLock) { // Paper
- this.moveVector = null;
- } // Paper
- }
- // Paper end - detailed watchdog information
}
private void applyMovementEmissionAndPlaySound(Entity.MovementEmission movementEmission, Vec3 movement, BlockPos pos, BlockState state) {
@@ -4948,9 +4922,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
public void setDeltaMovement(Vec3 deltaMovement) {
- synchronized (this.posLock) { // Paper - detailed watchdog information
this.deltaMovement = deltaMovement;
- } // Paper - detailed watchdog information
}
public void addDeltaMovement(Vec3 addend) {
@@ -5048,9 +5020,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
// Paper end - Block invalid positions and bounding box
if (this.position.x != x || this.position.y != y || this.position.z != z) {
- synchronized (this.posLock) { // Paper - detailed watchdog information
this.position = new Vec3(x, y, z);
- } // Paper - detailed watchdog information
int floor = Mth.floor(x);
int floor1 = Mth.floor(y);
int floor2 = Mth.floor(z);

View File

@@ -0,0 +1,54 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Thu, 17 Jul 2025 20:53:13 +0300
Subject: [PATCH] C2ME: The End Biome Cache
This patch is based on the following mixins:
* "com/ishland/c2me/opts/worldgen/vanilla/mixin/the_end_biome_cache/MixinTheEndBiomeSource.java"
By: ishland <ishlandmc@yeah.net>
As part of: C2ME (https://github.com/RelativityMC/C2ME-fabric)
Licensed under: MIT (https://opensource.org/licenses/MIT)
diff --git a/net/minecraft/world/level/biome/TheEndBiomeSource.java b/net/minecraft/world/level/biome/TheEndBiomeSource.java
index cf3172be76fa4c7987ed569138439ff42f92fa7f..0545a0dd25917d75b511d507dc19a5ca7d45b9d9 100644
--- a/net/minecraft/world/level/biome/TheEndBiomeSource.java
+++ b/net/minecraft/world/level/biome/TheEndBiomeSource.java
@@ -55,8 +55,37 @@ public class TheEndBiomeSource extends BiomeSource {
return CODEC;
}
+ // DivineMC start - C2ME: The End Biome Cache
+ private final ThreadLocal<it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap<Holder<Biome>>> cache = ThreadLocal.withInitial(it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap::new);
+ private final int cacheCapacity = org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.endBiomeCacheCapacity;
+
@Override
- public Holder<Biome> getNoiseBiome(int x, int y, int z, Climate.Sampler sampler) {
+ public Holder<Biome> getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler multiNoiseSampler) {
+ if (!org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.endBiomeCacheEnabled) {
+ return getVanillaNoiseBiome(biomeX, biomeY, biomeZ, multiNoiseSampler);
+ }
+
+ final long key = net.minecraft.world.level.ChunkPos.asLong(biomeX, biomeZ);
+ final it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap<Holder<Biome>> cacheThreadLocal = cache.get();
+ final Holder<Biome> biome = cacheThreadLocal.get(key);
+
+ if (biome != null) {
+ return biome;
+ } else {
+ final Holder<Biome> gennedBiome = getVanillaNoiseBiome(biomeX, biomeY, biomeZ, multiNoiseSampler);
+ cacheThreadLocal.put(key, gennedBiome);
+ if (cacheThreadLocal.size() > cacheCapacity) {
+ for (int i = 0; i < cacheCapacity / 16; i ++) {
+ cacheThreadLocal.removeFirst();
+ }
+ }
+
+ return gennedBiome;
+ }
+ }
+ // DivineMC end - C2ME: The End Biome Cache
+
+ private Holder<Biome> getVanillaNoiseBiome(int x, int y, int z, Climate.Sampler sampler) { // DivineMC - C2ME: The End Biome Cache
int blockPosX = QuartPos.toBlock(x);
int blockPosY = QuartPos.toBlock(y);
int blockPosZ = QuartPos.toBlock(z);

View File

@@ -0,0 +1,34 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Fri, 18 Jul 2025 13:54:17 +0300
Subject: [PATCH] Euclidean distance squared option
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
index fef167837e05d6e80246d4fccd037cc1c9500f97..1ef70cc1ca0a47ddae8655e88fa6b74fa7f81dc6 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
@@ -387,10 +387,19 @@ public final class RegionizedPlayerChunkLoader {
final int centerX = PlayerChunkLoaderData.this.lastChunkX;
final int centerZ = PlayerChunkLoaderData.this.lastChunkZ;
- return Integer.compare(
- Math.abs(c1x - centerX) + Math.abs(c1z - centerZ),
- Math.abs(c2x - centerX) + Math.abs(c2z - centerZ)
- );
+ // DivineMC start - Euclidean distance squared option
+ if (org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.useEuclideanDistanceSquared) {
+ return Integer.compare(
+ (c1x - centerX) * (c1x - centerX) + (c1z - centerZ) * (c1z - centerZ),
+ (c2x - centerX) * (c2x - centerX) + (c2z - centerZ) * (c2z - centerZ)
+ );
+ } else {
+ return Integer.compare(
+ Math.abs(c1x - centerX) + Math.abs(c1z - centerZ),
+ Math.abs(c2x - centerX) + Math.abs(c2z - centerZ)
+ );
+ }
+ // DivineMC end - Euclidean distance squared option
};
private final LongHeapPriorityQueue sendQueue = new LongHeapPriorityQueue(CLOSEST_MANHATTAN_DIST);
private final LongHeapPriorityQueue tickingQueue = new LongHeapPriorityQueue(CLOSEST_MANHATTAN_DIST);

View File

@@ -0,0 +1,144 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sun, 20 Jul 2025 00:09:31 +0300
Subject: [PATCH] Do not send spectator change packet
diff --git a/net/minecraft/server/level/ServerPlayerGameMode.java b/net/minecraft/server/level/ServerPlayerGameMode.java
index 6e7ed7451a45f4525946563617ccf0a55851449b..518d670d2f8535679d5d22cb1f15cb85e5bb50f0 100644
--- a/net/minecraft/server/level/ServerPlayerGameMode.java
+++ b/net/minecraft/server/level/ServerPlayerGameMode.java
@@ -75,10 +75,7 @@ public class ServerPlayerGameMode {
// CraftBukkit end
this.setGameModeForPlayer(gameModeForPlayer, this.gameModeForPlayer); // Paper - Fix MC-259571
this.player.onUpdateAbilities();
- this.level
- .getServer()
- .getPlayerList()
- .broadcastAll(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE, this.player), this.player); // CraftBukkit
+ this.sendGameModeUpdatePacket(gameModeForPlayer); // DivineMC - Do not send spectator change packet
this.level.updateSleepingPlayerList();
if (gameModeForPlayer == GameType.CREATIVE) {
this.player.resetCurrentImpulseContext();
@@ -571,4 +568,17 @@ public class ServerPlayerGameMode {
return false;
}
// Purpur end - Shift right click to use exp for mending
+
+ // DivineMC start - Do not send spectator change packet
+ private void sendGameModeUpdatePacket(GameType newGameMode) {
+ ClientboundPlayerInfoUpdatePacket packet = new ClientboundPlayerInfoUpdatePacket(
+ ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE, this.player);
+
+ if (org.bxteam.divinemc.config.DivineConfig.NetworkCategory.sendSpectatorChangePacket || newGameMode != GameType.SPECTATOR) {
+ this.level.getServer().getPlayerList().broadcastAll(packet, this.player);
+ } else {
+ this.player.connection.send(packet);
+ }
+ }
+ // DivineMC end - Do not send spectator change packet
}
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
index 96af2c75b526c59510965665da0b2ca00bf657b3..baa682c9ba48427edb10f5610a5a0a9e21da0581 100644
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -359,6 +359,8 @@ public abstract class PlayerList {
// CraftBukkit start - sendAll above replaced with this loop
ClientboundPlayerInfoUpdatePacket packet = ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(player)); // Paper - Add Listing API for Player
+ ClientboundPlayerInfoUpdatePacket modifiedPacket = this.createSpectatorFilteredPacket(packet); // DivineMC - Do not send spectator change packet
+
final List<ServerPlayer> onlinePlayers = Lists.newArrayListWithExpectedSize(this.players.size() - 1); // Paper - Use single player info update packet on join
for (int i = 0; i < this.players.size(); ++i) {
ServerPlayer entityplayer1 = (ServerPlayer) this.players.get(i);
@@ -367,7 +369,7 @@ public abstract class PlayerList {
// Paper start - Add Listing API for Player
if (entityplayer1.getBukkitEntity().isListed(bukkitPlayer)) {
// Paper end - Add Listing API for Player
- entityplayer1.connection.send(packet);
+ this.sendPlayerInfoPacket(entityplayer1, player, packet, modifiedPacket); // DivineMC - Do not send spectator change packet
// Paper start - Add Listing API for Player
} else {
entityplayer1.connection.send(ClientboundPlayerInfoUpdatePacket.createSinglePlayerInitializing(player, false));
@@ -383,7 +385,10 @@ public abstract class PlayerList {
}
// Paper start - Use single player info update packet on join
if (!onlinePlayers.isEmpty()) {
- player.connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(onlinePlayers, player)); // Paper - Add Listing API for Player
+ // DivineMC start - Do not send spectator change packet
+ ClientboundPlayerInfoUpdatePacket updatePacket = this.createFilteredPlayerListPacket(onlinePlayers, player);
+ player.connection.send(updatePacket); // Paper - Add Listing API for Player
+ // DivineMC end - Do not send spectator change packet
}
// Paper end - Use single player info update packet on join
player.sentListPacket = true;
@@ -1473,4 +1478,69 @@ public abstract class PlayerList {
public boolean isAllowCommandsForAllPlayers() {
return this.allowCommandsForAllPlayers;
}
+
+ // DivineMC start - Do not send spectator change packet
+ @Nullable
+ private ClientboundPlayerInfoUpdatePacket createSpectatorFilteredPacket(ClientboundPlayerInfoUpdatePacket originalPacket) {
+ if (org.bxteam.divinemc.config.DivineConfig.NetworkCategory.sendSpectatorChangePacket) {
+ return null;
+ }
+
+ ClientboundPlayerInfoUpdatePacket.Entry entry = originalPacket.entries().getFirst();
+ if (entry.gameMode() != net.minecraft.world.level.GameType.SPECTATOR) {
+ return null;
+ }
+
+ ClientboundPlayerInfoUpdatePacket.Entry filteredEntry = new ClientboundPlayerInfoUpdatePacket.Entry(
+ entry.profileId(),
+ entry.profile(),
+ entry.listed(),
+ entry.latency(),
+ net.minecraft.world.level.GameType.SURVIVAL,
+ entry.displayName(),
+ entry.showHat(),
+ entry.listOrder(),
+ entry.chatSession());
+
+ return new ClientboundPlayerInfoUpdatePacket(originalPacket.actions(), List.of(filteredEntry));
+ }
+
+ private void sendPlayerInfoPacket(ServerPlayer receiver, ServerPlayer joiningPlayer,
+ ClientboundPlayerInfoUpdatePacket originalPacket,
+ @Nullable ClientboundPlayerInfoUpdatePacket filteredPacket) {
+ if (org.bxteam.divinemc.config.DivineConfig.NetworkCategory.sendSpectatorChangePacket ||
+ receiver == joiningPlayer ||
+ filteredPacket == null) {
+ receiver.connection.send(originalPacket);
+ } else {
+ receiver.connection.send(filteredPacket);
+ }
+ }
+
+ private ClientboundPlayerInfoUpdatePacket createFilteredPlayerListPacket(List<ServerPlayer> onlinePlayers, ServerPlayer joiningPlayer) {
+ ClientboundPlayerInfoUpdatePacket updatePacket = ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(onlinePlayers, joiningPlayer);
+
+ if (org.bxteam.divinemc.config.DivineConfig.NetworkCategory.sendSpectatorChangePacket) {
+ return updatePacket;
+ }
+
+ List<ClientboundPlayerInfoUpdatePacket.Entry> newEntries = new java.util.ArrayList<>();
+ for (ClientboundPlayerInfoUpdatePacket.Entry entry : updatePacket.entries()) {
+ ClientboundPlayerInfoUpdatePacket.Entry newEntry = new ClientboundPlayerInfoUpdatePacket.Entry(
+ entry.profileId(),
+ entry.profile(),
+ entry.listed(),
+ entry.latency(),
+ entry.gameMode() == net.minecraft.world.level.GameType.SPECTATOR ?
+ net.minecraft.world.level.GameType.SURVIVAL : entry.gameMode(),
+ entry.displayName(),
+ entry.showHat(),
+ entry.listOrder(),
+ entry.chatSession());
+ newEntries.add(newEntry);
+ }
+
+ return new ClientboundPlayerInfoUpdatePacket(updatePacket.actions(), newEntries);
+ }
+ // DivineMC end - Do not send spectator change packet
}

View File

@@ -0,0 +1,32 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sun, 20 Jul 2025 16:09:38 +0300
Subject: [PATCH] Paper PR: Fire ServerListPingEvent for secondary motd send
Original license: GPLv3
Original project: https://github.com/PaperMC/Paper
Paper pull request: https://github.com/PaperMC/Paper/pull/8074
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
index b59078273bb6214295a448d5607538557d7eb1ee..c097afcdece95e33486c833063dc2aed159d93f7 100644
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -304,10 +304,15 @@ public abstract class PlayerList {
mutableComponent.withStyle(ChatFormatting.YELLOW);
Component joinMessage = mutableComponent; // Paper - Adventure
serverGamePacketListenerImpl.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot());
- ServerStatus status = this.server.getStatus();
- if (status != null && !cookie.transferred()) {
- player.sendServerStatus(status);
+ // DivineMC start - Paper PR: Fire ServerListPingEvent for secondary motd send
+ if (!cookie.transferred()) {
+ io.papermc.paper.util.MCUtil.scheduleAsyncTask(() -> {
+ if (player.hasDisconnected()) return;
+ net.minecraft.network.protocol.status.ServerStatus status = com.destroystokyo.paper.network.StandardPaperServerListPingEventImpl.getEventResponse(this.server, player.connection.connection);
+ if (status != null) player.sendServerStatus(status);
+ });
}
+ // DivineMC end - Paper PR: Fire ServerListPingEvent for secondary motd send
// player.connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(this.players)); // CraftBukkit - replaced with loop below
this.players.add(player);

View File

@@ -0,0 +1,11 @@
--- a/ca/spottedleaf/moonrise/patches/chunk_tick_iteration/ChunkTickConstants.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_tick_iteration/ChunkTickConstants.java
@@ -2,7 +_,7 @@
public final class ChunkTickConstants {
- public static final int PLAYER_SPAWN_TRACK_RANGE = 8;
+ public static final int PLAYER_SPAWN_TRACK_RANGE = (int) Math.round(org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.playerNearChunkDetectionRange / 16.0); // DivineMC - Configurable player spawn tracking range
// the smallest distance on x/z is at 45 degrees, we need to subtract 0.5 since this is calculated from chunk center and not chunk perimeter
// note: vanilla does not subtract 0.5 but the result is (luckily!) the same
public static final int NARROW_SPAWN_TRACK_RANGE = (int)Math.floor(((double)PLAYER_SPAWN_TRACK_RANGE / Math.sqrt(2.0)) - 0.5);

View File

@@ -1,21 +1,21 @@
--- a/io/papermc/paper/command/subcommands/FixLightCommand.java
+++ b/io/papermc/paper/command/subcommands/FixLightCommand.java
@@ -95,17 +_,22 @@
@@ -95,17 +_,23 @@
((StarLightLightingProvider)lightengine).starlight$serverRelightChunks(chunks,
(final ChunkPos chunkPos) -> {
++relitChunks[0];
- sender.getBukkitEntity().sendMessage(text().color(DARK_AQUA).append(
- text("Relit chunk ", BLUE), text(chunkPos.toString()),
- text(", progress: ", BLUE), text(ONE_DECIMAL_PLACES.get().format(100.0 * (double) (relitChunks[0]) / (double) pending[0]) + "%")
- ));
+ // DivineMC start - Make FixLight use action bar
+ // DivineMC start - Parchment: Make FixLight use action bar
+ sender.getBukkitEntity().sendActionBar(text().color(DARK_AQUA).append(
+ text("Relighting Chunks: ", DARK_AQUA), text(chunkPos.toString()),
+ text(" " + relitChunks[0], net.kyori.adventure.text.format.NamedTextColor.YELLOW),
+ text("/", DARK_AQUA),
+ text(pending[0] + " ", net.kyori.adventure.text.format.NamedTextColor.YELLOW),
+ text("(" + (int) (Math.round(100.0 * (double) (relitChunks[0]) / (double) pending[0])) + "%)", net.kyori.adventure.text.format.NamedTextColor.YELLOW)
+ )); // DivineMC end - Make FixLight use action bar
));
+ // DivineMC end - Parchment: Make FixLight use action bar
},
(final int totalRelit) -> {
final long end = System.nanoTime();
@@ -23,10 +23,10 @@
- text("Relit ", BLUE), text(totalRelit),
- text(" chunks. Took ", BLUE), text(ONE_DECIMAL_PLACES.get().format(1.0e-6 * (end - start)) + "ms")
- ));
+ // DivineMC start - Make FixLight use action bar
+ // DivineMC start - Parchment: Make FixLight use action bar
+ text("Relit ", DARK_AQUA), text(totalRelit, net.kyori.adventure.text.format.NamedTextColor.YELLOW),
+ text(" chunks. Took ", DARK_AQUA), text(ONE_DECIMAL_PLACES.get().format(1.0e-6 * (end - start)) + "ms", net.kyori.adventure.text.format.NamedTextColor.YELLOW)
+ )); // DivineMC end - Make FixLight use action bar
+ )); // DivineMC end - Parchment: Make FixLight use action bar
if (done != null) {
done.run();
}

View File

@@ -1,11 +0,0 @@
--- a/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java
+++ b/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java
@@ -19,7 +_,7 @@
@Override
public final void addPlayerListener(PlayerAdvancements playerAdvancements, CriterionTrigger.Listener<T> listener) {
- playerAdvancements.criterionData.computeIfAbsent(this, managerx -> Sets.newHashSet()).add(listener); // Paper - fix PlayerAdvancements leak
+ playerAdvancements.criterionData.computeIfAbsent(this, managerx -> Sets.newConcurrentHashSet()).add(listener); // Paper - fix PlayerAdvancements leak // DivineMC - use concurrent set
}
@Override

View File

@@ -14,3 +14,11 @@
if (!hasLoggedStop && isDebugging()) io.papermc.paper.util.TraceUtil.dumpTraceForThread("Server stopped"); // Paper - Debugging
shutdownThread = Thread.currentThread(); // Paper - Improved watchdog support
org.spigotmc.WatchdogThread.doStop(); // Paper - Improved watchdog support
@@ -1080,6 +_,7 @@
// Paper end - rewrite chunk system
// Paper start - Improved watchdog support - move final shutdown items here
Util.shutdownExecutors();
+ org.bxteam.divinemc.async.ExecutorShutdown.shutdown(this); // DivineMC - Shutdown executors
try {
net.minecrell.terminalconsole.TerminalConsoleAppender.close(); // Paper - Use TerminalConsoleAppender
} catch (final Exception ignored) {

View File

@@ -0,0 +1,11 @@
--- a/net/minecraft/server/PlayerAdvancements.java
+++ b/net/minecraft/server/PlayerAdvancements.java
@@ -60,7 +_,7 @@
private AdvancementHolder lastSelectedTab;
private boolean isFirstPacket = true;
private final Codec<PlayerAdvancements.Data> codec;
- public final Map<net.minecraft.advancements.critereon.SimpleCriterionTrigger<?>, Set<CriterionTrigger.Listener<?>>> criterionData = new java.util.IdentityHashMap<>(); // Paper - fix advancement data player leakage
+ public final Map<net.minecraft.advancements.critereon.SimpleCriterionTrigger<?>, Set<CriterionTrigger.Listener<?>>> criterionData = new it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap<>(); // Paper - fix advancement data player leakage // DivineMC - Use fastutil for criterion data
public PlayerAdvancements(DataFixer dataFixer, PlayerList playerList, ServerAdvancementManager manager, Path playerSavePath, ServerPlayer player) {
this.playerList = playerList;

View File

@@ -4,26 +4,35 @@
// Purpur end - Purpur config files
com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // Paper - load version history now
+ // DivineMC start - Pufferfish SIMD
+ // DivineMC start - Pufferfish: SIMD Support
+ try {
+ gg.pufferfish.pufferfish.simd.SIMDDetection.isEnabled = gg.pufferfish.pufferfish.simd.SIMDDetection.canEnable(LOGGER);
+ gg.pufferfish.pufferfish.simd.SIMDDetection.versionLimited = gg.pufferfish.pufferfish.simd.SIMDDetection.getJavaVersion() < 17 || gg.pufferfish.pufferfish.simd.SIMDDetection.getJavaVersion() > 21;
+ } catch (NoClassDefFoundError | Exception ignored) {
+ gg.pufferfish.pufferfish.simd.SIMDDetection.versionLimited = gg.pufferfish.pufferfish.simd.SIMDDetection.getJavaVersion() < gg.pufferfish.pufferfish.simd.SIMDDetection.MIN_JAVA_VERSION || gg.pufferfish.pufferfish.simd.SIMDDetection.getJavaVersion() > gg.pufferfish.pufferfish.simd.SIMDDetection.MAX_JAVA_VERSION;
+ } catch (final NoClassDefFoundError | Exception ignored) {
+ ignored.printStackTrace();
+ }
+
+ if (gg.pufferfish.pufferfish.simd.SIMDDetection.isEnabled) {
+ LOGGER.info("SIMD operations detected as functional. Will replace some operations with faster versions.");
+ } else if (gg.pufferfish.pufferfish.simd.SIMDDetection.versionLimited) {
+ LOGGER.warn("Will not enable SIMD! These optimizations are only safely supported on Java 17 and higher.");
+ LOGGER.warn("Will not enable SIMD! These optimizations are only safely supported on Java {}-{}", gg.pufferfish.pufferfish.simd.SIMDDetection.MIN_JAVA_VERSION, gg.pufferfish.pufferfish.simd.SIMDDetection.MAX_JAVA_VERSION);
+ } else {
+ LOGGER.warn("SIMD operations are available for your server, but are not configured!");
+ LOGGER.warn("To enable additional optimizations, add \"--add-modules=jdk.incubator.vector\" to your startup flags, BEFORE the \"-jar\".");
+ LOGGER.warn("If you have already added this flag, then SIMD operations are not supported on your JVM or CPU.");
+ LOGGER.warn("Debug: Java: {}, test run: {}", System.getProperty("java.version"), gg.pufferfish.pufferfish.simd.SIMDDetection.testRun);
+ }
+ // DivineMC end - Pufferfish SIMD
+ // DivineMC end - Pufferfish: SIMD Support
+
this.setPvpAllowed(properties.pvp);
this.setFlightAllowed(properties.allowFlight);
this.setMotd(properties.motd);
@@ -275,7 +_,7 @@
String proxyFlavor = (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled) ? "Velocity" : "BungeeCord";
String proxyLink = (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled) ? "https://docs.papermc.io/velocity/security" : "http://www.spigotmc.org/wiki/firewall-guide/";
// Paper end - Add Velocity IP Forwarding Support
- if (!this.usesAuthentication()) {
+ if (!io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode()) { // DivineMC - Disable offline warn if using proxy
LOGGER.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!");
LOGGER.warn("The server will make no attempt to authenticate usernames. Beware.");
// Spigot start

View File

@@ -1,19 +1,11 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sat, 1 Feb 2025 19:52:39 +0300
Subject: [PATCH] Optimize canSee checks
diff --git a/net/minecraft/server/level/ChunkMap.java b/net/minecraft/server/level/ChunkMap.java
index 7ebaf03342e8802948b4f412c3f7120927f7b3b3..c47b38a9ef01c9f9d58d64b2662d1b0e51353c0d 100644
--- a/net/minecraft/server/level/ChunkMap.java
+++ b/net/minecraft/server/level/ChunkMap.java
@@ -1417,7 +1417,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
@@ -1302,7 +_,7 @@
flag = flag && this.entity.broadcastToPlayer(player) && ChunkMap.this.isChunkTracked(player, this.entity.chunkPosition().x, this.entity.chunkPosition().z);
// Paper end - Configurable entity tracking range by Y
// CraftBukkit start - respect vanish API
- if (flag && !player.getBukkitEntity().canSee(this.entity.getBukkitEntity())) { // Paper - only consider hits
+ if (flag && !player.getBukkitEntity().canSeeChunkMapUpdatePlayer(this.entity.getBukkitEntity())) { // Paper - only consider hits // DivineMC - optimize canSee checks
+ if (flag && !player.getBukkitEntity().canSeeChunkMapUpdatePlayer(this.entity.getBukkitEntity())) { // Paper - only consider hits // DivineMC - SparklyPaper: Optimize "canSee" checks
flag = false;
}
// CraftBukkit end

View File

@@ -1,19 +1,18 @@
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -766,8 +_,14 @@
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.level());
if (packet.getId() == this.awaitingTeleport) {
if (this.awaitingPositionFromClient == null) {
- ServerGamePacketListenerImpl.LOGGER.warn("Disconnected on accept teleport packet. Was not expecting position data from client at this time"); // Purpur - Add more logger output for invalid movement kicks
- this.disconnect(Component.translatable("multiplayer.disconnect.invalid_player_movement"), org.bukkit.event.player.PlayerKickEvent.Cause.INVALID_PLAYER_MOVEMENT); // Paper - kick event cause
+ // DivineMC start - Graceful teleport handling
+ if (org.bxteam.divinemc.config.DivineConfig.NetworkCategory.gracefulTeleportHandling) {
+ LOGGER.info("Was not expecting position data from client at this time, gracefully returning instead of disconnect.");
+ } else {
+ ServerGamePacketListenerImpl.LOGGER.warn("Disconnected on accept teleport packet. Was not expecting position data from client at this time"); // Purpur - Add more logger output for invalid movement kicks
+ this.disconnect(Component.translatable("multiplayer.disconnect.invalid_player_movement"), org.bukkit.event.player.PlayerKickEvent.Cause.INVALID_PLAYER_MOVEMENT); // Paper - kick event cause
+ }
+ // DivineMC end - Graceful teleport handling
return;
}
@@ -313,6 +_,7 @@
private static final int MAX_SIGN_LINE_LENGTH = Integer.getInteger("Paper.maxSignLength", 80); // Paper - Limit client sign length
private final io.papermc.paper.event.packet.ClientTickEndEvent tickEndEvent; // Paper - add client tick end event
public final io.papermc.paper.connection.PaperPlayerGameConnection playerGameConnection; // Paper
+ public final org.leavesmc.leaves.protocol.syncmatica.exchange.ExchangeTarget exchangeTarget; // DivineMC - Leaves: Syncmatica Protocol
public ServerGamePacketListenerImpl(MinecraftServer server, Connection connection, ServerPlayer player, CommonListenerCookie cookie) {
super(server, connection, cookie);
@@ -324,6 +_,7 @@
this.chatMessageChain = new FutureChain(server.chatExecutor); // CraftBukkit - async chat
this.tickEndEvent = new io.papermc.paper.event.packet.ClientTickEndEvent(player.getBukkitEntity()); // Paper - add client tick end event
this.playerGameConnection = new io.papermc.paper.connection.PaperPlayerGameConnection(this); // Paper
+ this.exchangeTarget = new org.leavesmc.leaves.protocol.syncmatica.exchange.ExchangeTarget(this); // DivineMC - Leaves: Syncmatica Protocol
}
// Paper start - configuration phase API

View File

@@ -1,10 +1,10 @@
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -678,7 +_,6 @@
}
public ServerPlayer respawn(ServerPlayer player, boolean keepInventory, Entity.RemovalReason reason, @Nullable org.bukkit.event.player.PlayerRespawnEvent.RespawnReason eventReason, @Nullable org.bukkit.Location location) {
- player.stopRiding(); // CraftBukkit
this.players.remove(player);
this.playersByName.remove(player.getScoreboardName().toLowerCase(java.util.Locale.ROOT)); // Spigot
player.level().removePlayerImmediately(player, reason);
@@ -1143,6 +_,7 @@
player.connection.send(new ClientboundInitializeBorderPacket(worldBorder));
player.connection.send(new ClientboundSetTimePacket(level.getGameTime(), level.getDayTime(), level.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT)));
player.connection.send(new ClientboundSetDefaultSpawnPositionPacket(level.getSharedSpawnPos(), level.getSharedSpawnAngle()));
+ org.leavesmc.leaves.protocol.XaeroMapProtocol.onSendWorldInfo(player); // DivineMC - Leaves: Xaero's Map Protocol
if (level.isRaining()) {
// CraftBukkit start - handle player weather
// player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.START_RAINING, 0.0F));

View File

@@ -18,11 +18,11 @@
Object2IntMap<Stat<?>> map = new Object2IntOpenHashMap<>();
- for (Stat<?> stat : this.getDirty()) {
+ for (Stat<?> stat : this.dirty) { // DivineMC - Skip dirty stats copy when requesting player stats
+ for (Stat<?> stat : this.dirty) { // DivineMC - SparklyPaper: Skip dirty stats copy when requesting player stats
map.put(stat, this.getValue(stat));
}
+
+ this.dirty.clear(); // DivineMC - Skip dirty stats copy when requesting player stats
+ this.dirty.clear(); // DivineMC - SparklyPaper: Clear dirty stats after copying
player.connection.send(new ClientboundAwardStatsPacket(map));
}

View File

@@ -0,0 +1,34 @@
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -374,6 +_,7 @@
public boolean isTemporarilyActive;
public long activatedImmunityTick = Integer.MIN_VALUE;
public @Nullable Boolean immuneToFire = null; // Purpur - Fire immune API
+ private boolean boundingBoxChanged = false; // DivineMC - VMP: skip entity move if movement is zero
public void inactiveTick() {
}
@@ -1125,6 +_,7 @@
// Paper end - detailed watchdog information
public void move(MoverType type, Vec3 movement) {
+ if (!this.boundingBoxChanged && movement.equals(Vec3.ZERO)) return; // DivineMC - VMP: skip entity move if movement is zero
final Vec3 originalMovement = movement; // Paper - Expose pre-collision velocity
// Paper start - detailed watchdog information
ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread("Cannot move an entity off-main");
@@ -4219,6 +_,7 @@
}
public boolean canTeleport(Level fromLevel, Level toLevel) {
+ if (!fromLevel.divineConfig.allowEntityPortalWithPassenger && (this.isPassenger() || this.isVehicle())) return false; // DivineMC - Allow entity teleport with passenger
if (!this.isAlive() || !this.valid) return false; // Paper - Fix item duplication and teleport issues
if (fromLevel.dimension() == Level.END && toLevel.dimension() == Level.OVERWORLD) {
for (Entity entity : this.getPassengers()) {
@@ -4448,6 +_,7 @@
}
public final void setBoundingBox(AABB bb) {
+ if (!this.bb.equals(bb)) this.boundingBoxChanged = true; // DivineMC - VMP: skip entity move if movement is zero
// CraftBukkit start - block invalid bounding boxes
double minX = bb.minX,
minY = bb.minY,

View File

@@ -4,12 +4,12 @@
@Override
protected void doTick(ServerLevel level, Villager entity) {
+ // DivineMC start - skip useless secondary poi sensor
+ // DivineMC start - lithium: skip useless secondary poi sensor
+ if (org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.skipUselessSecondaryPoiSensor && entity.getVillagerData().profession().value().secondaryPoi().isEmpty()) {
+ entity.getBrain().eraseMemory(MemoryModuleType.SECONDARY_JOB_SITE);
+ return;
+ }
+ // DivineMC end - skip useless secondary poi sensor
+ // DivineMC end - lithium: skip useless secondary poi sensor
// Purpur start - Option for Villager Clerics to farm Nether Wart - make sure clerics don't wander to soul sand when the option is off
Brain<?> brain = entity.getBrain();
if (!level.purpurConfig.villagerClericsFarmWarts && entity.getVillagerData().profession().is(net.minecraft.world.entity.npc.VillagerProfession.CLERIC)) {

View File

@@ -1,20 +0,0 @@
--- a/net/minecraft/world/level/BaseCommandBlock.java
+++ b/net/minecraft/world/level/BaseCommandBlock.java
@@ -22,7 +_,7 @@
import net.minecraft.world.phys.Vec3;
public abstract class BaseCommandBlock implements CommandSource {
- private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm:ss");
+ private static final ThreadLocal<SimpleDateFormat> TIME_FORMAT = ThreadLocal.withInitial(() -> new SimpleDateFormat("HH:mm:ss")); // DivineMC - Make it thread safe
private static final Component DEFAULT_NAME = Component.literal("@");
private static final int NO_LAST_EXECUTION = -1;
private long lastExecution = -1L;
@@ -156,7 +_,7 @@
public void sendSystemMessage(Component component) {
if (this.trackOutput) {
org.spigotmc.AsyncCatcher.catchOp("sendSystemMessage to a command block"); // Paper - Don't broadcast messages to command blocks
- this.lastOutput = Component.literal("[" + TIME_FORMAT.format(new Date()) + "] ").append(component);
+ this.lastOutput = Component.literal("[" + TIME_FORMAT.get().format(new Date()) + "] ").append(component); // DivineMC - Make it thread safe
this.onUpdated();
}
}

View File

@@ -1,14 +1,6 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sat, 1 Feb 2025 19:43:42 +0300
Subject: [PATCH] Re-Fix MC-117075
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
index 6240f6f0799916f1c95505f3dfaeb00812abea70..6e8075618baf98fcc396f0b5e241a806805b3d94 100644
--- a/net/minecraft/world/level/Level.java
+++ b/net/minecraft/world/level/Level.java
@@ -104,7 +104,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
@@ -106,7 +_,7 @@
public static final int TICKS_PER_DAY = 24000;
public static final int MAX_ENTITY_SPAWN_Y = 20000000;
public static final int MIN_ENTITY_SPAWN_Y = -20000000;
@@ -17,7 +9,7 @@ index 6240f6f0799916f1c95505f3dfaeb00812abea70..6e8075618baf98fcc396f0b5e241a806
protected final NeighborUpdater neighborUpdater;
private final List<TickingBlockEntity> pendingBlockEntityTickers = Lists.newArrayList();
private boolean tickingBlockEntities;
@@ -1504,13 +1504,11 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
@@ -1501,13 +_,11 @@
boolean runsNormally = this.tickRateManager().runsNormally();
int tickedEntities = 0; // Paper - rewrite chunk system
@@ -32,7 +24,7 @@ index 6240f6f0799916f1c95505f3dfaeb00812abea70..6e8075618baf98fcc396f0b5e241a806
} else if (runsNormally && this.shouldTickBlocksAt(tickingBlockEntity.getPos())) {
tickingBlockEntity.tick();
// Paper start - rewrite chunk system
@@ -1520,7 +1518,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
@@ -1517,7 +_,7 @@
// Paper end - rewrite chunk system
}
}
@@ -40,4 +32,4 @@ index 6240f6f0799916f1c95505f3dfaeb00812abea70..6e8075618baf98fcc396f0b5e241a806
+ this.blockEntityTickers.removeMarkedEntries(); // DivineMC - optimize block entity removals - Fix MC-117075
this.tickingBlockEntities = false;
this.spigotConfig.currentPrimedTnt = 0; // Spigot
profilerFiller.pop();

View File

@@ -0,0 +1,20 @@
--- a/net/minecraft/world/level/LocalMobCapCalculator.java
+++ b/net/minecraft/world/level/LocalMobCapCalculator.java
@@ -42,14 +_,14 @@
}
static class MobCounts {
- private final Object2IntMap<MobCategory> counts = new Object2IntOpenHashMap<>(MobCategory.values().length);
+ private final int[] counts = new int[MobCategory.values().length]; // DivineMC - VMP: store mob counts in an array
public void add(MobCategory category) {
- this.counts.computeInt(category, (key, value) -> value == null ? 1 : value + 1);
+ this.counts[category.ordinal()]++; // DivineMC - VMP: store mob counts in an array
}
public boolean canSpawn(MobCategory category) {
- return this.counts.getOrDefault(category, 0) < category.getMaxInstancesPerChunk();
+ return this.counts[category.ordinal()] < category.getMaxInstancesPerChunk(); // DivineMC - VMP: store mob counts in an array
}
}
}

Some files were not shown because too many files have changed in this diff Show More