Compare commits

...

124 Commits

Author SHA1 Message Date
MrHua269
27cd8d6cdb Updated Upstream(Folia) 2024-12-03 16:42:17 +00:00
MrHua269
af556ab869 [ci skip]Changed maven repo link 2024-12-01 08:44:54 +08:00
MrHua269
4e8d54e073 Publish to snapshot repo 2024-12-01 08:39:28 +08:00
MrHua269
f8559b9ca6 Use https(x) 2024-12-01 08:29:55 +08:00
MrHua269
bc5a83c69c Use moliatopia maven repo 2024-12-01 08:21:08 +08:00
MrHua269
6a8df3771b Fix config for username checks 2024-11-30 23:02:49 +08:00
MrHua269
ff4fdcc7d1 Kaiiju Entity tick and removal limiter 2024-11-30 21:04:54 +08:00
Dreeam
94ae8e3ce0 Skip publish if failed 2024-11-30 01:32:08 -05:00
MrHua269
f1dfac26d8 Fix misplaced chunk hot counters 2024-11-30 14:17:55 +08:00
MrHua269
5d9dfc3e17 Fix NPE 2024-11-30 13:32:17 +08:00
MrHua269
ca44ba98a5 Dropped useless patch 2024-11-30 12:54:01 +08:00
MrHua269
27298b865c [ci skip]Removed useless files 2024-11-30 12:41:36 +08:00
MrHua269
bcea80b4d1 Updated workflow 2024-11-30 12:40:22 +08:00
MrHua269
d20e0b1940 Updated Upstream(Folia) 2024-11-30 12:36:35 +08:00
MrHua269
6fb1f6934b Disable timings warn msg and commands 2024-11-29 23:32:48 +08:00
MrHua269
ab28422974 [ci skip] Use https link 2024-11-29 00:28:40 +08:00
MrHua269
1247d8bf89 Drop 0018 2024-11-29 00:23:13 +08:00
MrHua269
76ce141d63 Revert 78cfb0a760 2024-11-16 15:30:15 +08:00
MrHua269
f9514f1866 Updated Upstream(Folia) 2024-11-16 15:26:10 +08:00
HaHaWTH
3102b1c581 [ci skip] Update dependencies 2024-11-07 23:39:53 +08:00
HaHaWTH
770e4b848d Updated Upstream (Folia) 2024-11-07 23:35:40 +08:00
MrHua269
78cfb0a760 Schedule chunk full task until scheduled 2024-11-03 13:15:52 +08:00
MrHua269
98552da7aa Leaves Fix Incorrect Collision Behavior for Block Shape 2024-11-02 21:49:07 +08:00
MrHua269
a50e2f5be9 Optimized lock acquiring of scheduling fixes 2024-11-02 11:34:14 +08:00
MrHua269
c275bd7e93 Try fixing reference counter 2024-11-01 22:33:57 +08:00
MrHua269
6825d1dbd1 Updated Upstream(Folia) 2024-10-25 00:10:20 +08:00
MrHua269
cad01d6368 Run reference counter getting inside ticket lock 2024-10-06 19:19:17 +08:00
MrHua269
dacd3c5a29 Tidy patches 2024-10-06 18:54:34 +08:00
MrHua269
4f051b3c62 Improve scheduling fixes 2024-10-06 18:52:25 +08:00
MrHua269
a0f4d02bc9 Fix java CP 2024-10-06 11:15:48 +08:00
MrHua269
63a8beaafc Try fixing folia spector teleportation fix 2024-10-06 11:09:58 +08:00
MrHua269
5905dbad61 Run reference acquiring inside ticket lock 2024-10-04 23:10:16 +08:00
M2ke4U
bfe835b8b9 [ci skip]Updated maven repo name 2024-10-01 22:09:54 +08:00
M2ke4U
bf5c6d04d4 [ci skip]Updated maven repo name 2024-10-01 22:09:30 +08:00
M2ke4U
e20088ff17 [ci skip]Update maven repo link 2024-10-01 22:02:31 +08:00
M2ke4U
62470e9097 [ci skip]Update maven repo link 2024-10-01 22:02:24 +08:00
M2ke4U
b96655d098 Update maven repo link 2024-10-01 21:44:17 +08:00
Dreeam
f3b16cb314 Fix scheduling result
Co-Authored-By: M2ke4U <79621885+MrHua269@users.noreply.github.com>
2024-09-21 11:27:11 -04:00
MrHua269
0296cd03b1 Add experimental config for folia scheduled issue fixing 2024-09-18 23:11:27 +08:00
MrHua269
791d374a94 Updated Upstream(Folia) 2024-08-31 16:13:07 +08:00
MrHua269
065b78f0d5 Add experiment config for command block command execution 2024-08-31 10:57:57 +08:00
MrHua269
156837d199 Updated Upstream(Folia) 2024-08-31 08:30:10 +08:00
MrHua269
5a60f7395f Updated Upstream(Folia) 2024-08-29 19:31:49 +08:00
MrHua269
973b437ad6 Updated Upstream(Folia) 2024-08-25 04:26:57 +00:00
MrHua269
051ed97668 Use LogUtils in tpsbar and membar 2024-08-19 10:14:42 +08:00
MrHua269
4918bb98e5 [ci skip]Removed useless patches 2024-08-19 10:07:05 +08:00
MrHua269
8d491c23a9 [ci skip]Updated README.md and README_EN.md 2024-08-19 10:03:01 +08:00
MrHua269
16eca828f1 [ci skip]Cleaned patches 2024-08-19 09:59:30 +08:00
MrHua269
7c312e7851 Updated Upstream(Folia) 2024-08-17 13:26:10 +08:00
MrHua269
76f1b9d02d Updated Upstream(Folia) 2024-08-15 09:36:00 +08:00
M2ke4U
896fd7bf1a [ci skip]Update README.md 2024-08-12 21:58:47 +08:00
M2ke4U
81f17dc7b0 [ci skip]Update README_EN.md 2024-08-12 21:58:11 +08:00
M2ke4U
5f694869c2 Fix javadoc error caused by SIMD 2024-08-12 21:38:31 +08:00
M2ke4U
dc0f1f9933 Use snapshots repo 2024-08-12 19:27:56 +08:00
M2ke4U
1a6ea9fc98 Remove gpr registrations 2024-08-12 19:21:13 +08:00
M2ke4U
f175359ad9 Update build.gradle.kts 2024-08-12 19:14:38 +08:00
M2ke4U
e6a76b5794 Update build_1.21.1.yml 2024-08-12 19:14:22 +08:00
M2ke4U
d170436ff0 Corrected publishing 2024-08-12 18:35:13 +08:00
M2ke4U
cc907e891d Added maven publish back 2024-08-12 18:29:44 +08:00
M2ke4U
5b9d44ee94 [ci skip]Added molia maven repo 2024-08-12 18:29:12 +08:00
M2ke4U
c749ca011a [ci skip] Corrected CI name 2024-08-12 10:49:10 +08:00
M2ke4U
72f6717b13 Try fixing folia #273 2024-08-12 10:43:27 +08:00
M2ke4U
55be3489f0 Add files via upload 2024-08-12 10:08:59 +08:00
MrHua269
d547f8ab3f Updated Upstream(Folia) 2024-08-09 11:49:29 +08:00
MrHua269
a22472fe99 Added config to disable async catchers 2024-08-07 14:35:13 +08:00
MrHua269
d15f2774ea Added config to disable entity tick catchers 2024-08-07 14:28:17 +08:00
MrHua269
b27cf9614e Fix vanilla end teleportation 2024-08-07 10:40:18 +08:00
MrHua269
98bbcd67e4 Check allow before getting block state while tripwire state updating 2024-08-06 21:07:45 +08:00
MrHua269
1ed71f5812 Force disable builtin spark plugin 2024-08-06 17:55:23 +08:00
MrHua269
14de6bf8c7 Correct wrong name "SMID" to SIMD 2024-08-06 17:20:26 +08:00
MrHua269
d0d9ce0c46 Correct java version checks in SIMD optimization 2024-08-06 17:20:14 +08:00
MrHua269
2e520168e1 Correct wrong name "SMID" to SIMD 2024-08-06 17:18:18 +08:00
MrHua269
58d45e32c5 Fix java CP 2024-08-06 17:15:51 +08:00
MrHua269
8830d65945 Pufferfish SMID Utilities 2024-08-06 14:33:07 +08:00
MrHua269
fb55d3e201 Try fixing unsafe teleportation 2024-08-06 14:19:37 +08:00
MrHua269
892dfcd2a0 Removed climbable check optimizations 2024-08-06 14:12:57 +08:00
MrHua269
6c600853dd Removed entity fluid looking up optimizations 2024-08-06 12:29:18 +08:00
MrHua269
1299dbfeea Try fixing lock acquiring issue in extra task optimizations 2024-08-06 09:17:26 +08:00
MrHua269
8e876b48f2 Kaiiju Vanilla end portal teleportation 2024-08-05 14:48:51 +08:00
MrHua269
a4794fb096 Try fixing unsafe teleportation again 2024-08-05 14:39:20 +08:00
MrHua269
064679fd22 Removed collision optimizations 2024-08-05 09:54:03 +08:00
M2ke4U
2541ddfd7b Fix unsafe teleportation 2024-08-04 23:43:27 +08:00
MrHua269
c5cb9503c9 Fix java CP 2024-08-04 23:04:00 +08:00
MrHua269
ab71de6298 Re-tidied optimizations from Pufferfish and fixed unsafe teleportation 2024-08-04 22:31:18 +08:00
MrHua269
7bba0412a3 Fix fluid looking up optimization 2024-08-04 19:14:51 +08:00
MrHua269
b56f9723e7 [ci skip]Updated README.md and README_EN.md 2024-08-04 10:05:40 +08:00
MrHua269
190e5e094a Add linear format from LinearPurpur 2024-08-04 09:59:50 +08:00
MrHua269
17e9d04db0 Add config for extra task execution 2024-08-03 19:50:59 +08:00
MrHua269
09861230f7 Ifn before checking the state 2024-08-02 22:39:45 +08:00
MrHua269
a92cfa3637 Try optimizing the task dispatching 2024-08-02 22:23:01 +08:00
MrHua269
84cf8fbb38 Updated Upstream(Folia) 2024-08-02 08:19:21 +08:00
MrHua269
620e093735 Fix concurrency issue caused by chunk hot 2024-08-01 11:27:32 +08:00
MrHua269
d01eef55ec Updated Upstream(Folia) 2024-08-01 10:59:43 +08:00
MrHua269
05101da67b Try fixing folia #253 2024-07-31 21:46:34 +08:00
MrHua269
32db7a453c Fix chunk hot 2024-07-31 17:31:57 +08:00
MrHua269
576d488a36 Updated CI 2024-07-31 15:48:57 +08:00
MrHua269
4959ecceba Updated Upstream(Folia) 2024-07-31 15:46:18 +08:00
ShintoKosei
6614f67647 Update CI 2024-07-30 18:41:34 +08:00
MrHua269
85f3a4a123 FoliaPR Add TPS From Region 2024-07-30 18:01:03 +08:00
ShintoKosei
99e29a0596 Fix Afdian Link 2024-07-30 15:09:00 +08:00
MrHua269
0a0cdb8d54 Added some optimizations 2024-07-29 20:16:25 +08:00
MrHua269
aa49ca63a4 Check null 2024-07-29 17:14:08 +08:00
MrHua269
fefc53dd71 Only run discard checks of projectile chunk-loading optimization on tick regions 2024-07-29 12:09:51 +08:00
MrHua269
0e049306c9 [ci skip]Tidy patches 2024-07-28 18:47:45 +08:00
MrHua269
e991f0b80f Fix incorrect scheduling in POI fixes 2024-07-23 11:39:44 +08:00
MrHua269
4752f00d09 Updated POI fixes 2024-07-17 20:45:13 +08:00
Dreeam
e6027bdfbf Fix sending keepalive packet
7708a4c06f
2024-07-10 06:05:27 +08:00
MrHua269
1f881dd409 Corrected watchdog hook position 2024-07-01 12:25:00 +08:00
MrHua269
be0d1b1bb2 Added YieldJobState fixes to POI fixes 2024-07-01 11:20:13 +08:00
Stabrinai
3fd73145d6 Verify signature only in online-mode 2024-06-30 20:49:45 +08:00
MrHua269
b8963f9862 Try fixing NPE and append missing functions in Watchdog 2024-06-29 22:04:25 +08:00
MrHua269
83a868e3d2 Fix problematic inversions in 0012 2024-06-29 21:46:41 +08:00
MrHua269
9153d07d43 Fix wrong file extension checks 2024-06-28 21:43:19 +08:00
MrHua269
fcf4731fa2 Re-added and rewrote linear region format 2024-06-27 19:45:01 +08:00
MrHua269
0795ae027d Updated Upstream(Folia) 2024-06-20 04:52:40 +00:00
MrHua269
f2a13748e8 Do not teleport Nan entities in large velocity fix 2024-06-16 14:48:54 +00:00
MrHua269
acc31af9f6 Added config for: Pufferfish Reduce entity fluid lookups if no fluids 2024-06-16 11:02:32 +00:00
MrHua269
9121c2ba4e Added a simple membar 2024-06-15 13:01:48 +00:00
MrHua269
0cc6f1cdb3 Added comments for some config 2024-06-15 07:46:05 +00:00
MrHua269
ac1cc484c2 Added comments for some config 2024-06-15 04:17:37 +00:00
MrHua269
b208bcc81f Finish remain renaming and works on membar 2024-06-11 12:44:19 +00:00
M2ke4U
43eda55b88 Move rambar patch to unapplied because it is still in testing stage 2024-06-10 21:13:54 +08:00
MrHua269
e6ee20986b Try fixing folia off region POI accessing issue 2024-06-10 10:51:53 +00:00
MrHua269
46aec00348 Clean patches 2024-06-02 07:14:13 +00:00
83 changed files with 3748 additions and 4944 deletions

2
.github/FUNDING.yml vendored
View File

@@ -11,4 +11,4 @@ issuehunt: # Replace with a single IssueHunt username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
polar: # Replace with a single Polar username
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
custom: https://afdian.net/a/Luminol
custom: https://afdian.com/a/Luminol

View File

@@ -1,10 +1,10 @@
name: Luminol CI - vev/1.20.6
name: Luminol CI - dev/1.21.3
on:
push:
branches: [ "ver/1.20.6" ]
branches: [ "dev/1.21.3" ]
pull_request:
branches: [ "ver/1.20.6" ]
branches: [ "de/1.21.3" ]
permissions: write-all
@@ -32,6 +32,12 @@ jobs:
run: gradle applyPatches
- name: CreateJar
run: gradle createMojmapBundlerJar createMojmapPaperclipJar
- name: Publish to repo
continue-on-error: true
run: |
export MAVEN_REPO_USER=${{ secrets.MAVEN_REPO_USER }}
export MAVEN_REPO_PASSWORD=${{ secrets.MAVEN_REPO_PASSWORD }}
./gradlew publish -PpublishDevBundle=true
- name: SetENV
run: sh scripts/SetENV.sh
- name: Upload Artifact
@@ -59,8 +65,9 @@ jobs:
token: "${{ secrets.GITHUB_TOKEN }}"
- name: Push to API
if: "!contains(github.event.commits[0].message, '[release skip]')"
continue-on-error: true
env:
secret_v2: ${{ secrets.API_KEY }}
tag: ${{ env.tag }}
project_id: ${{ env.project_id }}
run: sh scripts/PushToAPI.sh
run: sh scripts/PushToAPI.sh

View File

@@ -31,19 +31,34 @@
使用 Gradle:
```kotlin
repositories {
maven {
url = "https://maven.moliatopia.icu/repository/maven-snapshots/"
}
}
dependencies {
compileOnly("me.earthme.luminol:luminol-api:1.20.6-R0.1-SNAPSHOT")
compileOnly("me.earthme.luminol:luminol-api:1.21.3-R0.1-20241201.004037-1")
}
```
使用 Maven
```xml
<dependency>
<groupId>me.earthme.luminol</groupId>
<artifactId>luminol-api</artifactId>
<version>1.20.6-R0.1-SNAPSHOT</version>
</dependency>
<repositories>
<repository>
<id>moliatopia</id>
<url>https://maven.moliatopia.icu/repository/maven-snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>me.earthme.luminol</groupId>
<artifactId>luminol-api</artifactId>
<version>1.21.3-R0.1-20241201.004037-1</version>
</dependency>
</dependencies>
```
## 联系方式
@@ -70,4 +85,4 @@ dependencies {
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=LuminolMC/Luminol%2CLuminolMC/LightingLuminol&type=Date" />
<img alt="Star历史表" src="https://api.star-history.com/svg?repos=LuminolMC/Luminol%2CLuminolMC/LightingLuminol&type=Date" />
</picture>
</a>
</a>

View File

@@ -32,19 +32,34 @@ To build a paperclip jar, you need to run the following command. You can find th
For gradle:
```kotlin
repositories {
maven {
url = "https://maven.moliatopia.icu/repository/maven-snapshots/"
}
}
dependencies {
compileOnly("me.earthme.luminol:luminol-api:1.20.6-R0.1-SNAPSHOT")
compileOnly("me.earthme.luminol:luminol-api:1.21.3-R0.1-20241201.004037-1")
}
```
For maven
```xml
<repositories>
<repository>
<id>moliatopia</id>
<url>https://maven.moliatopia.icu/repository/maven-snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>me.earthme.luminol</groupId>
<artifactId>luminol-api</artifactId>
<version>1.20.6-R0.1-SNAPSHOT</version>
<groupId>me.earthme.luminol</groupId>
<artifactId>luminol-api</artifactId>
<version>1.21.3-R0.1-20241201.004037-1</version>
</dependency>
</dependencies>
```
## Contact

View File

@@ -1,128 +1,122 @@
plugins {
java
`maven-publish`
id("io.papermc.paperweight.patcher") version "1.7.1"
}
val paperMavenPublicUrl = "https://repo.papermc.io/repository/maven-public/"
repositories {
mavenCentral()
maven(paperMavenPublicUrl) {
content { onlyForConfigurations(configurations.paperclip.name) }
}
}
dependencies {
remapper("net.fabricmc:tiny-remapper:0.10.1:fat")
decompiler("org.vineflower:vineflower:1.10.1")
paperclip("io.papermc:paperclip:3.0.3")
}
subprojects {
apply(plugin = "java")
apply(plugin = "maven-publish")
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
tasks.withType<JavaCompile> {
options.encoding = Charsets.UTF_8.name()
options.release.set(21)
}
tasks.withType<Javadoc> {
options.encoding = Charsets.UTF_8.name()
}
tasks.withType<ProcessResources> {
filteringCharset = Charsets.UTF_8.name()
}
repositories {
mavenCentral()
maven(paperMavenPublicUrl)
maven("https://oss.sonatype.org/content/groups/public/")
maven("https://ci.emc.gs/nexus/content/groups/aikar/")
maven("https://repo.aikar.co/content/groups/aikar")
maven("https://repo.md-5.net/content/repositories/releases/")
maven("https://hub.spigotmc.org/nexus/content/groups/public/")
maven("https://jitpack.io")
maven("https://repo.codemc.io/repository/maven-public/")
}
}
paperweight {
serverProject.set(project(":luminol-server"))
remapRepo.set("https://maven.fabricmc.net/")
decompileRepo.set("https://maven.quiltmc.org/")
useStandardUpstream("folia") {
url.set(github("PaperMC", "Folia"))
ref.set(providers.gradleProperty("foliaCommit"))
withStandardPatcher {
apiSourceDirPath.set("Folia-API")
serverSourceDirPath.set("Folia-Server")
apiPatchDir.set(layout.projectDirectory.dir("patches/api"))
apiOutputDir.set(layout.projectDirectory.dir("Luminol-API"))
serverPatchDir.set(layout.projectDirectory.dir("patches/server"))
serverOutputDir.set(layout.projectDirectory.dir("Luminol-Server"))
}
patchTasks.register("generatedApi") {
isBareDirectory = true
upstreamDirPath = "paper-api-generator/generated"
patchDir = layout.projectDirectory.dir("patches/generatedApi")
outputDir = layout.projectDirectory.dir("paper-api-generator/generated")
}
}
}
tasks.generateDevelopmentBundle {
apiCoordinates.set("me.earthme.luminol:luminol-api")
libraryRepositories.addAll(
"https://repo.maven.apache.org/maven2/",
"https://maven.pkg.github.com/LuminolMC/Luminol",
paperMavenPublicUrl,
)
}
allprojects {
publishing {
repositories {
maven {
name = "githubPackage"
url = uri("https://maven.pkg.github.com/LuminolMC/Luminol")
credentials.username = System.getenv("GITHUB_USERNAME")
credentials.password = System.getenv("GITHUB_TOKEN")
}
publications {
register<MavenPublication>("gpr") {
from(components["java"])
}
}
}
}
}
publishing {
if (project.hasProperty("publishDevBundle")) {
publications.create<MavenPublication>("devBundle") {
artifact(tasks.generateDevelopmentBundle) {
artifactId = "dev-bundle"
}
}
}
}
plugins {
java
`maven-publish`
id("io.papermc.paperweight.patcher") version "1.7.5"
}
val paperMavenPublicUrl = "https://repo.papermc.io/repository/maven-public/"
repositories {
mavenCentral()
maven(paperMavenPublicUrl) {
content { onlyForConfigurations(configurations.paperclip.name) }
}
}
dependencies {
remapper("net.fabricmc:tiny-remapper:0.10.3:fat")
decompiler("org.vineflower:vineflower:1.10.1")
paperclip("io.papermc:paperclip:3.0.3")
}
subprojects {
apply(plugin = "java")
apply(plugin = "maven-publish")
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
tasks.withType<JavaCompile> {
options.encoding = Charsets.UTF_8.name()
options.release.set(21)
}
tasks.withType<Javadoc> {
options.encoding = Charsets.UTF_8.name()
}
tasks.withType<ProcessResources> {
filteringCharset = Charsets.UTF_8.name()
}
repositories {
mavenCentral()
maven(paperMavenPublicUrl)
maven("https://oss.sonatype.org/content/groups/public/")
maven("https://ci.emc.gs/nexus/content/groups/aikar/")
maven("https://repo.aikar.co/content/groups/aikar")
maven("https://repo.md-5.net/content/repositories/releases/")
maven("https://hub.spigotmc.org/nexus/content/groups/public/")
maven("https://jitpack.io")
maven("https://repo.codemc.io/repository/maven-public/")
}
}
paperweight {
serverProject.set(project(":luminol-server"))
remapRepo.set("https://maven.fabricmc.net/")
decompileRepo.set("https://maven.quiltmc.org/")
useStandardUpstream("folia") {
url.set(github("PaperMC", "Folia"))
ref.set(providers.gradleProperty("foliaCommit"))
withStandardPatcher {
apiSourceDirPath.set("Folia-API")
serverSourceDirPath.set("Folia-Server")
apiPatchDir.set(layout.projectDirectory.dir("patches/api"))
apiOutputDir.set(layout.projectDirectory.dir("Luminol-API"))
serverPatchDir.set(layout.projectDirectory.dir("patches/server"))
serverOutputDir.set(layout.projectDirectory.dir("Luminol-Server"))
}
patchTasks.register("generatedApi") {
isBareDirectory = true
upstreamDirPath = "paper-api-generator/generated"
patchDir = layout.projectDirectory.dir("patches/generatedApi")
outputDir = layout.projectDirectory.dir("paper-api-generator/generated")
}
}
}
tasks.generateDevelopmentBundle {
apiCoordinates.set("me.earthme.luminol:luminol-api")
libraryRepositories.addAll(
"https://repo.maven.apache.org/maven2/",
"https://maven.pkg.github.com/LuminolMC/Luminol",
paperMavenPublicUrl,
)
}
allprojects {
publishing {
repositories {
maven {
name = "moliaMavenRepo"
url = uri("https://maven.moliatopia.icu/repository/maven-snapshots/")
credentials.username = System.getenv("MAVEN_REPO_USER")
credentials.password = System.getenv("MAVEN_REPO_PASSWORD")
}
}
}
}
publishing {
if (project.hasProperty("publishDevBundle")) {
publications.create<MavenPublication>("devBundle") {
artifact(tasks.generateDevelopmentBundle) {
artifactId = "dev-bundle"
}
}
}
}

View File

@@ -1,13 +1,13 @@
group = me.earthme.luminol
version = 1.20.6-R0.1-SNAPSHOT
version = 1.21.3-R0.1-SNAPSHOT
foliaCommit = 36e5e836e8b72e39462545709fc656e69bfb53cf
foliaCommit = e1601057b3e8131127788aafc8f4e80b800556c3
org.gradle.caching = true
org.gradle.parallel = true
org.gradle.vfs.watch = false
org.gradle.jvmargs = -Xmx3G
mcVersion = 1.20.6
GroupMCV = 1.20
preVersion = false
mcVersion = 1.21.3
GroupMCV = 1.21
preVersion = true

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Rebrand to Luminol
diff --git a/src/main/java/io/papermc/paper/ServerBuildInfo.java b/src/main/java/io/papermc/paper/ServerBuildInfo.java
index 9df9d09aa477d4cd3c496ba0933c816df1ef0964..b8a5e4f02499e3a3c370d43f6bbb84ffba58e1f3 100644
index 652ff54e7c50412503725d628bfe72ed03059790..ee163b9fa8f441aa4b3e2309f33e8f932dfc02d7 100644
--- a/src/main/java/io/papermc/paper/ServerBuildInfo.java
+++ b/src/main/java/io/papermc/paper/ServerBuildInfo.java
@@ -18,6 +18,13 @@ public interface ServerBuildInfo {
@@ -19,6 +19,13 @@ public interface ServerBuildInfo {
*/
Key BRAND_PAPER_ID = Key.key("papermc", "paper");

View File

@@ -1,14 +1,14 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Sat, 27 Apr 2024 13:22:59 +0000
From: MrHua269 <wangxyper@163.com>
Date: Fri, 25 Oct 2024 00:07:15 +0800
Subject: [PATCH] KioCG Chunk API
diff --git a/src/main/java/org/bukkit/Chunk.java b/src/main/java/org/bukkit/Chunk.java
index d547ae2b20c58bc703de4532b3b591dd34ddb1c6..8721954514f813d0a1200935e27a3ac00ceca135 100644
index bc8b5bc17706250b8535b1b309134843d2ce2bb1..1cfe84ad1094e3c4fab96487f328be53e035a64c 100644
--- a/src/main/java/org/bukkit/Chunk.java
+++ b/src/main/java/org/bukkit/Chunk.java
@@ -377,4 +377,6 @@ public interface Chunk extends PersistentDataHolder {
@@ -389,4 +389,6 @@ public interface Chunk extends PersistentDataHolder {
*/
UNLOADED;
}
@@ -16,13 +16,13 @@ index d547ae2b20c58bc703de4532b3b591dd34ddb1c6..8721954514f813d0a1200935e27a3ac0
+ long getChunkHotAvg(); // KioCG
}
diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
index 6c327a07bf8a6aa11a2d7dad12b2830acc539484..d66a165ca910bf47da837fb166e5c295325ef9a8 100644
index 95f0b3186e313c7fbd5c8531d52b82a69e525f94..ce98b3de2fe935de4c280f7af9940499d6f09926 100644
--- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java
@@ -3806,4 +3806,6 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@Override
Spigot spigot();
// Spigot end
@@ -3911,4 +3911,6 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
*/
void sendEntityEffect(org.bukkit.@NotNull EntityEffect effect, @NotNull Entity target);
// Paper end - entity effect API
+
+ long getNearbyChunkHot(); // KioCG
}

View File

@@ -0,0 +1,68 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <wangxyper@163.com>
Date: Tue, 30 Jul 2024 17:58:25 +0800
Subject: [PATCH] FoliaPR Add TPS From Region
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index 5ce98e09e9bfcae45896401c69578aa879222893..dacb9342f21ba045b97f004c6c9970adbc2b9eb5 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -2429,6 +2429,28 @@ public final class Bukkit {
}
// Paper end
+ // Folia start
+ /**
+ * Gets the current location TPS.
+ *
+ * @param location the location for which to get the TPS
+ * @return current location TPS (5s, 15s, 1m, 5m, 15m in Folia-Server), or null if the region doesn't exist
+ */
+ public double @Nullable [] getTPS(Location location) {
+ return server.getTPS(location);
+ }
+
+ /**
+ * Gets the current chunk TPS.
+ *
+ * @param chunk the chunk for which to get the TPS
+ * @return current chunk TPS (5s, 15s, 1m, 5m, 15m in Folia-Server), or null if the region doesn't exist
+ */
+ public double @Nullable [] getTPS(Chunk chunk){
+ return server.getTPS(chunk);
+ }
+ // Folia end
+
/**
* Get the advancement specified by this key.
*
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index a92bd4da6788f1331a4838ab5760baec2dc6e8ec..32ec411df95dbce73700ce47fb24737f1f508bb5 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -2076,6 +2076,24 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
double getAverageTickTime();
// Paper end
+ // Folia start
+ /**
+ * Gets the current location TPS.
+ *
+ * @param location the location for which to get the TPS
+ * @return current location TPS (5s, 15s, 1m, 5m, 15m in Folia-Server), or null if the region doesn't exist
+ */
+ public double @Nullable [] getTPS(Location location);
+
+ /**
+ * Gets the current chunk TPS.
+ *
+ * @param chunk the chunk for which to get the TPS
+ * @return current chunk TPS (5s, 15s, 1m, 5m, 15m in Folia-Server), or null if the region doesn't exist
+ */
+ public double @Nullable [] getTPS(Chunk chunk);
+ // Folia end
+
// Paper start
/**
* Gets the active {@link org.bukkit.command.CommandMap}

View File

@@ -0,0 +1,118 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <wangxyper@163.com>
Date: Tue, 6 Aug 2024 14:32:22 +0800
Subject: [PATCH] Pufferfish SIMD Utilities
diff --git a/build.gradle.kts b/build.gradle.kts
index e29e5024fa693baae469d47fe77b57118f14627c..46a4af5eb9a12a3263e6d73867f6a905a6c85e64 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -148,6 +148,13 @@ val generateApiVersioningFile by tasks.registering {
}
}
+// Pufferfish Start
+tasks.withType<JavaCompile> {
+ val compilerArgs = options.compilerArgs
+ compilerArgs.add("--add-modules=jdk.incubator.vector")
+}
+// Pufferfish End
+
tasks.jar {
from(generateApiVersioningFile.map { it.outputs.files.singleFile }) {
into("META-INF/maven/${project.group}/${project.name}")
@@ -207,6 +214,7 @@ tasks.withType<Javadoc> {
into("build/docs/javadoc")
}
}
+ options.addStringOption("-add-modules", "jdk.incubator.vector") // Pufferfish - SIMD support
}
tasks.test {
diff --git a/src/main/java/gg/pufferfish/pufferfish/simd/SIMDChecker.java b/src/main/java/gg/pufferfish/pufferfish/simd/SIMDChecker.java
new file mode 100644
index 0000000000000000000000000000000000000000..f00c008c03e2533f568085838cf13cb9b5b32cd9
--- /dev/null
+++ b/src/main/java/gg/pufferfish/pufferfish/simd/SIMDChecker.java
@@ -0,0 +1,39 @@
+package gg.pufferfish.pufferfish.simd;
+
+import jdk.incubator.vector.FloatVector;
+import jdk.incubator.vector.IntVector;
+import jdk.incubator.vector.VectorSpecies;
+import org.slf4j.Logger;
+
+/**
+ * Basically, java is annoying and we have to push this out to its own class.
+ */
+@Deprecated
+public class SIMDChecker {
+
+ @Deprecated
+ public static boolean canEnable(Logger logger) {
+ try {
+ if (SIMDDetection.getJavaVersion() < 17 || SIMDDetection.getJavaVersion() > 21) {
+ 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 " + FSPEC.vectorBitSize() + " bits (float)");
+
+ if (ISPEC.elementSize() < 2 || FSPEC.elementSize() < 2) {
+ logger.warn("SIMD is not properly supported on this system!");
+ return false;
+ }
+
+ return true;
+ }
+ } catch (NoClassDefFoundError | Exception ignored) {} // Basically, we don't do anything. This lets us detect if it's not functional and disable it.
+ return false;
+ }
+
+}
diff --git a/src/main/java/gg/pufferfish/pufferfish/simd/SIMDDetection.java b/src/main/java/gg/pufferfish/pufferfish/simd/SIMDDetection.java
new file mode 100644
index 0000000000000000000000000000000000000000..cd953435a6179eaae7c9cc250a791cae26c5567b
--- /dev/null
+++ b/src/main/java/gg/pufferfish/pufferfish/simd/SIMDDetection.java
@@ -0,0 +1,35 @@
+package gg.pufferfish.pufferfish.simd;
+
+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 boolean canEnable(Logger logger) {
+ try {
+ return SIMDChecker.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.")) {
+ version = version.substring(2, 3);
+ } else {
+ int dot = version.indexOf(".");
+ if(dot != -1) { version = version.substring(0, dot); }
+ }
+ version = version.split("-")[0]; // Azul is stupid
+ return Integer.parseInt(version);
+ }
+
+}

View File

@@ -0,0 +1,45 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 12:34:50 +0800
Subject: [PATCH] Disable timings warn msg and commands
diff --git a/src/main/java/co/aikar/timings/Timings.java b/src/main/java/co/aikar/timings/Timings.java
index 89017af09ce32e7a66014fc3aeb50155921252a5..b862779b48176dd7e67a2f1a3e7f24bc8c84e993 100644
--- a/src/main/java/co/aikar/timings/Timings.java
+++ b/src/main/java/co/aikar/timings/Timings.java
@@ -147,7 +147,7 @@ public final class Timings {
public static void setTimingsEnabled(boolean enabled) {
enabled = false; // Folia - region threading - disable timings
if (enabled && !warnedAboutDeprecationOnEnable) {
- Bukkit.getLogger().severe(PlainTextComponentSerializer.plainText().serialize(deprecationMessage()));
+ // Bukkit.getLogger().severe(PlainTextComponentSerializer.plainText().serialize(deprecationMessage())); // Luminol - Disable timings warn msg and commands
warnedAboutDeprecationOnEnable = true;
}
}
diff --git a/src/main/java/org/bukkit/command/SimpleCommandMap.java b/src/main/java/org/bukkit/command/SimpleCommandMap.java
index 5df19bd701c67506689fc7f49d91f99ebfbc83f0..baf0cbd2f995ebe2e4382244eff6e15ec125d790 100644
--- a/src/main/java/org/bukkit/command/SimpleCommandMap.java
+++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java
@@ -39,7 +39,7 @@ public class SimpleCommandMap implements CommandMap {
register("bukkit", new VersionCommand("version"));
register("bukkit", new ReloadCommand("reload"));
//register("bukkit", new PluginsCommand("plugins")); // Paper
- register("bukkit", new co.aikar.timings.TimingsCommand("timings")); // Paper
+ //register("bukkit", new co.aikar.timings.TimingsCommand("timings")); // Paper // Luminol - Disable timings warn msg and commands
}
public void setFallbackCommands() {
diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
index 9611e8e254b4fa9579dc9ffd5198182c43819c56..170fefdc50605c0c4d742a606c18d871966e6e72 100644
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
@@ -966,7 +966,7 @@ public final class SimplePluginManager implements PluginManager {
*/
@Deprecated(forRemoval = true)
public void useTimings(boolean use) {
- co.aikar.timings.Timings.setTimingsEnabled(use); // Paper
+ // co.aikar.timings.Timings.setTimingsEnabled(use); // Paper // Luminol - Disable timings warn msg and commands
}
// Paper start

View File

@@ -1,19 +1,19 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Mon, 1 Jan 2024 07:59:27 +0000
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 11:15:18 +0800
Subject: [PATCH] Fix build
diff --git a/build.gradle.kts b/build.gradle.kts
index eb2f9941b24af591f1e56339b97f5284a765cf81..32bfe781e5298e5ad1bd2ed4471fb824c49f0ab4 100644
index 142714c7d47eb5de937ad385c81968148a7e4828..a4b74fabc9f5a57c8897794e69855f2f3f82f986 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -13,7 +13,7 @@ configurations.named(log4jPlugins.compileClasspathConfigurationName) {
val alsoShade: Configuration by configurations.creating
@@ -25,7 +25,7 @@ abstract class MockitoAgentProvider : CommandLineArgumentProvider {
// Paper end - configure mockito agent that is needed in newer java versions
dependencies {
- implementation(project(":folia-api")) // Folia
+ implementation(project(":luminol-api")) // Folia // Luminol
// Paper start
implementation("org.jline:jline-terminal-jansi:3.21.0")
implementation("net.minecrell:terminalconsoleappender:1.3.0")
implementation("org.jline:jline-terminal-ffm:3.27.1") // use ffm on java 22+
implementation("org.jline:jline-terminal-jni:3.27.1") // fall back to jni on java 21

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Rebrand to Luminol
diff --git a/build.gradle.kts b/build.gradle.kts
index 32bfe781e5298e5ad1bd2ed4471fb824c49f0ab4..f9919b9da90317bd615d7e57607df73ebcc1d077 100644
index a4b74fabc9f5a57c8897794e69855f2f3f82f986..623816729867d0bee60075c00334e2011795049a 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -80,14 +80,14 @@ tasks.jar {
@@ -99,14 +99,14 @@ tasks.jar {
val gitBranch = git("rev-parse", "--abbrev-ref", "HEAD").getText().trim() // Paper
attributes(
"Main-Class" to "org.bukkit.craftbukkit.Main",

View File

@@ -1,21 +1,21 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Wed, 7 Feb 2024 00:45:19 +0000
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 11:22:17 +0800
Subject: [PATCH] Empty config file base
diff --git a/build.gradle.kts b/build.gradle.kts
index f9919b9da90317bd615d7e57607df73ebcc1d077..ab07c307bea0d3b79a6239bdcca9714e1ddf3b28 100644
index 623816729867d0bee60075c00334e2011795049a..fcc16a93482527b364c8ba1da5cb659b35fdfd4e 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -14,6 +14,7 @@ val alsoShade: Configuration by configurations.creating
@@ -26,6 +26,7 @@ abstract class MockitoAgentProvider : CommandLineArgumentProvider {
dependencies {
implementation(project(":luminol-api")) // Folia // Luminol
+ implementation("com.electronwill.night-config:toml:3.6.6") // Luminol - Night config
// Paper start
implementation("org.jline:jline-terminal-jansi:3.21.0")
implementation("net.minecrell:terminalconsoleappender:1.3.0")
implementation("org.jline:jline-terminal-ffm:3.27.1") // use ffm on java 22+
implementation("org.jline:jline-terminal-jni:3.27.1") // fall back to jni on java 21
diff --git a/src/main/java/me/earthme/luminol/commands/LuminolConfigCommand.java b/src/main/java/me/earthme/luminol/commands/LuminolConfigCommand.java
new file mode 100644
index 0000000000000000000000000000000000000000..5c8745dffa80cf47e856d04d283937bda86881f8
@@ -125,17 +125,18 @@ index 0000000000000000000000000000000000000000..fffc5eb4be4b78a886f3c340bd60f3a2
+}
diff --git a/src/main/java/me/earthme/luminol/config/EnumConfigCategory.java b/src/main/java/me/earthme/luminol/config/EnumConfigCategory.java
new file mode 100644
index 0000000000000000000000000000000000000000..ac2a92fe0ddbebb71ea4dd8c96f461d06ec29a4c
index 0000000000000000000000000000000000000000..7b75405c468d24ed8aea5aa54ae5ac339118bf60
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/EnumConfigCategory.java
@@ -0,0 +1,18 @@
@@ -0,0 +1,19 @@
+package me.earthme.luminol.config;
+
+public enum EnumConfigCategory {
+ OPTIMIZATIONS("optimizations"),
+ FIXES("fixes"),
+ MISC("misc"),
+ GAMEPLAY("gameplay");
+ GAMEPLAY("gameplay"),
+ EXPERIMENT("experiment");
+
+ private final String baseKeyName;
+
@@ -191,20 +192,18 @@ index 0000000000000000000000000000000000000000..9f6896711907ac30fe0c00130207b970
+}
diff --git a/src/main/java/me/earthme/luminol/config/LuminolConfig.java b/src/main/java/me/earthme/luminol/config/LuminolConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..2b4e64796bf01b0a5fcb306850cd60837ed4d36b
index 0000000000000000000000000000000000000000..976cc572861174787b37992388a03ab01f8703a4
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/LuminolConfig.java
@@ -0,0 +1,218 @@
@@ -0,0 +1,220 @@
+package me.earthme.luminol.config;
+
+import com.electronwill.nightconfig.core.file.CommentedFileConfig;
+import io.papermc.paper.threadedregions.RegionizedServer;
+import me.earthme.luminol.commands.LuminolConfigCommand;
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.scheduler.MinecraftInternalPlugin;
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Field;
@@ -218,7 +217,6 @@ index 0000000000000000000000000000000000000000..2b4e64796bf01b0a5fcb306850cd6083
+import java.util.concurrent.CompletableFuture;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
@@ -229,7 +227,6 @@ index 0000000000000000000000000000000000000000..2b4e64796bf01b0a5fcb306850cd6083
+ private static final Set<IConfigModule> allInstanced = new HashSet<>();
+ private static CommentedFileConfig configFileInstance;
+ public static boolean alreadyInited = false;
+ private static MinecraftInternalPlugin NULL_PLUGIN = new MinecraftInternalPlugin();
+
+ public static void setupLatch(){
+ Bukkit.getCommandMap().register("luminolconfig","luminol",new LuminolConfigCommand());
@@ -249,7 +246,13 @@ index 0000000000000000000000000000000000000000..2b4e64796bf01b0a5fcb306850cd6083
+
+ @Contract(" -> new")
+ public static @NotNull CompletableFuture<Void> reloadAsync(){
+ return CompletableFuture.runAsync(LuminolConfig::reload,task -> Bukkit.getGlobalRegionScheduler().run(NULL_PLUGIN,scheduled -> task.run()));
+ return CompletableFuture.runAsync(LuminolConfig::reload,task -> RegionizedServer.getInstance().addTask(() -> {
+ try{
+ task.run();
+ }catch (Exception e){
+ logger.error(e);
+ }
+ }));
+ }
+
+ public static void dropAllInstanced(){
@@ -413,16 +416,175 @@ index 0000000000000000000000000000000000000000..2b4e64796bf01b0a5fcb306850cd6083
+ }
+ }
+}
diff --git a/src/main/java/me/earthme/luminol/utils/NullPlugin.java b/src/main/java/me/earthme/luminol/utils/NullPlugin.java
new file mode 100644
index 0000000000000000000000000000000000000000..de94c8e39f0ae0da80d5a79af63413e287f5d190
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/utils/NullPlugin.java
@@ -0,0 +1,152 @@
+package me.earthme.luminol.utils;
+
+import io.papermc.paper.plugin.configuration.PluginMeta;
+import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
+import org.bukkit.Server;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.configuration.file.FileConfiguration;
+import org.bukkit.generator.BiomeProvider;
+import org.bukkit.generator.ChunkGenerator;
+import org.bukkit.plugin.*;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.List;
+import java.util.logging.Logger;
+
+public class NullPlugin extends PluginBase {
+ private boolean enabled = true;
+
+ private final String pluginName;
+ private PluginDescriptionFile pdf;
+
+ public NullPlugin() {
+ this.pluginName = "Minecraft";
+ pdf = new PluginDescriptionFile(pluginName, "1.0", "nms");
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ @Override
+ public File getDataFolder() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public PluginDescriptionFile getDescription() {
+ return pdf;
+ }
+ // Paper start
+ @Override
+ public io.papermc.paper.plugin.configuration.PluginMeta getPluginMeta() {
+ return pdf;
+ }
+ // Paper end
+
+ @Override
+ public FileConfiguration getConfig() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public InputStream getResource(String filename) {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public void saveConfig() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public void saveDefaultConfig() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public void saveResource(String resourcePath, boolean replace) {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public void reloadConfig() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public PluginLogger getLogger() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public PluginLoader getPluginLoader() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public Server getServer() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ @Override
+ public void onDisable() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public void onLoad() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public void onEnable() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public boolean isNaggable() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public void setNaggable(boolean canNag) {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public @Nullable BiomeProvider getDefaultBiomeProvider(@NotNull String worldName, @Nullable String id) {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ // Paper start - lifecycle events
+ @Override
+ public @NotNull io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager<org.bukkit.plugin.Plugin> getLifecycleManager() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+ // Paper end - lifecycle events
+}
\ No newline at end of file
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
index bd333ffb44798069e180cad67c07d86425253024..bbd3b57b83b71ae9840124909f3864c36254f02c 100644
index 78f33298e809a7f6d079d9f2c64e2caa47a1b25a..e3c8deea68ef49bcd07359e243a12afb57cbcf52 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
@@ -222,6 +222,8 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@@ -223,6 +223,8 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
this.paperConfigurations.initializeGlobalConfiguration(this.registryAccess());
this.paperConfigurations.initializeWorldDefaultsConfiguration(this.registryAccess());
// Paper end - initialize global and world-defaults configuration
+ me.earthme.luminol.config.LuminolConfig.loadConfig(); //Luminol - load config file
+ me.earthme.luminol.config.LuminolConfig.setupLatch(); //Luminol - load config file
this.server.spark.enableEarlyIfRequested(); // Paper - spark
// Paper start - fix converting txt to json file; convert old users earlier after PlayerList creation but before file load/save
if (this.convertOldUsers()) {
this.getProfileCache().save(false); // Paper

View File

@@ -47,10 +47,10 @@ index 0000000000000000000000000000000000000000..94e7c8910e3623163528a844fd7a08b3
+ }
+}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 4c9c227c1395744128f347e9303f8a13667a4aa3..45f96e545a1a9883c9925d49f5eb69968313a0e9 100644
index ce51c9e98aabf6d4a2a5c8c4eff80608c0dc9bd3..aa395491cba3f26eefb0e3bb7e51bd4348953f3e 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -2019,7 +2019,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -2121,7 +2121,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@DontObfuscate
public String getServerModName() {

View File

@@ -1,62 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Wed, 7 Feb 2024 00:53:03 +0000
Subject: [PATCH] Add config for unsafe teleportation
diff --git a/src/main/java/me/earthme/luminol/config/modules/fixes/UnsafeTeleportationConfig.java b/src/main/java/me/earthme/luminol/config/modules/fixes/UnsafeTeleportationConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..1b0de6f0ccab72c409a63dc1904829008e30328e
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/fixes/UnsafeTeleportationConfig.java
@@ -0,0 +1,20 @@
+package me.earthme.luminol.config.modules.fixes;
+
+import me.earthme.luminol.config.ConfigInfo;
+import me.earthme.luminol.config.EnumConfigCategory;
+import me.earthme.luminol.config.IConfigModule;
+
+public class UnsafeTeleportationConfig implements IConfigModule {
+ @ConfigInfo(baseName = "enabled", comments = "If you want to use sand duping,please turn on this")
+ public static boolean enabled = false;
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.FIXES;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "allow_unsafe_teleportation";
+ }
+}
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index d8be7c8dca41b6ad6d9a28590be9e33ef9045bdb..bacc97007f09fca97cd2a9d097f93cf78f4d0166 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -4112,6 +4112,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
protected boolean tryEndPortal() {
io.papermc.paper.util.TickThread.ensureTickThread(this, "Cannot portal entity async");
+ if (me.earthme.luminol.config.modules.fixes.UnsafeTeleportationConfig.enabled && !(this instanceof Player)) return false; //Luminol - Unsafe teleportation
BlockPos pos = this.portalBlock;
ServerLevel world = this.portalWorld;
this.portalBlock = null;
diff --git a/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java b/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java
index aeac09f628bd04070fd302842c304a7dfd39b229..dcdb7199ce731b2899ebd847f7c2d66dcd6d62bd 100644
--- a/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java
@@ -61,6 +61,13 @@ public class EndPortalBlock extends BaseEntityBlock {
// return; // CraftBukkit - always fire event in case plugins wish to change it
}
+ //Luminol start - Unsafe teleportation
+ if (me.earthme.luminol.config.modules.fixes.UnsafeTeleportationConfig.enabled && !(entity instanceof net.minecraft.world.entity.player.Player)){
+ entity.endPortalLogicAsync();
+ return;
+ }
+ //Luminol end - Unsafe teleportation
+
// Paper start - move all of this logic into portal tick
entity.portalWorld = ((ServerLevel)world);
entity.portalBlock = pos.immutable();

View File

@@ -1,6 +1,6 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Wed, 7 Feb 2024 00:59:18 +0000
From: MrHua269 <wangxyper@163.com>
Date: Wed, 31 Jul 2024 12:01:17 +0800
Subject: [PATCH] Add config for void trading
@@ -31,15 +31,15 @@ index 0000000000000000000000000000000000000000..22f3c6c70e4287f1bdd0b18f87f57efe
+ }
+}
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index b194f3448b5199e1204da31e1408f2e80803a77d..6b8cbf681203c20eebb214c5c0b0fe0374aa30dc 100644
index cd1af13c91b215d896618fa0f2790da1a53ea80a..ea9f783ccecefc81bfe97ab91bd8dc494860d318 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -3011,7 +3011,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
@@ -2907,7 +2907,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
// Spigot Start
if (entity.getBukkitEntity() instanceof org.bukkit.inventory.InventoryHolder && (!(entity instanceof ServerPlayer) || entity.getRemovalReason() != Entity.RemovalReason.KILLED)) { // SPIGOT-6876: closeInventory clears death message
// Paper start - Fix merchant inventory not closing on entity removal
- if (entity.getBukkitEntity() instanceof org.bukkit.inventory.Merchant merchant && merchant.getTrader() != null) {
+ if (!me.earthme.luminol.config.modules.fixes.VoidTradingFixConfig.enabled && (entity.getBukkitEntity() instanceof org.bukkit.inventory.Merchant merchant && merchant.getTrader() != null)) { //Luminol - Add config for void trading
+ if (!me.earthme.luminol.config.modules.fixes.VoidTradingFixConfig.enabled && (entity.getBukkitEntity() instanceof org.bukkit.inventory.Merchant merchant && merchant.getTrader() != null)) { // Luminol - Add config for void trading
merchant.getTrader().closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.UNLOADED);
}
// Paper end - Fix merchant inventory not closing on entity removal

View File

@@ -0,0 +1,71 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 11:26:36 +0800
Subject: [PATCH] Add config for unsafe teleportation
diff --git a/src/main/java/me/earthme/luminol/config/modules/fixes/UnsafeTeleportationConfig.java b/src/main/java/me/earthme/luminol/config/modules/fixes/UnsafeTeleportationConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..ea374875f529b30db17e8b8cb07b99a600b722dc
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/fixes/UnsafeTeleportationConfig.java
@@ -0,0 +1,20 @@
+package me.earthme.luminol.config.modules.fixes;
+
+import me.earthme.luminol.config.ConfigInfo;
+import me.earthme.luminol.config.EnumConfigCategory;
+import me.earthme.luminol.config.IConfigModule;
+
+public class UnsafeTeleportationConfig implements IConfigModule {
+ @ConfigInfo(baseName = "enabled", comments = "Allow non player entities enter end portals if enabled.If you want to use sand duping,please turn on this")
+ public static boolean enabled = false;
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.FIXES;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "allow_unsafe_teleportation";
+ }
+}
diff --git a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
index 8203bc134888a57056a6cb301beb9ff21983716f..cac7453f83be82671fb21c8712ff190b234a6ae0 100644
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
@@ -69,7 +69,7 @@ public class FallingBlockEntity extends Entity {
public float fallDamagePerDistance;
@Nullable
public CompoundTag blockData;
- public boolean forceTickAfterTeleportToDuplicate;
+ public boolean forceTickAfterTeleportToDuplicate = me.earthme.luminol.config.modules.fixes.UnsafeTeleportationConfig.enabled; // Luminol - Unsafe teleportation
protected static final EntityDataAccessor<BlockPos> DATA_START_POS = SynchedEntityData.defineId(FallingBlockEntity.class, EntityDataSerializers.BLOCK_POS);
public boolean autoExpire = true; // Paper - Expand FallingBlock API
@@ -435,7 +435,7 @@ public class FallingBlockEntity extends Entity {
boolean flag = (resourcekey1 == Level.END || resourcekey == Level.END) && resourcekey1 != resourcekey;
Entity entity = super.teleport(teleportTarget);
- this.forceTickAfterTeleportToDuplicate = entity != null && flag && io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.allowUnsafeEndPortalTeleportation; // Paper
+ this.forceTickAfterTeleportToDuplicate = entity != null && flag && (io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.allowUnsafeEndPortalTeleportation || me.earthme.luminol.config.modules.fixes.UnsafeTeleportationConfig.enabled); // Paper // Luminol - Unsafe teleportation
return entity;
}
}
diff --git a/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java b/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java
index 403cced72fa043a9084afb5bb8fa037ccb511d41..f8e40758e6aed473a06cce18f20e727e44a06436 100644
--- a/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java
@@ -76,7 +76,11 @@ public class EndPortalBlock extends BaseEntityBlock implements Portal {
if (event.isCancelled()) return; // Paper - make cancellable
// CraftBukkit end
// Folia - region threading - do not show credits
-
+ // Luminol start - unsafe teleportation
+ if (me.earthme.luminol.config.modules.fixes.UnsafeTeleportationConfig.enabled && !(entity instanceof net.minecraft.world.entity.player.Player)) {
+ entity.endPortalLogicAsync(pos);
+ }
+ // Luminol end
entity.setAsInsidePortal(this, pos);
}

View File

@@ -1,12 +1,12 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Wed, 7 Feb 2024 02:33:00 +0000
From: MrHua269 <wangxyper@163.com>
Date: Wed, 31 Jul 2024 12:02:01 +0800
Subject: [PATCH] Add config for vanilla random
diff --git a/src/main/java/me/earthme/luminol/config/modules/fixes/VanillaRandomSourceConfig.java b/src/main/java/me/earthme/luminol/config/modules/fixes/VanillaRandomSourceConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..ee247014c9a2ec1bbb7f25ef41da110a270154d6
index 0000000000000000000000000000000000000000..0e6bfc03be660415c333024b56ac6565e3b61ab1
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/fixes/VanillaRandomSourceConfig.java
@@ -0,0 +1,20 @@
@@ -17,7 +17,7 @@ index 0000000000000000000000000000000000000000..ee247014c9a2ec1bbb7f25ef41da110a
+import me.earthme.luminol.config.IConfigModule;
+
+public class VanillaRandomSourceConfig implements IConfigModule {
+ @ConfigInfo(baseName = "enable_for_player_entity")
+ @ConfigInfo(baseName = "enable_for_player_entity",comments = "Related with RNG cracks")
+ public static boolean useLegacyRandomSourceForPlayers = false;
+
+ @Override
@@ -31,10 +31,10 @@ index 0000000000000000000000000000000000000000..ee247014c9a2ec1bbb7f25ef41da110a
+ }
+}
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index bacc97007f09fca97cd2a9d097f93cf78f4d0166..723ae767d7a34643bba5ed616e3943d3d7633312 100644
index 451d4cf162e39acd7ed215f82a5a84f6be6e166a..d98a86e911c6b6bc181d5148e806e2452cb1c6f4 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -569,7 +569,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -590,7 +590,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
this.bb = Entity.INITIAL_AABB;
this.stuckSpeedMultiplier = Vec3.ZERO;
this.nextStep = 1.0F;

View File

@@ -1,6 +1,6 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Wed, 7 Feb 2024 04:39:56 +0000
From: MrHua269 <wangxyper@163.com>
Date: Wed, 31 Jul 2024 12:05:39 +0800
Subject: [PATCH] Add a simple tpsbar
@@ -117,39 +117,38 @@ index 0000000000000000000000000000000000000000..aafb2f5052c7c8e5971a47308253badb
+}
diff --git a/src/main/java/me/earthme/luminol/functions/GlobalServerTpsBar.java b/src/main/java/me/earthme/luminol/functions/GlobalServerTpsBar.java
new file mode 100644
index 0000000000000000000000000000000000000000..3f1478dde900d671c4bfa43df80f629519cd602e
index 0000000000000000000000000000000000000000..026807e0851d67c6d57e81f573ac1bf8fedc6109
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/functions/GlobalServerTpsBar.java
@@ -0,0 +1,225 @@
@@ -0,0 +1,224 @@
+package me.earthme.luminol.functions;
+
+import com.mojang.logging.LogUtils;
+import io.papermc.paper.threadedregions.ThreadedRegionizer;
+import io.papermc.paper.threadedregions.TickData;
+import io.papermc.paper.threadedregions.TickRegions;
+import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
+import me.earthme.luminol.config.modules.misc.TpsBarConfig;
+import me.earthme.luminol.utils.NullPlugin;
+import net.kyori.adventure.bossbar.BossBar;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.minimessage.MiniMessage;
+import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.server.level.ServerPlayer;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
+import org.bukkit.craftbukkit.scheduler.MinecraftInternalPlugin;
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+
+import java.util.*;
+import java.util.concurrent.TimeUnit;
+
+public class GlobalServerTpsBar {
+ protected static final MinecraftInternalPlugin NULL_PLUGIN = new MinecraftInternalPlugin();
+ protected static final NullPlugin NULL_PLUGIN = new NullPlugin();
+ protected static final Map<UUID,BossBar> uuid2Bossbars = new HashMap<>();
+ protected static volatile ScheduledTask tpsbarTask = null;
+ private static final Logger logger = LogManager.getLogger();
+ private static final Logger logger = LogUtils.getLogger();
+
+ public static void init(){
+ cancelBarUpdateTask();
@@ -159,7 +158,7 @@ index 0000000000000000000000000000000000000000..3f1478dde900d671c4bfa43df80f6295
+ try {
+ update();
+ }catch (Exception e){
+ logger.error(e);
+ logger.error(e.getLocalizedMessage());
+ }
+ },1,TpsBarConfig.updateInterval);
+ }
@@ -233,7 +232,7 @@ index 0000000000000000000000000000000000000000..3f1478dde900d671c4bfa43df80f6295
+ private static void updateBarValues(){
+ for (Player apiPlayer : Bukkit.getOnlinePlayers()){
+ final ServerPlayer nmsPlayer = ((CraftPlayer) apiPlayer).getHandle();
+ final ThreadedRegionizer.ThreadedRegion<TickRegions.TickRegionData, TickRegions.TickRegionSectionData> region = ((ServerLevel) nmsPlayer.level()).regioniser.getRegionAtUnsynchronised(nmsPlayer.sectionX,nmsPlayer.sectionZ);
+ final ThreadedRegionizer.ThreadedRegion<TickRegions.TickRegionData, TickRegions.TickRegionSectionData> region = ((ServerLevel) nmsPlayer.level()).regioniser.getRegionAtUnsynchronised(nmsPlayer.moonrise$getSectionX(),nmsPlayer.moonrise$getSectionZ());
+
+ if (region == null){
+ continue;
@@ -347,10 +346,10 @@ index 0000000000000000000000000000000000000000..3f1478dde900d671c4bfa43df80f6295
+ }
+}
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
index bbd3b57b83b71ae9840124909f3864c36254f02c..09bde51d3da062c5788151c15c448eaf2a02ea1b 100644
index e3c8deea68ef49bcd07359e243a12afb57cbcf52..279bc6eede3a1ae77b810f0553efe36adeeefaa4 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
@@ -850,6 +850,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@@ -802,6 +802,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@Override
public void stopServer() {
@@ -359,22 +358,23 @@ index bbd3b57b83b71ae9840124909f3864c36254f02c..09bde51d3da062c5788151c15c448eaf
//Util.shutdownExecutors(); // Paper - moved into super
SkullBlockEntity.clear();
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 95b72e49469554983e07205b0bd462eec6c9fd86..db32beabfa7ba17b1c46d36fa1dc27bc20e06feb 100644
index 68a88928a3aae9d2ea6cd18088ede0a54c31d0d2..8148cbbea2de545e538ce81b51de3919ba11ef59 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -302,6 +302,7 @@ public class ServerPlayer extends Player {
// Paper start - replace player chunk loader
private final java.util.concurrent.atomic.AtomicReference<io.papermc.paper.chunk.system.RegionizedPlayerChunkLoader.ViewDistances> viewDistances = new java.util.concurrent.atomic.AtomicReference<>(new io.papermc.paper.chunk.system.RegionizedPlayerChunkLoader.ViewDistances(-1, -1, -1));
public io.papermc.paper.chunk.system.RegionizedPlayerChunkLoader.PlayerChunkLoaderData chunkLoader;
@@ -329,7 +329,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
public com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper - PlayerNaturallySpawnCreaturesEvent
public @Nullable String clientBrandName = null; // Paper - Brand support
public org.bukkit.event.player.PlayerQuitEvent.QuitReason quitReason = null; // Paper - Add API for quit reason; there are a lot of changes to do if we change all methods leading to the event
-
+ public volatile boolean isTpsBarVisible = false; //Luminol - Tps bar
public io.papermc.paper.chunk.system.RegionizedPlayerChunkLoader.ViewDistances getViewDistances() {
return this.viewDistances.get();
// Paper start - rewrite chunk system
private ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.PlayerChunkLoaderData chunkLoader;
private final ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.ViewDistanceHolder viewDistanceHolder = new ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.ViewDistanceHolder();
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 96201b5b458d8e0cbebf586062fac1ec2d81fdd0..ed4bdf27c38d881fd3896a736652686ff9107f16 100644
index b2ae1de0b18a7b5c684b04e3f81fdf071e013c61..5eb2432cb0a43afee70be081a8e05aaf35de4859 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -2369,6 +2369,9 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@@ -2405,6 +2405,9 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
handle.expToDrop = data.getInt("expToDrop");
handle.keepLevel = data.getBoolean("keepLevel");
}
@@ -384,7 +384,7 @@ index 96201b5b458d8e0cbebf586062fac1ec2d81fdd0..ed4bdf27c38d881fd3896a736652686f
}
}
@@ -2390,6 +2393,9 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@@ -2426,6 +2429,9 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
data.putLong("lastPlayed", System.currentTimeMillis());
data.putString("lastKnownName", handle.getScoreboardName());

View File

@@ -0,0 +1,355 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <wangxyper@163.com>
Date: Wed, 31 Jul 2024 12:18:09 +0800
Subject: [PATCH] Add a simple membar
diff --git a/src/main/java/me/earthme/luminol/commands/MembarCommand.java b/src/main/java/me/earthme/luminol/commands/MembarCommand.java
new file mode 100644
index 0000000000000000000000000000000000000000..a5cbad6b947b1c3e1499bc6d311e17a5eb570c2f
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/commands/MembarCommand.java
@@ -0,0 +1,47 @@
+package me.earthme.luminol.commands;
+
+import me.earthme.luminol.config.modules.misc.MembarConfig;
+import me.earthme.luminol.functions.GlobalServerMemoryBar;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.format.TextColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+
+public class MembarCommand extends Command {
+ public MembarCommand(@NotNull String name) {
+ super(name);
+ this.setPermission("luminol.commands.membar");
+ this.setDescription("Show the memory usage through a bossbar");
+ this.setUsage("/membar");
+ }
+
+ @Override
+ public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
+ if (!testPermission(sender)){
+ return true;
+ }
+
+ if (!MembarConfig.memoryBarEnabled){
+ sender.sendMessage(Component.text("Membar was already disabled!").color(TextColor.color(255,0,0)));
+ return true;
+ }
+
+ if (!(sender instanceof Player player)){
+ sender.sendMessage(Component.text("Only player can use this command!").color(TextColor.color(255,0,0)));
+ return true;
+ }
+
+ if (GlobalServerMemoryBar.isPlayerVisible(player)) {
+ player.sendMessage(Component.text("Disabled mem bar").color(TextColor.color(0,255,0)));
+ GlobalServerMemoryBar.setVisibilityForPlayer(player,false);
+ return true;
+ }
+
+ player.sendMessage(Component.text("Enabled mem bar").color(TextColor.color(0,255,0)));
+ GlobalServerMemoryBar.setVisibilityForPlayer(player,true);
+
+ return true;
+ }
+}
diff --git a/src/main/java/me/earthme/luminol/config/modules/misc/MembarConfig.java b/src/main/java/me/earthme/luminol/config/modules/misc/MembarConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..b632c4a636974535bf001f010de1dcb6b25868c0
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/misc/MembarConfig.java
@@ -0,0 +1,50 @@
+package me.earthme.luminol.config.modules.misc;
+
+import com.electronwill.nightconfig.core.file.CommentedFileConfig;
+import me.earthme.luminol.commands.MembarCommand;
+import me.earthme.luminol.config.ConfigInfo;
+import me.earthme.luminol.config.DoNotLoad;
+import me.earthme.luminol.config.EnumConfigCategory;
+import me.earthme.luminol.config.IConfigModule;
+import me.earthme.luminol.functions.GlobalServerMemoryBar;
+import org.bukkit.Bukkit;
+
+import java.util.List;
+
+public class MembarConfig implements IConfigModule {
+ @ConfigInfo(baseName = "enabled")
+ public static boolean memoryBarEnabled = false;
+ @ConfigInfo(baseName = "format")
+ public static String memBarFormat = "<gray>Memory usage <yellow>:</yellow> <used>MB<yellow>/</yellow><available>MB";
+ @ConfigInfo(baseName = "memory_color_list")
+ public static List<String> memColors = List.of("GREEN","YELLOW","RED","PURPLE");
+ @ConfigInfo(baseName = "update_interval_ticks")
+ public static int updateInterval = 15;
+
+ @DoNotLoad
+ private static boolean inited = false;
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.MISC;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "membar";
+ }
+
+ @Override
+ public void onLoaded(CommentedFileConfig configInstance){
+ if (memoryBarEnabled){
+ GlobalServerMemoryBar.init();
+ }else{
+ GlobalServerMemoryBar.cancelBarUpdateTask();
+ }
+
+ if (!inited){
+ Bukkit.getCommandMap().register("membar","luminol",new MembarCommand("membar"));
+ inited = true;
+ }
+ }
+}
diff --git a/src/main/java/me/earthme/luminol/functions/GlobalServerMemoryBar.java b/src/main/java/me/earthme/luminol/functions/GlobalServerMemoryBar.java
new file mode 100644
index 0000000000000000000000000000000000000000..47809d78392fe0cb30ad68ca1c331784f1843269
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/functions/GlobalServerMemoryBar.java
@@ -0,0 +1,186 @@
+package me.earthme.luminol.functions;
+
+import com.mojang.logging.LogUtils;
+import io.papermc.paper.threadedregions.ThreadedRegionizer;
+import io.papermc.paper.threadedregions.TickRegions;
+import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
+import me.earthme.luminol.config.modules.misc.MembarConfig;
+import me.earthme.luminol.utils.NullPlugin;
+import net.kyori.adventure.bossbar.BossBar;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.minimessage.MiniMessage;
+import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.server.level.ServerPlayer;
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryUsage;
+import java.util.*;
+
+public class GlobalServerMemoryBar {
+ protected static final NullPlugin NULL_PLUGIN = new NullPlugin();
+ protected static final Map<UUID, BossBar> uuid2Bossbars = new HashMap<>();
+ protected static volatile ScheduledTask membarTask = null;
+ private static final Logger logger = LogUtils.getLogger();
+
+ public static void init(){
+ cancelBarUpdateTask();
+
+ Bukkit.getGlobalRegionScheduler().runAtFixedRate(NULL_PLUGIN, c -> {
+ membarTask = c;
+ try {
+ update();
+ }catch (Exception e){
+ logger.error(e.getLocalizedMessage());
+ }
+ },1, MembarConfig.updateInterval);
+ }
+
+ public static void removeAllBars(){
+ for (Map.Entry<UUID,BossBar> barEntry : uuid2Bossbars.entrySet()){
+ final UUID playerUUID = barEntry.getKey();
+ final BossBar memBar = barEntry.getValue();
+
+ final Player targetPlayer = Bukkit.getPlayer(playerUUID);{
+ if (targetPlayer != null){
+ targetPlayer.hideBossBar(memBar);
+ }
+ }
+ }
+
+ uuid2Bossbars.clear();
+ }
+
+ public static void cancelBarUpdateTask(){
+ removeAllBars();
+
+ if (membarTask == null || membarTask.isCancelled()){
+ return;
+ }
+
+ membarTask.cancel();
+ }
+
+ public static boolean isPlayerVisible(Player player){
+ return ((CraftPlayer) player).getHandle().isMemBarVisible;
+ }
+
+ public static void setVisibilityForPlayer(Player target,boolean canSee){
+ ((CraftPlayer) target).getHandle().isMemBarVisible = canSee;
+ }
+
+ private static void update(){
+ updateBarValues();
+ cleanUpPlayers();
+ }
+
+ private static void cleanUpPlayers(){
+ final List<UUID> toRemove = new ArrayList<>();
+
+ for (Map.Entry<UUID,BossBar> bossBarEntry : uuid2Bossbars.entrySet()){
+ final UUID uuid = bossBarEntry.getKey();
+ boolean shouldRemove = true;
+
+ final Player target = Bukkit.getPlayer(uuid);
+ if (target != null){
+ shouldRemove = !isPlayerVisible(target);
+ }
+
+ if (shouldRemove){
+ toRemove.add(uuid);
+ }
+ }
+
+ for (UUID uuid : toRemove){
+ final BossBar removed = uuid2Bossbars.remove(uuid);
+ if (removed != null){
+ final Player targetPlayer = Bukkit.getPlayer(uuid);
+ if (targetPlayer != null){
+ targetPlayer.hideBossBar(removed);
+ }
+ }
+ }
+ }
+
+ private static void updateBarValues(){
+ MemoryUsage heap = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
+
+ long used = heap.getUsed();
+ long xmx = heap.getMax();
+
+
+
+ for (Player apiPlayer : Bukkit.getOnlinePlayers()){
+ final ServerPlayer nmsPlayer = ((CraftPlayer) apiPlayer).getHandle();
+ final ThreadedRegionizer.ThreadedRegion<TickRegions.TickRegionData, TickRegions.TickRegionSectionData> region = ((ServerLevel) nmsPlayer.level()).regioniser.getRegionAtUnsynchronised(nmsPlayer.moonrise$getSectionX(),nmsPlayer.moonrise$getSectionZ());
+
+ if (region == null){
+ continue;
+ }
+
+ BossBar targetBossbar = uuid2Bossbars.get(nmsPlayer.getUUID());
+
+ if (targetBossbar == null && isPlayerVisible(apiPlayer)){
+ targetBossbar = BossBar.bossBar(Component.text(""),0.0F, BossBar.Color.valueOf(MembarConfig.memColors.get(3)), BossBar.Overlay.NOTCHED_20);
+ uuid2Bossbars.put(nmsPlayer.getUUID(),targetBossbar);
+ apiPlayer.showBossBar(targetBossbar);
+ }
+
+ if (targetBossbar != null){
+ updateMembar(targetBossbar,used,xmx);
+ }
+ }
+ }
+
+ private static void updateMembar(@NotNull BossBar bar, long used, long xmx){
+ double percent = Math.max(Math.min((float) used / xmx, 1.0F), 0.0F);
+ bar.name(MiniMessage.miniMessage().deserialize(
+ MembarConfig.memBarFormat,
+ Placeholder.component("used", getMemoryComponent(used,xmx)),
+ Placeholder.component("available",getMaxMemComponent(xmx))
+ ));
+ bar.color(barColorFromMemory(percent));
+ bar.progress((float) percent);
+ }
+
+ private static @NotNull Component getMaxMemComponent(double max){
+ final BossBar.Color colorBukkit = BossBar.Color.GREEN;
+ final String colorString = colorBukkit.name();
+
+ final String content = "<%s><text></%s>";
+ final String replaced = String.format(content,colorString,colorString);
+
+ return MiniMessage.miniMessage().deserialize(replaced,Placeholder.parsed("text", String.format("%.2f", (double)max / (1024 * 1024))));
+ }
+
+ private static @NotNull Component getMemoryComponent(long used,long max){
+ final BossBar.Color colorBukkit = barColorFromMemory(Math.max(Math.min((float) used / max, 1.0F), 0.0F));
+ final String colorString = colorBukkit.name();
+
+ final String content = "<%s><text></%s>";
+ final String replaced = String.format(content,colorString,colorString);
+
+ return MiniMessage.miniMessage().deserialize(replaced,Placeholder.parsed("text", String.format("%.2f", (double)used / (1024 * 1024))));
+ }
+
+ private static BossBar.Color barColorFromMemory(double memPercent){
+ if (memPercent == -1){
+ return BossBar.Color.valueOf(MembarConfig.memColors.get(3));
+ }
+
+ if (memPercent <= 50){
+ return BossBar.Color.valueOf(MembarConfig.memColors.getFirst());
+ }
+
+ if (memPercent <= 70){
+ return BossBar.Color.valueOf(MembarConfig.memColors.get(1));
+ }
+
+ return BossBar.Color.valueOf(MembarConfig.memColors.get(2));
+ }
+}
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
index 279bc6eede3a1ae77b810f0553efe36adeeefaa4..4ff5105d32c41a8ea145e7833ea6a3cee0108031 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
@@ -803,6 +803,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@Override
public void stopServer() {
me.earthme.luminol.functions.GlobalServerTpsBar.cancelBarUpdateTask(); //Luminol - Tpsbar
+ me.earthme.luminol.functions.GlobalServerMemoryBar.cancelBarUpdateTask(); //Luminol - Memory bar
super.stopServer();
//Util.shutdownExecutors(); // Paper - moved into super
SkullBlockEntity.clear();
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 8148cbbea2de545e538ce81b51de3919ba11ef59..3f4518b29c9f0c4ad9561bde2ffded8404608cae 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -330,6 +330,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
public @Nullable String clientBrandName = null; // Paper - Brand support
public org.bukkit.event.player.PlayerQuitEvent.QuitReason quitReason = null; // Paper - Add API for quit reason; there are a lot of changes to do if we change all methods leading to the event
public volatile boolean isTpsBarVisible = false; //Luminol - Tps bar
+ public volatile boolean isMemBarVisible = false; //Luminol - Memory bar
// Paper start - rewrite chunk system
private ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.PlayerChunkLoaderData chunkLoader;
private final ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.ViewDistanceHolder viewDistanceHolder = new ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.ViewDistanceHolder();
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 5eb2432cb0a43afee70be081a8e05aaf35de4859..566c404acfced53414f3d0facd22d03b71841587 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -2408,6 +2408,9 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
//Luminol start - Tpsbar
getHandle().isTpsBarVisible = data.getBoolean("tpsbarVisible");
//Luminol end
+ //Luminol start - Membar
+ getHandle().isMemBarVisible = data.getBoolean("membarVisible");
+ //Luminol end
}
}
@@ -2432,6 +2435,9 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
//Luminol start - Tpsbar
data.putBoolean("tpsbarVisible",handle.isTpsBarVisible);
//Luminol end
+ //Luminol start - Membar
+ data.putBoolean("membarVisible", handle.isMemBarVisible);
+ //Luminol end
// Paper start - persist for use in offline save data
if (!nbttagcompound.contains("Paper")) {
nbttagcompound.put("Paper", new CompoundTag());

View File

@@ -1,46 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Wed, 7 Feb 2024 04:50:10 +0000
Subject: [PATCH] Add config for username check
diff --git a/src/main/java/me/earthme/luminol/config/modules/misc/UsernameCheckConfig.java b/src/main/java/me/earthme/luminol/config/modules/misc/UsernameCheckConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..c7e4724cc4ab8d911bcaf0106c098b266c843bb1
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/misc/UsernameCheckConfig.java
@@ -0,0 +1,20 @@
+package me.earthme.luminol.config.modules.misc;
+
+import me.earthme.luminol.config.ConfigInfo;
+import me.earthme.luminol.config.EnumConfigCategory;
+import me.earthme.luminol.config.IConfigModule;
+
+public class UsernameCheckConfig implements IConfigModule {
+ @ConfigInfo(baseName = "enabled")
+ public static boolean enabled = true;
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.MISC;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "username_checks";
+ }
+}
diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
index 83b09feec13a00c35e6f8d4f0ccdae1c8da9c0e5..d946a08f7a7532079eab83a7d4affc89e6e6ac1e 100644
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
@@ -171,7 +171,8 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
public void handleHello(ServerboundHelloPacket packet) {
Validate.validState(this.state == ServerLoginPacketListenerImpl.State.HELLO, "Unexpected hello packet", new Object[0]);
// Paper start - Validate usernames
- if (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode()
+ if (me.earthme.luminol.config.modules.misc.UsernameCheckConfig.enabled //Luminol - Add config for username check
+ && io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode()
&& io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.performUsernameValidation
&& !this.iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation) {
Validate.validState(StringUtil.isReasonablePlayerName(packet.name()), "Invalid characters in username", new Object[0]);

View File

@@ -0,0 +1,68 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Wed, 7 Feb 2024 04:50:10 +0000
Subject: [PATCH] Add config for username check
diff --git a/src/main/java/me/earthme/luminol/config/modules/misc/UsernameCheckConfig.java b/src/main/java/me/earthme/luminol/config/modules/misc/UsernameCheckConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..c7e4724cc4ab8d911bcaf0106c098b266c843bb1
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/misc/UsernameCheckConfig.java
@@ -0,0 +1,20 @@
+package me.earthme.luminol.config.modules.misc;
+
+import me.earthme.luminol.config.ConfigInfo;
+import me.earthme.luminol.config.EnumConfigCategory;
+import me.earthme.luminol.config.IConfigModule;
+
+public class UsernameCheckConfig implements IConfigModule {
+ @ConfigInfo(baseName = "enabled")
+ public static boolean enabled = true;
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.MISC;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "username_checks";
+ }
+}
diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
index 227d62a69a453d49c28568ecb41ecef85a35405b..d1f70437eb43dd536e7b3dac7a770525eff55318 100644
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
@@ -178,7 +178,8 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
public void handleHello(ServerboundHelloPacket packet) {
Validate.validState(this.state == ServerLoginPacketListenerImpl.State.HELLO, "Unexpected hello packet", new Object[0]);
// Paper start - Validate usernames
- if (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode()
+ if (me.earthme.luminol.config.modules.misc.UsernameCheckConfig.enabled //Luminol - Add config for username check
+ && io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode()
&& io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.performUsernameValidation
&& !this.iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation) {
Validate.validState(StringUtil.isReasonablePlayerName(packet.name()), "Invalid characters in username", new Object[0]);
diff --git a/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java b/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java
index f58dec12326734c61f4bc2298a87fb38f1ac1dc4..249ecfb1b1830befa43ba172c65527b077bb8f4e 100644
--- a/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java
+++ b/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java
@@ -42,7 +42,7 @@ public final class CraftPlayerProfile implements PlayerProfile, com.destroystoky
Preconditions.checkArgument(isValidSkullProfile, "The skull profile is missing a name or textures!");
// Paper start - Validate
Preconditions.checkArgument(gameProfile.getName().length() <= 16, "The name of the profile is longer than 16 characters");
- Preconditions.checkArgument(net.minecraft.util.StringUtil.isValidPlayerName(gameProfile.getName()), "The name of the profile contains invalid characters: %s", gameProfile.getName());
+ Preconditions.checkArgument(!me.earthme.luminol.config.modules.misc.UsernameCheckConfig.enabled || net.minecraft.util.StringUtil.isValidPlayerName(gameProfile.getName()), "The name of the profile contains invalid characters: %s", gameProfile.getName()); // Luminol - Add config for username checks
final PropertyMap properties = gameProfile.getProperties();
Preconditions.checkArgument(properties.size() <= 16, "The profile contains more than 16 properties");
for (final Property property : properties.values()) {
@@ -79,7 +79,7 @@ public final class CraftPlayerProfile implements PlayerProfile, com.destroystoky
Preconditions.checkArgument((uniqueId != null) || !StringUtils.isBlank(name), "uniqueId is null or name is blank");
}
Preconditions.checkArgument(name == null || name.length() <= 16, "The name of the profile is longer than 16 characters"); // Paper - Validate
- Preconditions.checkArgument(name == null || net.minecraft.util.StringUtil.isValidPlayerName(name), "The name of the profile contains invalid characters: %s", name); // Paper - Validate
+ Preconditions.checkArgument(!me.earthme.luminol.config.modules.misc.UsernameCheckConfig.enabled || name == null || net.minecraft.util.StringUtil.isValidPlayerName(name), "The name of the profile contains invalid characters: %s", name); // Paper - Validate // Luminol - Add config for username checks
this.uniqueId = uniqueId;
this.name = name;
}

View File

@@ -31,15 +31,15 @@ index 0000000000000000000000000000000000000000..502b93c7bda9e8577a1901a8777b7cf9
+ }
+}
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
index 09bde51d3da062c5788151c15c448eaf2a02ea1b..6f86f25efbd4e6e79476c1563dc8f4c114c10695 100644
index 4ff5105d32c41a8ea145e7833ea6a3cee0108031..295504dab771c8bb8c668545fe5d62eae0561b76 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
@@ -294,7 +294,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@@ -297,7 +297,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
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 (!this.usesAuthentication() && !me.earthme.luminol.config.modules.misc.OfflineModeWarningConfig.enabled) { //Luminol - Add config for offline mod warning
+ if (!this.usesAuthentication() && me.earthme.luminol.config.modules.misc.OfflineModeWarningConfig.enabled) { //Luminol - Add config for offline mod warning
DedicatedServer.LOGGER.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!");
DedicatedServer.LOGGER.warn("The server will make no attempt to authenticate usernames. Beware.");
// Spigot start

View File

@@ -1,258 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Sun, 10 Mar 2024 05:04:33 +0000
Subject: [PATCH] Add a simple watchdog for tick regions
diff --git a/src/main/java/io/papermc/paper/threadedregions/RegionizedServer.java b/src/main/java/io/papermc/paper/threadedregions/RegionizedServer.java
index fc3d332aa1c1d469cedfe2aaa7102dcd78e25642..1ae61bc6603dd3ac290e3ead20416f9c5b63ff02 100644
--- a/src/main/java/io/papermc/paper/threadedregions/RegionizedServer.java
+++ b/src/main/java/io/papermc/paper/threadedregions/RegionizedServer.java
@@ -279,6 +279,7 @@ public final class RegionizedServer {
*/
private void globalTick(final int tickCount) {
+ me.earthme.luminol.utils.LuminolWatchDog.globalRegionHeartBeat(); //Luminol
/*
if (false) {
io.papermc.paper.threadedregions.ThreadedTicketLevelPropagator.main(null);
diff --git a/src/main/java/io/papermc/paper/threadedregions/ThreadedRegionizer.java b/src/main/java/io/papermc/paper/threadedregions/ThreadedRegionizer.java
index 531aa50f2c84e13358e8918bb0c15ea3cd036cb5..fd0053369eb68f0fd596d8acfba4a5247ef8105a 100644
--- a/src/main/java/io/papermc/paper/threadedregions/ThreadedRegionizer.java
+++ b/src/main/java/io/papermc/paper/threadedregions/ThreadedRegionizer.java
@@ -167,6 +167,8 @@ public final class ThreadedRegionizer<R extends ThreadedRegionizer.ThreadedRegio
if (removed != region) {
throw new IllegalStateException("Expected to remove " + region + ", but removed " + removed);
}
+
+ me.earthme.luminol.utils.LuminolWatchDog.onRegionDeath(region); //Luminol - Simple watchdog
}
public int getSectionCoordinate(final int chunkCoordinate) {
diff --git a/src/main/java/io/papermc/paper/threadedregions/TickRegions.java b/src/main/java/io/papermc/paper/threadedregions/TickRegions.java
index 2ad25dd345ab42125d456f2b9cf67d8c4515c8b7..78c50292fb25e8703e9c91db892f05456f07d72f 100644
--- a/src/main/java/io/papermc/paper/threadedregions/TickRegions.java
+++ b/src/main/java/io/papermc/paper/threadedregions/TickRegions.java
@@ -402,6 +402,7 @@ public final class TickRegions implements ThreadedRegionizer.RegionCallbacks<Tic
@Override
protected void tickRegion(final int tickCount, final long startTime, final long scheduledEnd) {
+ me.earthme.luminol.utils.LuminolWatchDog.tickRegionHeartBeat(); //Luminol - Simple watchdog
final ca.spottedleaf.leafprofiler.RegionizedProfiler.Handle profiler = io.papermc.paper.threadedregions.TickRegionScheduler.getProfiler(); // Folia - profiler
profiler.startTick(); try { // Folia - profiler
MinecraftServer.getServer().tickServer(startTime, scheduledEnd, TimeUnit.MILLISECONDS.toMillis(10L), this.region);
diff --git a/src/main/java/me/earthme/luminol/config/modules/misc/WatchdogConfig.java b/src/main/java/me/earthme/luminol/config/modules/misc/WatchdogConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..71d80b401470db777a86274d32f178bb2aa023d5
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/misc/WatchdogConfig.java
@@ -0,0 +1,27 @@
+package me.earthme.luminol.config.modules.misc;
+
+import me.earthme.luminol.config.ConfigInfo;
+import me.earthme.luminol.config.EnumConfigCategory;
+import me.earthme.luminol.config.HotReloadUnsupported;
+import me.earthme.luminol.config.IConfigModule;
+
+public class WatchdogConfig implements IConfigModule {
+
+ @HotReloadUnsupported
+ @ConfigInfo(baseName = "enabled")
+ public static boolean enabled = false;
+ @ConfigInfo(baseName = "warn_period_ticks")
+ public static long warnPeriodTicks = 5 * 20;
+ @ConfigInfo(baseName = "timeout_ticks")
+ public static long timeOutTicks = 30 * 20;
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.MISC;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "watchdog";
+ }
+}
diff --git a/src/main/java/me/earthme/luminol/utils/LuminolWatchDog.java b/src/main/java/me/earthme/luminol/utils/LuminolWatchDog.java
new file mode 100644
index 0000000000000000000000000000000000000000..8901c50863032f4ae189fe47d44f9fe91f884a6c
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/utils/LuminolWatchDog.java
@@ -0,0 +1,162 @@
+package me.earthme.luminol.utils;
+
+import com.google.common.collect.Maps;
+import io.papermc.paper.threadedregions.ThreadedRegionizer;
+import io.papermc.paper.threadedregions.TickRegionScheduler;
+import io.papermc.paper.util.StacktraceDeobfuscator;
+import me.earthme.luminol.config.modules.misc.WatchdogConfig;
+import net.minecraft.server.MinecraftServer;
+import org.apache.commons.lang3.tuple.Pair;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.slf4j.Logger;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadInfo;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+public class LuminolWatchDog {
+ private static final Object keepaliveDataLock = new Object();
+ private static Pair<Thread,Long> globalRegionLastKeepalive = null;
+ private static final Map<Thread,Pair<ThreadedRegionizer.ThreadedRegion<?,?>,Long>> otherTickRegionKeepalive = Maps.newHashMap();
+ private static final Executor checkTimer = CompletableFuture.delayedExecutor(50, TimeUnit.MILLISECONDS,Executors.newSingleThreadExecutor());
+ private static final Logger logger = MinecraftServer.LOGGER;
+ private static int tickCount = 0;
+ private static boolean runScheduleNext = true;
+
+ public static void boot(){
+ runCheck();
+ }
+
+ private static void scheduleCheck(){
+ checkTimer.execute(LuminolWatchDog::runCheck);
+ }
+
+ private static void runCheck(){
+ try {
+ if (MinecraftServer.getServer().isStopped() || !runScheduleNext){
+ return;
+ }
+
+ tickCount++;
+
+ final List<Pair<Thread,Long>> threadsToWarn = new ArrayList<>();
+ final long currentTimeNano = System.nanoTime();
+ boolean shouldStopServer = false;
+
+ synchronized (keepaliveDataLock){
+ if (globalRegionLastKeepalive != null){
+ final Thread lastGlobalRegionThread = globalRegionLastKeepalive.getLeft();
+ final long lastTicked = globalRegionLastKeepalive.getRight();
+
+ final long timeEscaped = currentTimeNano - lastTicked;
+
+ if (timeEscaped >= WatchdogConfig.warnPeriodTicks * 50 * 1000 * 1000){
+ threadsToWarn.add(Pair.of(lastGlobalRegionThread,timeEscaped));
+ }
+ }
+
+ for(Pair<Thread,Long> warnInfo : threadsToWarn){
+ final Thread targetThread = warnInfo.getLeft();
+ final long timeEscaped = warnInfo.getRight();
+
+ final ThreadedRegionizer.ThreadedRegion<?,?> targetRegion;
+
+ synchronized (keepaliveDataLock){
+ targetRegion = otherTickRegionKeepalive.get(targetThread).getLeft();
+ }
+
+ if (tickCount % WatchdogConfig.warnPeriodTicks == 0){
+ dumpSingleRegion(targetThread,targetRegion,timeEscaped);
+ }
+
+ if (timeEscaped > WatchdogConfig.timeOutTicks * 50 * 1000 * 1000){
+ shouldStopServer = true;
+ runScheduleNext = false;
+ }
+ }
+
+ if (shouldStopServer){
+ MinecraftServer.getServer().stopServer();
+ }
+ }
+ }finally {
+ if (runScheduleNext){
+ scheduleCheck();
+ }
+ }
+ }
+
+ private static void dumpSingleRegion(@NotNull Thread thread, @Nullable ThreadedRegionizer.ThreadedRegion<?,?> region,long timeEscaped){
+ final StringBuilder messageBuilder = new StringBuilder();
+ messageBuilder.append("====================================").append("\n");
+ messageBuilder.append("There is a single region that has no responding in " + TimeUnit.NANOSECONDS.toSeconds(timeEscaped) + " seconds!").append("\n");
+ messageBuilder.append("If you believe this is a bug,please send it to github issue after checking your plugins!").append("\n");
+ messageBuilder.append("Tick Region: ").append(region == null ? "Global Region" : "ChunkX(Center): " + region.getCenterChunk().x + " ChunkZ(Center): " + region.getCenterChunk().z).append("\n");
+ messageBuilder.append("Thread Name: ").append(thread.getName()).append("\n");
+ messageBuilder.append("Thread Id: ").append(thread.getId()).append("\n");
+
+ final ThreadInfo targetThreadInfo = ManagementFactory.getThreadMXBean().getThreadInfo(thread.getId());
+
+ messageBuilder.append("Is Suspend: ").append(targetThreadInfo.isSuspended()).append("\n");
+ messageBuilder.append("Thread State: ").append(targetThreadInfo.getThreadState()).append("\n");
+ messageBuilder.append("Thread Priority: ").append(targetThreadInfo.getPriority()).append("\n");
+ messageBuilder.append("Thread Stack Trace:").append("\n");
+
+ for (StackTraceElement stackTraceElement : StacktraceDeobfuscator.INSTANCE.deobfuscateStacktrace(thread.getStackTrace())){
+ messageBuilder.append("\t\t").append(stackTraceElement).append("\n");
+ }
+
+ messageBuilder.append("\n");
+ messageBuilder.append("====================================");
+
+ logger.error(messageBuilder.toString());
+ }
+
+ public static void globalRegionHeartBeat(){
+ if (!WatchdogConfig.enabled){
+ return;
+ }
+
+ synchronized (keepaliveDataLock){
+ globalRegionLastKeepalive = Pair.of(Thread.currentThread(),System.nanoTime());
+ }
+ }
+
+ public static void tickRegionHeartBeat(){
+ if (!WatchdogConfig.enabled){
+ return;
+ }
+
+ final ThreadedRegionizer.ThreadedRegion<?,?> currentRegion = TickRegionScheduler.getCurrentRegion();
+
+ if (currentRegion == null) {
+ return;
+ }
+
+ synchronized (keepaliveDataLock){
+ if (!otherTickRegionKeepalive.containsKey(Thread.currentThread())){
+ otherTickRegionKeepalive.put(Thread.currentThread(),Pair.of(currentRegion,System.nanoTime()));
+ return;
+ }
+
+ otherTickRegionKeepalive.replace(Thread.currentThread(),Pair.of(currentRegion,System.nanoTime()));
+ }
+ }
+
+ public static void onRegionDeath(ThreadedRegionizer.ThreadedRegion<?,?> currentRegion){
+ if (!WatchdogConfig.enabled){
+ return;
+ }
+
+ synchronized (keepaliveDataLock){
+ otherTickRegionKeepalive.remove(Thread.currentThread());
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 45f96e545a1a9883c9925d49f5eb69968313a0e9..97016c309d0a0fc13d733269f7dfb81ca0d8c574 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1226,6 +1226,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.statusIcon = (ServerStatus.Favicon) this.loadStatusIcon().orElse(null); // CraftBukkit - decompile error
this.status = this.buildServerStatus();
+ me.earthme.luminol.utils.LuminolWatchDog.boot(); //Luminol - Simple watchdog
+
// Folia start - region threading
if (true) {
io.papermc.paper.threadedregions.RegionizedServer.getInstance().init(); // Folia - region threading - only after loading worlds

View File

@@ -0,0 +1,62 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Stabrinai <wujiaxin752@outlook.com>
Date: Sun, 30 Jun 2024 20:46:42 +0800
Subject: [PATCH] Add config to verify signature only in online-mode
diff --git a/src/main/java/me/earthme/luminol/config/modules/misc/PublickeyVerifyConfig.java b/src/main/java/me/earthme/luminol/config/modules/misc/PublickeyVerifyConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..e45ce3abf49684c911678abcefd69586246cc0e3
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/misc/PublickeyVerifyConfig.java
@@ -0,0 +1,21 @@
+package me.earthme.luminol.config.modules.misc;
+
+import me.earthme.luminol.config.ConfigInfo;
+import me.earthme.luminol.config.EnumConfigCategory;
+import me.earthme.luminol.config.IConfigModule;
+
+public class PublickeyVerifyConfig implements IConfigModule {
+
+ @ConfigInfo(baseName = "enabled")
+ public static boolean enabled = false;
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.MISC;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "verify_publickey_only_in_online_mode";
+ }
+}
diff --git a/src/main/java/net/minecraft/world/entity/player/ProfilePublicKey.java b/src/main/java/net/minecraft/world/entity/player/ProfilePublicKey.java
index 2fa51c3a70f43cd23b8f494fc643d66cecfda7d2..2c541f300ea1657e2d75d0eeb36809aaf437b205 100644
--- a/src/main/java/net/minecraft/world/entity/player/ProfilePublicKey.java
+++ b/src/main/java/net/minecraft/world/entity/player/ProfilePublicKey.java
@@ -9,12 +9,15 @@ import java.time.Duration;
import java.time.Instant;
import java.util.Arrays;
import java.util.UUID;
+
+import me.earthme.luminol.config.modules.misc.PublickeyVerifyConfig;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ThrowingComponent;
import net.minecraft.util.Crypt;
import net.minecraft.util.ExtraCodecs;
import net.minecraft.util.SignatureValidator;
+import org.bukkit.Bukkit;
public record ProfilePublicKey(ProfilePublicKey.Data data) {
public static final Component EXPIRED_PROFILE_PUBLIC_KEY = Component.translatable("multiplayer.disconnect.expired_public_key");
@@ -23,7 +26,7 @@ public record ProfilePublicKey(ProfilePublicKey.Data data) {
public static final Codec<ProfilePublicKey> TRUSTED_CODEC = ProfilePublicKey.Data.CODEC.xmap(ProfilePublicKey::new, ProfilePublicKey::data);
public static ProfilePublicKey createValidated(SignatureValidator servicesSignatureVerifier, UUID playerUuid, ProfilePublicKey.Data publicKeyData) throws ProfilePublicKey.ValidationException {
- if (!publicKeyData.validateSignature(servicesSignatureVerifier, playerUuid)) {
+ if ((!PublickeyVerifyConfig.enabled || Bukkit.getServer().getOnlineMode()) && !publicKeyData.validateSignature(servicesSignatureVerifier, playerUuid)) { // Luminol - Verify signature only in online-mode
throw new ProfilePublicKey.ValidationException(INVALID_SIGNATURE, org.bukkit.event.player.PlayerKickEvent.Cause.INVALID_PUBLIC_KEY_SIGNATURE); // Paper - kick event causes
} else {
return new ProfilePublicKey(publicKeyData);

View File

@@ -1,48 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Wed, 7 Feb 2024 06:30:03 +0000
Subject: [PATCH] Try fixing folia spector teleportation
diff --git a/src/main/java/me/earthme/luminol/config/modules/fixes/FoliaSpectorTeleportationFixConfig.java b/src/main/java/me/earthme/luminol/config/modules/fixes/FoliaSpectorTeleportationFixConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..8487799cdfb776eaca33b57f7c99ae3aeadb890d
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/fixes/FoliaSpectorTeleportationFixConfig.java
@@ -0,0 +1,20 @@
+package me.earthme.luminol.config.modules.fixes;
+
+import me.earthme.luminol.config.ConfigInfo;
+import me.earthme.luminol.config.EnumConfigCategory;
+import me.earthme.luminol.config.IConfigModule;
+
+public class FoliaSpectorTeleportationFixConfig implements IConfigModule {
+ @ConfigInfo(baseName = "enabled")
+ public static boolean fixSpectorTeleportFolia = false;
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.FIXES;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "folia.fix_spector_teleportation";
+ }
+}
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 11b5155820d38a42e62f68fe0f70fe4daf80f5d1..90f4cc0bd3722400411e6b1aa2d03205a350ee8a 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -892,6 +892,11 @@ public class ServerPlayer extends Player {
}
Entity entity = this.getCamera();
+ //Luminol start - Fix folia spector teleportation
+ if (!io.papermc.paper.util.TickThread.isTickThreadFor(entity) && me.earthme.luminol.config.modules.fixes.FoliaSpectorTeleportationFixConfig.fixSpectorTeleportFolia){
+ this.setCamera(this);
+ }
+ //Luminol end
if (entity != this) {
if (entity.isAlive()) {

View File

@@ -0,0 +1,45 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <wangxyper@163.com>
Date: Wed, 7 Aug 2024 14:27:24 +0800
Subject: [PATCH] Add config to disable entity tick catchers
diff --git a/src/main/java/me/earthme/luminol/config/modules/experiment/DisableEntityCatchConfig.java b/src/main/java/me/earthme/luminol/config/modules/experiment/DisableEntityCatchConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..0fd71151a85dd87c2294033e2e7512ac365caa62
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/experiment/DisableEntityCatchConfig.java
@@ -0,0 +1,20 @@
+package me.earthme.luminol.config.modules.experiment;
+
+import me.earthme.luminol.config.ConfigInfo;
+import me.earthme.luminol.config.EnumConfigCategory;
+import me.earthme.luminol.config.IConfigModule;
+
+public class DisableEntityCatchConfig implements IConfigModule {
+ @ConfigInfo(baseName = "enabled")
+ public static boolean enabled = false;
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.EXPERIMENT;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "disable_entity_exception_catchers";
+ }
+}
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index 3d96f7ae648b47cc7494578d9776e7ea6dee0964..6161137e2249d592e2b6c7e0b94b7163b55788c7 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -1537,7 +1537,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
try {
tickConsumer.accept(entity);
} catch (Throwable throwable) {
- if (throwable instanceof ThreadDeath) throw throwable; // Paper
+ if (throwable instanceof ThreadDeath || me.earthme.luminol.config.modules.experiment.DisableEntityCatchConfig.enabled) throw throwable; // Paper // Luminol
// Paper start - Prevent block entity and entity crashes
final String msg = String.format("Entity threw exception at %s:%s,%s,%s", entity.level().getWorld().getName(), entity.getX(), entity.getY(), entity.getZ());
MinecraftServer.LOGGER.error(msg, throwable);

View File

@@ -0,0 +1,106 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <wangxyper@163.com>
Date: Wed, 7 Aug 2024 14:34:15 +0800
Subject: [PATCH] Add config to disable async catchers
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/util/TickThread.java b/src/main/java/ca/spottedleaf/moonrise/common/util/TickThread.java
index 7d626bec6f0a4497026de6c0311e27cf95cfd757..2760e66046a37327d279a5bcdfb56a5b073b82a5 100644
--- a/src/main/java/ca/spottedleaf/moonrise/common/util/TickThread.java
+++ b/src/main/java/ca/spottedleaf/moonrise/common/util/TickThread.java
@@ -26,49 +26,49 @@ public class TickThread extends Thread {
*/
@Deprecated
public static void ensureTickThread(final String reason) {
- if (!isTickThread()) {
+ if (!isTickThread() && !me.earthme.luminol.config.modules.experiment.DisableAsyncCatcherConfig.enabled) { // Luminol
LOGGER.error("Thread " + Thread.currentThread().getName() + " failed main thread check: " + reason, new Throwable());
throw new IllegalStateException(reason);
}
}
public static void ensureTickThread(final Level world, final BlockPos pos, final String reason) {
- if (!isTickThreadFor(world, pos)) {
+ if (!isTickThreadFor(world, pos) && !me.earthme.luminol.config.modules.experiment.DisableAsyncCatcherConfig.enabled) { // Luminol
LOGGER.error("Thread " + Thread.currentThread().getName() + " failed main thread check: " + reason, new Throwable());
throw new IllegalStateException(reason);
}
}
public static void ensureTickThread(final Level world, final ChunkPos pos, final String reason) {
- if (!isTickThreadFor(world, pos)) {
+ if (!isTickThreadFor(world, pos) && !me.earthme.luminol.config.modules.experiment.DisableAsyncCatcherConfig.enabled) { // Luminol
LOGGER.error("Thread " + Thread.currentThread().getName() + " failed main thread check: " + reason, new Throwable());
throw new IllegalStateException(reason);
}
}
public static void ensureTickThread(final Level world, final int chunkX, final int chunkZ, final String reason) {
- if (!isTickThreadFor(world, chunkX, chunkZ)) {
+ if (!isTickThreadFor(world, chunkX, chunkZ) && !me.earthme.luminol.config.modules.experiment.DisableAsyncCatcherConfig.enabled) { // Luminol
LOGGER.error("Thread " + Thread.currentThread().getName() + " failed main thread check: " + reason, new Throwable());
throw new IllegalStateException(reason);
}
}
public static void ensureTickThread(final Entity entity, final String reason) {
- if (!isTickThreadFor(entity)) {
+ if (!isTickThreadFor(entity) && !me.earthme.luminol.config.modules.experiment.DisableAsyncCatcherConfig.enabled) { // Luminol
LOGGER.error("Thread " + Thread.currentThread().getName() + " failed main thread check: " + reason, new Throwable());
throw new IllegalStateException(reason);
}
}
public static void ensureTickThread(final Level world, final AABB aabb, final String reason) {
- if (!isTickThreadFor(world, aabb)) {
+ if (!isTickThreadFor(world, aabb) && !me.earthme.luminol.config.modules.experiment.DisableAsyncCatcherConfig.enabled) { // Luminol
LOGGER.error("Thread " + Thread.currentThread().getName() + " failed main thread check: " + reason, new Throwable());
throw new IllegalStateException(reason);
}
}
public static void ensureTickThread(final Level world, final double blockX, final double blockZ, final String reason) {
- if (!isTickThreadFor(world, blockX, blockZ)) {
+ if (!isTickThreadFor(world, blockX, blockZ) && !me.earthme.luminol.config.modules.experiment.DisableAsyncCatcherConfig.enabled) { // Luminol
LOGGER.error("Thread " + Thread.currentThread().getName() + " failed main thread check: " + reason, new Throwable());
throw new IllegalStateException(reason);
}
diff --git a/src/main/java/me/earthme/luminol/config/modules/experiment/DisableAsyncCatcherConfig.java b/src/main/java/me/earthme/luminol/config/modules/experiment/DisableAsyncCatcherConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..61f653eeca366672ded88c491cf5c59e546e7301
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/experiment/DisableAsyncCatcherConfig.java
@@ -0,0 +1,20 @@
+package me.earthme.luminol.config.modules.experiment;
+
+import me.earthme.luminol.config.ConfigInfo;
+import me.earthme.luminol.config.EnumConfigCategory;
+import me.earthme.luminol.config.IConfigModule;
+
+public class DisableAsyncCatcherConfig implements IConfigModule {
+ @ConfigInfo(baseName = "enabled")
+ public static boolean enabled = false;
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.EXPERIMENT;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "disable_async_catchers";
+ }
+}
diff --git a/src/main/java/org/spigotmc/AsyncCatcher.java b/src/main/java/org/spigotmc/AsyncCatcher.java
index 1f23e775eba1c34e01145bd91b0ce26fed6ca9de..3e0dbf379fc1b5baa27936cb902b3c54f9b0f4c9 100644
--- a/src/main/java/org/spigotmc/AsyncCatcher.java
+++ b/src/main/java/org/spigotmc/AsyncCatcher.java
@@ -9,7 +9,7 @@ public class AsyncCatcher
public static void catchOp(String reason)
{
- if (!ca.spottedleaf.moonrise.common.util.TickThread.isTickThread()) // Paper // Paper - rewrite chunk system
+ if (!ca.spottedleaf.moonrise.common.util.TickThread.isTickThread() && !me.earthme.luminol.config.modules.experiment.DisableAsyncCatcherConfig.enabled) // Paper // Paper - rewrite chunk system // Luminol
{
MinecraftServer.LOGGER.error("Thread " + Thread.currentThread().getName() + " failed main thread check: " + reason, new Throwable()); // Paper
throw new IllegalStateException( "Asynchronous " + reason + "!" );

View File

@@ -1,149 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Wed, 7 Feb 2024 06:58:52 +0000
Subject: [PATCH] Prevent teleportAsync calling during moving event being
diff --git a/src/main/java/me/earthme/luminol/config/modules/fixes/FoliaTeleportAsyncFixConfig.java b/src/main/java/me/earthme/luminol/config/modules/fixes/FoliaTeleportAsyncFixConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..b8aceab54bb60000e7c56810140271022f5147a2
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/fixes/FoliaTeleportAsyncFixConfig.java
@@ -0,0 +1,22 @@
+package me.earthme.luminol.config.modules.fixes;
+
+import me.earthme.luminol.config.ConfigInfo;
+import me.earthme.luminol.config.EnumConfigCategory;
+import me.earthme.luminol.config.IConfigModule;
+
+public class FoliaTeleportAsyncFixConfig implements IConfigModule {
+ @ConfigInfo(baseName = "enabled")
+ public static boolean enabled = false;
+ @ConfigInfo(baseName = "throw_on_detected")
+ public static boolean throwOnDetected = true;
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.FIXES;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "folia.prevent_teleportasync_call_during_moving";
+ }
+}
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 90f4cc0bd3722400411e6b1aa2d03205a350ee8a..f87c7a77b8d5748c08488470bf60ea84ab95a819 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -347,6 +347,10 @@ public class ServerPlayer extends Player {
public double lastEntitySpawnRadiusSquared = -1.0;
// Paper end - optimise chunk tick iteration
+ //Luminol start - Prevent teleportAsync calling during moving event being handled
+ public boolean handlingMoveEvent = false;
+ //Luminol end
+
public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile, ClientInformation clientOptions) {
super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile);
this.chatVisibility = ChatVisiblity.FULL;
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 2c65527fa7bc2fce769e15f35a45ebae381c6bac..c13e3da32415607b3f0f88b6c34630a28af75128 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -695,7 +695,9 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
Location oldTo = to.clone();
PlayerMoveEvent event = new PlayerMoveEvent(player, from, to);
+ this.player.handlingMoveEvent = true; //Luminol - Prevent teleportAsync calling during moving event being handled
this.cserver.getPluginManager().callEvent(event);
+ this.player.handlingMoveEvent = false; //Luminol - Prevent teleportAsync calling during moving event being handled
// If the event is cancelled we move the player back to their old location.
if (event.isCancelled()) {
@@ -1612,7 +1614,9 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
Location oldTo = to.clone();
PlayerMoveEvent event = new PlayerMoveEvent(player, from, to);
+ this.player.handlingMoveEvent = true; //Luminol - Prevent teleportAsync calling during moving event being handled
this.cserver.getPluginManager().callEvent(event);
+ this.player.handlingMoveEvent = false; //Luminol - Prevent teleportAsync calling during moving event being handled
// If the event is cancelled we move the player back to their old location.
if (event.isCancelled()) {
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index f39e8291d2d8b15201835b8c018776ef6eda8d24..7112c529a652b6ab6a418b3a44fc1f075061cc74 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -4033,6 +4033,18 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
java.util.function.Consumer<Entity> teleportComplete) {
io.papermc.paper.util.TickThread.ensureTickThread(this, "Cannot teleport entity async");
+ //Luminol start - Prevent teleportAsync calling during moving event being handled
+ if (this instanceof ServerPlayer player && me.earthme.luminol.config.modules.fixes.FoliaTeleportAsyncFixConfig.enabled){
+ if (player.handlingMoveEvent){
+ if (me.earthme.luminol.config.modules.fixes.FoliaTeleportAsyncFixConfig.throwOnDetected){
+ throw new IllegalStateException("Player " + player.getScoreboardName() + " is trying to teleport to " + pos + " during move event handling!");
+ }
+ MinecraftServer.LOGGER.warn("Player {} is trying to teleport to {} during move event handling!",player.getScoreboardName(),pos);
+ return false;
+ }
+ }
+ //Luminol end
+
if (!ServerLevel.isInSpawnableBounds(new BlockPos(io.papermc.paper.util.CoordinateUtils.getBlockX(pos), io.papermc.paper.util.CoordinateUtils.getBlockY(pos), io.papermc.paper.util.CoordinateUtils.getBlockZ(pos)))) {
return false;
}
diff --git a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java
index 4d7454e5a64fc18e63793a221daa94617f17c666..a1dc46ec6d53389eb7c801a7a14c4169406de580 100644
--- a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java
+++ b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java
@@ -375,7 +375,21 @@ public abstract class AbstractMinecart extends VehicleEntity {
this.level().getCraftServer().getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleUpdateEvent(vehicle));
if (!from.equals(to)) {
+ //Luminol start - Prevent teleportAsync calling during moving event being handled
+ for (Entity passenger : this.getPassengers()) {
+ if (passenger instanceof net.minecraft.server.level.ServerPlayer player){
+ player.handlingMoveEvent = true;
+ }
+ }
+ //Luminol end
this.level().getCraftServer().getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleMoveEvent(vehicle, from, to));
+ //Luminol start - Prevent teleportAsync calling during moving event being handled
+ for (Entity passenger : this.getPassengers()) {
+ if (passenger instanceof net.minecraft.server.level.ServerPlayer player){
+ player.handlingMoveEvent = false;
+ }
+ }
+ //Luminol end
}
// CraftBukkit end
if (this.getMinecartType() == AbstractMinecart.Type.RIDEABLE && this.getDeltaMovement().horizontalDistanceSqr() > 0.01D) {
diff --git a/src/main/java/net/minecraft/world/entity/vehicle/Boat.java b/src/main/java/net/minecraft/world/entity/vehicle/Boat.java
index b068cff9b5aa457d65b679529956e8210296d799..d002519a356072284faa5f879e188f3e3062939f 100644
--- a/src/main/java/net/minecraft/world/entity/vehicle/Boat.java
+++ b/src/main/java/net/minecraft/world/entity/vehicle/Boat.java
@@ -370,8 +370,22 @@ public class Boat extends VehicleEntity implements VariantHolder<Boat.Type> {
server.getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleUpdateEvent(vehicle));
if (this.lastLocation != null && !this.lastLocation.equals(to)) {
+ //Luminol start - Prevent teleportAsync calling during moving event being handled
+ for (Entity passenger : this.getPassengers()) {
+ if (passenger instanceof net.minecraft.server.level.ServerPlayer player){
+ player.handlingMoveEvent = true;
+ }
+ }
+ //Luminol end
VehicleMoveEvent event = new VehicleMoveEvent(vehicle, this.lastLocation, to);
server.getPluginManager().callEvent(event);
+ //Luminol start - Prevent teleportAsync calling during moving event being handled
+ for (Entity passenger : this.getPassengers()) {
+ if (passenger instanceof net.minecraft.server.level.ServerPlayer player){
+ player.handlingMoveEvent = false;
+ }
+ }
+ //Luminol end
}
this.lastLocation = vehicle.getLocation();
// CraftBukkit end

View File

@@ -0,0 +1,45 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <wangxyper@163.com>
Date: Sat, 31 Aug 2024 10:56:58 +0800
Subject: [PATCH] Add experiment config for command block command execution
diff --git a/src/main/java/me/earthme/luminol/config/modules/experiment/CommandBlockConfig.java b/src/main/java/me/earthme/luminol/config/modules/experiment/CommandBlockConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..3eafc59cc015569d3da8b1d8c4bfd046af17e0be
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/experiment/CommandBlockConfig.java
@@ -0,0 +1,20 @@
+package me.earthme.luminol.config.modules.experiment;
+
+import me.earthme.luminol.config.ConfigInfo;
+import me.earthme.luminol.config.EnumConfigCategory;
+import me.earthme.luminol.config.IConfigModule;
+
+public class CommandBlockConfig implements IConfigModule {
+ @ConfigInfo(baseName = "enable")
+ public static boolean enabled = false;
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.EXPERIMENT;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "force_enable_command_block_execution";
+ }
+}
diff --git a/src/main/java/net/minecraft/world/level/BaseCommandBlock.java b/src/main/java/net/minecraft/world/level/BaseCommandBlock.java
index b8a571fcc44f67ac8f6089e039a8620bf6c40603..c973535eba031f102c6cae8f9b75547ba3a95376 100644
--- a/src/main/java/net/minecraft/world/level/BaseCommandBlock.java
+++ b/src/main/java/net/minecraft/world/level/BaseCommandBlock.java
@@ -117,7 +117,7 @@ public abstract class BaseCommandBlock implements CommandSource {
}
public boolean performCommand(Level world) {
- if (true) return false; // Folia - region threading
+ if (!me.earthme.luminol.config.modules.experiment.CommandBlockConfig.enabled) return false; // Folia - region threading // Luminol
if (!world.isClientSide && world.getGameTime() != this.lastExecution) {
if ("Searge".equalsIgnoreCase(this.command)) {
this.lastOutput = Component.literal("#itzlipofutzli");

View File

@@ -1,50 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: M2ke4U <79621885+MrHua269@users.noreply.github.com>
Date: Sun, 26 Nov 2023 20:25:38 +0800
Subject: [PATCH] Kaiiju Vanilla end portal teleportation
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 7112c529a652b6ab6a418b3a44fc1f075061cc74..643631e11c88285f33d050bf7b4b1e2f63b5c992 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -4240,12 +4240,17 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
targetPos, 16, // load 16 blocks to be safe from block physics
ca.spottedleaf.concurrentutil.executor.standard.PrioritisedExecutor.Priority.HIGH,
(chunks) -> {
- ServerLevel.makeObsidianPlatform(destination, null, targetPos);
+ //ServerLevel.makeObsidianPlatform(destination, null, targetPos); // Kaiiju - Vanilla end teleportation - moved down
+ // Kaiiju start - Vanilla end teleportation
+ Vec3 finalPos;
+ if (this instanceof Player) finalPos = Vec3.atBottomCenterOf(targetPos.below());
+ else finalPos = Vec3.atBottomCenterOf(targetPos);
+ // Kaiiju end
// the portal obsidian is placed at targetPos.y - 2, so if we want to place the entity
// on the obsidian, we need to spawn at targetPos.y - 1
portalInfoCompletable.complete(
- new PortalInfo(Vec3.atBottomCenterOf(targetPos.below()), Vec3.ZERO, 90.0f, 0.0f, destination, null)
+ new PortalInfo(finalPos, this.getDeltaMovement(), 90.0f, 0.0f, destination, null) // Kaiiju - Vanilla end teleportation
);
}
);
@@ -4432,6 +4437,10 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
if (!this.canPortalAsync(takePassengers)) {
return false;
}
+ // Kaiiju start - sync end platform spawning & entity teleportation
+ final java.util.function.Consumer<Entity> tpComplete = type == PortalType.END && destination.getTypeKey() == LevelStem.END ?
+ e -> ServerLevel.makeObsidianPlatform(destination, null, ServerLevel.END_SPAWN_POINT) : teleportComplete;
+ // Kaiiju end
Vec3 initialPosition = this.position();
ChunkPos initialPositionChunk = new ChunkPos(
@@ -4490,7 +4499,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
// place
passengerTree.root.placeInAsync(
originWorld, destination, Entity.TELEPORT_FLAG_LOAD_CHUNK | (takePassengers ? Entity.TELEPORT_FLAG_TELEPORT_PASSENGERS : 0L),
- passengerTree, teleportComplete
+ passengerTree, tpComplete // Kaiiju - vanilla end teleportation
);
});

View File

@@ -0,0 +1,67 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Wed, 7 Feb 2024 06:30:03 +0000
Subject: [PATCH] Try fixing folia spector teleportation
diff --git a/src/main/java/me/earthme/luminol/config/modules/fixes/FoliaSpectorTeleportationFixConfig.java b/src/main/java/me/earthme/luminol/config/modules/fixes/FoliaSpectorTeleportationFixConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..01f8c6ff3662569be5a4ff998bcd4fbbcb555105
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/fixes/FoliaSpectorTeleportationFixConfig.java
@@ -0,0 +1,25 @@
+package me.earthme.luminol.config.modules.fixes;
+
+import me.earthme.luminol.config.ConfigInfo;
+import me.earthme.luminol.config.EnumConfigCategory;
+import me.earthme.luminol.config.IConfigModule;
+
+public class FoliaSpectorTeleportationFixConfig implements IConfigModule {
+ @ConfigInfo(baseName = "enabled", comments =
+ """
+ The teleportation of spector players would call absMoveTo directly.\s
+ And when the camera teleported to another region,this would call absMoveTo\s
+ to let the spector player move to another region without any checks, which \s
+ would trigger the async catcher and crash the server""")
+ public static boolean fixSpectorTeleportFolia = false;
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.FIXES;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "folia.fix_spector_teleportation";
+ }
+}
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 5358a0d5a4d4b1ab1c3b300ed04061bc9dc1ff37..61726ff1fecb1e153a95328c37787dd2070ff0c4 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -1165,9 +1165,24 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
}
Entity entity = this.getCamera();
+ //Luminol start - Fix folia spector teleportation
+ if (!ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(entity) && me.earthme.luminol.config.modules.fixes.FoliaSpectorTeleportationFixConfig.fixSpectorTeleportFolia){
+ this.setCamera(this);
+ }
+ //Luminol end
if (entity != this) {
- if (entity.isAlive()) {
+ // Luminol start - Fix folia spector teleportation
+ var flag = false;
+ var cameraPos = entity.blockPosition();
+ var cameraLevel = entity.level();
+ if (!ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(cameraLevel, cameraPos) && me.earthme.luminol.config.modules.fixes.FoliaSpectorTeleportationFixConfig.fixSpectorTeleportFolia){
+ this.setCamera(this);
+ flag = true;
+ }
+ // Luminol end
+
+ if (entity.isAlive() && !flag) { // Luminol - Fix folia spector teleportation
this.absMoveTo(entity.getX(), entity.getY(), entity.getZ(), entity.getYRot(), entity.getXRot());
this.serverLevel().getChunkSource().move(this);
if (this.wantsToStopRiding()) {

View File

@@ -1,15 +1,15 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Wed, 7 Feb 2024 06:34:15 +0000
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 11:36:43 +0800
Subject: [PATCH] Teleport async if entity was moving to another region at once
diff --git a/src/main/java/me/earthme/luminol/config/modules/fixes/FoliaEntityMovingFixConfig.java b/src/main/java/me/earthme/luminol/config/modules/fixes/FoliaEntityMovingFixConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..73d99a105a18231901e691922b0c283adae0cc79
index 0000000000000000000000000000000000000000..0e51d465db3554ac80d00c6b85cc1f013f3949ba
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/fixes/FoliaEntityMovingFixConfig.java
@@ -0,0 +1,22 @@
@@ -0,0 +1,28 @@
+package me.earthme.luminol.config.modules.fixes;
+
+import me.earthme.luminol.config.ConfigInfo;
@@ -17,7 +17,13 @@ index 0000000000000000000000000000000000000000..73d99a105a18231901e691922b0c283a
+import me.earthme.luminol.config.IConfigModule;
+
+public class FoliaEntityMovingFixConfig implements IConfigModule {
+ @ConfigInfo(baseName = "enabled")
+ @ConfigInfo(baseName = "enabled", comments =
+ """
+ A simple fix of a issue on folia\s
+ (Some times the entity would\s
+ have a large moment that cross the\s
+ different tick regions and it would\s
+ make the server crashed) but sometimes it might doesn't work""")
+ public static boolean enabled = false;
+ @ConfigInfo(baseName = "warn_on_detected")
+ public static boolean warnOnDetected = true;
@@ -33,10 +39,10 @@ index 0000000000000000000000000000000000000000..73d99a105a18231901e691922b0c283a
+ }
+}
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 723ae767d7a34643bba5ed616e3943d3d7633312..f39e8291d2d8b15201835b8c018776ef6eda8d24 100644
index d98a86e911c6b6bc181d5148e806e2452cb1c6f4..403585b38a2d8bc1e25fa8e3e4014470a65461b9 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -1128,10 +1128,40 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -1173,6 +1173,10 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
// Paper end - detailed watchdog information
@@ -44,18 +50,21 @@ index 723ae767d7a34643bba5ed616e3943d3d7633312..f39e8291d2d8b15201835b8c018776ef
+ private volatile boolean preventMoving = false;
+ //Luminol end
+
public void move(MoverType movementType, Vec3 movement) {
public void move(MoverType type, Vec3 movement) {
final Vec3 originalMovement = movement; // Paper - Expose pre-collision velocity
// Paper start - detailed watchdog information
io.papermc.paper.util.TickThread.ensureTickThread("Cannot move an entity off-main");
@@ -1183,6 +1187,32 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
this.moveStartZ = this.getZ();
this.moveVector = movement;
}
+ //Luminol start - Fix high position moving
+ if (me.earthme.luminol.config.modules.fixes.FoliaEntityMovingFixConfig.enabled && io.papermc.paper.util.TickThread.isTickThread()){ //Except the threads because it may be called by the chunk system worker thread
+ if (this.preventMoving){
+ if (me.earthme.luminol.config.modules.fixes.FoliaEntityMovingFixConfig.enabled && ca.spottedleaf.moonrise.common.util.TickThread.isTickThread()){ //Except the threads because it may be called by the chunk system worker thread
+ var finalPosition = movement.add(this.position);
+ if (this.preventMoving || Double.isNaN(finalPosition.x) || Double.isNaN(finalPosition.y) || Double.isNaN(finalPosition.z)){
+ return;
+ }
+
+ var finalPosition = movement.add(this.position);
+ if (!io.papermc.paper.util.TickThread.isTickThreadFor(((ServerLevel) this.level),finalPosition)){
+ if (!ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(((ServerLevel) this.level),finalPosition)){
+ this.preventMoving = true;
+ this.teleportAsync(
+ (ServerLevel) this.level(),
@@ -74,6 +83,6 @@ index 723ae767d7a34643bba5ed616e3943d3d7633312..f39e8291d2d8b15201835b8c018776ef
+ }
+ }
+ //Luminol end
synchronized (this.posLock) {
this.moveStartX = this.getX();
this.moveStartY = this.getY();
try {
// Paper end - detailed watchdog information
if (this.noPhysics) {

View File

@@ -1,19 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: M2ke4U <79621885+MrHua269@users.noreply.github.com>
Date: Sun, 26 Nov 2023 15:59:49 +0800
Subject: [PATCH] Pufferfish Optimize entity coordinate key
diff --git a/src/main/java/io/papermc/paper/util/MCUtil.java b/src/main/java/io/papermc/paper/util/MCUtil.java
index 08d282400644be5949f28eb879b333cc221da2cc..49ccb27a17bec1d4ff31bc8d72e4724d65adc20c 100644
--- a/src/main/java/io/papermc/paper/util/MCUtil.java
+++ b/src/main/java/io/papermc/paper/util/MCUtil.java
@@ -215,7 +215,7 @@ public final class MCUtil {
}
public static long getCoordinateKey(final Entity entity) {
- return ((long)(MCUtil.fastFloor(entity.getZ()) >> 4) << 32) | ((MCUtil.fastFloor(entity.getX()) >> 4) & 0xFFFFFFFFL);
+ return ((long)(entity.blockPosition.getZ() >> 4) << 32) | ((entity.blockPosition.getX() >> 4) & 0xFFFFFFFFL); // Pufferfish - eliminate double->long cast in hotpath
}
public static long getCoordinateKey(final ChunkPos pair) {

View File

@@ -0,0 +1,89 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Mon, 10 Jun 2024 10:51:08 +0000
Subject: [PATCH] Try fixing folia off region POI accessing issue
diff --git a/src/main/java/me/earthme/luminol/config/modules/fixes/FoliaPOIAccessOffRegionFixConfig.java b/src/main/java/me/earthme/luminol/config/modules/fixes/FoliaPOIAccessOffRegionFixConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..7812a71f05dd32646037afd22cdabf72bb23b0d1
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/fixes/FoliaPOIAccessOffRegionFixConfig.java
@@ -0,0 +1,25 @@
+package me.earthme.luminol.config.modules.fixes;
+
+import me.earthme.luminol.config.ConfigInfo;
+import me.earthme.luminol.config.EnumConfigCategory;
+import me.earthme.luminol.config.IConfigModule;
+
+public class FoliaPOIAccessOffRegionFixConfig implements IConfigModule {
+ @ConfigInfo(baseName = "enabled", comments =
+ """
+ The POIManager of folia has something which has not been patched\s
+ for regionized ticking and these would trigger the async catcher\s
+ and make the server crash.If you would like to prevent it and didn't\s
+ mind the side effect(currently unknown), you can enable this""")
+ public static boolean enabled = false;
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.FIXES;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "folia.fix_poi_access_off_region";
+ }
+}
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/GoToPotentialJobSite.java b/src/main/java/net/minecraft/world/entity/ai/behavior/GoToPotentialJobSite.java
index aac1df9e2c0652bc6348af0404deba7465f82d42..ad812fd30d21ee3b7727105c66f2fc495a44f6ca 100644
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/GoToPotentialJobSite.java
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/GoToPotentialJobSite.java
@@ -49,10 +49,17 @@ public class GoToPotentialJobSite extends Behavior<Villager> {
ServerLevel serverLevel2 = serverLevel.getServer().getLevel(pos.dimension());
if (serverLevel2 != null) {
PoiManager poiManager = serverLevel2.getPoiManager();
+ //Luminol start - Fix off region POI accessing
+ java.lang.Runnable scheduledRelease = () -> {
if (poiManager.exists(blockPos, poiType -> true)) {
poiManager.release(blockPos);
}
-
+ };
+ if (!ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(serverLevel2, blockPos) && me.earthme.luminol.config.modules.fixes.FoliaPOIAccessOffRegionFixConfig.enabled)
+ io.papermc.paper.threadedregions.RegionizedServer.getInstance().taskQueue.queueTickTaskQueue(serverLevel2, blockPos.getX() >> 4, blockPos.getZ() >> 4, scheduledRelease);
+ else
+ scheduledRelease.run();
+ //Luminol end
DebugPackets.sendPoiTicketCountPacket(serverLevel, blockPos);
}
});
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/YieldJobSite.java b/src/main/java/net/minecraft/world/entity/ai/behavior/YieldJobSite.java
index d1a9b62d3304916275dd6b4c4e783cf1563b5e21..7d90e57b59ca1be1cc64ff6b53c64ea1f1767ad0 100644
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/YieldJobSite.java
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/YieldJobSite.java
@@ -33,7 +33,10 @@ public class YieldJobSite {
} else if (entity.getVillagerData().getProfession() != VillagerProfession.NONE) {
return false;
} else {
- BlockPos blockPos = context.<GlobalPos>get(potentialJobSite).pos();
+ final GlobalPos globalPos = context.<GlobalPos>get(potentialJobSite); //Luminol - Try fixing off main POI accessing
+ final net.minecraft.server.level.ServerLevel targetLevel = net.minecraft.server.MinecraftServer.getServer().getLevel(globalPos.dimension()); //Luminol - Try fixing off main POI accessing
+ BlockPos blockPos = globalPos.pos(); //Luminol - Try fixing off main POI accessing
+ if (!ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(targetLevel, blockPos) && me.earthme.luminol.config.modules.fixes.FoliaPOIAccessOffRegionFixConfig.enabled) return true; //Luminol - Try fixing off main POI accessing
Optional<Holder<PoiType>> optional = world.getPoiManager().getType(blockPos);
if (optional.isEmpty()) {
return true;
diff --git a/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.java b/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.java
index f3f98e6276dda3bc4f290fc2d80569f7e1e7ef66..edc127c94a54aed42120a5b4cc7036b5ddc8c656 100644
--- a/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.java
+++ b/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.java
@@ -212,7 +212,7 @@ public class PoiManager extends SectionStorage<PoiSection, PoiSection.Packed> im
public Stream<PoiRecord> getInSquare(Predicate<Holder<PoiType>> typePredicate, BlockPos pos, int radius, PoiManager.Occupancy occupationStatus) {
int i = Math.floorDiv(radius, 16) + 1;
- return ChunkPos.rangeClosed(new ChunkPos(pos), i).flatMap(chunkPos -> this.getInChunk(typePredicate, chunkPos, occupationStatus)).filter(poi -> {
+ return ChunkPos.rangeClosed(new ChunkPos(pos), i).filter(cpos -> me.earthme.luminol.config.modules.fixes.FoliaPOIAccessOffRegionFixConfig.enabled ? ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(this.world,cpos) : true).flatMap(chunkPos -> this.getInChunk(typePredicate, chunkPos, occupationStatus)).filter(poi -> { //Luminol - Fix off region POI access
BlockPos blockPos2 = poi.getPos();
return Math.abs(blockPos2.getX() - pos.getX()) <= radius && Math.abs(blockPos2.getZ() - pos.getZ()) <= radius;
});

View File

@@ -0,0 +1,151 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 11:41:53 +0800
Subject: [PATCH] Force disable builtin spark plugin
diff --git a/src/main/java/io/papermc/paper/plugin/provider/source/FileProviderSource.java b/src/main/java/io/papermc/paper/plugin/provider/source/FileProviderSource.java
index 48604e7f96adc9e226e034054c5e2bad0b024eb5..99f0c1e4d3437154a1062b0a8f94b7a04dd935af 100644
--- a/src/main/java/io/papermc/paper/plugin/provider/source/FileProviderSource.java
+++ b/src/main/java/io/papermc/paper/plugin/provider/source/FileProviderSource.java
@@ -88,7 +88,7 @@ public class FileProviderSource implements ProviderSource<Path, Path> {
}
final PluginMeta config = type.getConfig(file);
- if ((config.getName().equals("spark") && config.getMainClass().equals("me.lucko.spark.bukkit.BukkitSparkPlugin")) && !SparksFly.isPluginPreferred()) {
+ if ((config.getName().equals("spark") && config.getMainClass().equals("me.lucko.spark.bukkit.BukkitSparkPlugin")) && !SparksFly.isPluginPreferred() && false) { // Luminol - Force disable builtin spark
LOGGER.info("The spark plugin will not be loaded as this server bundles the spark profiler.");
return;
}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index aa395491cba3f26eefb0e3bb7e51bd4348953f3e..420b0f22bb58cab43ff4b707bd40823ab2cad9bd 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -808,8 +808,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// Paper end - Configurable player collision
this.server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.POSTWORLD);
- this.server.spark.registerCommandBeforePlugins(this.server); // Paper - spark
- this.server.spark.enableAfterPlugins(this.server); // Paper - spark
+ if (false) this.server.spark.registerCommandBeforePlugins(this.server); // Paper - spark // Luminol - Force disable builtin spark
+ if (false) this.server.spark.enableAfterPlugins(this.server); // Paper - spark // Luminol - Force disable builtin spark
if (io.papermc.paper.plugin.PluginInitializerManager.instance().pluginRemapper != null) io.papermc.paper.plugin.PluginInitializerManager.instance().pluginRemapper.pluginsEnabled(); // Paper - Remap plugins
io.papermc.paper.command.brigadier.PaperCommands.INSTANCE.setValid(); // Paper - reset invalid state for event fire below
io.papermc.paper.plugin.lifecycle.event.LifecycleEventRunner.INSTANCE.callReloadableRegistrarEvent(io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents.COMMANDS, io.papermc.paper.command.brigadier.PaperCommands.INSTANCE, org.bukkit.plugin.Plugin.class, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL); // Paper - call commands event for regular plugins
@@ -1125,7 +1125,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
Commands.COMMAND_SENDING_POOL.shutdownNow(); // Paper - Perf: Async command map building; Shutdown and don't bother finishing
// CraftBukkit start
if (this.server != null) {
- this.server.spark.disable(); // Paper - spark
+ if (false) this.server.spark.disable(); // Paper - spark // Luminol - Force disable builtin spark
this.server.disablePlugins();
this.server.waitForAsyncTasksShutdown(); // Paper - Wait for Async Tasks during shutdown
}
@@ -1345,7 +1345,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// tasks are default scheduled at -1 + delay, and first tick will tick at 1
final long actualDoneTimeMs = System.currentTimeMillis() - org.bukkit.craftbukkit.Main.BOOT_TIME.toEpochMilli(); // Paper - Add total time
LOGGER.info("Done ({})! For help, type \"help\"", String.format(java.util.Locale.ROOT, "%.3fs", actualDoneTimeMs / 1000.00D)); // Paper - Add total time
- this.server.spark.enableBeforePlugins(); // Paper - spark
+ if (false) this.server.spark.enableBeforePlugins(); // Paper - spark // Luminol - Force disable builtin spark
org.spigotmc.WatchdogThread.tick();
// Paper end - Improved Watchdog Support
org.spigotmc.WatchdogThread.hasStarted = true; // Paper
@@ -1728,7 +1728,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
if (this.emptyTicks >= j) {
- this.server.spark.tickStart(); // Paper - spark
+ if (false)this.server.spark.tickStart(); // Paper - spark // Luminol - Force disable builtin spark
if (this.emptyTicks == j) {
MinecraftServer.LOGGER.info("Server empty for {} seconds, pausing", this.pauseWhileEmptySeconds());
this.autoSave();
@@ -1747,7 +1747,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// Paper end - avoid issues with certain tasks not processing during sleep
// Folia - region threading
this.tickConnection();
- this.server.spark.tickEnd(((double)(System.nanoTime() - lastTick) / 1000000D)); // Paper - spark
+ if (false) this.server.spark.tickEnd(((double)(System.nanoTime() - lastTick) / 1000000D)); // Paper - spark // Luminol - Force disable builtin spark
+ // Paper end - Server Tick Events
return;
}
}
@@ -1772,7 +1773,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
};
// Folia end - region threading
- this.server.spark.tickStart(); // Paper - spark
+ if (false) this.server.spark.tickStart(); // Paper - spark // Luminol - Force disable builtin spark
new com.destroystokyo.paper.event.server.ServerTickStartEvent((int)region.getCurrentTick()).callEvent(); // Paper - Server Tick Events // Folia - region threading
// Folia start - region threading
if (region != null) {
@@ -1843,7 +1844,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
long remaining = scheduledEnd - endTime; // Folia - region ticking
new com.destroystokyo.paper.event.server.ServerTickEndEvent((int)io.papermc.paper.threadedregions.RegionizedServer.getCurrentTick(), ((double)(endTime - startTime) / 1000000D), remaining).callEvent(); // Folia - region ticking
// Paper end - Server Tick Events
- this.server.spark.tickEnd(((double)(endTime - startTime) / 1000000D)); // Paper - spark // Folia - region ticking
+ if (false) this.server.spark.tickEnd(((double)(endTime - startTime) / 1000000D)); // Paper - spark // Folia - region ticking // Luminol - Force disable builtin spark
gameprofilerfiller.push("tallying");
// Folia - region threading
gameprofilerfiller.pop();
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
index 295504dab771c8bb8c668545fe5d62eae0561b76..49b4ef6457743b5f955bff70694378d4975e44a7 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
@@ -225,7 +225,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
// Paper end - initialize global and world-defaults configuration
me.earthme.luminol.config.LuminolConfig.loadConfig(); //Luminol - load config file
me.earthme.luminol.config.LuminolConfig.setupLatch(); //Luminol - load config file
- this.server.spark.enableEarlyIfRequested(); // Paper - spark
+ if (false) this.server.spark.enableEarlyIfRequested(); // Paper - spark // Luminol - Force disable builtin spark
// Paper start - fix converting txt to json file; convert old users earlier after PlayerList creation but before file load/save
if (this.convertOldUsers()) {
this.getProfileCache().save(false); // Paper
@@ -235,7 +235,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
org.spigotmc.WatchdogThread.doStart(org.spigotmc.SpigotConfig.timeoutTime, org.spigotmc.SpigotConfig.restartOnCrash); // Paper - start watchdog thread
thread.start(); // Paper - Enhance console tab completions for brigadier commands; start console thread after MinecraftServer.console & PaperConfig are initialized
io.papermc.paper.command.PaperCommands.registerCommands(this); // Paper - setup /paper command
- this.server.spark.registerCommandBeforePlugins(this.server); // Paper - spark
+ if (false) this.server.spark.registerCommandBeforePlugins(this.server); // Paper - spark // Luminol - Force disable builtin spark
com.destroystokyo.paper.Metrics.PaperMetrics.startMetrics(); // Paper - start metrics
com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // Paper - load version history now
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index a8975cee866cf2c617b6d4976df71e5c20cf0e3d..ac180d082b05f2a5fa557b49e3d34e81e4957766 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -312,7 +312,7 @@ public final class CraftServer implements Server {
public static Exception excessiveVelEx; // Paper - Velocity warnings
private final io.papermc.paper.logging.SysoutCatcher sysoutCatcher = new io.papermc.paper.logging.SysoutCatcher(); // Paper
private final io.papermc.paper.potion.PaperPotionBrewer potionBrewer; // Paper - Custom Potion Mixes
- public final io.papermc.paper.SparksFly spark; // Paper - spark
+ public io.papermc.paper.SparksFly spark; // Paper - spark // Luminol - Force disable builtin spark
// Paper start - Folia region threading API
private final io.papermc.paper.threadedregions.scheduler.FoliaRegionScheduler regionizedScheduler = new io.papermc.paper.threadedregions.scheduler.FoliaRegionScheduler(); // Folia - region threading
@@ -490,7 +490,7 @@ public final class CraftServer implements Server {
}
this.potionBrewer = new io.papermc.paper.potion.PaperPotionBrewer(console); // Paper - custom potion mixes
datapackManager = new io.papermc.paper.datapack.PaperDatapackManager(console.getPackRepository()); // Paper
- this.spark = new io.papermc.paper.SparksFly(this); // Paper - spark
+ if (false) this.spark = new io.papermc.paper.SparksFly(this); // Paper - spark // Luminol - Force disable builtin spark
}
public boolean getCommandBlockOverride(String command) {
@@ -1154,7 +1154,7 @@ public final class CraftServer implements Server {
this.reloadData();
org.spigotmc.SpigotConfig.registerCommands(); // Spigot
io.papermc.paper.command.PaperCommands.registerCommands(this.console); // Paper
- this.spark.registerCommandBeforePlugins(this); // Paper - spark
+ if (false) this.spark.registerCommandBeforePlugins(this); // Paper - spark // Luminol - Force disable builtin spark
this.overrideAllCommandBlockCommands = this.commandsConfiguration.getStringList("command-block-overrides").contains("*");
this.ignoreVanillaPermissions = this.commandsConfiguration.getBoolean("ignore-vanilla-permissions");
@@ -1183,7 +1183,7 @@ public final class CraftServer implements Server {
this.loadPlugins();
this.enablePlugins(PluginLoadOrder.STARTUP);
this.enablePlugins(PluginLoadOrder.POSTWORLD);
- this.spark.registerCommandAfterPlugins(this); // Paper - spark
+ if (false) this.spark.registerCommandAfterPlugins(this); // Paper - spark // Luminol - Force disable builtin spark
if (io.papermc.paper.plugin.PluginInitializerManager.instance().pluginRemapper != null) io.papermc.paper.plugin.PluginInitializerManager.instance().pluginRemapper.pluginsEnabled(); // Paper - Remap plugins
// Paper start - brigadier command API
io.papermc.paper.command.brigadier.PaperCommands.INSTANCE.setValid(); // to clear invalid state for event fire below

View File

@@ -5,14 +5,14 @@ Subject: [PATCH] Kaiiju Don't pathfind outside region
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/MoveToTargetSink.java b/src/main/java/net/minecraft/world/entity/ai/behavior/MoveToTargetSink.java
index 2a7a26ca447cc78f24e61a2bf557411c31eb16b2..28602455d659dfac4653ab5b7bf4139f65c190ad 100644
index 2a7a26ca447cc78f24e61a2bf557411c31eb16b2..361e79e13dacc765283b2736324f365400e9860e 100644
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/MoveToTargetSink.java
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/MoveToTargetSink.java
@@ -120,7 +120,9 @@ public class MoveToTargetSink extends Behavior<Mob> {
private boolean tryComputePath(Mob entity, WalkTarget walkTarget, long time) {
BlockPos blockPos = walkTarget.getTarget().currentBlockPosition();
+ if (io.papermc.paper.util.TickThread.isTickThreadFor((ServerLevel) entity.level(), blockPos)) // Kaiiju - Don't pathfind outside region
+ if (ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor((ServerLevel) entity.level(), blockPos)) // Kaiiju - Don't pathfind outside region
this.path = entity.getNavigation().createPath(blockPos, 0);
+ else this.path = null; // Kaiiju - Don't pathfind outside region
this.speedModifier = walkTarget.getSpeedModifier();

View File

@@ -1,237 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: M2ke4U <79621885+MrHua269@users.noreply.github.com>
Date: Sun, 26 Nov 2023 16:00:59 +0800
Subject: [PATCH] Pufferfish Improve fluid direction caching
diff --git a/src/main/java/gg/airplane/structs/FluidDirectionCache.java b/src/main/java/gg/airplane/structs/FluidDirectionCache.java
new file mode 100644
index 0000000000000000000000000000000000000000..aa8467b9dda1f7707e41f50ac7b3e9d7343723ec
--- /dev/null
+++ b/src/main/java/gg/airplane/structs/FluidDirectionCache.java
@@ -0,0 +1,136 @@
+package gg.airplane.structs;
+
+import it.unimi.dsi.fastutil.HashCommon;
+
+/**
+ * This is a replacement for the cache used in FluidTypeFlowing.
+ * The requirements for the previous cache were:
+ * - Store 200 entries
+ * - Look for the flag in the cache
+ * - If it exists, move to front of cache
+ * - If it doesn't exist, remove last entry in cache and insert in front
+ *
+ * This class accomplishes something similar, however has a few different
+ * requirements put into place to make this more optimize:
+ *
+ * - maxDistance is the most amount of entries to be checked, instead
+ * of having to check the entire list.
+ * - In combination with that, entries are all tracked by age and how
+ * frequently they're used. This enables us to remove old entries,
+ * without constantly shifting any around.
+ *
+ * Usage of the previous map would have to reset the head every single usage,
+ * shifting the entire map. Here, nothing happens except an increment when
+ * the cache is hit, and when it needs to replace an old element only a single
+ * element is modified.
+ */
+public class FluidDirectionCache<T> {
+
+ private static class FluidDirectionEntry<T> {
+ private final T data;
+ private final boolean flag;
+ private int uses = 0;
+ private int age = 0;
+
+ private FluidDirectionEntry(T data, boolean flag) {
+ this.data = data;
+ this.flag = flag;
+ }
+
+ public int getValue() {
+ return this.uses - (this.age >> 1); // age isn't as important as uses
+ }
+
+ public void incrementUses() {
+ this.uses = this.uses + 1 & Integer.MAX_VALUE;
+ }
+
+ public void incrementAge() {
+ this.age = this.age + 1 & Integer.MAX_VALUE;
+ }
+ }
+
+ private final FluidDirectionEntry[] entries;
+ private final int mask;
+ private final int maxDistance; // the most amount of entries to check for a value
+
+ public FluidDirectionCache(int size) {
+ int arraySize = HashCommon.nextPowerOfTwo(size);
+ this.entries = new FluidDirectionEntry[arraySize];
+ this.mask = arraySize - 1;
+ this.maxDistance = Math.min(arraySize, 4);
+ }
+
+ public Boolean getValue(T data) {
+ FluidDirectionEntry curr;
+ int pos;
+
+ if ((curr = this.entries[pos = HashCommon.mix(data.hashCode()) & this.mask]) == null) {
+ return null;
+ } else if (data.equals(curr.data)) {
+ curr.incrementUses();
+ return curr.flag;
+ }
+
+ int checked = 1; // start at 1 because we already checked the first spot above
+
+ while ((curr = this.entries[pos = (pos + 1) & this.mask]) != null) {
+ if (data.equals(curr.data)) {
+ curr.incrementUses();
+ return curr.flag;
+ } else if (++checked >= this.maxDistance) {
+ break;
+ }
+ }
+
+ return null;
+ }
+
+ public void putValue(T data, boolean flag) {
+ FluidDirectionEntry<T> curr;
+ int pos;
+
+ if ((curr = this.entries[pos = HashCommon.mix(data.hashCode()) & this.mask]) == null) {
+ this.entries[pos] = new FluidDirectionEntry<>(data, flag); // add
+ return;
+ } else if (data.equals(curr.data)) {
+ curr.incrementUses();
+ return;
+ }
+
+ int checked = 1; // start at 1 because we already checked the first spot above
+
+ while ((curr = this.entries[pos = (pos + 1) & this.mask]) != null) {
+ if (data.equals(curr.data)) {
+ curr.incrementUses();
+ return;
+ } else if (++checked >= this.maxDistance) {
+ this.forceAdd(data, flag);
+ return;
+ }
+ }
+
+ this.entries[pos] = new FluidDirectionEntry<>(data, flag); // add
+ }
+
+ private void forceAdd(T data, boolean flag) {
+ int expectedPos = HashCommon.mix(data.hashCode()) & this.mask;
+
+ int toRemovePos = expectedPos;
+ FluidDirectionEntry entryToRemove = this.entries[toRemovePos];
+
+ for (int i = expectedPos + 1; i < expectedPos + this.maxDistance; i++) {
+ int pos = i & this.mask;
+ FluidDirectionEntry entry = this.entries[pos];
+ if (entry.getValue() < entryToRemove.getValue()) {
+ toRemovePos = pos;
+ entryToRemove = entry;
+ }
+
+ entry.incrementAge(); // use this as a mechanism to age the other entries
+ }
+
+ // remove the least used/oldest entry
+ this.entries[toRemovePos] = new FluidDirectionEntry(data, flag);
+ }
+}
diff --git a/src/main/java/net/minecraft/world/level/material/FlowingFluid.java b/src/main/java/net/minecraft/world/level/material/FlowingFluid.java
index 6d8ff6c06af5545634f255ed17dc1e489ece2548..6411aa4ff6bd4cabb25c426fa8f4a7eedb969c03 100644
--- a/src/main/java/net/minecraft/world/level/material/FlowingFluid.java
+++ b/src/main/java/net/minecraft/world/level/material/FlowingFluid.java
@@ -45,6 +45,8 @@ public abstract class FlowingFluid extends Fluid {
public static final BooleanProperty FALLING = BlockStateProperties.FALLING;
public static final IntegerProperty LEVEL = BlockStateProperties.LEVEL_FLOWING;
private static final int CACHE_SIZE = 200;
+ // Pufferfish start - use our own cache
+ /*
private static final ThreadLocal<Object2ByteLinkedOpenHashMap<Block.BlockStatePairKey>> OCCLUSION_CACHE = ThreadLocal.withInitial(() -> {
Object2ByteLinkedOpenHashMap<Block.BlockStatePairKey> object2bytelinkedopenhashmap = new Object2ByteLinkedOpenHashMap<Block.BlockStatePairKey>(200) {
protected void rehash(int i) {}
@@ -53,6 +55,14 @@ public abstract class FlowingFluid extends Fluid {
object2bytelinkedopenhashmap.defaultReturnValue((byte) 127);
return object2bytelinkedopenhashmap;
});
+ */
+
+ private static final ThreadLocal<gg.airplane.structs.FluidDirectionCache<Block.BlockStatePairKey>> localFluidDirectionCache = ThreadLocal.withInitial(() -> {
+ // Pufferfish todo - mess with this number for performance
+ // with 2048 it seems very infrequent on a small world that it has to remove old entries
+ return new gg.airplane.structs.FluidDirectionCache<>(2048);
+ });
+ // Pufferfish end
private final Map<FluidState, VoxelShape> shapes = Maps.newIdentityHashMap();
public FlowingFluid() {}
@@ -251,6 +261,8 @@ public abstract class FlowingFluid extends Fluid {
return false;
}
// Paper end - optimise collisions
+ // Pufferfish start - modify to use our cache
+ /*
Object2ByteLinkedOpenHashMap object2bytelinkedopenhashmap;
if (!state.getBlock().hasDynamicShape() && !fromState.getBlock().hasDynamicShape()) {
@@ -258,9 +270,16 @@ public abstract class FlowingFluid extends Fluid {
} else {
object2bytelinkedopenhashmap = null;
}
+ */
+ gg.airplane.structs.FluidDirectionCache<Block.BlockStatePairKey> cache = null;
+
+ if (!state.getBlock().hasDynamicShape() && !fromState.getBlock().hasDynamicShape()) {
+ cache = localFluidDirectionCache.get();
+ }
Block.BlockStatePairKey block_a;
+ /*
if (object2bytelinkedopenhashmap != null) {
block_a = new Block.BlockStatePairKey(state, fromState, face);
byte b0 = object2bytelinkedopenhashmap.getAndMoveToFirst(block_a);
@@ -271,11 +290,22 @@ public abstract class FlowingFluid extends Fluid {
} else {
block_a = null;
}
+ */
+ if (cache != null) {
+ block_a = new Block.BlockStatePairKey(state, fromState, face);
+ Boolean flag = cache.getValue(block_a);
+ if (flag != null) {
+ return flag;
+ }
+ } else {
+ block_a = null;
+ }
VoxelShape voxelshape = state.getCollisionShape(world, pos);
VoxelShape voxelshape1 = fromState.getCollisionShape(world, fromPos);
boolean flag = !Shapes.mergedFaceOccludes(voxelshape, voxelshape1, face);
+ /*
if (object2bytelinkedopenhashmap != null) {
if (object2bytelinkedopenhashmap.size() == 200) {
object2bytelinkedopenhashmap.removeLastByte();
@@ -283,6 +313,11 @@ public abstract class FlowingFluid extends Fluid {
object2bytelinkedopenhashmap.putAndMoveToFirst(block_a, (byte) (flag ? 1 : 0));
}
+ */
+ if (cache != null) {
+ cache.putValue(block_a, flag);
+ }
+ // Pufferfish end
return flag;
}

View File

@@ -0,0 +1,66 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 11:48:36 +0800
Subject: [PATCH] Kaiiju Vanilla end portal teleportation
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 403585b38a2d8bc1e25fa8e3e4014470a65461b9..39ce6a8cd2713379712a0795bb372c7be31c45c6 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -114,6 +114,7 @@ import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.border.WorldBorder;
+import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.entity.EntityAccess;
import net.minecraft.world.level.entity.EntityInLevelCallback;
import net.minecraft.world.level.gameevent.DynamicGameEventListener;
@@ -4424,13 +4425,18 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
targetPos, 16, // load 16 blocks to be safe from block physics
ca.spottedleaf.concurrentutil.util.Priority.HIGH,
(chunks) -> {
- net.minecraft.world.level.levelgen.feature.EndPlatformFeature.createEndPlatform(destination, targetPos.below(), true, null);
+ //net.minecraft.world.level.levelgen.feature.EndPlatformFeature.createEndPlatform(destination, targetPos.below(), true, null); // Kaiiju - Vanilla end teleportation - moved down
+ // Kaiiju start - Vanilla end teleportation
+ Vec3 finalPos;
+ if (this instanceof Player) finalPos = Vec3.atBottomCenterOf(targetPos.below());
+ else finalPos = Vec3.atBottomCenterOf(targetPos);
+ // Kaiiju end
// the portal obsidian is placed at targetPos.y - 2, so if we want to place the entity
// on the obsidian, we need to spawn at targetPos.y - 1
portalInfoCompletable.complete(
new net.minecraft.world.level.portal.TeleportTransition(
- destination, Vec3.atBottomCenterOf(targetPos.below()), Vec3.ZERO, 90.0f, 0.0f,
+ destination, Vec3.atBottomCenterOf(targetPos.below()), this.getDeltaMovement(), 90.0f, 0.0f, // Kaiiju - Vanilla end teleportation
TeleportTransition.PLAY_PORTAL_SOUND.then(TeleportTransition.PLACE_PORTAL_TICKET),
org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.END_PORTAL
)
@@ -4626,6 +4632,10 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
if (!this.canPortalAsync(destination, takePassengers)) {
return false;
}
+ // Kaiiju start - sync end platform spawning & entity teleportation
+ final java.util.function.Consumer<Entity> tpComplete = type == PortalType.END && destination.getTypeKey() == LevelStem.END ?
+ e -> net.minecraft.world.level.levelgen.feature.EndPlatformFeature.createEndPlatform(destination, ServerLevel.END_SPAWN_POINT.below(), true, null) : teleportComplete;
+ // Kaiiju end
Vec3 initialPosition = this.position();
ChunkPos initialPositionChunk = new ChunkPos(
@@ -4690,9 +4700,14 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
info.postTeleportTransition().onTransition(teleported);
}
- if (teleportComplete != null) {
+ // Kaiiju start - vanilla end teleportation
+ /*if (teleportComplete != null) {
teleportComplete.accept(teleported);
+ }*/
+ if (tpComplete != null){
+ tpComplete.accept(teleported);
}
+ // Kaiiju end
}
);
});

View File

@@ -0,0 +1,330 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 20:29:38 +0800
Subject: [PATCH] Kaiiju Entity tick and removal limiter
diff --git a/build.gradle.kts b/build.gradle.kts
index fcc16a93482527b364c8ba1da5cb659b35fdfd4e..bdff148efc08334708cd58f7af4b87d6a07ef69f 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -27,6 +27,7 @@ abstract class MockitoAgentProvider : CommandLineArgumentProvider {
dependencies {
implementation(project(":luminol-api")) // Folia // Luminol
implementation("com.electronwill.night-config:toml:3.6.6") // Luminol - Night config
+ implementation("io.github.classgraph:classgraph:4.8.158") // Kaiiju - Entity throttling & Removal
// Paper start
implementation("org.jline:jline-terminal-ffm:3.27.1") // use ffm on java 22+
implementation("org.jline:jline-terminal-jni:3.27.1") // fall back to jni on java 21
diff --git a/src/main/java/dev/kaiijumc/kaiiju/KaiijuEntityLimits.java b/src/main/java/dev/kaiijumc/kaiiju/KaiijuEntityLimits.java
new file mode 100644
index 0000000000000000000000000000000000000000..40e80fc685a42bbaeea3e6e64754121178cc7d22
--- /dev/null
+++ b/src/main/java/dev/kaiijumc/kaiiju/KaiijuEntityLimits.java
@@ -0,0 +1,141 @@
+package dev.kaiijumc.kaiiju;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.logging.Level;
+
+import com.google.common.base.Throwables;
+import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
+import io.github.classgraph.ClassGraph;
+import io.github.classgraph.ClassInfo;
+import io.github.classgraph.ScanResult;
+import org.slf4j.Logger;
+
+import com.mojang.logging.LogUtils;
+import net.minecraft.world.entity.Entity;
+import org.bukkit.Bukkit;
+import org.bukkit.configuration.InvalidConfigurationException;
+import org.bukkit.configuration.file.YamlConfiguration;
+
+@SuppressWarnings("unused")
+public class KaiijuEntityLimits {
+ private static final Logger LOGGER = LogUtils.getLogger();
+ private static final File CONFIG_FOLDER = new File("luminol_config");
+
+ protected static final String HEADER =
+ "Per region entity limits for Kaiiju.\n"
+ + "If there are more of particular entity type in a region than limit, entity ticking will be throttled.\n"
+ + "Example: for Wither limit 100 & 300 Withers in a region -> 100 Withers tick every tick & every Wither ticks every 3 ticks.\n"
+ + "Available entities: GlowSquid, Ambient, Bat, Animal, Bee, Cat, Chicken, Cod, Cow, Dolphin, Fish, FishSchool, Fox, Golem, IronGolem, "
+ + "MushroomCow, Ocelot, Panda, Parrot, Perchable, Pig, PolarBear, PufferFish, Rabbit, Salmon, Sheep, Snowman, Squid, TropicalFish, Turtle, "
+ + "WaterAnimal, Wolf, Allay, Axolotl, Camel, Frog, Tadpole, Goat, Horse, HorseAbstract, HorseChestedAbstract, HorseDonkey, HorseMule, "
+ + "HorseSkeleton, HorseZombie, Llama, LlamaTrader, Sniffer, EnderCrystal, EnderDragon, Wither, ArmorStand, Hanging, ItemFrame, Leash, "
+ + "Painting, GlowItemFrame, FallingBlock, Item, TNTPrimed, Blaze, CaveSpider, Creeper, Drowned, Enderman, Endermite, Evoker, Ghast, "
+ + "GiantZombie, Guardian, GuardianElder, IllagerAbstract, IllagerIllusioner, IllagerWizard, MagmaCube, Monster, MonsterPatrolling, Phantom, "
+ + "PigZombie, Pillager, Ravager, Shulker, Silverfish, Skeleton, SkeletonAbstract, SkeletonStray, SkeletonWither, Slime, Spider, Strider, Vex, "
+ + "Vindicator, Witch, Zoglin, Zombie, ZombieHusk, ZombieVillager, Hoglin, Piglin, PiglinAbstract, PiglinBrute, Warden, Villager, "
+ + "VillagerTrader, Arrow, DragonFireball, Egg, EnderPearl, EnderSignal, EvokerFangs, Fireball, FireballFireball, Fireworks, FishingHook, "
+ + "LargeFireball, LlamaSpit, Potion, Projectile, ProjectileThrowable, ShulkerBullet, SmallFireball, Snowball, SpectralArrow, ThrownExpBottle, "
+ + "ThrownTrident, TippedArrow, WitherSkull, Raider, ChestBoat, Boat, MinecartAbstract, MinecartChest, MinecartCommandBlock, MinecartContainer, "
+ + "MinecartFurnace, MinecartHopper, MinecartMobSpawner, MinecartRideable, MinecartTNT\n";
+ protected static final File ENTITY_LIMITS_FILE = new File(CONFIG_FOLDER, "kaiiju_entity_limits.yml");
+ public static YamlConfiguration entityLimitsConfig;
+ public static boolean enabled = false;
+
+ protected static Map<Class<? extends Entity>, EntityLimit> entityLimits;
+
+ static final String ENTITY_PREFIX = "Entity";
+
+ public static void init() {
+ init(true);
+ }
+
+ private static void init(boolean setup) {
+ entityLimitsConfig = new YamlConfiguration();
+
+ if (ENTITY_LIMITS_FILE.exists()) {
+ try {
+ entityLimitsConfig.load(ENTITY_LIMITS_FILE);
+ } catch (InvalidConfigurationException ex) {
+ Bukkit.getLogger().log(Level.SEVERE, "Could not load kaiiju_entity_limits.yml, please correct your syntax errors", ex);
+ throw Throwables.propagate(ex);
+ } catch (IOException ignore) {}
+ } else {
+ if (setup) {
+ entityLimitsConfig.options().header(HEADER);
+ entityLimitsConfig.options().copyDefaults(true);
+ entityLimitsConfig.set("enabled", enabled);
+ entityLimitsConfig.set("Axolotl.limit", 1000);
+ entityLimitsConfig.set("Axolotl.removal", 2000);
+ try {
+ entityLimitsConfig.save(ENTITY_LIMITS_FILE);
+ } catch (IOException ex) {
+ Bukkit.getLogger().log(Level.SEVERE, "Could not save " + ENTITY_LIMITS_FILE, ex);
+ }
+ }
+ }
+
+ enabled = entityLimitsConfig.getBoolean("enabled");
+
+ entityLimits = new Object2ObjectOpenHashMap<>();
+ try (ScanResult scanResult = new ClassGraph().enableAllInfo().acceptPackages("net.minecraft.world.entity").scan()) {
+ Map<String, ClassInfo> entityClasses = new HashMap<>();
+ for (ClassInfo classInfo : scanResult.getAllClasses()) {
+ Class<?> entityClass = Class.forName(classInfo.getName());
+ if (Entity.class.isAssignableFrom(entityClass)) {
+ String entityName = extractEntityName(entityClass.getSimpleName());
+ entityClasses.put(entityName, classInfo);
+ }
+ }
+
+ for (String key : entityLimitsConfig.getKeys(false)) {
+ if (key.equals("enabled")) {
+ continue;
+ }
+
+ if (!entityClasses.containsKey(key)) {
+ LOGGER.error("Unknown entity '" + key + "' in kaiiju-entity-limits.yml, skipping");
+ continue;
+ }
+ int limit = entityLimitsConfig.getInt(key + ".limit");
+ int removal = entityLimitsConfig.getInt(key + ".removal");
+
+ if (limit < 1) {
+ LOGGER.error(key + " has a limit less than the minimum of 1, ignoring");
+ continue;
+ }
+ if (removal <= limit && removal != -1) {
+ LOGGER.error(key + " has a removal limit that is less than or equal to its limit, setting removal to limit * 10");
+ removal = limit * 10;
+ }
+
+ entityLimits.put((Class<? extends Entity>) Class.forName(entityClasses.get(key).getName()), new EntityLimit(limit, removal));
+ }
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static EntityLimit getEntityLimit(Entity entity) {
+ return entityLimits.get(entity.getClass());
+ }
+
+ private static String extractEntityName(String input) {
+ int prefixLength = ENTITY_PREFIX.length();
+
+ if (input.length() <= prefixLength || !input.startsWith(ENTITY_PREFIX)) {
+ return input;
+ } else {
+ return input.substring(prefixLength);
+ }
+ }
+
+ public record EntityLimit(int limit, int removal) {
+ @Override
+ public String toString() {
+ return "EntityLimit{limit=" + limit + ", removal=" + removal + "}";
+ }
+ }
+}
diff --git a/src/main/java/dev/kaiijumc/kaiiju/KaiijuEntityThrottler.java b/src/main/java/dev/kaiijumc/kaiiju/KaiijuEntityThrottler.java
new file mode 100644
index 0000000000000000000000000000000000000000..eb690efacf083e4ff3e321578b12c534e6a40196
--- /dev/null
+++ b/src/main/java/dev/kaiijumc/kaiiju/KaiijuEntityThrottler.java
@@ -0,0 +1,84 @@
+package dev.kaiijumc.kaiiju;
+
+import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
+import net.minecraft.world.entity.Entity;
+import io.papermc.paper.threadedregions.RegionizedWorldData;
+
+public class KaiijuEntityThrottler {
+ private static class TickInfo {
+ int currentTick;
+ int continueFrom;
+ int toTick;
+ int toRemove;
+ }
+
+ public static class EntityThrottlerReturn {
+ public boolean skip;
+ public boolean remove;
+ }
+
+ private final Object2ObjectOpenHashMap<KaiijuEntityLimits.EntityLimit, TickInfo> entityLimitTickInfoMap = new Object2ObjectOpenHashMap<>();
+
+ public void tickLimiterStart() {
+ for (TickInfo tickInfo : entityLimitTickInfoMap.values()) {
+ tickInfo.currentTick = 0;
+ }
+ }
+
+ public EntityThrottlerReturn tickLimiterShouldSkip(Entity entity) {
+ EntityThrottlerReturn retVal = new EntityThrottlerReturn();
+ if (entity.isRemoved()) return retVal;
+ KaiijuEntityLimits.EntityLimit entityLimit = KaiijuEntityLimits.getEntityLimit(entity);
+
+ if (entityLimit != null) {
+ TickInfo tickInfo = entityLimitTickInfoMap.computeIfAbsent(entityLimit, el -> {
+ TickInfo newTickInfo = new TickInfo();
+ newTickInfo.toTick = entityLimit.limit();
+ return newTickInfo;
+ });
+
+ tickInfo.currentTick++;
+ if (tickInfo.currentTick <= tickInfo.toRemove && entityLimit.removal() > 0) {
+ retVal.skip = false;
+ retVal.remove = true;
+ return retVal;
+ }
+
+ if (tickInfo.currentTick < tickInfo.continueFrom) {
+ retVal.skip = true;
+ return retVal;
+ }
+ if (tickInfo.currentTick - tickInfo.continueFrom < tickInfo.toTick) {
+ retVal.skip = false;
+ return retVal;
+ }
+ retVal.skip = true;
+ return retVal;
+ } else {
+ retVal.skip = false;
+ return retVal;
+ }
+ }
+
+ public void tickLimiterFinish(RegionizedWorldData regionizedWorldData) {
+ for (var entry : entityLimitTickInfoMap.entrySet()) {
+ KaiijuEntityLimits.EntityLimit entityLimit = entry.getKey();
+ TickInfo tickInfo = entry.getValue();
+
+ int additionals = 0;
+ int nextContinueFrom = tickInfo.continueFrom + tickInfo.toTick;
+ if (nextContinueFrom >= tickInfo.currentTick) {
+ additionals = entityLimit.limit() - (tickInfo.currentTick - tickInfo.continueFrom);
+ nextContinueFrom = 0;
+ }
+ tickInfo.continueFrom = nextContinueFrom;
+ tickInfo.toTick = entityLimit.limit() + additionals;
+
+ if (tickInfo.toRemove == 0 && tickInfo.currentTick > entityLimit.removal()) {
+ tickInfo.toRemove = tickInfo.currentTick - entityLimit.removal();
+ } else if (tickInfo.toRemove != 0) {
+ tickInfo.toRemove = 0;
+ }
+ }
+ }
+}
diff --git a/src/main/java/io/papermc/paper/threadedregions/RegionizedWorldData.java b/src/main/java/io/papermc/paper/threadedregions/RegionizedWorldData.java
index 1b741d4bccfd45beeec43300f44770516c0d850e..3c37ad27488486f9bb0f972369ccaee2284df673 100644
--- a/src/main/java/io/papermc/paper/threadedregions/RegionizedWorldData.java
+++ b/src/main/java/io/papermc/paper/threadedregions/RegionizedWorldData.java
@@ -354,6 +354,7 @@ public final class RegionizedWorldData {
private final IteratorSafeOrderedReferenceSet<Mob> navigatingMobs = new IteratorSafeOrderedReferenceSet<>();
public final ReferenceList<Entity> trackerEntities = new ReferenceList<>(EMPTY_ENTITY_ARRAY); // Moonrise - entity tracker
public final ReferenceList<Entity> trackerUnloadedEntities = new ReferenceList<>(EMPTY_ENTITY_ARRAY); // Moonrise - entity tracker
+ public final dev.kaiijumc.kaiiju.KaiijuEntityThrottler entityThrottler = new dev.kaiijumc.kaiiju.KaiijuEntityThrottler(); // Kaiiju
// block ticking
private final ObjectLinkedOpenHashSet<BlockEventData> blockEvents = new ObjectLinkedOpenHashSet<>();
diff --git a/src/main/java/me/earthme/luminol/config/modules/misc/KaiijuEntityLimiterConfig.java b/src/main/java/me/earthme/luminol/config/modules/misc/KaiijuEntityLimiterConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..038d9ab60cfac7e40e7c0c0644fa0a0d035eac01
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/misc/KaiijuEntityLimiterConfig.java
@@ -0,0 +1,23 @@
+package me.earthme.luminol.config.modules.misc;
+
+import com.electronwill.nightconfig.core.file.CommentedFileConfig;
+import dev.kaiijumc.kaiiju.KaiijuEntityLimits;
+import me.earthme.luminol.config.EnumConfigCategory;
+import me.earthme.luminol.config.IConfigModule;
+
+public class KaiijuEntityLimiterConfig implements IConfigModule {
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.MISC;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "kaiiju_entity_limiter";
+ }
+
+ @Override
+ public void onLoaded(CommentedFileConfig configInstance) {
+ KaiijuEntityLimits.init();
+ }
+}
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index f15015e7ea2b4bc68f3d93ff9bb54da46389c098..8c96d9ece6fac543b1aef39565f8c47e6b27068f 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -810,6 +810,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
}
profiler.startTimer(ca.spottedleaf.leafprofiler.LProfilerRegistry.ACTIVATE_ENTITIES); try { // Folia - profiler
+ if (dev.kaiijumc.kaiiju.KaiijuEntityLimits.enabled) regionizedWorldData.entityThrottler.tickLimiterStart(); // Kaiiju
org.spigotmc.ActivationRange.activateEntities(this); // Spigot
} finally { profiler.stopTimer(ca.spottedleaf.leafprofiler.LProfilerRegistry.ACTIVATE_ENTITIES); } // Folia - profiler
profiler.startTimer(ca.spottedleaf.leafprofiler.LProfilerRegistry.ENTITY_TICK); try { // Folia - profiler
@@ -831,6 +832,13 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
entity.stopRiding();
}
+ // Kaiiju start
+ if (dev.kaiijumc.kaiiju.KaiijuEntityLimits.enabled) {
+ dev.kaiijumc.kaiiju.KaiijuEntityThrottler.EntityThrottlerReturn throttle = regionizedWorldData.entityThrottler.tickLimiterShouldSkip(entity);
+ if (throttle.remove && !entity.hasCustomName()) entity.remove(Entity.RemovalReason.DISCARDED);
+ if (throttle.skip) return;
+ }
+ // Kaiiju end
gameprofilerfiller.push("tick");
this.guardEntityTick(this::tickNonPassenger, entity);
gameprofilerfiller.pop();
@@ -838,6 +846,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
}
}
});
+ if (dev.kaiijumc.kaiiju.KaiijuEntityLimits.enabled) regionizedWorldData.entityThrottler.tickLimiterFinish(regionizedWorldData); // Kaiiju
} finally { profiler.stopTimer(ca.spottedleaf.leafprofiler.LProfilerRegistry.ENTITY_TICK); } // Folia - profiler
gameprofilerfiller.pop();
profiler.startTimer(ca.spottedleaf.leafprofiler.LProfilerRegistry.TILE_ENTITY); try { // Folia - profiler

View File

@@ -1,31 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Tue, 6 Feb 2024 03:17:39 +0000
Subject: [PATCH] Pufferfish Early return optimization for target finding
diff --git a/src/main/java/net/minecraft/world/entity/ai/targeting/TargetingConditions.java b/src/main/java/net/minecraft/world/entity/ai/targeting/TargetingConditions.java
index d2f0c3b26d4beedb49d86e0242d843590d469d02..c55fe31f3fc1c9ccb949c6bfb64e1bd6f37b8356 100644
--- a/src/main/java/net/minecraft/world/entity/ai/targeting/TargetingConditions.java
+++ b/src/main/java/net/minecraft/world/entity/ai/targeting/TargetingConditions.java
@@ -76,9 +76,18 @@ public class TargetingConditions {
}
if (this.range > 0.0) {
- double d = this.testInvisible ? targetEntity.getVisibilityPercent(baseEntity) : 1.0;
- double e = Math.max((this.useFollowRange ? this.getFollowRange(baseEntity) : this.range) * d, 2.0); // Paper - Fix MC-145656
+ // Pufferfish start - check range before getting visibility
+ // d = invisibility percent, e = follow range adjusted for invisibility, f = distance
double f = baseEntity.distanceToSqr(targetEntity.getX(), targetEntity.getY(), targetEntity.getZ());
+ double followRangeRaw = this.useFollowRange ? this.getFollowRange(baseEntity) : this.range;
+
+ if (f > followRangeRaw * followRangeRaw) { // the actual follow range will always be this value or smaller, so if the distance is larger then it never will return true after getting invis
+ return false;
+ }
+
+ double d = this.testInvisible ? targetEntity.getVisibilityPercent(baseEntity) : 1.0;
+ double e = Math.max((followRangeRaw) * d, 2.0D); // Paper - Fix MC-145656
+ // Pufferfish end
if (f > e * e) {
return false;
}

View File

@@ -1,6 +1,6 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Wed, 7 Feb 2024 04:46:30 +0000
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 11:50:09 +0800
Subject: [PATCH] Petal Reduce sensor work
@@ -33,15 +33,15 @@ index 0000000000000000000000000000000000000000..dd45cf1fde5ee4cf8347064f106c64b8
+ }
+}
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index ef5cd008de4d145b67c70e48ae21ea969aedb1f0..8345d8431e1c05639f14919b9bad1029249a5f50 100644
index bd2d62f73e4f1fa1e655012d04e104acca5db198..b136a3d32198cf0e3127966bffbac73315c78f8a 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -983,12 +983,12 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Targeti
@@ -938,12 +938,12 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
return;
}
// Paper end - Allow nerfed mobs to jump and float
+ int i = this.tickCount + this.getId(); //Luminol - Petal - Move up
ProfilerFiller gameprofilerfiller = this.level().getProfiler();
ProfilerFiller gameprofilerfiller = Profiler.get();
gameprofilerfiller.push("sensing");
- this.sensing.tick();

View File

@@ -1,35 +1,14 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Sun, 14 Jan 2024 00:40:35 +0000
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 11:52:43 +0800
Subject: [PATCH] Pufferfish Cache climbing check for activation
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 643631e11c88285f33d050bf7b4b1e2f63b5c992..94c9f407f526b2d43cf61725b414b113de03c67d 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -312,7 +312,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
public double yo;
public double zo;
private Vec3 position;
- private BlockPos blockPosition;
+ public BlockPos blockPosition; // Pufferfish - private->public
private ChunkPos chunkPosition;
private Vec3 deltaMovement;
private float yRot;
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index a1e90547816ebf0811e7b22af793f40015d6c4f3..00589ca4361482cdd852d699c4bc632ae85b5dd3 100644
index b63393c131f736cd51666c675ac18918e038eca6..f9a4ba5cc7c1029a5201e140c80648d07ca80936 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -150,7 +150,6 @@ import org.bukkit.event.entity.EntityTeleportEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
// CraftBukkit end
-import co.aikar.timings.MinecraftTimings; // Paper
public abstract class LivingEntity extends Entity implements Attackable {
@@ -2069,6 +2068,20 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -2139,6 +2139,20 @@ public abstract class LivingEntity extends Entity implements Attackable {
return this.lastClimbablePos;
}
@@ -51,15 +30,15 @@ index a1e90547816ebf0811e7b22af793f40015d6c4f3..00589ca4361482cdd852d699c4bc632a
if (this.isSpectator()) {
return false;
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
index 4fc4690d03fd5f39e019f16845954052210c7361..c77beef9651aa2f7333d536e8ff4af3281834619 100644
index f2f5eb1a443ac411539e1c87eec60e76682b82fa..cbe785f5fab22630e8a80519664791e2ac621b9f 100644
--- a/src/main/java/org/spigotmc/ActivationRange.java
+++ b/src/main/java/org/spigotmc/ActivationRange.java
@@ -307,7 +307,7 @@ public class ActivationRange
@@ -304,7 +304,7 @@ public class ActivationRange
if ( entity instanceof LivingEntity )
{
LivingEntity living = (LivingEntity) entity;
- if ( living.onClimbable() || living.jumping || living.hurtTime > 0 || living.activeEffects.size() > 0 || living.isFreezing()) // Paper
+ if ( living.onClimableCached() || living.jumping || living.hurtTime > 0 || living.activeEffects.size() > 0 || living.isFreezing()) // Paper // Pufferfish - use cached
+ if ( living.onClimableCached() || living.jumping || living.hurtTime > 0 || living.activeEffects.size() > 0 || living.isFreezing() ) // Paper // Pufferfish - use cached
{
return 1; // Paper
}

View File

@@ -1,25 +1,25 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: M2ke4U <79621885+MrHua269@users.noreply.github.com>
Date: Sun, 26 Nov 2023 16:07:56 +0800
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 11:53:29 +0800
Subject: [PATCH] Pufferfish Reduce chunk loading & lookups
diff --git a/src/main/java/net/minecraft/world/entity/monster/EnderMan.java b/src/main/java/net/minecraft/world/entity/monster/EnderMan.java
index 260202fab3ac300552c557b44dcf251f083c6a78..9cf4e2f309e182c69e9592ac606c0ae85a1200b6 100644
index 48dcd2bc12ce1d08cc5195bff5460dc0dd9902d3..c7153cfec847fca4ce5d9ec729628aed5bed11be 100644
--- a/src/main/java/net/minecraft/world/entity/monster/EnderMan.java
+++ b/src/main/java/net/minecraft/world/entity/monster/EnderMan.java
@@ -318,11 +318,17 @@ public class EnderMan extends Monster implements NeutralMob {
@@ -307,11 +307,17 @@ public class EnderMan extends Monster implements NeutralMob {
private boolean teleport(double x, double y, double z) {
BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos(x, y, z);
- while (blockposition_mutableblockposition.getY() > this.level().getMinBuildHeight() && !this.level().getBlockState(blockposition_mutableblockposition).blocksMotion()) {
- while (blockposition_mutableblockposition.getY() > this.level().getMinY() && !this.level().getBlockState(blockposition_mutableblockposition).blocksMotion()) {
+ // Pufferfish start - single chunk lookup
+ net.minecraft.world.level.chunk.LevelChunk chunk = this.level().getChunkIfLoaded(blockposition_mutableblockposition);
+ if (chunk == null) {
+ return false;
+ }
+ // Pufferfish end
+ while (blockposition_mutableblockposition.getY() > this.level().getMinBuildHeight() && !chunk.getBlockState(blockposition_mutableblockposition).blocksMotion()) { // Pufferfish
+ while (blockposition_mutableblockposition.getY() > this.level().getMinY() && !chunk.getBlockState(blockposition_mutableblockposition).blocksMotion()) { // Pufferfish
blockposition_mutableblockposition.move(Direction.DOWN);
}

View File

@@ -1,153 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: M2ke4U <79621885+MrHua269@users.noreply.github.com>
Date: Sun, 26 Nov 2023 16:10:26 +0800
Subject: [PATCH] Pufferfish Reduce entity fluid lookups if no fluids
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 94c9f407f526b2d43cf61725b414b113de03c67d..94bac805d032015587e88b4de3cf7064a534e736 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -5317,16 +5317,18 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
public boolean updateFluidHeightAndDoFluidPushing(TagKey<Fluid> tag, double speed) {
- if (this.touchingUnloadedChunk()) {
+ if (false && this.touchingUnloadedChunk()) { // Pufferfish - cost of a lookup here is the same cost as below, so skip
return false;
} else {
AABB axisalignedbb = this.getBoundingBox().deflate(0.001D);
- int i = Mth.floor(axisalignedbb.minX);
- int j = Mth.ceil(axisalignedbb.maxX);
- int k = Mth.floor(axisalignedbb.minY);
- int l = Mth.ceil(axisalignedbb.maxY);
- int i1 = Mth.floor(axisalignedbb.minZ);
- int j1 = Mth.ceil(axisalignedbb.maxZ);
+ // Pufferfish start - rename
+ int minBlockX = Mth.floor(axisalignedbb.minX);
+ int maxBlockX = Mth.ceil(axisalignedbb.maxX);
+ int minBlockY = Mth.floor(axisalignedbb.minY);
+ int maxBlockY = Mth.ceil(axisalignedbb.maxY);
+ int minBlockZ = Mth.floor(axisalignedbb.minZ);
+ int maxBlockZ = Mth.ceil(axisalignedbb.maxZ);
+ // Pufferfish end
double d1 = 0.0D;
boolean flag = this.isPushedByFluid();
boolean flag1 = false;
@@ -5334,14 +5336,61 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
int k1 = 0;
BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();
- for (int l1 = i; l1 < j; ++l1) {
- for (int i2 = k; i2 < l; ++i2) {
- for (int j2 = i1; j2 < j1; ++j2) {
- blockposition_mutableblockposition.set(l1, i2, j2);
- FluidState fluid = this.level().getFluidState(blockposition_mutableblockposition);
+ // Pufferfish start - based off CollisionUtil.getCollisionsForBlocksOrWorldBorder
+ final int minSection = io.papermc.paper.util.WorldUtil.getMinSection(this.level());
+ final int maxSection = io.papermc.paper.util.WorldUtil.getMaxSection(this.level());
+ final int minBlock = minSection << 4;
+ final int maxBlock = (maxSection << 4) | 15;
+
+ // special cases:
+ if (minBlockY > maxBlock || maxBlockY < minBlock) {
+ // no point in checking
+ return false;
+ }
+
+ int minYIterate = Math.max(minBlock, minBlockY);
+ int maxYIterate = Math.min(maxBlock, maxBlockY);
+
+ int minChunkX = minBlockX >> 4;
+ int maxChunkX = maxBlockX >> 4;
+
+ int minChunkZ = minBlockZ >> 4;
+ int maxChunkZ = maxBlockZ >> 4;
+
+ for (int currChunkZ = minChunkZ; currChunkZ <= maxChunkZ; ++currChunkZ) {
+ int minZ = currChunkZ == minChunkZ ? minBlockZ & 15 : 0; // coordinate in chunk
+ int maxZ = currChunkZ == maxChunkZ ? maxBlockZ & 15 : 16; // coordinate in chunk
+
+ for (int currChunkX = minChunkX; currChunkX <= maxChunkX; ++currChunkX) {
+ int minX = currChunkX == minChunkX ? minBlockX & 15 : 0; // coordinate in chunk
+ int maxX = currChunkX == maxChunkX ? maxBlockX & 15 : 16; // coordinate in chunk
+
+ net.minecraft.world.level.chunk.ChunkAccess chunk = this.level().getChunkIfLoadedImmediately(currChunkX, currChunkZ);
+ if (chunk == null) {
+ return false; // if we're touching an unloaded chunk then it's false
+ }
+
+ net.minecraft.world.level.chunk.LevelChunkSection[] sections = chunk.getSections();
+
+ for (int currY = minYIterate; currY < maxYIterate; ++currY) {
+ net.minecraft.world.level.chunk.LevelChunkSection section = sections[(currY >> 4) - minSection];
+
+ if (section == null || section.hasOnlyAir() || section.fluidStateCount == 0) { // if no fluids, nothing in this section
+ // empty
+ // skip to next section
+ currY = (currY & ~(15)) + 15; // increment by 15: iterator loop increments by the extra one
+ continue;
+ }
+
+ net.minecraft.world.level.chunk.PalettedContainer<BlockState> blocks = section.states;
+
+ for (int currZ = minZ; currZ < maxZ; ++currZ) {
+ for (int currX = minX; currX < maxX; ++currX) {
+ FluidState fluid = blocks.get(currX & 15, currY & 15, currZ & 15).getFluidState();
if (fluid.is(tag)) {
- double d2 = (double) ((float) i2 + fluid.getHeight(this.level(), blockposition_mutableblockposition));
+ blockposition_mutableblockposition.set((currChunkX << 4) + currX, currY, (currChunkZ << 4) + currZ);
+ double d2 = (double) ((float) currY + fluid.getHeight(this.level(), blockposition_mutableblockposition));
if (d2 >= axisalignedbb.minY) {
flag1 = true;
@@ -5363,9 +5412,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
// CraftBukkit end
}
}
+ }
+ }
}
}
}
+ // Pufferfish end
if (vec3d.length() > 0.0D) {
if (k1 > 0) {
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
index a2a5aef769ee8bb638a5a9f3da9812fa4a85dda5..7288261b8924d08e93abecb664e2273c624a325b 100644
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
@@ -25,6 +25,7 @@ public class LevelChunkSection {
public final PalettedContainer<BlockState> states;
// CraftBukkit start - read/write
private PalettedContainer<Holder<Biome>> biomes;
+ public short fluidStateCount; // Pufferfish
public final com.destroystokyo.paper.util.maplist.IBlockDataList tickingList = new com.destroystokyo.paper.util.maplist.IBlockDataList(); // Paper
// Paper start - optimise collisions
private int specialCollidingBlocks;
@@ -102,6 +103,7 @@ public class LevelChunkSection {
if (!fluid.isEmpty()) {
--this.tickingFluidCount;
+ --this.fluidStateCount; // Pufferfish
}
if (!state.isAir()) {
@@ -116,6 +118,7 @@ public class LevelChunkSection {
if (!fluid1.isEmpty()) {
++this.tickingFluidCount;
+ ++this.fluidStateCount; // Pufferfish
}
this.updateBlockCallback(x, y, z, iblockdata1, state); // Paper - optimise collisions
@@ -162,6 +165,7 @@ public class LevelChunkSection {
if (fluid.isRandomlyTicking()) {
this.tickingFluidCount = (short) (this.tickingFluidCount + 1);
}
+ this.fluidStateCount++; // Pufferfish
}
// Paper start - optimise collisions

View File

@@ -1,6 +1,6 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Tue, 6 Feb 2024 03:21:56 +0000
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 11:54:17 +0800
Subject: [PATCH] Pufferfish Fix Paper#6045, block goal shouldn't load chunks

View File

@@ -1,79 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Wed, 7 Feb 2024 05:19:37 +0000
Subject: [PATCH] Pufferfish Entity TTL
diff --git a/src/main/java/me/earthme/luminol/config/modules/optimizations/EntityTTLOptimizationConfig.java b/src/main/java/me/earthme/luminol/config/modules/optimizations/EntityTTLOptimizationConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..15697d69659b6e1e776acf5094684b5f0c079b57
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/optimizations/EntityTTLOptimizationConfig.java
@@ -0,0 +1,38 @@
+package me.earthme.luminol.config.modules.optimizations;
+
+import com.electronwill.nightconfig.core.file.CommentedFileConfig;
+import me.earthme.luminol.config.EnumConfigCategory;
+import me.earthme.luminol.config.IConfigModule;
+import net.minecraft.core.registries.BuiltInRegistries;
+import net.minecraft.world.entity.EntityType;
+
+import java.util.Locale;
+
+public class EntityTTLOptimizationConfig implements IConfigModule {
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.OPTIMIZATIONS;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "entity_time_outs";
+ }
+
+ @Override
+ public void onLoaded(CommentedFileConfig config) {
+ // Set some defaults
+ this.get("optimizations.entity_timeouts.SNOWBALL", -1,config);
+ this.get("optimizations.entity_timeouts.LLAMA_SPIT", -1,config);
+ config.setComment("optimizations.entity_timeouts",
+ """
+ These values define a entity's maximum lifespan. If an
+ entity is in this list and it has survived for longer than
+ that number of ticks, then it will be removed. Setting a value to
+ -1 disables this feature.""");
+ for (EntityType<?> entityType : BuiltInRegistries.ENTITY_TYPE) {
+ String type = EntityType.getKey(entityType).getPath().toUpperCase(Locale.ROOT);
+ entityType.ttl = this.get("optimizations.entity_timeouts." + type, -1,config);
+ }
+ }
+}
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 94bac805d032015587e88b4de3cf7064a534e736..5caa390a167c770f657f142fe3355d127fc95cce 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -856,6 +856,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
public void tick() {
+ // Pufferfish start - entity TTL
+ if (type != EntityType.PLAYER && type.ttl >= 0 && this.tickCount >= type.ttl) {
+ discard();
+ return;
+ }
+ // Pufferfish end - entity TTL
this.baseTick();
}
diff --git a/src/main/java/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java
index a2f0fb8b4057bd3a84d18298e49c4d02955240d3..aa2bb97ef305ed234a11b05e665ac1062b571591 100644
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
@@ -325,6 +325,7 @@ public class EntityType<T extends Entity> implements FeatureElement, EntityTypeT
private final EntityDimensions dimensions;
private final float spawnDimensionsScale;
private final FeatureFlagSet requiredFeatures;
+ public int ttl = -1; // Pufferfish
private static <T extends Entity> EntityType<T> register(String id, EntityType.Builder type) { // CraftBukkit - decompile error
return (EntityType) Registry.register(BuiltInRegistries.ENTITY_TYPE, id, (EntityType<T>) type.build(id)); // CraftBukkit - decompile error

View File

@@ -1,6 +1,6 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Wed, 7 Feb 2024 05:45:24 +0000
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 11:54:58 +0800
Subject: [PATCH] Pufferfish Reduce projectile chunk loading
@@ -33,37 +33,41 @@ index 0000000000000000000000000000000000000000..12683ec5a5102e45b6171fea0b833ba5
+ }
+}
diff --git a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
index a8d2f7a9d0bcb6db0b38ac30b098d59951053b47..77eee09a301a838f21834319d4962eba1c8dcbed 100644
index 522fa33311b433f8c0eff4cb10dd80128f3c96d7..3a832be7d14276f38f1a35ca9f9a540be7b7d1b4 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
@@ -46,6 +46,36 @@ public abstract class Projectile extends Entity implements TraceableEntity {
@@ -58,6 +58,40 @@ public abstract class Projectile extends Entity implements TraceableEntity {
super(type, world);
}
+ // Pufferfish start
+ private static long loadedThisTick = 0;
+ private static long loadedTick;
+ private static final java.lang.ThreadLocal<Long> loadedThisTick = java.lang.ThreadLocal.withInitial(() -> 0L);
+ private static final java.lang.ThreadLocal<Long> loadedTick = java.lang.ThreadLocal.withInitial(() -> 0L);
+
+ private int loadedLifetime = 0;
+ @Override
+ public void setPos(double x, double y, double z) {
+ long currentTick = io.papermc.paper.threadedregions.TickRegionScheduler.getCurrentRegion().getData().getCurrentTick();
+ if (loadedTick != currentTick) {
+ loadedTick = currentTick;
+ loadedThisTick = 0;
+ }
+ int previousX = Mth.floor(this.getX()) >> 4, previousZ = Mth.floor(this.getZ()) >> 4;
+ int newX = Mth.floor(x) >> 4, newZ = Mth.floor(z) >> 4;
+ if (previousX != newX || previousZ != newZ) {
+ boolean isLoaded = ((net.minecraft.server.level.ServerChunkCache) this.level().getChunkSource()).getChunkAtIfLoadedMainThread(newX, newZ) != null;
+ if (!isLoaded) {
+ if (Projectile.loadedThisTick > me.earthme.luminol.config.modules.optimizations.ProjectileChunkReduceConfig.maxProjectileLoadsPerTick) {
+ if (++this.loadedLifetime > me.earthme.luminol.config.modules.optimizations.ProjectileChunkReduceConfig.maxProjectileLoadsPerProjectile) {
+ this.discard();
+ if (io.papermc.paper.threadedregions.TickRegionScheduler.getCurrentRegion() != null && ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(this)){
+ long currentTick = io.papermc.paper.threadedregions.TickRegionScheduler.getCurrentRegion().getData().getCurrentTick();
+
+ if (loadedTick.get() != currentTick) {
+ loadedTick.set(currentTick);
+ loadedThisTick.set(0L);
+ }
+
+ int previousX = Mth.floor(this.getX()) >> 4, previousZ = Mth.floor(this.getZ()) >> 4;
+ int newX = Mth.floor(x) >> 4, newZ = Mth.floor(z) >> 4;
+ if ((previousX != newX || previousZ != newZ) && ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(this.level(), newX, newZ)) {
+ boolean isLoaded = ((net.minecraft.server.level.ServerChunkCache) this.level().getChunkSource()).getChunkAtIfCachedImmediately(newX, newZ) != null;
+ if (!isLoaded) {
+ if (Projectile.loadedThisTick.get() > me.earthme.luminol.config.modules.optimizations.ProjectileChunkReduceConfig.maxProjectileLoadsPerTick) {
+ if (++this.loadedLifetime > me.earthme.luminol.config.modules.optimizations.ProjectileChunkReduceConfig.maxProjectileLoadsPerProjectile) {
+ this.discard();
+ }
+ return;
+ }
+ return;
+ Projectile.loadedThisTick.set(Projectile.loadedThisTick.get() + 1);
+ }
+ Projectile.loadedThisTick++;
+ }
+ }
+ super.setPos(x, y, z);

View File

@@ -1,6 +1,6 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Wed, 7 Feb 2024 05:56:56 +0000
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 11:58:37 +0800
Subject: [PATCH] Pufferfish Dynamic Activation of Brain
@@ -71,50 +71,47 @@ index 0000000000000000000000000000000000000000..af5893ba1f738ec9827d7b714682c314
+ }
+}
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 6b8cbf681203c20eebb214c5c0b0fe0374aa30dc..12c46e7a3f6a8675921d95dee97ece4a83252282 100644
index 8c96d9ece6fac543b1aef39565f8c47e6b27068f..230b448d8dd5c49e2cd45d9f06a439912402d914 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -994,6 +994,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
this.timings.entityTick.startTiming(); // Spigot
@@ -815,6 +815,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
} finally { profiler.stopTimer(ca.spottedleaf.leafprofiler.LProfilerRegistry.ACTIVATE_ENTITIES); } // Folia - profiler
profiler.startTimer(ca.spottedleaf.leafprofiler.LProfilerRegistry.ENTITY_TICK); try { // Folia - profiler
regionizedWorldData.forEachTickingEntity((entity) -> { // Folia - regionised ticking
+ entity.activatedPriorityReset = false; // Pufferfish - DAB
if (!entity.isRemoved()) {
if (false && this.shouldDiscardEntity(entity)) { // CraftBukkit - We prevent spawning in general, so this butchering is not needed
entity.discard();
if (!tickratemanager.isEntityFrozen(entity)) {
gameprofilerfiller.push("checkDespawn");
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 5caa390a167c770f657f142fe3355d127fc95cce..18c6fe66fa944f5e5b7892df4d8fef4c7346d3bc 100644
index 39ce6a8cd2713379712a0795bb372c7be31c45c6..8d0aae7ae8abec5eac1357a1ea28df0cddab2f36 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -483,6 +483,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -390,6 +390,8 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
public boolean freezeLocked = false; // Paper - Freeze Tick Lock API
public boolean fixedPose = false; // Paper - Expand Pose API
private final int despawnTime; // Paper - entity despawn time limit
+ public boolean activatedPriorityReset = false; // Pufferfish - DAB
+ public int activatedPriority = me.earthme.luminol.config.modules.optimizations.EntityDABConfig.maximumActivationPrio; // Pufferfish - DAB (golf score)
// Folia - region ticking
// Paper end - optimise entity tracking
+ //Pufferfish start
+ public boolean activatedPriorityReset = false; // DAB
+ public int activatedPriority = me.earthme.luminol.config.modules.optimizations.EntityDABConfig.maximumActivationPrio; // golf score
+ // Pufferfish end
+
public float getBukkitYaw() {
return this.yRot;
}
public void setOrigin(@javax.annotation.Nonnull Location location) {
this.origin = location.toVector();
diff --git a/src/main/java/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java
index aa2bb97ef305ed234a11b05e665ac1062b571591..29699e51b3e791a1a82a19c95fd6a3f30bac75d5 100644
index 0d18403c6c25555f78e2d6810520839f30258c8e..85865f13404c70fa44ee95968ec1511cba2e3efe 100644
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
@@ -316,6 +316,7 @@ public class EntityType<T extends Entity> implements FeatureElement, EntityTypeT
private final boolean canSpawnFarFromPlayer;
@@ -385,6 +385,7 @@ public class EntityType<T extends Entity> implements FeatureElement, EntityTypeT
private final int clientTrackingRange;
private final int updateInterval;
private final String descriptionId;
+ public boolean dabEnabled = false; // Pufferfish
@Nullable
private String descriptionId;
@Nullable
private Component description;
private final Optional<ResourceKey<LootTable>> lootTable;
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 8345d8431e1c05639f14919b9bad1029249a5f50..208f0995479df5741ff780df607451f27c6f91af 100644
index b136a3d32198cf0e3127966bffbac73315c78f8a..34500f330f51e4c2c7b2b99ba57b0574ee3b266d 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -249,10 +249,10 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Targeti
@@ -247,10 +247,10 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
@Override
public void inactiveTick() {
super.inactiveTick();
@@ -127,7 +124,7 @@ index 8345d8431e1c05639f14919b9bad1029249a5f50..208f0995479df5741ff780df607451f2
this.targetSelector.tick();
}
}
@@ -992,16 +992,20 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Targeti
@@ -947,16 +947,20 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
if (i % 2 != 0 && this.tickCount > 1) {
gameprofilerfiller.push("targetSelector");
@@ -149,160 +146,171 @@ index 8345d8431e1c05639f14919b9bad1029249a5f50..208f0995479df5741ff780df607451f2
gameprofilerfiller.pop();
}
diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java b/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java
index 74d4f653d5c7f1923c59019effd78337402f7025..73f2a527d18f61db97d5b5050ebe67822771cf58 100644
index 29ae74339a4831ccef3d01e8054931715ba192ad..dd08eb5d44de5a482df538bca18a2255bb93a81f 100644
--- a/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java
+++ b/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java
@@ -43,9 +43,13 @@ public class GoalSelector {
@@ -38,9 +38,12 @@ public class GoalSelector {
}
// Paper start
// Paper start - EAR 2
- public boolean inactiveTick() {
+ public boolean inactiveTick(int tickRate, boolean inactive) { // Pufferfish start
+ if (inactive && !me.earthme.luminol.config.modules.optimizations.EntityDABConfig.dearEnabled) tickRate = 4; // reset to Paper's
+ tickRate = Math.min(tickRate, 3);
this.curRate++;
- return this.curRate % 3 == 0; // TODO newGoalRate was already unused in 1.20.4, check if this is correct
+ //return this.curRate % 3 == 0; // TODO newGoalRate was already unused in 1.20.4, check if this is correct
+ return this.curRate % tickRate == 0; // Luminol - Waiting Paper
+ return this.curRate % tickRate == 0; // TODO newGoalRate was already unused in 1.20.4, check if this is correct
+ // Pufferfish end
}
public boolean hasTasks() {
for (WrappedGoal task : this.availableGoals) {
diff --git a/src/main/java/net/minecraft/world/entity/animal/allay/Allay.java b/src/main/java/net/minecraft/world/entity/animal/allay/Allay.java
index 991e3274091c4e25eebc6debd44653e5b566eedb..789d3469ce4983868e4b880b6053bd2d8c33a10a 100644
index 05c3d43fafc781e2c2d762dd5f509753df8da3b3..94692082aa85d7e4e52a4e16bb5e49b0bf6eb93f 100644
--- a/src/main/java/net/minecraft/world/entity/animal/allay/Allay.java
+++ b/src/main/java/net/minecraft/world/entity/animal/allay/Allay.java
@@ -215,9 +215,11 @@ public class Allay extends PathfinderMob implements InventoryCarrier, VibrationS
@@ -219,11 +219,13 @@ public class Allay extends PathfinderMob implements InventoryCarrier, VibrationS
return 0.4F;
}
+ private int behaviorTick = 0; // Pufferfish
@Override
protected void customServerAiStep() {
this.level().getProfiler().push("allayBrain");
protected void customServerAiStep(ServerLevel world) {
ProfilerFiller gameprofilerfiller = Profiler.get();
gameprofilerfiller.push("allayBrain");
+ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish
this.getBrain().tick((ServerLevel) this.level(), this);
this.level().getProfiler().pop();
this.level().getProfiler().push("allayActivityUpdate");
this.getBrain().tick(world, this);
gameprofilerfiller.pop();
gameprofilerfiller.push("allayActivityUpdate");
diff --git a/src/main/java/net/minecraft/world/entity/animal/axolotl/Axolotl.java b/src/main/java/net/minecraft/world/entity/animal/axolotl/Axolotl.java
index a8cc6ddbf45370fe632e5c5fb7ceef3d299e62a4..98766696556b520cf565ccadc8dba207832b4ae3 100644
index 31b10cd404b672d7ce21c2107d8f83e32de26ef4..cb47876a13cb1990bb0ab4cff1bbe57b3b2d0a5e 100644
--- a/src/main/java/net/minecraft/world/entity/animal/axolotl/Axolotl.java
+++ b/src/main/java/net/minecraft/world/entity/animal/axolotl/Axolotl.java
@@ -268,9 +268,11 @@ public class Axolotl extends Animal implements LerpingModel, VariantHolder<Axolo
@@ -292,11 +292,13 @@ public class Axolotl extends Animal implements VariantHolder<Axolotl.Variant>, B
return true;
}
+ private int behaviorTick = 0; // Pufferfish
@Override
protected void customServerAiStep() {
this.level().getProfiler().push("axolotlBrain");
protected void customServerAiStep(ServerLevel world) {
ProfilerFiller gameprofilerfiller = Profiler.get();
gameprofilerfiller.push("axolotlBrain");
+ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish
this.getBrain().tick((ServerLevel) this.level(), this);
this.level().getProfiler().pop();
this.level().getProfiler().push("axolotlActivityUpdate");
this.getBrain().tick(world, this);
gameprofilerfiller.pop();
gameprofilerfiller.push("axolotlActivityUpdate");
diff --git a/src/main/java/net/minecraft/world/entity/animal/frog/Frog.java b/src/main/java/net/minecraft/world/entity/animal/frog/Frog.java
index 816977990639ec0559b652fc9666afd5046f0a5d..714703519965e8dae42be7442f292b581cc7c049 100644
index 36846ba6b6c7494c745ebd8b221479a9d02ff318..3461c7150fc44ee608169aa993f6ff44d4c978be 100644
--- a/src/main/java/net/minecraft/world/entity/animal/frog/Frog.java
+++ b/src/main/java/net/minecraft/world/entity/animal/frog/Frog.java
@@ -181,9 +181,11 @@ public class Frog extends Animal implements VariantHolder<Holder<FrogVariant>> {
@@ -184,10 +184,12 @@ public class Frog extends Animal implements VariantHolder<Holder<FrogVariant>> {
.ifPresent(this::setVariant);
}
+ private int behaviorTick = 0; // Pufferfish
@Override
protected void customServerAiStep() {
this.level().getProfiler().push("frogBrain");
protected void customServerAiStep(ServerLevel world) {
ProfilerFiller profilerFiller = Profiler.get();
profilerFiller.push("frogBrain");
+ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish
this.getBrain().tick((ServerLevel)this.level(), this);
this.level().getProfiler().pop();
this.level().getProfiler().push("frogActivityUpdate");
this.getBrain().tick(world, this);
profilerFiller.pop();
profilerFiller.push("frogActivityUpdate");
diff --git a/src/main/java/net/minecraft/world/entity/animal/frog/Tadpole.java b/src/main/java/net/minecraft/world/entity/animal/frog/Tadpole.java
index 290d41136f5ec7671bc4990dfe50da0a770c124d..0d34e9e0f7ce35c3c28a9216cf3cdd5eddfe90f6 100644
index 48ac8c3f6e00c3c2dc67b6c994be7c0ac6dfcf81..cf326ef35bac732e7addf75537963593d5b268ae 100644
--- a/src/main/java/net/minecraft/world/entity/animal/frog/Tadpole.java
+++ b/src/main/java/net/minecraft/world/entity/animal/frog/Tadpole.java
@@ -83,9 +83,11 @@ public class Tadpole extends AbstractFish {
@@ -83,11 +83,13 @@ public class Tadpole extends AbstractFish {
return SoundEvents.TADPOLE_FLOP;
}
+ private int behaviorTick = 0; // Pufferfish
@Override
protected void customServerAiStep() {
this.level().getProfiler().push("tadpoleBrain");
protected void customServerAiStep(ServerLevel world) {
ProfilerFiller gameprofilerfiller = Profiler.get();
gameprofilerfiller.push("tadpoleBrain");
+ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish
this.getBrain().tick((ServerLevel) this.level(), this);
this.level().getProfiler().pop();
this.level().getProfiler().push("tadpoleActivityUpdate");
this.getBrain().tick(world, this);
gameprofilerfiller.pop();
gameprofilerfiller.push("tadpoleActivityUpdate");
diff --git a/src/main/java/net/minecraft/world/entity/animal/goat/Goat.java b/src/main/java/net/minecraft/world/entity/animal/goat/Goat.java
index 02e49c7ae5e120302b6479cf3e3934b9217eebf0..81c9f1c2895adedec246732df9f9dadddfa5f345 100644
index 76aca47d8638d5c37c57d3a59fa7f8ceaa5a53b4..fb92cd4b0c15b614c0c06d2867039aee1a6212a2 100644
--- a/src/main/java/net/minecraft/world/entity/animal/goat/Goat.java
+++ b/src/main/java/net/minecraft/world/entity/animal/goat/Goat.java
@@ -190,9 +190,11 @@ public class Goat extends Animal {
@@ -192,11 +192,13 @@ public class Goat extends Animal {
return (Brain<Goat>) super.getBrain(); // CraftBukkit - decompile error
}
+ private int behaviorTick = 0; // Pufferfish
@Override
protected void customServerAiStep() {
this.level().getProfiler().push("goatBrain");
protected void customServerAiStep(ServerLevel world) {
ProfilerFiller gameprofilerfiller = Profiler.get();
gameprofilerfiller.push("goatBrain");
+ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish
this.getBrain().tick((ServerLevel) this.level(), this);
this.level().getProfiler().pop();
this.level().getProfiler().push("goatActivityUpdate");
this.getBrain().tick(world, this);
gameprofilerfiller.pop();
gameprofilerfiller.push("goatActivityUpdate");
diff --git a/src/main/java/net/minecraft/world/entity/monster/hoglin/Hoglin.java b/src/main/java/net/minecraft/world/entity/monster/hoglin/Hoglin.java
index c583d883118ded5e1884c757427dc5e73c10dd27..6f8a22c51ba5e2713dcdfc61c61b35123f9bf326 100644
index 6ea90e54759dbeab025e0a1896ee834ea9986427..3f625cb9b1237ca8f782bca2f182dfe72853bd96 100644
--- a/src/main/java/net/minecraft/world/entity/monster/hoglin/Hoglin.java
+++ b/src/main/java/net/minecraft/world/entity/monster/hoglin/Hoglin.java
@@ -153,9 +153,11 @@ public class Hoglin extends Animal implements Enemy, HoglinBase {
@@ -156,10 +156,12 @@ public class Hoglin extends Animal implements Enemy, HoglinBase {
return (Brain<Hoglin>)super.getBrain();
}
+ private int behaviorTick; // Pufferfish
@Override
protected void customServerAiStep() {
this.level().getProfiler().push("hoglinBrain");
protected void customServerAiStep(ServerLevel world) {
ProfilerFiller profilerFiller = Profiler.get();
profilerFiller.push("hoglinBrain");
+ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish
this.getBrain().tick((ServerLevel)this.level(), this);
this.level().getProfiler().pop();
this.getBrain().tick(world, this);
profilerFiller.pop();
HoglinAi.updateActivity(this);
diff --git a/src/main/java/net/minecraft/world/entity/monster/piglin/Piglin.java b/src/main/java/net/minecraft/world/entity/monster/piglin/Piglin.java
index a8ab486c7e11ec137da48174af6f1030dfd48056..5878a6ecadc2b9f7ac9f70622a8c85e2940e139a 100644
index e04d2c5e75dc774fe893a552474fdb8045c32693..d1870bf4c01c846a721480eb6611a67db9b98d02 100644
--- a/src/main/java/net/minecraft/world/entity/monster/piglin/Piglin.java
+++ b/src/main/java/net/minecraft/world/entity/monster/piglin/Piglin.java
@@ -294,9 +294,11 @@ public class Piglin extends AbstractPiglin implements CrossbowAttackMob, Invento
@@ -304,11 +304,13 @@ public class Piglin extends AbstractPiglin implements CrossbowAttackMob, Invento
return !this.cannotHunt;
}
+ private int behaviorTick; // Pufferfish
@Override
protected void customServerAiStep() {
this.level().getProfiler().push("piglinBrain");
protected void customServerAiStep(ServerLevel world) {
ProfilerFiller gameprofilerfiller = Profiler.get();
gameprofilerfiller.push("piglinBrain");
+ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish
this.getBrain().tick((ServerLevel) this.level(), this);
this.level().getProfiler().pop();
this.getBrain().tick(world, this);
gameprofilerfiller.pop();
PiglinAi.updateActivity(this);
diff --git a/src/main/java/net/minecraft/world/entity/monster/warden/Warden.java b/src/main/java/net/minecraft/world/entity/monster/warden/Warden.java
index ddd60be52dce5773c80934be5aa5705db239e3dd..9cf56f2ada025aae0710099bcc3b5c62fd7bbb9e 100644
index 6180019da58b19d2595da508aed3196af922d587..457f9f6bf6a8e8f2e0b4246a0589e344756370d2 100644
--- a/src/main/java/net/minecraft/world/entity/monster/warden/Warden.java
+++ b/src/main/java/net/minecraft/world/entity/monster/warden/Warden.java
@@ -271,11 +271,13 @@ public class Warden extends Monster implements VibrationSystem {
@@ -275,11 +275,13 @@ public class Warden extends Monster implements VibrationSystem {
}
+ private int behaviorTick = 0; // Pufferfish
@Override
protected void customServerAiStep() {
ServerLevel worldserver = (ServerLevel) this.level();
protected void customServerAiStep(ServerLevel world) {
ProfilerFiller gameprofilerfiller = Profiler.get();
worldserver.getProfiler().push("wardenBrain");
gameprofilerfiller.push("wardenBrain");
+ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish
this.getBrain().tick(worldserver, this);
this.level().getProfiler().pop();
super.customServerAiStep();
this.getBrain().tick(world, this);
gameprofilerfiller.pop();
super.customServerAiStep(world);
diff --git a/src/main/java/net/minecraft/world/entity/npc/Villager.java b/src/main/java/net/minecraft/world/entity/npc/Villager.java
index 6339967b154af1ca9632c7b8b315d612f4b80ea2..c4b7fd6c9d0f26361295a70d63f6fc080063d129 100644
index d33dc470850acdc0cecfbad7f7990a9deb57edaf..75d214a828d30fb7f81a510b115ca14071e6294a 100644
--- a/src/main/java/net/minecraft/world/entity/npc/Villager.java
+++ b/src/main/java/net/minecraft/world/entity/npc/Villager.java
@@ -143,6 +143,8 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
@@ -142,6 +142,8 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
return holder.is(PoiTypes.MEETING);
});
@@ -311,33 +319,33 @@ index 6339967b154af1ca9632c7b8b315d612f4b80ea2..c4b7fd6c9d0f26361295a70d63f6fc08
public Villager(EntityType<? extends Villager> entityType, Level world) {
this(entityType, world, VillagerType.PLAINS);
}
@@ -246,6 +248,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
@@ -245,6 +247,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
}
// Spigot End
+ private int behaviorTick = 0; // Pufferfish
@Override
@Deprecated // Paper
protected void customServerAiStep() {
protected void customServerAiStep(ServerLevel world) {
// Paper start - EAR 2
@@ -255,7 +258,11 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
protected void customServerAiStep(final boolean inactive) {
// Paper end
this.level().getProfiler().push("villagerBrain");
- if (!inactive) this.getBrain().tick((ServerLevel) this.level(), this); // Paper
ProfilerFiller gameprofilerfiller = Profiler.get();
gameprofilerfiller.push("villagerBrain");
- if (!inactive) this.getBrain().tick(world, this);
+ // Pufferfish start
+ if (!inactive && this.behaviorTick++ % this.activatedPriority == 0) {
+ this.getBrain().tick((ServerLevel) this.level(), this); // Paper
+ }
+ // Pufferfish end
this.level().getProfiler().pop();
gameprofilerfiller.pop();
if (this.assignProfessionWhenSpawned) {
this.assignProfessionWhenSpawned = false;
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
index c77beef9651aa2f7333d536e8ff4af3281834619..9628cc2b7f200e0bab4fed48997dde3e266200ee 100644
index cbe785f5fab22630e8a80519664791e2ac621b9f..820145408fa2150820c4c14ea55bee23e7e9a366 100644
--- a/src/main/java/org/spigotmc/ActivationRange.java
+++ b/src/main/java/org/spigotmc/ActivationRange.java
@@ -38,6 +38,10 @@ import co.aikar.timings.MinecraftTimings;
import net.minecraft.world.entity.schedule.Activity;
@@ -37,6 +37,10 @@ import net.minecraft.world.entity.projectile.ThrownTrident;
import net.minecraft.world.entity.raid.Raider;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
+// Pufferfish start
@@ -347,7 +355,7 @@ index c77beef9651aa2f7333d536e8ff4af3281834619..9628cc2b7f200e0bab4fed48997dde3e
public class ActivationRange
{
@@ -232,6 +236,25 @@ public class ActivationRange
@@ -230,6 +234,25 @@ public class ActivationRange
}
// Paper end - Configurable marker ticking
ActivationRange.activateEntity(entity, bbByType); // Folia - threaded regions
@@ -373,18 +381,3 @@ index c77beef9651aa2f7333d536e8ff4af3281834619..9628cc2b7f200e0bab4fed48997dde3e
}
// Paper end
}
@@ -248,12 +271,12 @@ public class ActivationRange
if ( io.papermc.paper.threadedregions.RegionizedServer.getCurrentTick() > entity.activatedTick ) // Folia - threaded regions
{
if ( entity.defaultActivationState )
- {
+ { // Pufferfish - diff on change
entity.activatedTick = io.papermc.paper.threadedregions.RegionizedServer.getCurrentTick(); // Folia - threaded regions
return;
}
if ( bbByType[entity.activationType.ordinal()].intersects( entity.getBoundingBox() ) ) // Folia - threaded regions
- {
+ { // Pufferfish - diff on change
entity.activatedTick = io.papermc.paper.threadedregions.RegionizedServer.getCurrentTick(); // Folia - threaded regions
}
}

View File

@@ -1,14 +1,14 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: M2ke4U <79621885+MrHua269@users.noreply.github.com>
Date: Sun, 26 Nov 2023 16:15:28 +0800
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 11:59:05 +0800
Subject: [PATCH] Pufferfish Only check for spooky season once an hour
diff --git a/src/main/java/net/minecraft/world/entity/ambient/Bat.java b/src/main/java/net/minecraft/world/entity/ambient/Bat.java
index dc27ddf5131e7398a5390a5187261d4c7fb6ccaa..39cc49b746b0a775fde5d173dd4f712ab4a84a97 100644
index 60c2868f255d372226e0c1389caaa5477bbef41e..4f2993214f1789251742fe106bc7acad5b37440b 100644
--- a/src/main/java/net/minecraft/world/entity/ambient/Bat.java
+++ b/src/main/java/net/minecraft/world/entity/ambient/Bat.java
@@ -239,13 +239,25 @@ public class Bat extends AmbientCreature {
@@ -242,13 +242,25 @@ public class Bat extends AmbientCreature {
}
}

View File

@@ -0,0 +1,65 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 11:59:52 +0800
Subject: [PATCH] Pufferfish Simpler ShapelessRecipes comparison for Vanilla
diff --git a/src/main/java/net/minecraft/world/item/crafting/ShapelessRecipe.java b/src/main/java/net/minecraft/world/item/crafting/ShapelessRecipe.java
index 12f95bee2a69fd5df7c4a165537e01299e60c5f6..d7ce86752e4138cdd3844b3374609753aa20f9ea 100644
--- a/src/main/java/net/minecraft/world/item/crafting/ShapelessRecipe.java
+++ b/src/main/java/net/minecraft/world/item/crafting/ShapelessRecipe.java
@@ -31,8 +31,13 @@ public class ShapelessRecipe implements CraftingRecipe {
final List<Ingredient> ingredients;
@Nullable
private PlacementInfo placementInfo;
+ private final boolean isBukkit; // Pufferfish
+ // Pufferfish start
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.isBukkit = isBukkit; // Pufferfish end
this.group = group;
this.category = category;
this.result = result;
@@ -80,6 +85,28 @@ public class ShapelessRecipe implements CraftingRecipe {
}
public boolean matches(CraftingInput input, Level world) {
+ // Pufferfish start
+ 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();
+ }
+ // Pufferfish end
+
// Paper start - Improve exact choice recipe ingredients & unwrap ternary
if (input.ingredientCount() != this.ingredients.size()) {
return false;
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java
index 7c989318dc7ad89bb0d9143fcaac1e4bba6f5907..143a4d4efcc989ed4a4c73cc304e1978ad8f0699 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java
@@ -44,6 +44,6 @@ public class CraftShapelessRecipe extends ShapelessRecipe implements CraftRecipe
data.add(this.toNMS(i, true));
}
- MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.ShapelessRecipe(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), CraftItemStack.asNMSCopy(this.getResult()), data)));
+ MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.ShapelessRecipe(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), CraftItemStack.asNMSCopy(this.getResult()), data, true))); // Pufferfish
}
}

View File

@@ -1,31 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Tue, 20 Feb 2024 13:11:11 +0000
Subject: [PATCH] Pufferfish Reduce entity allocations
diff --git a/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java b/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java
index 9ef8f014af332da129bfcd3370da983ec035ecc6..bc178967affd21ad04b83ea26639a2dd9b497454 100644
--- a/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java
+++ b/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java
@@ -22,9 +22,11 @@ public class AttributeMap {
private final Map<Holder<Attribute>, AttributeInstance> attributes = new Object2ObjectOpenHashMap<>();
private final Set<AttributeInstance> dirtyAttributes = new ObjectOpenHashSet<>();
private final AttributeSupplier supplier;
+ private final java.util.function.Function<Holder<Attribute>, AttributeInstance> createInstance; // Pufferfish
public AttributeMap(AttributeSupplier defaultAttributes) {
this.supplier = defaultAttributes;
+ this.createInstance = attributex -> this.supplier.createInstance(this::onAttributeModified, attributex); // Pufferfish
}
private void onAttributeModified(AttributeInstance instance) {
@@ -43,7 +45,7 @@ public class AttributeMap {
@Nullable
public AttributeInstance getInstance(Holder<Attribute> attribute) {
- return this.attributes.computeIfAbsent(attribute, attributex -> this.supplier.createInstance(this::onAttributeModified, attributex));
+ return this.attributes.computeIfAbsent(attribute, this.createInstance); // Pufferfish - cache lambda, as for some reason java allocates it anyways
}
public boolean hasAttribute(Holder<Attribute> attribute) {

View File

@@ -1,6 +1,6 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Tue, 20 Feb 2024 13:03:42 +0000
From: MrHua269 <wangxyper@163.com>
Date: Sun, 4 Aug 2024 21:41:52 +0800
Subject: [PATCH] Pufferfish Throttle goal selector during inactive ticking
@@ -31,10 +31,10 @@ index 0000000000000000000000000000000000000000..acc032f727e605e79b688efb4873ff47
+ }
+}
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 208f0995479df5741ff780df607451f27c6f91af..78619c2ce66c34c4866755aa8c6c9ae18d594498 100644
index 34500f330f51e4c2c7b2b99ba57b0574ee3b266d..8082fb0d0793743ee6123f4bb5c6d79b078d5f86 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -245,11 +245,13 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Targeti
@@ -243,11 +243,13 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
return this.lookControl;
}

View File

@@ -1,473 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Mon, 25 Mar 2024 13:48:33 +0000
Subject: [PATCH] Pufferfish Improve container checking with a bitset
diff --git a/src/main/java/gg/airplane/structs/ItemListWithBitset.java b/src/main/java/gg/airplane/structs/ItemListWithBitset.java
new file mode 100644
index 0000000000000000000000000000000000000000..1b7a4ee47f4445d7f2ac91d3a73ae113edbdddb2
--- /dev/null
+++ b/src/main/java/gg/airplane/structs/ItemListWithBitset.java
@@ -0,0 +1,114 @@
+package gg.airplane.structs;
+
+import net.minecraft.core.NonNullList;
+import net.minecraft.world.item.ItemStack;
+import org.apache.commons.lang.Validate;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.AbstractList;
+import java.util.Arrays;
+import java.util.List;
+
+public class ItemListWithBitset extends AbstractList<ItemStack> {
+ public static ItemListWithBitset fromList(List<ItemStack> list) {
+ if (list instanceof ItemListWithBitset ours) {
+ return ours;
+ }
+ return new ItemListWithBitset(list);
+ }
+
+ private static ItemStack[] createArray(int size) {
+ ItemStack[] array = new ItemStack[size];
+ Arrays.fill(array, ItemStack.EMPTY);
+ return array;
+ }
+
+ private final ItemStack[] items;
+
+ private long bitSet = 0;
+ private final long allBits;
+
+ private static class OurNonNullList extends NonNullList<ItemStack> {
+ protected OurNonNullList(List<ItemStack> delegate) {
+ super(delegate, ItemStack.EMPTY);
+ }
+ }
+
+ public final NonNullList<ItemStack> nonNullList = new OurNonNullList(this);
+
+ private ItemListWithBitset(List<ItemStack> list) {
+ this(list.size());
+
+ for (int i = 0; i < list.size(); i++) {
+ this.set(i, list.get(i));
+ }
+ }
+
+ public ItemListWithBitset(int size) {
+ Validate.isTrue(size < Long.BYTES * 8, "size is too large");
+
+ this.items = createArray(size);
+ this.allBits = ((1L << size) - 1);
+ }
+
+ public boolean isCompletelyEmpty() {
+ return this.bitSet == 0;
+ }
+
+ public boolean hasFullStacks() {
+ return (this.bitSet & this.allBits) == allBits;
+ }
+
+ @Override
+ public ItemStack set(int index, @NotNull ItemStack itemStack) {
+ ItemStack existing = this.items[index];
+
+ this.items[index] = itemStack;
+
+ if (itemStack == ItemStack.EMPTY) {
+ this.bitSet &= ~(1L << index);
+ } else {
+ this.bitSet |= 1L << index;
+ }
+
+ return existing;
+ }
+
+ @NotNull
+ @Override
+ public ItemStack get(int var0) {
+ return this.items[var0];
+ }
+
+ @Override
+ public int size() {
+ return this.items.length;
+ }
+
+ @Override
+ public void clear() {
+ Arrays.fill(this.items, ItemStack.EMPTY);
+ }
+
+ // these are unsupported for block inventories which have a static size
+ @Override
+ public void add(int var0, ItemStack var1) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ItemStack remove(int var0) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String toString() {
+ return "ItemListWithBitset{" +
+ "items=" + Arrays.toString(items) +
+ ", bitSet=" + Long.toString(bitSet, 2) +
+ ", allBits=" + Long.toString(allBits, 2) +
+ ", size=" + this.items.length +
+ '}';
+ }
+}
diff --git a/src/main/java/net/minecraft/world/CompoundContainer.java b/src/main/java/net/minecraft/world/CompoundContainer.java
index 241fec02e6869c638d3a160819b32173a081467b..6a8f9e8f5bf108674c47018def28906e2d0a729c 100644
--- a/src/main/java/net/minecraft/world/CompoundContainer.java
+++ b/src/main/java/net/minecraft/world/CompoundContainer.java
@@ -1,5 +1,6 @@
package net.minecraft.world;
+import net.minecraft.core.Direction; // Pufferfish
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
@@ -64,6 +65,23 @@ public class CompoundContainer implements Container {
this.container2 = second;
}
+ // Pufferfish start
+ @Override
+ public boolean hasEmptySlot(Direction enumdirection) {
+ return this.container1.hasEmptySlot(null) || this.container2.hasEmptySlot(null);
+ }
+
+ @Override
+ public boolean isCompletelyFull(Direction enumdirection) {
+ return this.container1.isCompletelyFull(null) && this.container2.isCompletelyFull(null);
+ }
+
+ @Override
+ public boolean isCompletelyEmpty(Direction enumdirection) {
+ return this.container1.isCompletelyEmpty(null) && this.container2.isCompletelyEmpty(null);
+ }
+ // Pufferfish end
+
@Override
public int getContainerSize() {
return this.container1.getContainerSize() + this.container2.getContainerSize();
diff --git a/src/main/java/net/minecraft/world/Container.java b/src/main/java/net/minecraft/world/Container.java
index f402dbbfe3a443e6bc51f88b85abe937852b52f0..541cb29a10e2c87a8214ff5beadb71bc1922d353 100644
--- a/src/main/java/net/minecraft/world/Container.java
+++ b/src/main/java/net/minecraft/world/Container.java
@@ -3,6 +3,8 @@ package net.minecraft.world;
import java.util.Set;
import java.util.function.Predicate;
import net.minecraft.core.BlockPos;
+
+import net.minecraft.core.Direction; // Pufferfish
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
@@ -14,6 +16,63 @@ import org.bukkit.craftbukkit.entity.CraftHumanEntity;
// CraftBukkit end
public interface Container extends Clearable {
+ // Pufferfish start - allow the inventory to override and optimize these frequent calls
+ default boolean hasEmptySlot(@org.jetbrains.annotations.Nullable Direction enumdirection) { // there is a slot with 0 items in it
+ if (this instanceof WorldlyContainer worldlyContainer) {
+ for (int i : worldlyContainer.getSlotsForFace(enumdirection)) {
+ if (this.getItem(i).isEmpty()) {
+ return true;
+ }
+ }
+ } else {
+ int size = this.getContainerSize();
+ for (int i = 0; i < size; i++) {
+ if (this.getItem(i).isEmpty()) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ default boolean isCompletelyFull(@org.jetbrains.annotations.Nullable Direction enumdirection) { // every stack is maxed
+ if (this instanceof WorldlyContainer worldlyContainer) {
+ for (int i : worldlyContainer.getSlotsForFace(enumdirection)) {
+ ItemStack itemStack = this.getItem(i);
+ if (itemStack.getCount() < itemStack.getMaxStackSize()) {
+ return false;
+ }
+ }
+ } else {
+ int size = this.getContainerSize();
+ for (int i = 0; i < size; i++) {
+ ItemStack itemStack = this.getItem(i);
+ if (itemStack.getCount() < itemStack.getMaxStackSize()) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ default boolean isCompletelyEmpty(@org.jetbrains.annotations.Nullable Direction enumdirection) {
+ if (this instanceof WorldlyContainer worldlyContainer) {
+ for (int i : worldlyContainer.getSlotsForFace(enumdirection)) {
+ if (!this.getItem(i).isEmpty()) {
+ return false;
+ }
+ }
+ } else {
+ int size = this.getContainerSize();
+ for (int i = 0; i < size; i++) {
+ if (!this.getItem(i).isEmpty()) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ // Pufferfish end
float DEFAULT_DISTANCE_BUFFER = 4.0F;
diff --git a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecartContainer.java b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecartContainer.java
index 2704389bc3ec6dbbf1b568a4380972f8c0d62d15..c53cdaa59da87d96e34f06185b1f73e56a5bfc6c 100644
--- a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecartContainer.java
+++ b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecartContainer.java
@@ -30,7 +30,10 @@ import org.bukkit.inventory.InventoryHolder;
public abstract class AbstractMinecartContainer extends AbstractMinecart implements ContainerEntity {
+ // Pufferfish start
private NonNullList<ItemStack> itemStacks;
+ private gg.airplane.structs.ItemListWithBitset itemStacksOptimized;
+ // Pufferfish end
@Nullable
public ResourceKey<LootTable> lootTable;
public long lootTableSeed;
@@ -92,12 +95,18 @@ public abstract class AbstractMinecartContainer extends AbstractMinecart impleme
protected AbstractMinecartContainer(EntityType<?> type, Level world) {
super(type, world);
- this.itemStacks = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY); // CraftBukkit - SPIGOT-3513
+ // Pufferfish start
+ this.itemStacksOptimized = new gg.airplane.structs.ItemListWithBitset(this.getContainerSize()); // CraftBukkit - SPIGOT-3513
+ this.itemStacks = this.itemStacksOptimized.nonNullList;
+ // Pufferfish end
}
protected AbstractMinecartContainer(EntityType<?> type, double x, double y, double z, Level world) {
super(type, world, x, y, z);
- this.itemStacks = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY); // CraftBukkit - SPIGOT-3513
+ // Pufferfish start
+ this.itemStacksOptimized = new gg.airplane.structs.ItemListWithBitset(this.getContainerSize()); // CraftBukkit - SPIGOT-3513
+ this.itemStacks = this.itemStacksOptimized.nonNullList;
+ // Pufferfish end
}
@Override
@@ -166,6 +175,10 @@ public abstract class AbstractMinecartContainer extends AbstractMinecart impleme
protected void readAdditionalSaveData(CompoundTag nbt) {
super.readAdditionalSaveData(nbt);
this.lootableData.loadNbt(nbt); // Paper
+ // Pufferfish start
+ this.itemStacksOptimized = new gg.airplane.structs.ItemListWithBitset(this.getContainerSize());
+ this.itemStacks = this.itemStacksOptimized.nonNullList;
+ // Pufferfish end
this.readChestVehicleSaveData(nbt, this.registryAccess());
}
diff --git a/src/main/java/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java
index 15fd1fe1b55b6421d2c09e8385c9f69fa0152e56..21c747f00892a8372c3ef239f63d59ccaa315295 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java
@@ -119,19 +119,7 @@ public abstract class BaseContainerBlockEntity extends BlockEntity implements Co
@Override
public boolean isEmpty() {
- Iterator iterator = this.getItems().iterator();
-
- ItemStack itemstack;
-
- do {
- if (!iterator.hasNext()) {
- return true;
- }
-
- itemstack = (ItemStack) iterator.next();
- } while (itemstack.isEmpty());
-
- return false;
+ return this.isCompletelyEmpty(null); // Pufferfish - use super
}
@Override
diff --git a/src/main/java/net/minecraft/world/level/block/entity/ChestBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/ChestBlockEntity.java
index b88aa184cd06a0485146f58a5b61a56a50911209..7b64c57795fe27d8397500bfa41f71f9d2103b20 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/ChestBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/ChestBlockEntity.java
@@ -32,7 +32,10 @@ import org.bukkit.entity.HumanEntity;
public class ChestBlockEntity extends RandomizableContainerBlockEntity implements LidBlockEntity {
private static final int EVENT_SET_OPEN_COUNT = 1;
+ // Pufferfish start
private NonNullList<ItemStack> items;
+ private gg.airplane.structs.ItemListWithBitset optimizedItems;
+ // Pufferfish end
public final ContainerOpenersCounter openersCounter;
private final ChestLidController chestLidController;
@@ -66,9 +69,13 @@ public class ChestBlockEntity extends RandomizableContainerBlockEntity implement
}
// CraftBukkit end
+ private final boolean isNative = getClass().equals(ChestBlockEntity.class); // Pufferfish
protected ChestBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
- this.items = NonNullList.withSize(27, ItemStack.EMPTY);
+ // Pufferfish start
+ this.optimizedItems = new gg.airplane.structs.ItemListWithBitset(27);
+ this.items = this.optimizedItems.nonNullList;
+ // Pufferfish end
this.openersCounter = new ContainerOpenersCounter() {
@Override
protected void onOpen(Level world, BlockPos pos, BlockState state) {
@@ -99,6 +106,23 @@ public class ChestBlockEntity extends RandomizableContainerBlockEntity implement
this.chestLidController = new ChestLidController();
}
+ // Pufferfish start
+ @Override
+ public boolean hasEmptySlot(Direction enumdirection) {
+ return isNative ? !this.optimizedItems.hasFullStacks() : super.hasEmptySlot(enumdirection);
+ }
+
+ @Override
+ public boolean isCompletelyFull(Direction enumdirection) {
+ return isNative ? this.optimizedItems.hasFullStacks() && super.isCompletelyFull(enumdirection) : super.isCompletelyFull(enumdirection);
+ }
+
+ @Override
+ public boolean isCompletelyEmpty(Direction enumdirection) {
+ return isNative && this.optimizedItems.isCompletelyEmpty() || super.isCompletelyEmpty(enumdirection);
+ }
+ // Pufferfish end
+
public ChestBlockEntity(BlockPos pos, BlockState state) {
this(BlockEntityType.CHEST, pos, state);
}
@@ -116,7 +140,10 @@ public class ChestBlockEntity extends RandomizableContainerBlockEntity implement
@Override
protected void loadAdditional(CompoundTag nbt, HolderLookup.Provider registryLookup) {
super.loadAdditional(nbt, registryLookup);
- this.items = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);
+ // Pufferfish start
+ this.optimizedItems = new gg.airplane.structs.ItemListWithBitset(this.getContainerSize());
+ this.items = this.optimizedItems.nonNullList;
+ // Pufferfish end
if (!this.tryLoadLootTable(nbt)) {
ContainerHelper.loadAllItems(nbt, this.items, registryLookup);
}
@@ -188,7 +215,10 @@ public class ChestBlockEntity extends RandomizableContainerBlockEntity implement
@Override
protected void setItems(NonNullList<ItemStack> inventory) {
- this.items = inventory;
+ // Pufferfish start
+ this.optimizedItems = gg.airplane.structs.ItemListWithBitset.fromList(inventory);
+ this.items = this.optimizedItems.nonNullList;
+ // Pufferfish end
}
@Override
diff --git a/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java
index f24a50b39393e5cdbb3b995d4a90faea142068f8..c2b40b0676a557c789ff3ce0ac1cb07345dee4b9 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java
@@ -47,7 +47,10 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
public static final int MOVE_ITEM_SPEED = 8;
public static final int HOPPER_CONTAINER_SIZE = 5;
private static final int[][] CACHED_SLOTS = new int[54][];
+ // Pufferfish start
private NonNullList<ItemStack> items;
+ private gg.airplane.structs.ItemListWithBitset optimizedItems; // Pufferfish
+ // Pufferfish end
public int cooldownTime;
private long tickedGameTime = Long.MIN_VALUE; // Folia - region threading
private Direction facing;
@@ -94,15 +97,38 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
public HopperBlockEntity(BlockPos pos, BlockState state) {
super(BlockEntityType.HOPPER, pos, state);
- this.items = NonNullList.withSize(5, ItemStack.EMPTY);
+ // Pufferfish start
+ this.optimizedItems = new gg.airplane.structs.ItemListWithBitset(5);
+ this.items = this.optimizedItems.nonNullList;
+ // Pufferfish end
this.cooldownTime = -1;
this.facing = (Direction) state.getValue(HopperBlock.FACING);
}
+ // Pufferfish start
+ @Override
+ public boolean hasEmptySlot(Direction enumdirection) {
+ return !this.optimizedItems.hasFullStacks();
+ }
+
+ @Override
+ public boolean isCompletelyFull(Direction enumdirection) {
+ return this.optimizedItems.hasFullStacks() && super.isCompletelyFull(enumdirection);
+ }
+
+ @Override
+ public boolean isCompletelyEmpty(Direction enumdirection) {
+ return this.optimizedItems.isCompletelyEmpty() || super.isCompletelyEmpty(enumdirection);
+ }
+ // Pufferfish end
+
@Override
protected void loadAdditional(CompoundTag nbt, HolderLookup.Provider registryLookup) {
super.loadAdditional(nbt, registryLookup);
- this.items = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);
+ // Pufferfish start
+ this.optimizedItems = new gg.airplane.structs.ItemListWithBitset(this.getContainerSize());
+ this.items = this.optimizedItems.nonNullList;
+ // Pufferfish end
if (!this.tryLoadLootTable(nbt)) {
ContainerHelper.loadAllItems(nbt, this.items, registryLookup);
}
@@ -537,6 +563,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
}
private static boolean isFullContainer(Container inventory, Direction direction) {
+ if (true) return inventory.isCompletelyFull(direction); // Pufferfish - use bitsets
int[] aint = HopperBlockEntity.getSlots(inventory, direction);
int[] aint1 = aint;
int i = aint.length;
@@ -736,7 +763,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
if (HopperBlockEntity.canPlaceItemInContainer(to, stack, slot, side)) {
boolean flag = false;
- boolean flag1 = to.isEmpty();
+ boolean flag1 = to.isCompletelyEmpty(side); // Pufferfish
if (itemstack1.isEmpty()) {
// Spigot start - SPIGOT-6693, InventorySubcontainer#setItem
@@ -924,7 +951,10 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
@Override
protected void setItems(NonNullList<ItemStack> inventory) {
- this.items = inventory;
+ // Pufferfish start
+ this.optimizedItems = gg.airplane.structs.ItemListWithBitset.fromList(inventory);
+ this.items = this.optimizedItems.nonNullList;
+ // Pufferfish end
}
public static void entityInside(Level world, BlockPos pos, BlockState state, Entity entity, HopperBlockEntity blockEntity) {

View File

@@ -1,6 +1,6 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Wed, 7 Feb 2024 04:55:43 +0000
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 12:05:17 +0800
Subject: [PATCH] Pufferfish Optimize suffocation
@@ -31,19 +31,19 @@ index 0000000000000000000000000000000000000000..3e48cd297b4869e5c89b6abc43c726d3
+ }
+}
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 00589ca4361482cdd852d699c4bc632ae85b5dd3..e49d18132e63ba7486c59fbb5cd236a872812e5c 100644
index f9a4ba5cc7c1029a5201e140c80648d07ca80936..c079466246af4345e185faf96043ec148fdea2a8 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -441,7 +441,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
boolean flag = this instanceof net.minecraft.world.entity.player.Player;
@@ -482,7 +482,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
if (!this.level().isClientSide) {
if (world1 instanceof ServerLevel) {
worldserver1 = (ServerLevel) world1;
- if (this.isInWall()) {
+ if (shouldCheckForSuffocation() && this.isInWall()) { // Pufferfish - optimize suffocation
this.hurt(this.damageSources().inWall(), 1.0F);
this.hurtServer(worldserver1, this.damageSources().inWall(), 1.0F);
} else if (flag && !this.level().getWorldBorder().isWithinBounds(this.getBoundingBox())) {
double d0 = this.level().getWorldBorder().getDistanceToBorder(this) + this.level().getWorldBorder().getDamageSafeZone();
@@ -1449,6 +1449,19 @@ public abstract class LivingEntity extends Entity implements Attackable {
double d1 = this.level().getWorldBorder().getDistanceToBorder(this) + this.level().getWorldBorder().getDamageSafeZone();
@@ -1456,6 +1456,19 @@ public abstract class LivingEntity extends Entity implements Attackable {
return this.getHealth() <= 0.0F;
}
@@ -61,13 +61,13 @@ index 00589ca4361482cdd852d699c4bc632ae85b5dd3..e49d18132e63ba7486c59fbb5cd236a8
+ // Pufferfish end
+
@Override
public boolean hurt(DamageSource source, float amount) {
if (this.isInvulnerableTo(source)) {
public boolean hurtServer(ServerLevel world, DamageSource source, float amount) {
if (this.isInvulnerableTo(world, source)) {
diff --git a/src/main/java/net/minecraft/world/entity/boss/wither/WitherBoss.java b/src/main/java/net/minecraft/world/entity/boss/wither/WitherBoss.java
index 7ddca52f7fe3f289b4b867e134326b1ead1a2aee..5040b1a7125dd9647a98fd812f558ec3a2171092 100644
index 244e38db508efa3eebebb6392c4ebb0805367baf..d62c0d3c2bd5df5ee908bdcfdffaae9ce780810f 100644
--- a/src/main/java/net/minecraft/world/entity/boss/wither/WitherBoss.java
+++ b/src/main/java/net/minecraft/world/entity/boss/wither/WitherBoss.java
@@ -154,6 +154,13 @@ public class WitherBoss extends Monster implements PowerableMob, RangedAttackMob
@@ -152,6 +152,13 @@ public class WitherBoss extends Monster implements RangedAttackMob {
this.bossEvent.setName(this.getDisplayName());
}

View File

@@ -0,0 +1,84 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 12:06:01 +0800
Subject: [PATCH] Pufferfish SIMD Utilities
diff --git a/build.gradle.kts b/build.gradle.kts
index bdff148efc08334708cd58f7af4b87d6a07ef69f..0345be6306b2d81987709c3feb31e2d7fb2f254f 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -88,6 +88,14 @@ paperweight {
craftBukkitPackageVersion.set("v1_21_R2") // also needs to be updated in MappingEnvironment
}
+
+// Pufferfish Start
+tasks.withType<JavaCompile> {
+ val compilerArgs = options.compilerArgs
+ compilerArgs.add("--add-modules=jdk.incubator.vector")
+}
+// Pufferfish End
+
tasks.jar {
archiveClassifier.set("dev")
diff --git a/src/main/java/me/earthme/luminol/config/modules/optimizations/SIMDConfig.java b/src/main/java/me/earthme/luminol/config/modules/optimizations/SIMDConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..76cea165bcef0794a66ef7c29721f7716869420f
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/optimizations/SIMDConfig.java
@@ -0,0 +1,53 @@
+package me.earthme.luminol.config.modules.optimizations;
+
+import com.electronwill.nightconfig.core.file.CommentedFileConfig;
+import com.mojang.logging.LogUtils;
+import gg.pufferfish.pufferfish.simd.SIMDDetection;
+import me.earthme.luminol.config.ConfigInfo;
+import me.earthme.luminol.config.DoNotLoad;
+import me.earthme.luminol.config.EnumConfigCategory;
+import me.earthme.luminol.config.IConfigModule;
+import org.slf4j.Logger;
+
+public class SIMDConfig implements IConfigModule {
+ @DoNotLoad
+ private static final Logger LOGGER = LogUtils.getLogger();
+ @ConfigInfo(baseName = "enabled")
+ public static boolean enabled = true;
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.OPTIMIZATIONS;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "use_simd";
+ }
+
+ @Override
+ public void onLoaded(CommentedFileConfig configInstance) {
+ if (!enabled){
+ return;
+ }
+
+ // Attempt to detect vectorization
+ try {
+ SIMDDetection.isEnabled = SIMDDetection.canEnable(LOGGER);
+ SIMDDetection.versionLimited = SIMDDetection.getJavaVersion() < 17;
+ } catch (NoClassDefFoundError | Exception ignored) {
+ ignored.printStackTrace();
+ }
+
+ if (SIMDDetection.isEnabled) {
+ LOGGER.info("SIMD operations detected as functional. Will replace some operations with faster versions.");
+ } else if (SIMDDetection.versionLimited) {
+ LOGGER.warn("Will not enable SIMD! These optimizations are only safely supported on Java 17+.");
+ } 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"), SIMDDetection.testRun);
+ }
+ }
+}

View File

@@ -1,104 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Wed, 7 Feb 2024 06:03:02 +0000
Subject: [PATCH] Gale Don't load chunks to activate climbing entities
diff --git a/src/main/java/me/earthme/luminol/config/modules/optimizations/LoadChunksToActiveClimbingEntitiesConfig.java b/src/main/java/me/earthme/luminol/config/modules/optimizations/LoadChunksToActiveClimbingEntitiesConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..ed62d25d6cd6dfcf8c5db20ced36eb3d3c79dafd
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/optimizations/LoadChunksToActiveClimbingEntitiesConfig.java
@@ -0,0 +1,20 @@
+package me.earthme.luminol.config.modules.optimizations;
+
+import me.earthme.luminol.config.ConfigInfo;
+import me.earthme.luminol.config.EnumConfigCategory;
+import me.earthme.luminol.config.IConfigModule;
+
+public class LoadChunksToActiveClimbingEntitiesConfig implements IConfigModule {
+ @ConfigInfo(baseName = "allow")
+ public static boolean allow = false;
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.OPTIMIZATIONS;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "load_chunks_to_active_climbing_entities";
+ }
+}
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 18c6fe66fa944f5e5b7892df4d8fef4c7346d3bc..a9e32fba699c718011abc52d91ec7158ab22b5ea 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -5515,6 +5515,16 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return this.inBlockState;
}
+ // Gale start - don't load chunks to activate climbing entities
+ public @Nullable BlockState getFeetBlockStateIfLoaded() {
+ if (this.inBlockState == null) {
+ this.inBlockState = this.level.getBlockStateIfLoaded(this.blockPosition());
+ }
+
+ return this.inBlockState;
+ }
+ // Gale end - don't load chunks to activate climbing entities
+
public ChunkPos chunkPosition() {
return this.chunkPosition;
}
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index e49d18132e63ba7486c59fbb5cd236a872812e5c..d4ab1b3253e4eeb72dd2e197757b446273bcc10e 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -2088,19 +2088,43 @@ public abstract class LivingEntity extends Entity implements Attackable {
public boolean onClimableCached() {
if (!this.blockPosition().equals(this.lastClimbingPosition)) {
- this.cachedOnClimable = this.onClimbable();
- this.lastClimbingPosition = this.blockPosition();
+ // Gale start - don't load chunks to activate climbing entities
+ Boolean onClimbableIfLoaded = this.onClimbable(me.earthme.luminol.config.modules.optimizations.LoadChunksToActiveClimbingEntitiesConfig.allow);
+ if (onClimbableIfLoaded != null) {
+ this.cachedOnClimable = onClimbableIfLoaded;
+ this.lastClimbingPosition = this.blockPosition();
+ } else {
+ this.cachedOnClimable = false;
+ this.lastClimbingPosition = null;
+ }
+ // Gale end - don't load chunks to activate climbing entities
}
return this.cachedOnClimable;
}
// Pufferfish end
public boolean onClimbable() {
+ // Gale start - don't load chunks to activate climbing entities
+ return onClimbable(true);
+ }
+
+ public Boolean onClimbable(boolean loadChunk) {
+ // Gale end - don't load chunks to activate climbing entities
if (this.isSpectator()) {
return false;
} else {
BlockPos blockposition = this.blockPosition();
- BlockState iblockdata = this.getInBlockState();
+ // Gale start - don't load chunks to activate climbing entities
+ BlockState iblockdata;
+ if (loadChunk) {
+ iblockdata = this.getInBlockState();
+ } else {
+ iblockdata = this.getFeetBlockStateIfLoaded();
+ if (iblockdata == null) {
+ return null;
+ }
+ }
+ // Gale end - don't load chunks to activate climbing entities
if (iblockdata.is(BlockTags.CLIMBABLE)) {
this.lastClimbablePos = Optional.of(blockposition);

View File

@@ -1,6 +1,6 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Wed, 7 Feb 2024 06:00:22 +0000
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 12:07:11 +0800
Subject: [PATCH] Gale Variable entity wake-up duration
@@ -31,10 +31,10 @@ index 0000000000000000000000000000000000000000..fa30e8dc39a2d4bd1399e41230b307b1
+ }
+}
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
index 9628cc2b7f200e0bab4fed48997dde3e266200ee..3a6ae320891f1e3202c59b63a5f2c96c18727314 100644
index 820145408fa2150820c4c14ea55bee23e7e9a366..57eb8bfb0e9d4a45d89eca75a2de219bff626bb5 100644
--- a/src/main/java/org/spigotmc/ActivationRange.java
+++ b/src/main/java/org/spigotmc/ActivationRange.java
@@ -75,28 +75,41 @@ public class ActivationRange
@@ -74,28 +74,41 @@ public class ActivationRange
if (entity.activationType == ActivationType.VILLAGER) {
if (inactiveFor > config.wakeUpInactiveVillagersEvery && worldData.wakeupInactiveRemainingVillagers > 0) { // Folia - threaded regions
worldData.wakeupInactiveRemainingVillagers--; // Folia - threaded regions

View File

@@ -1,23 +1,23 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: M2ke4U <79621885+MrHua269@users.noreply.github.com>
Date: Sun, 26 Nov 2023 17:21:44 +0800
From: MrHua269 <wangxyper@163.com>
Date: Sun, 4 Aug 2024 22:14:21 +0800
Subject: [PATCH] Gale Optimize sun burn tick
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index a9e32fba699c718011abc52d91ec7158ab22b5ea..f3c1a5b5880aefd1b3121be27172735134016437 100644
index 8d0aae7ae8abec5eac1357a1ea28df0cddab2f36..537187df8f400f8625216b0fc21cd19c3bf28e85 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -311,7 +311,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -274,7 +274,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
public double xo;
public double yo;
public double zo;
- private Vec3 position;
+ public Vec3 position; // Gale - JettPack - optimize sun burn tick - private -> public
public BlockPos blockPosition; // Pufferfish - private->public
private BlockPos blockPosition;
private ChunkPos chunkPosition;
private Vec3 deltaMovement;
@@ -2121,9 +2121,17 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -2204,9 +2204,19 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
/** @deprecated */
@Deprecated
public float getLightLevelDependentMagicValue() {
@@ -26,7 +26,9 @@ index a9e32fba699c718011abc52d91ec7158ab22b5ea..f3c1a5b5880aefd1b3121be271727351
}
+ // Gale start - JettPack - optimize sun burn tick - allow passing BlockPos to getLightLevelDependentMagicValue
+ /** @deprecated */
+ /**
+ * @deprecated
+ */
+ @Deprecated
+ public float getLightLevelDependentMagicValue(BlockPos pos) {
+ return this.level().hasChunkAt(this.getBlockX(), this.getBlockZ()) ? this.level.getLightLevelDependentMagicValue(pos) : 0.0F;
@@ -35,14 +37,14 @@ index a9e32fba699c718011abc52d91ec7158ab22b5ea..f3c1a5b5880aefd1b3121be271727351
+
public void absMoveTo(double x, double y, double z, float yaw, float pitch) {
this.absMoveTo(x, y, z);
this.setYRot(yaw % 360.0F);
this.absRotateTo(yaw, pitch);
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 78619c2ce66c34c4866755aa8c6c9ae18d594498..26362c7fa4fcc39f40c2736fd14647542e7161e2 100644
index 8082fb0d0793743ee6123f4bb5c6d79b078d5f86..0e0b971c93cdfd8cfae8019c4710f72fdd096c6a 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -1869,13 +1869,29 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Targeti
return flag;
}
@@ -1766,13 +1766,29 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
protected void playAttackSound() {}
+ // Gale start - JettPack - optimize sun burn tick - cache eye blockpos
+ private BlockPos cached_eye_blockpos;

View File

@@ -1,31 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Sun, 28 Jan 2024 09:30:22 +0000
Subject: [PATCH] Gale Check frozen ticks before landing block
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 30ee36f31069a11f87b7bd619020e25a342bae00..fffe8413eec4ae3eda2d21d958aa2534661a0558 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -608,11 +608,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
}
protected void tryAddFrost() {
- if (!this.getBlockStateOnLegacy().isAir()) {
int i = this.getTicksFrozen();
if (i > 0) {
- AttributeInstance attributemodifiable = this.getAttribute(Attributes.MOVEMENT_SPEED);
+ AttributeInstance attributemodifiable = this.getBlockStateOnLegacy().isAir() ? null : this.getAttribute(Attributes.MOVEMENT_SPEED); // Gale - Lithium - check frozen ticks before landing block
if (attributemodifiable == null) {
return;
@@ -622,7 +621,6 @@ public abstract class LivingEntity extends Entity implements Attackable {
attributemodifiable.addTransientModifier(new AttributeModifier(LivingEntity.SPEED_MODIFIER_POWDER_SNOW_UUID, "Powder snow slow", (double) f, AttributeModifier.Operation.ADD_VALUE));
}
- }
}

View File

@@ -1,6 +1,6 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Sun, 28 Jan 2024 09:31:27 +0000
From: MrHua269 <wangxyper@163.com>
Date: Wed, 31 Jul 2024 13:38:04 +0800
Subject: [PATCH] Gale Use platform math functions
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
@@ -98,45 +98,11 @@ public class Main {
}
```
diff --git a/src/main/java/io/papermc/paper/util/MCUtil.java b/src/main/java/io/papermc/paper/util/MCUtil.java
index 2034c67f5702b7b8d093ef2dd7601901c5fef363..2a88165dd4edbc2ca1acd2f6e0a4b99ec61cf958 100644
--- a/src/main/java/io/papermc/paper/util/MCUtil.java
+++ b/src/main/java/io/papermc/paper/util/MCUtil.java
@@ -168,13 +168,11 @@ public final class MCUtil {
}
public static int fastFloor(double x) {
- int truncated = (int)x;
- return x < (double)truncated ? truncated - 1 : truncated;
+ return (int) Math.floor(x); // Gale - use platform math functions
}
public static int fastFloor(float x) {
- int truncated = (int)x;
- return x < (double)truncated ? truncated - 1 : truncated;
+ return (int) Math.floor(x); // Gale - use platform math functions
}
public static float normalizeYaw(float f) {
@@ -235,11 +233,11 @@ public final class MCUtil {
}
public static int getChunkCoordinate(final double coordinate) {
- return MCUtil.fastFloor(coordinate) >> 4;
+ return ((int) Math.floor(coordinate)) >> 4; // Gale - use platform math functions
}
public static int getBlockCoordinate(final double coordinate) {
- return MCUtil.fastFloor(coordinate);
+ return (int) Math.floor(coordinate); // Gale - use platform math functions
}
public static long getBlockKey(final int x, final int y, final int z) {
diff --git a/src/main/java/net/minecraft/util/Mth.java b/src/main/java/net/minecraft/util/Mth.java
index 990ea96de8e940390b67e9462fcfd6025f2f5770..e102c109d01e0f992808a6096b5f6a323b52d970 100644
index ef93fc37759e0b54387c8a59adc2b19258cfeb7d..6b21782ad18cd5dbd1b9a59e5dc12c670c2a42fb 100644
--- a/src/main/java/net/minecraft/util/Mth.java
+++ b/src/main/java/net/minecraft/util/Mth.java
@@ -58,13 +58,11 @@ public class Mth {
@@ -58,18 +58,15 @@ public class Mth {
}
public static int floor(float value) {
@@ -152,7 +118,13 @@ index 990ea96de8e940390b67e9462fcfd6025f2f5770..e102c109d01e0f992808a6096b5f6a32
}
public static long lfloor(double value) {
@@ -81,13 +79,11 @@ public class Mth {
- long l = (long)value;
- return value < (double)l ? l - 1L : l;
+ return (long) Math.floor(value); // Gale - use platform math functions
}
public static float abs(float value) {
@@ -81,13 +78,11 @@ public class Mth {
}
public static int ceil(float value) {
@@ -168,7 +140,7 @@ index 990ea96de8e940390b67e9462fcfd6025f2f5770..e102c109d01e0f992808a6096b5f6a32
}
public static int clamp(int value, int min, int max) {
@@ -123,15 +119,7 @@ public class Mth {
@@ -123,15 +118,7 @@ public class Mth {
}
public static double absMax(double a, double b) {

View File

@@ -1,19 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Sun, 28 Jan 2024 09:31:27 +0000
Subject: [PATCH] Gale Don't trigger lootable refresh for non-player
interaction
diff --git a/src/main/java/net/minecraft/world/level/block/entity/RandomizableContainerBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/RandomizableContainerBlockEntity.java
index 17da915ffa638500a83b67db0940a7b9a9b333a1..e47c9481f39426e1767e73275edbf9a1d298caea 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/RandomizableContainerBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/RandomizableContainerBlockEntity.java
@@ -74,6 +74,7 @@ public abstract class RandomizableContainerBlockEntity extends BaseContainerBloc
@Override
public void unpackLootTable(@org.jetbrains.annotations.Nullable final Player player) {
+ if (player == null) return; // Gale - EMC - don't trigger lootable refresh for non-player interaction
// Copied from super with changes, always check the original method
net.minecraft.world.level.Level level = this.getLevel();
BlockPos blockPos = this.getBlockPos();

View File

@@ -1,11 +1,11 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Sat, 6 Apr 2024 05:18:00 +0000
From: MrHua269 <wangxyper@163.com>
Date: Wed, 31 Jul 2024 14:22:07 +0800
Subject: [PATCH] Gale Replace throttle tracker map with optimized collection
diff --git a/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
index 45a2683c9489bee6d67a1f3d702c17f2e9dc02e4..8e90f35218e66690359dac35828a1485a77f34c1 100644
index ddf42645402afefc0f5caebc684b191eef9d6ec2..a943f83e874d348251ddd3feb732e543641172d9 100644
--- a/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
@@ -1,5 +1,7 @@
@@ -15,8 +15,8 @@ index 45a2683c9489bee6d67a1f3d702c17f2e9dc02e4..8e90f35218e66690359dac35828a1485
+import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
import net.minecraft.SharedConstants;
import net.minecraft.network.Connection;
import net.minecraft.network.chat.Component;
@@ -14,7 +16,8 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.network.DisconnectionDetails;
@@ -15,7 +17,8 @@ import net.minecraft.server.MinecraftServer;
// CraftBukkit start
import java.net.InetAddress;
@@ -26,7 +26,7 @@ index 45a2683c9489bee6d67a1f3d702c17f2e9dc02e4..8e90f35218e66690359dac35828a1485
// CraftBukkit end
public class ServerHandshakePacketListenerImpl implements ServerHandshakePacketListener {
@@ -25,7 +28,7 @@ public class ServerHandshakePacketListenerImpl implements ServerHandshakePacketL
@@ -26,7 +29,7 @@ public class ServerHandshakePacketListenerImpl implements ServerHandshakePacketL
static final java.util.regex.Pattern PROP_PATTERN = java.util.regex.Pattern.compile("\\w{0,16}");
// Spigot end
// CraftBukkit start - add fields
@@ -35,7 +35,7 @@ index 45a2683c9489bee6d67a1f3d702c17f2e9dc02e4..8e90f35218e66690359dac35828a1485
private static int throttleCounter = 0;
// CraftBukkit end
private static final Component IGNORE_STATUS_REASON = Component.translatable("disconnect.ignoring_status_request");
@@ -86,7 +89,7 @@ public class ServerHandshakePacketListenerImpl implements ServerHandshakePacketL
@@ -87,7 +90,7 @@ public class ServerHandshakePacketListenerImpl implements ServerHandshakePacketL
InetAddress address = ((java.net.InetSocketAddress) this.connection.getRemoteAddress()).getAddress();
synchronized (ServerHandshakePacketListenerImpl.throttleTracker) {
@@ -44,7 +44,7 @@ index 45a2683c9489bee6d67a1f3d702c17f2e9dc02e4..8e90f35218e66690359dac35828a1485
ServerHandshakePacketListenerImpl.throttleTracker.put(address, currentTime);
Component chatmessage = io.papermc.paper.adventure.PaperAdventure.asVanilla(io.papermc.paper.configuration.GlobalConfiguration.get().messages.kick.connectionThrottle); // Paper - Configurable connection throttle kick message
this.connection.send(new ClientboundLoginDisconnectPacket(chatmessage));
@@ -100,13 +103,7 @@ public class ServerHandshakePacketListenerImpl implements ServerHandshakePacketL
@@ -101,13 +104,7 @@ public class ServerHandshakePacketListenerImpl implements ServerHandshakePacketL
ServerHandshakePacketListenerImpl.throttleCounter = 0;
// Cleanup stale entries

View File

@@ -1,183 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Fri, 9 Feb 2024 23:43:16 +0000
Subject: [PATCH] Gale Optimize world generation chunk and block access
diff --git a/src/main/java/me/jellysquid/mods/lithium/common/util/Pos.java b/src/main/java/me/jellysquid/mods/lithium/common/util/Pos.java
new file mode 100644
index 0000000000000000000000000000000000000000..f2f10b651e4fbecdd1ea1bc28ebf40d685a67cee
--- /dev/null
+++ b/src/main/java/me/jellysquid/mods/lithium/common/util/Pos.java
@@ -0,0 +1,95 @@
+// Gale - Lithium - position utility
+
+package me.jellysquid.mods.lithium.common.util;
+
+import net.minecraft.core.SectionPos;
+import net.minecraft.world.level.LevelHeightAccessor;
+
+public class Pos {
+
+ public static class BlockCoord {
+ public static int getYSize(LevelHeightAccessor view) {
+ return view.getHeight();
+ }
+ public static int getMinY(LevelHeightAccessor view) {
+ return view.getMinBuildHeight();
+ }
+ public static int getMaxYInclusive(LevelHeightAccessor view) {
+ return view.getMaxBuildHeight() - 1;
+ }
+ public static int getMaxYExclusive(LevelHeightAccessor view) {
+ return view.getMaxBuildHeight();
+ }
+
+ public static int getMaxInSectionCoord(int sectionCoord) {
+ return 15 + getMinInSectionCoord(sectionCoord);
+ }
+
+ public static int getMaxYInSectionIndex(LevelHeightAccessor view, int sectionIndex){
+ return getMaxInSectionCoord(SectionYCoord.fromSectionIndex(view, sectionIndex));
+ }
+
+ public static int getMinInSectionCoord(int sectionCoord) {
+ return SectionPos.sectionToBlockCoord(sectionCoord);
+ }
+
+ public static int getMinYInSectionIndex(LevelHeightAccessor view, int sectionIndex) {
+ return getMinInSectionCoord(SectionYCoord.fromSectionIndex(view, sectionIndex));
+ }
+ }
+
+ public static class ChunkCoord {
+ public static int fromBlockCoord(int blockCoord) {
+ return SectionPos.blockToSectionCoord(blockCoord);
+ }
+
+ public static int fromBlockSize(int i) {
+ return i >> 4; //same method as fromBlockCoord, just be clear about coord/size semantic difference
+ }
+ }
+
+ public static class SectionYCoord {
+ public static int getNumYSections(LevelHeightAccessor view) {
+ return view.getSectionsCount();
+ }
+ public static int getMinYSection(LevelHeightAccessor view) {
+ return view.getMinSection();
+ }
+ public static int getMaxYSectionInclusive(LevelHeightAccessor view) {
+ return view.getMaxSection() - 1;
+ }
+ public static int getMaxYSectionExclusive(LevelHeightAccessor view) {
+ return view.getMaxSection();
+ }
+
+ public static int fromSectionIndex(LevelHeightAccessor view, int sectionCoord) {
+ return sectionCoord + SectionYCoord.getMinYSection(view);
+ }
+ public static int fromBlockCoord(int blockCoord) {
+ return SectionPos.blockToSectionCoord(blockCoord);
+ }
+ }
+
+ public static class SectionYIndex {
+ public static int getNumYSections(LevelHeightAccessor view) {
+ return view.getSectionsCount();
+ }
+ public static int getMinYSectionIndex(LevelHeightAccessor view) {
+ return 0;
+ }
+ public static int getMaxYSectionIndexInclusive(LevelHeightAccessor view) {
+ return view.getSectionsCount() - 1;
+ }
+ public static int getMaxYSectionIndexExclusive(LevelHeightAccessor view) {
+ return view.getSectionsCount();
+ }
+
+ public static int fromSectionCoord(LevelHeightAccessor view, int sectionCoord) {
+ return sectionCoord - SectionYCoord.getMinYSection(view);
+ }
+ public static int fromBlockCoord(LevelHeightAccessor view, int blockCoord) {
+ return fromSectionCoord(view, SectionPos.blockToSectionCoord(blockCoord));
+ }
+ }
+
+}
diff --git a/src/main/java/net/minecraft/server/level/WorldGenRegion.java b/src/main/java/net/minecraft/server/level/WorldGenRegion.java
index 888cf5257fba032b9edd95a89e71ca8b4ed1fb81..dc89751d1ddd71fb98657abfdb67da7f395ef3db 100644
--- a/src/main/java/net/minecraft/server/level/WorldGenRegion.java
+++ b/src/main/java/net/minecraft/server/level/WorldGenRegion.java
@@ -86,6 +86,10 @@ public class WorldGenRegion implements WorldGenLevel {
private Supplier<String> currentlyGenerating;
private final AtomicLong subTickCount = new AtomicLong();
private static final ResourceLocation WORLDGEN_REGION_RANDOM = new ResourceLocation("worldgen_region_random");
+ // Gale start - Lithium - optimize world generation chunk and block access
+ private ChunkAccess[] chunksArr;
+ private int minChunkX, minChunkZ;
+ // Gale end - Lithium - optimize world generation chunk and block access
// Folia start - region threading
private final net.minecraft.world.level.StructureManager structureManager;
@@ -116,6 +120,11 @@ public class WorldGenRegion implements WorldGenLevel {
this.lastPos = ((ChunkAccess) chunks.get(chunks.size() - 1)).getPos();
this.structureManager = world.structureManager().forWorldGenRegion(this); // Folia - region threading
}
+ // Gale start - Lithium - optimize world generation chunk and block access
+ this.minChunkX = this.firstPos.x;
+ this.minChunkZ = this.firstPos.z;
+ this.chunksArr = chunks.toArray(new ChunkAccess[0]);
+ // Gale end - Lithium - optimize world generation chunk and block access
}
// Paper start - starlight
@@ -154,8 +163,28 @@ public class WorldGenRegion implements WorldGenLevel {
@Override
public ChunkAccess getChunk(int chunkX, int chunkZ) {
- return this.getChunk(chunkX, chunkZ, ChunkStatus.EMPTY);
+ // Gale start - Lithium - optimize world generation chunk and block access - use the chunk array for faster access
+ int x = chunkX - this.minChunkX;
+ int z = chunkZ - this.minChunkZ;
+ int w = this.size;
+
+ if (x >= 0 && z >= 0 && x < w && z < w) {
+ return this.chunksArr[x + z * w];
+ } else {
+ throw new NullPointerException("No chunk exists at " + new ChunkPos(chunkX, chunkZ));
+ }
+ // Gale end - Lithium - optimize world generation chunk and block access - use the chunk array for faster access
+ }
+
+ // Gale start - Lithium - optimize world generation chunk and block access
+ /**
+ * Use our chunk fetch function
+ */
+ public ChunkAccess getChunk(BlockPos pos) {
+ // Skip checking chunk.getStatus().isAtLeast(ChunkStatus.EMPTY) here, because it is always true
+ return this.getChunk(SectionPos.blockToSectionCoord(pos.getX()), SectionPos.blockToSectionCoord(pos.getZ()));
}
+ // Gale end - Lithium - optimize world generation chunk and block access
@Nullable
@Override
@@ -220,7 +249,17 @@ public class WorldGenRegion implements WorldGenLevel {
@Override
public BlockState getBlockState(BlockPos pos) {
- return this.getChunk(SectionPos.blockToSectionCoord(pos.getX()), SectionPos.blockToSectionCoord(pos.getZ())).getBlockState(pos);
+ // Gale start - Lithium - optimize world generation chunk and block access - avoid pointer de-referencing, make method easier to inline
+ int x = SectionPos.blockToSectionCoord(pos.getX()) - this.minChunkX;
+ int z = SectionPos.blockToSectionCoord(pos.getZ()) - this.minChunkZ;
+ int w = this.size;
+
+ if (x >= 0 && z >= 0 && x < w && z < w) {
+ return this.chunksArr[x + z * w].getBlockState(pos);
+ } else {
+ throw new NullPointerException("No chunk exists at " + new ChunkPos(pos));
+ }
+ // Gale end - Lithium - optimize world generation chunk and block access - avoid pointer de-referencing, make method easier to inline
}
@Override

View File

@@ -1,14 +1,14 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Tue, 6 Feb 2024 04:21:05 +0000
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 12:13:26 +0800
Subject: [PATCH] Gale Skip entity move if movement is zero
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index f3c1a5b5880aefd1b3121be27172735134016437..d975134fe5dd38a8655406a39821593f055b7381 100644
index 537187df8f400f8625216b0fc21cd19c3bf28e85..75182b1f12ed5ad0ff541aee28b40a72b783230d 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -320,6 +320,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -283,6 +283,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
public float yRotO;
public float xRotO;
private AABB bb;
@@ -16,10 +16,10 @@ index f3c1a5b5880aefd1b3121be27172735134016437..d975134fe5dd38a8655406a39821593f
public boolean onGround;
public boolean horizontalCollision;
public boolean verticalCollision;
@@ -1144,6 +1145,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -1181,6 +1182,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
//Luminol end
public void move(MoverType movementType, Vec3 movement) {
public void move(MoverType type, Vec3 movement) {
+ // Gale start - VMP - skip entity move if movement is zero
+ if (!this.boundingBoxChanged && movement.equals(Vec3.ZERO)) {
+ return;
@@ -27,8 +27,8 @@ index f3c1a5b5880aefd1b3121be27172735134016437..d975134fe5dd38a8655406a39821593f
+ // Gale end - VMP - skip entity move if movement is zero
final Vec3 originalMovement = movement; // Paper - Expose pre-collision velocity
// Paper start - detailed watchdog information
io.papermc.paper.util.TickThread.ensureTickThread("Cannot move an entity off-main");
@@ -5006,6 +5012,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread("Cannot move an entity off-main");
@@ -5245,6 +5251,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
public final void setBoundingBox(AABB boundingBox) {

View File

@@ -1,27 +1,27 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Sun, 28 Jan 2024 09:11:58 +0000
From: MrHua269 <wangxyper@163.com>
Date: Wed, 31 Jul 2024 14:25:46 +0800
Subject: [PATCH] Sparkly Paper Optimize canSee checks
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index c547d51eebd965f2be7ac45bc0981626c0515ef1..b7d91b7e8eb31f838cf540246f2d9b9c32b28780 100644
index ad6d635971d0f5d23c923b1dc83c0b18e8f4a94a..926e070e3b3f1a8ce8a9c668e39239a837b35b0e 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -1422,7 +1422,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
@@ -1256,7 +1256,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
// Folia end - region threading
// CraftBukkit start - respect vanish API
- if (flag && (!io.papermc.paper.util.TickThread.isTickThreadFor(player) || !player.getBukkitEntity().canSee(this.entity.getBukkitEntity()))) { // Paper - only consider hits // Folia - region threading
+ if (flag && (!io.papermc.paper.util.TickThread.isTickThreadFor(player) || !player.getBukkitEntity().canSeeChunkMapUpdatePlayer(this.entity.getBukkitEntity()))) { // Paper - only consider hits // Folia - region threading // SparklyPaper - optimize canSee checks
- if (flag && (!ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(player) || !player.getBukkitEntity().canSee(this.entity.getBukkitEntity()))) { // Paper - only consider hits // Folia - region threading
+ if (flag && (!ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(player) || !player.getBukkitEntity().canSeeChunkMapUpdatePlayer(this.entity.getBukkitEntity()))) { // Paper - only consider hits // Folia - region threading // SparklyPaper - optimize canSee checks
flag = false;
}
// CraftBukkit end
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index ed4bdf27c38d881fd3896a736652686ff9107f16..eb5ec3637aedb643801f369e43d39ef987546ce0 100644
index 566c404acfced53414f3d0facd22d03b71841587..611caf02205a7a97aa1175ab6250124d547bd071 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -198,7 +198,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@@ -205,7 +205,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
private boolean hasPlayedBefore = false;
private final ConversationTracker conversationTracker = new ConversationTracker();
private final Set<String> channels = new HashSet<String>();
@@ -30,7 +30,7 @@ index ed4bdf27c38d881fd3896a736652686ff9107f16..eb5ec3637aedb643801f369e43d39ef9
private final Set<UUID> unlistedEntities = new HashSet<>(); // Paper - Add Listing API for Player
private static final WeakHashMap<Plugin, WeakReference<Plugin>> pluginWeakReferences = new WeakHashMap<>();
private int hash = 0;
@@ -2233,9 +2233,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@@ -2269,9 +2269,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override
public boolean canSee(org.bukkit.entity.Entity entity) {

View File

@@ -1,424 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Tue, 20 Feb 2024 13:21:53 +0000
Subject: [PATCH] Gale Faster chunk serialization
diff --git a/src/main/java/me/jellysquid/mods/lithium/common/world/chunk/LithiumHashPalette.java b/src/main/java/me/jellysquid/mods/lithium/common/world/chunk/LithiumHashPalette.java
new file mode 100644
index 0000000000000000000000000000000000000000..349618b7f544bf9a30e0796d4d9a26407a2b8329
--- /dev/null
+++ b/src/main/java/me/jellysquid/mods/lithium/common/world/chunk/LithiumHashPalette.java
@@ -0,0 +1,192 @@
+// Gale - Lithium - faster chunk serialization
+
+package me.jellysquid.mods.lithium.common.world.chunk;
+
+import com.google.common.collect.ImmutableList;
+import it.unimi.dsi.fastutil.HashCommon;
+import it.unimi.dsi.fastutil.objects.Reference2IntMap;
+import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap;
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.Predicate;
+import net.minecraft.core.IdMap;
+import net.minecraft.network.FriendlyByteBuf;
+import net.minecraft.network.VarInt;
+import net.minecraft.world.level.chunk.Palette;
+import net.minecraft.world.level.chunk.PaletteResize;
+
+import static it.unimi.dsi.fastutil.Hash.FAST_LOAD_FACTOR;
+
+/**
+ * Generally provides better performance over the vanilla {@link net.minecraft.world.level.chunk.HashMapPalette} when calling
+ * {@link LithiumHashPalette#idFor(Object)} through using a faster backing map and reducing pointer chasing.
+ */
+public class LithiumHashPalette<T> implements Palette<T> {
+ private static final int ABSENT_VALUE = -1;
+
+ private final IdMap<T> idList;
+ private final PaletteResize<T> resizeHandler;
+ private final int indexBits;
+
+ private final Reference2IntMap<T> table;
+ private T[] entries;
+ private int size = 0;
+
+ public LithiumHashPalette(IdMap<T> idList, PaletteResize<T> resizeHandler, int indexBits, T[] entries, Reference2IntMap<T> table, int size) {
+ this.idList = idList;
+ this.resizeHandler = resizeHandler;
+ this.indexBits = indexBits;
+ this.entries = entries;
+ this.table = table;
+ this.size = size;
+ }
+
+ public LithiumHashPalette(IdMap<T> idList, int bits, PaletteResize<T> resizeHandler, List<T> list) {
+ this(idList, bits, resizeHandler);
+
+ for (T t : list) {
+ this.addEntry(t);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public LithiumHashPalette(IdMap<T> idList, int bits, PaletteResize<T> resizeHandler) {
+ this.idList = idList;
+ this.indexBits = bits;
+ this.resizeHandler = resizeHandler;
+
+ int capacity = 1 << bits;
+
+ this.entries = (T[]) new Object[capacity];
+ this.table = new Reference2IntOpenHashMap<>(capacity, FAST_LOAD_FACTOR);
+ this.table.defaultReturnValue(ABSENT_VALUE);
+ }
+
+ @Override
+ public int idFor(T obj) {
+ int id = this.table.getInt(obj);
+
+ if (id == ABSENT_VALUE) {
+ id = this.computeEntry(obj);
+ }
+
+ return id;
+ }
+
+ @Override
+ public boolean maybeHas(Predicate<T> predicate) {
+ for (int i = 0; i < this.size; ++i) {
+ if (predicate.test(this.entries[i])) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private int computeEntry(T obj) {
+ int id = this.addEntry(obj);
+
+ if (id >= 1 << this.indexBits) {
+ if (this.resizeHandler == null) {
+ throw new IllegalStateException("Cannot grow");
+ } else {
+ id = this.resizeHandler.onResize(this.indexBits + 1, obj);
+ }
+ }
+
+ return id;
+ }
+
+ private int addEntry(T obj) {
+ int nextId = this.size;
+
+ if (nextId >= this.entries.length) {
+ this.resize(this.size);
+ }
+
+ this.table.put(obj, nextId);
+ this.entries[nextId] = obj;
+
+ this.size++;
+
+ return nextId;
+ }
+
+ private void resize(int neededCapacity) {
+ this.entries = Arrays.copyOf(this.entries, HashCommon.nextPowerOfTwo(neededCapacity + 1));
+ }
+
+ @Override
+ public T valueFor(int id) {
+ T[] entries = this.entries;
+
+ if (id >= 0 && id < entries.length) {
+ return entries[id];
+ }
+
+ return null;
+ }
+
+ @Override
+ public void read(FriendlyByteBuf buf) {
+ this.clear();
+
+ int entryCount = buf.readVarInt();
+
+ for (int i = 0; i < entryCount; ++i) {
+ this.addEntry(this.idList.byId(buf.readVarInt()));
+ }
+ }
+
+ @Override
+ public void write(FriendlyByteBuf buf) {
+ int size = this.size;
+ buf.writeVarInt(size);
+
+ for (int i = 0; i < size; ++i) {
+ buf.writeVarInt(this.idList.getId(this.valueFor(i)));
+ }
+ }
+
+ @Override
+ public int getSerializedSize() {
+ int size = VarInt.getByteSize(this.size);
+
+ for (int i = 0; i < this.size; ++i) {
+ size += VarInt.getByteSize(this.idList.getId(this.valueFor(i)));
+ }
+
+ return size;
+ }
+
+ @Override
+ public int getSize() {
+ return this.size;
+ }
+
+ @Override
+ public Palette<T> copy() {
+ return new LithiumHashPalette<>(this.idList, this.resizeHandler, this.indexBits, this.entries.clone(), new Reference2IntOpenHashMap<>(this.table), this.size);
+ }
+
+ private void clear() {
+ Arrays.fill(this.entries, null);
+ this.table.clear();
+ this.size = 0;
+ }
+
+ public List<T> getElements() {
+ ImmutableList.Builder<T> builder = new ImmutableList.Builder<>();
+ for (T entry : this.entries) {
+ if (entry != null) {
+ builder.add(entry);
+ }
+ }
+ return builder.build();
+ }
+
+ public static <A> Palette<A> create(int bits, IdMap<A> idList, PaletteResize<A> listener, List<A> list) {
+ return new LithiumHashPalette<>(idList, bits, listener, list);
+ }
+}
diff --git a/src/main/java/net/minecraft/util/BitStorage.java b/src/main/java/net/minecraft/util/BitStorage.java
index 8bafd5fd7499ba4a04bf706cfd1e156073716e21..f62aab492f231e688b448389b1910e6fc2f5d8e6 100644
--- a/src/main/java/net/minecraft/util/BitStorage.java
+++ b/src/main/java/net/minecraft/util/BitStorage.java
@@ -31,4 +31,6 @@ public interface BitStorage {
}
// Paper end
+
+ <T> void compact(net.minecraft.world.level.chunk.Palette<T> srcPalette, net.minecraft.world.level.chunk.Palette<T> dstPalette, short[] out); // Gale - Lithium - faster chunk serialization
}
diff --git a/src/main/java/net/minecraft/util/SimpleBitStorage.java b/src/main/java/net/minecraft/util/SimpleBitStorage.java
index 8d7d763bf51cac556057645e6169c9447993189b..c1e5f04df9529e9236a5c8a047b02ad560085025 100644
--- a/src/main/java/net/minecraft/util/SimpleBitStorage.java
+++ b/src/main/java/net/minecraft/util/SimpleBitStorage.java
@@ -389,4 +389,45 @@ public class SimpleBitStorage implements BitStorage {
super(message);
}
}
+
+ // Gale 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;
+ }
+ }
+ }
+ }
+ // Gale end - Lithium - faster chunk serialization
+
}
diff --git a/src/main/java/net/minecraft/util/ZeroBitStorage.java b/src/main/java/net/minecraft/util/ZeroBitStorage.java
index 01f5b946fabbe34f31110e75973dab9f39897346..1cd79ab7635d4a5e55538c1130f487245f45b4b6 100644
--- a/src/main/java/net/minecraft/util/ZeroBitStorage.java
+++ b/src/main/java/net/minecraft/util/ZeroBitStorage.java
@@ -71,4 +71,6 @@ public class ZeroBitStorage implements BitStorage {
public BitStorage copy() {
return this;
}
+
+ @Override public <T> void compact(net.minecraft.world.level.chunk.Palette<T> srcPalette, net.minecraft.world.level.chunk.Palette<T> dstPalette, short[] out) {} // Gale - Lithium - faster chunk serialization
}
diff --git a/src/main/java/net/minecraft/world/level/chunk/PaletteResize.java b/src/main/java/net/minecraft/world/level/chunk/PaletteResize.java
index acae3eb30e0689048937f479dc3070f0688abdad..4b79f0474a9013dd4fdb68c6363ca1942ba8b007 100644
--- a/src/main/java/net/minecraft/world/level/chunk/PaletteResize.java
+++ b/src/main/java/net/minecraft/world/level/chunk/PaletteResize.java
@@ -1,5 +1,5 @@
package net.minecraft.world.level.chunk;
-interface PaletteResize<T> {
+public interface PaletteResize<T> { // Gale - Lithium - faster chunk serialization - package -> public
int onResize(int newBits, T object);
}
diff --git a/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java b/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java
index adfbdca12fbdee2602feb0158674166d5256e49e..9990e60f61d678e20cfffe22848eb5cc7c554b8a 100644
--- a/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java
+++ b/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java
@@ -25,6 +25,22 @@ import net.minecraft.util.ThreadingDetector;
import net.minecraft.util.ZeroBitStorage;
public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainerRO<T> {
+
+ // Gale 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];
+ };
+ }
+ // Gale end - Lithium - faster chunk serialization
+
private static final int MIN_PALETTE_BITS = 0;
private final PaletteResize<T> dummyPaletteResize = (newSize, added) -> 0;
public final IdMap<T> registry;
@@ -304,28 +320,54 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
public synchronized PalettedContainerRO.PackedData<T> pack(IdMap<T> idList, PalettedContainer.Strategy paletteProvider) { // Paper - synchronize
this.acquire();
- PalettedContainerRO.PackedData var12;
+ // Gale start - Lithium - faster chunk serialization
+ Optional<LongStream> data = Optional.empty();
+ List<T> elements = null;
try {
- HashMapPalette<T> hashMapPalette = new HashMapPalette<>(idList, this.data.storage.getBits(), this.dummyPaletteResize);
- int i = paletteProvider.size();
- int[] is = new int[i];
- this.data.storage.unpack(is);
- swapPalette(is, id -> hashMapPalette.idFor(this.data.palette.valueFor(id)));
- int j = paletteProvider.calculateBitsForSerialization(idList, hashMapPalette.getSize());
- Optional<LongStream> optional;
- if (j != 0) {
- SimpleBitStorage simpleBitStorage = new SimpleBitStorage(j, i, is);
- optional = Optional.of(Arrays.stream(simpleBitStorage.getRaw()));
- } else {
- optional = Optional.empty();
+ // The palette that will be serialized
+ me.jellysquid.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) {
+ // If the palette only contains one entry, don't attempt to repack it.
+ elements = List.of(palette.valueFor(0));
+ } else if (palette instanceof me.jellysquid.mods.lithium.common.world.chunk.LithiumHashPalette<T> lithiumHashPalette) {
+ hashPalette = lithiumHashPalette;
}
- var12 = new PalettedContainerRO.PackedData<>(hashMapPalette.getEntries(), optional);
+ if (elements == null) {
+ me.jellysquid.mods.lithium.common.world.chunk.LithiumHashPalette<T> compactedPalette = new me.jellysquid.mods.lithium.common.world.chunk.LithiumHashPalette<>(idList, storage.getBits(), this.dummyPaletteResize);
+ short[] array = this.getOrCreate(paletteProvider.size());
+
+ storage.compact(this.data.palette(), compactedPalette, array);
+
+ // If the palette didn't change during compaction, do a simple copy of the data array
+ if (hashPalette != null && hashPalette.getSize() == compactedPalette.getSize() && storage.getBits() == paletteProvider.calculateBitsForSerialization(idList, 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 = paletteProvider.calculateBitsForSerialization(idList, compactedPalette.getSize());
+ if (bits != 0) {
+ // Re-pack the integer array as the palette has changed size
+ SimpleBitStorage copy = new SimpleBitStorage(bits, array.length);
+ for (int i = 0; i < array.length; ++i) {
+ copy.set(i, array[i]);
+ }
+
+ // We don't need to clone the data array as we are the sole owner of it
+ data = this.asOptional(copy.getRaw());
+ }
+
+ elements = compactedPalette.getElements();
+ }
+ }
} finally {
this.release();
}
- return var12;
+ return new PalettedContainerRO.PackedData<>(elements, data);
+ // Gale end - Lithium - faster chunk serialization
}
private static <T> void swapPalette(int[] is, IntUnaryOperator applier) {
@@ -364,13 +406,33 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
@Override
public void count(PalettedContainer.CountConsumer<T> counter) {
- if (this.data.palette.getSize() == 1) {
- counter.accept(this.data.palette.valueFor(0), this.data.storage.getSize());
- } else {
- Int2IntOpenHashMap int2IntOpenHashMap = new Int2IntOpenHashMap();
- this.data.storage.getAll(key -> int2IntOpenHashMap.addTo(key, 1));
- int2IntOpenHashMap.int2IntEntrySet().forEach(entry -> counter.accept(this.data.palette.valueFor(entry.getIntKey()), entry.getIntValue()));
+ // Gale start - Lithium - faster chunk serialization
+ int len = this.data.palette().getSize();
+
+ // Do not allocate huge arrays if we're using a large palette
+ if (len > 4096) {
+ // VanillaCopy
+ if (this.data.palette.getSize() == 1) {
+ counter.accept(this.data.palette.valueFor(0), this.data.storage.getSize());
+ } else {
+ Int2IntOpenHashMap int2IntOpenHashMap = new Int2IntOpenHashMap();
+ this.data.storage.getAll(key -> int2IntOpenHashMap.addTo(key, 1));
+ int2IntOpenHashMap.int2IntEntrySet().forEach(entry -> counter.accept(this.data.palette.valueFor(entry.getIntKey()), entry.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) {
+ counter.accept(obj, counts[i]);
+ }
}
+ // Gale end - Lithium - faster chunk serialization
}
static record Configuration<T>(Palette.Factory factory, int bits) {

View File

@@ -0,0 +1,45 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <wangxyper@163.com>
Date: Wed, 31 Jul 2024 14:28:06 +0800
Subject: [PATCH] SparklyPaper Skip "MapItem#update()" if the map does not have
diff --git a/src/main/java/me/earthme/luminol/config/modules/optimizations/MapItemUpdateSkipConfig.java b/src/main/java/me/earthme/luminol/config/modules/optimizations/MapItemUpdateSkipConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..6235ff18455a21695bdc2d65367558d3936a45c5
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/optimizations/MapItemUpdateSkipConfig.java
@@ -0,0 +1,20 @@
+package me.earthme.luminol.config.modules.optimizations;
+
+import me.earthme.luminol.config.ConfigInfo;
+import me.earthme.luminol.config.EnumConfigCategory;
+import me.earthme.luminol.config.IConfigModule;
+
+public class MapItemUpdateSkipConfig implements IConfigModule {
+ @ConfigInfo(baseName = "enabled")
+ public static boolean enabled = true;
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.OPTIMIZATIONS;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "skip_map_item_updates_if_no_bukkit_render";
+ }
+}
diff --git a/src/main/java/net/minecraft/world/item/MapItem.java b/src/main/java/net/minecraft/world/item/MapItem.java
index 58f3c9598301a5b34142ddf958aa7a4db634be3d..c002b449688981c192468fb210e8fd9ef3f91553 100644
--- a/src/main/java/net/minecraft/world/item/MapItem.java
+++ b/src/main/java/net/minecraft/world/item/MapItem.java
@@ -280,7 +280,7 @@ public class MapItem extends Item {
mapItemSavedData.tickCarriedBy(player, stack);
}
- if (!mapItemSavedData.locked && (selected || entity instanceof Player && ((Player)entity).getOffhandItem() == stack)) {
+ if (!mapItemSavedData.locked && (!me.earthme.luminol.config.modules.optimizations.MapItemUpdateSkipConfig.enabled || mapItemSavedData.mapView.getRenderers().stream().anyMatch(mapRenderer -> mapRenderer.getClass() == org.bukkit.craftbukkit.map.CraftMapRenderer.class)) && (selected || entity instanceof Player && ((Player)entity).getOffhandItem() == stack)) { // SparklyPaper - don't update maps if they don't have the CraftMapRenderer in the render list
this.update(world, entity, mapItemSavedData);
}
} // Folia - region threading

View File

@@ -0,0 +1,28 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <wangxyper@163.com>
Date: Sun, 4 Aug 2024 22:29:01 +0800
Subject: [PATCH] SparklyPaper Skip "distanceToSqr" call in
"ServerEntity#sendChanges" if the delta movement hasn't changed
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
index 90eb4927fa51ce3df86aa7b6c71f49150a03e337..f4590eb0eef02a425056e73e7dc71328b8a5f773 100644
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
@@ -230,6 +230,8 @@ public class ServerEntity {
if ((this.trackDelta || this.entity.hasImpulse || this.entity instanceof LivingEntity && ((LivingEntity) this.entity).isFallFlying()) && this.tickCount > 0) {
Vec3 vec3d1 = this.entity.getDeltaMovement();
+
+ if (vec3d1 != this.lastSentMovement) { // SparklyPaper start - skip distanceToSqr call in ServerEntity#sendChanges if the delta movement hasn't changed
double d0 = vec3d1.distanceToSqr(this.lastSentMovement);
if (d0 > 1.0E-7D || d0 > 0.0D && vec3d1.lengthSqr() == 0.0D) {
@@ -244,6 +246,7 @@ public class ServerEntity {
this.broadcast.accept(new ClientboundSetEntityMotionPacket(this.entity.getId(), this.lastSentMovement));
}
}
+ } // SparklyPaper end
}
if (packet1 != null) {

View File

@@ -0,0 +1,31 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <wangxyper@163.com>
Date: Wed, 31 Jul 2024 14:48:44 +0800
Subject: [PATCH] Leaf Skip event if no listeners
diff --git a/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java b/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java
index 7ce9ebba8ce304d1f3f21d4f15ee5f3560d7700b..9180f23529a31b6b0a5b38bb7cda3e32d487f691 100644
--- a/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java
+++ b/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java
@@ -36,15 +36,17 @@ class PaperEventManager {
// SimplePluginManager
public void callEvent(@NotNull Event event) {
+ // Leaf start - Skip event if no listeners
+ RegisteredListener[] listeners = event.getHandlers().getRegisteredListeners();
+ if (listeners.length == 0) return;
+ // Leaf end - Skip event if no listeners
+
if (event.isAsynchronous() && this.server.isPrimaryThread()) {
throw new IllegalStateException(event.getEventName() + " may only be triggered asynchronously.");
} else if (!event.isAsynchronous() && !this.server.isPrimaryThread() && !this.server.isStopping()) {
throw new IllegalStateException(event.getEventName() + " may only be triggered synchronously.");
}
- HandlerList handlers = event.getHandlers();
- RegisteredListener[] listeners = handlers.getRegisteredListeners();
-
for (RegisteredListener registration : listeners) {
if (!registration.getPlugin().isEnabled()) {
continue;

View File

@@ -1,6 +1,6 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Wed, 7 Feb 2024 08:35:11 +0000
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 12:24:00 +0800
Subject: [PATCH] Purpur use alternative keep alive
@@ -31,10 +31,10 @@ index 0000000000000000000000000000000000000000..43bbc2c30bdd3872a0179e0070403c3e
+ }
+}
diff --git a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
index f907dbb55369395058091dd75ae435d2025d94dd..20720424f5e63d07c885759b8b5104311aa6c7c8 100644
index d01063b964a67ecff2998a9e02e7f37a9af88c84..1e72e96db43ab7ae2f1ed88a973a95543b791461 100644
--- a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
@@ -73,6 +73,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
@@ -80,6 +80,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
private long keepAliveChallenge;
private long closedListenerTime;
private boolean closed = false;
@@ -42,16 +42,16 @@ index f907dbb55369395058091dd75ae435d2025d94dd..20720424f5e63d07c885759b8b510431
private int latency;
private volatile boolean suspendFlushingOnServerThread = false;
public final java.util.Map<java.util.UUID, net.kyori.adventure.resource.ResourcePackCallback> packCallbacks = new java.util.concurrent.ConcurrentHashMap<>(); // Paper - adventure resource pack callbacks
@@ -135,6 +136,16 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
@@ -148,6 +149,16 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
@Override
public void handleKeepAlive(ServerboundKeepAlivePacket packet) {
+ // Purpur start
+ if (me.earthme.luminol.config.modules.optimizations.PurpurAlternativeKeepaliveConfig.useAlternateKeepAlive) {
+ long id = packet.getId();
+ if (keepAlives.size() > 0 && keepAlives.contains(id)) {
+ int ping = (int) (Util.getMillis() - id);
+ if (this.keepAlivePending && !keepAlives.isEmpty() && keepAlives.contains(packet.getId())) {
+ int ping = (int) (Util.getMillis() - packet.getId());
+ this.latency = (this.latency * 3 + ping) / 4;
+ this.keepAlivePending = false;
+ keepAlives.clear(); // we got a valid response, lets roll with it and forget the rest
+ }
+ } else
@@ -59,32 +59,33 @@ index f907dbb55369395058091dd75ae435d2025d94dd..20720424f5e63d07c885759b8b510431
//PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); // CraftBukkit // Paper - handle ServerboundKeepAlivePacket async
if (this.keepAlivePending && packet.getId() == this.keepAliveChallenge) {
int i = (int) (Util.getMillis() - this.keepAliveTime);
@@ -264,6 +275,20 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
@@ -273,6 +284,21 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
long currentTime = Util.getMillis();
long elapsedTime = currentTime - this.keepAliveTime;
+ // Purpur start
+ if (me.earthme.luminol.config.modules.optimizations.PurpurAlternativeKeepaliveConfig.useAlternateKeepAlive) {
+ if (elapsedTime >= 1000L) { // 1 second
+ if (!processedDisconnect && keepAlives.size() * 1000L >= KEEPALIVE_LIMIT) {
+ if (this.keepAlivePending && !this.processedDisconnect && keepAlives.size() * 1000L >= KEEPALIVE_LIMIT) {
+ LOGGER.warn("{} was kicked due to keepalive timeout!", this.player.getScoreboardName());
+ disconnect(ServerCommonPacketListenerImpl.TIMEOUT_DISCONNECTION_MESSAGE, org.bukkit.event.player.PlayerKickEvent.Cause.TIMEOUT);
+ } else {
+ keepAliveTime = currentTime; // hijack this field for 1 second intervals
+ keepAlives.add(currentTime); // currentTime is ID
+ send(new ClientboundKeepAlivePacket(currentTime));
+ this.disconnect(ServerCommonPacketListenerImpl.TIMEOUT_DISCONNECTION_MESSAGE, org.bukkit.event.player.PlayerKickEvent.Cause.TIMEOUT);
+ } else if (this.checkIfClosed(currentTime)) {
+ this.keepAlivePending = true;
+ this.keepAliveTime = currentTime; // hijack this field for 1 second intervals
+ this.keepAlives.add(currentTime); // currentTime is ID
+ this.send(new ClientboundKeepAlivePacket(currentTime));
+ }
+ }
+ } else {
+
if (!this.isSingleplayerOwner() && elapsedTime >= 15000L) { // Paper - use vanilla's 15000L between keep alive packets
if (this.keepAlivePending && !this.processedDisconnect && elapsedTime >= KEEPALIVE_LIMIT) { // Paper - check keepalive limit, don't fire if already disconnected
this.disconnect(ServerCommonPacketListenerImpl.TIMEOUT_DISCONNECTION_MESSAGE, org.bukkit.event.player.PlayerKickEvent.Cause.TIMEOUT); // Paper - kick event cause
@@ -275,6 +300,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
this.disconnect(ServerCommonPacketListenerImpl.TIMEOUT_DISCONNECTION_MESSAGE, PlayerKickEvent.Cause.TIMEOUT); // Paper - kick event cause
@@ -284,6 +310,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
}
}
// Paper end - give clients a longer time to respond to pings as per pre 1.12.2 timings
+ } // Purpur end
this.server.getProfiler().pop();
Profiler.get().pop();
}

View File

@@ -1,10 +1,21 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Sat, 27 Apr 2024 12:36:55 +0000
Subject: [PATCH] KioCG Chunk API
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 12:28:45 +0800
Subject: [PATCH] KioCG Chunk API and display of chunkhot in tpsbar
TODO: Add back missing method in CraftPhotographer.java
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/util/ChunkSystem.java b/src/main/java/ca/spottedleaf/moonrise/common/util/ChunkSystem.java
index 30eb7fd0b83ad1626d337cb770fac3dda5202344..cbe8f1fce4327bcc2a677b3da268cf52fef90335 100644
--- a/src/main/java/ca/spottedleaf/moonrise/common/util/ChunkSystem.java
+++ b/src/main/java/ca/spottedleaf/moonrise/common/util/ChunkSystem.java
@@ -127,6 +127,7 @@ public final class ChunkSystem {
}
public static void onChunkNotTicking(final LevelChunk chunk, final ChunkHolder holder) {
+ chunk.getChunkHot().clear(); // KioCG
chunk.getLevel().getCurrentWorldData().removeTickingChunk(chunk.moonrise$getChunkAndHolder()); // Folia - region threading
((ChunkTickServerLevel)(ServerLevel)chunk.getLevel()).moonrise$removeChunkForPlayerTicking(chunk); // Moonrise - chunk tick iteration
}
diff --git a/src/main/java/com/kiocg/ChunkHot.java b/src/main/java/com/kiocg/ChunkHot.java
new file mode 100644
index 0000000000000000000000000000000000000000..53b4397997bc9b9b9d88e48304b37a2590161906
@@ -101,17 +112,95 @@ index 0000000000000000000000000000000000000000..53b4397997bc9b9b9d88e48304b37a25
+ return total / ((long) TIMES_LENGTH * 20L);
+ }
+}
diff --git a/src/main/java/me/earthme/luminol/config/modules/misc/TpsBarConfig.java b/src/main/java/me/earthme/luminol/config/modules/misc/TpsBarConfig.java
index aafb2f5052c7c8e5971a47308253badb3027093c..9fe7ac7ba83bbcc9a2a851a5cace47641323f4d2 100644
--- a/src/main/java/me/earthme/luminol/config/modules/misc/TpsBarConfig.java
+++ b/src/main/java/me/earthme/luminol/config/modules/misc/TpsBarConfig.java
@@ -12,11 +12,13 @@ public class TpsBarConfig implements IConfigModule {
@ConfigInfo(baseName = "enabled")
public static boolean tpsbarEnabled = false;
@ConfigInfo(baseName = "format")
- public static String tpsBarFormat = "<gray>TPS<yellow>:</yellow> <tps> MSPT<yellow>:</yellow> <mspt> Ping<yellow>:</yellow> <ping>ms";
+ public static String tpsBarFormat = "<gray>TPS<yellow>:</yellow> <tps> MSPT<yellow>:</yellow> <mspt> Ping<yellow>:</yellow> <ping>ms ChunkHot<yellow>:</yellow> <chunkhot>";
@ConfigInfo(baseName = "tps_color_list")
public static List<String> tpsColors = List.of("GREEN","YELLOW","RED","PURPLE");
@ConfigInfo(baseName = "ping_color_list")
public static List<String> pingColors = List.of("GREEN","YELLOW","RED","PURPLE");
+ @ConfigInfo(baseName = "chunkhot_color_list")
+ public static List<String> chunkHotColors = List.of("GREEN","YELLOW","RED","PURPLE");
@ConfigInfo(baseName = "update_interval_ticks")
public static int updateInterval = 15;
diff --git a/src/main/java/me/earthme/luminol/functions/GlobalServerTpsBar.java b/src/main/java/me/earthme/luminol/functions/GlobalServerTpsBar.java
index 026807e0851d67c6d57e81f573ac1bf8fedc6109..c45f6bd60d1cf7a915aa6ceea07c0929507b86e2 100644
--- a/src/main/java/me/earthme/luminol/functions/GlobalServerTpsBar.java
+++ b/src/main/java/me/earthme/luminol/functions/GlobalServerTpsBar.java
@@ -138,7 +138,8 @@ public class GlobalServerTpsBar {
TpsBarConfig.tpsBarFormat,
Placeholder.component("tps",getTpsComponent(tps)),
Placeholder.component("mspt",getMsptComponent(mspt)),
- Placeholder.component("ping",getPingComponent(player.getPing()))
+ Placeholder.component("ping",getPingComponent(player.getPing())),
+ Placeholder.component("chunkhot",getChunkHotComponent(player.getNearbyChunkHot()))
));
bar.color(barColorFromTps(tps));
bar.progress((float) Math.min((float)1,Math.max(mspt / 50,0)));
@@ -180,6 +181,32 @@ public class GlobalServerTpsBar {
return MiniMessage.miniMessage().deserialize(replaced,Placeholder.parsed("text", String.format("%.2f", mspt)));
}
+ private static @NotNull Component getChunkHotComponent(long chunkHot){
+ final BossBar.Color colorBukkit = barColorFromChunkHot(chunkHot);
+ final String colorString = colorBukkit.name();
+
+ final String content = "<%s><text></%s>";
+ final String replaced = String.format(content,colorString,colorString);
+
+ return MiniMessage.miniMessage().deserialize(replaced,Placeholder.parsed("text", String.valueOf(chunkHot)));
+ }
+
+ private static BossBar.Color barColorFromChunkHot(long chunkHot){
+ if (chunkHot == -1){
+ return BossBar.Color.valueOf(TpsBarConfig.chunkHotColors.get(3));
+ }
+
+ if (chunkHot <= 300000L){
+ return BossBar.Color.valueOf(TpsBarConfig.chunkHotColors.get(0));
+ }
+
+ if (chunkHot <= 500000L){
+ return BossBar.Color.valueOf(TpsBarConfig.chunkHotColors.get(1));
+ }
+
+ return BossBar.Color.valueOf(TpsBarConfig.chunkHotColors.get(2));
+ }
+
private static BossBar.Color barColorFromMspt(double mspt){
if (mspt == -1){
return BossBar.Color.valueOf(TpsBarConfig.tpsColors.get(3));
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 97016c309d0a0fc13d733269f7dfb81ca0d8c574..e169a9d4c2e633fdba3fe425e2f3f766d2200af5 100644
index 420b0f22bb58cab43ff4b707bd40823ab2cad9bd..968f96e6fa971ad06b2a961071f1f80bc6dcfe97 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1699,6 +1699,17 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1801,6 +1801,29 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
} finally { foliaProfiler.stopTimer(ca.spottedleaf.leafprofiler.LProfilerRegistry.ENTITY_SCHEDULER_TICK); } // Folia - profiler
}
// Folia end - region threading
+ // KioCG start - ChunkHot
+ final ca.spottedleaf.moonrise.common.list.IteratorSafeOrderedReferenceSet<net.minecraft.world.level.chunk.LevelChunk> chunks = new ca.spottedleaf.moonrise.common.list.IteratorSafeOrderedReferenceSet<>();
+ if (region != null){
+ for (net.minecraft.server.level.ServerChunkCache.ChunkAndHolder chunkAndHolder : region.world.getCurrentWorldData().getTickingChunks()){
+ final net.minecraft.world.level.chunk.LevelChunk chunk = chunkAndHolder.chunk();
+
+ if (!ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(region.world, chunk.locX, chunk.locZ)){
+ continue;
+ }
+
+ chunks.add(chunk);
+ }
+ }
+ if (region != null && io.papermc.paper.threadedregions.RegionizedServer.getCurrentTick() % 20 == 0){
+ final Iterator<net.minecraft.world.level.chunk.LevelChunk> chunkIterator = region.world.getCurrentWorldData().getChunks().unsafeIterator();
+ final Iterator<net.minecraft.world.level.chunk.LevelChunk> chunkIterator = chunks.unsafeIterator();
+ while (chunkIterator.hasNext()){
+ final net.minecraft.world.level.chunk.LevelChunk targetChunk = chunkIterator.next();
+
@@ -120,16 +209,16 @@ index 97016c309d0a0fc13d733269f7dfb81ca0d8c574..e169a9d4c2e633fdba3fe425e2f3f766
+ }
+ }
+ //KioCG end
// Folia - region threading
if (region == null) this.tickRateManager.tick(); // Folia - region threading
this.tickChildren(shouldKeepTicking, region); // Folia - region threading
@@ -1708,6 +1719,20 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
if (region == null && i - this.lastServerStatus >= MinecraftServer.STATUS_EXPIRE_TIME_NANOS) { // Folia - region threading
@@ -1809,6 +1832,20 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
// Folia - region threading
+ // KioCG start - ChunkHot
+ if (region != null && io.papermc.paper.threadedregions.RegionizedServer.getCurrentTick() % 20 == 0){
+ final Iterator<net.minecraft.world.level.chunk.LevelChunk> chunkIterator = region.world.getCurrentWorldData().getChunks().unsafeIterator();
+ final Iterator<net.minecraft.world.level.chunk.LevelChunk> chunkIterator = chunks.unsafeIterator();
+ while (chunkIterator.hasNext()){
+ final net.minecraft.world.level.chunk.LevelChunk targetChunk = chunkIterator.next();
+
@@ -142,63 +231,64 @@ index 97016c309d0a0fc13d733269f7dfb81ca0d8c574..e169a9d4c2e633fdba3fe425e2f3f766
+ }
+ //KioCG end
// Paper start - Incremental chunk and player saving
final ProfilerFiller profiler = Profiler.get();
int playerSaveInterval = io.papermc.paper.configuration.GlobalConfiguration.get().playerAutoSave.rate;
if (playerSaveInterval < 0) {
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 12c46e7a3f6a8675921d95dee97ece4a83252282..573cca66b905c5decb0e59c58cfa861d1788d5d3 100644
index 71a8aa164d48ec632c8dcb24ff0073e26b67bb9e..c95c731cdcf02a338a6a437c0195d6f5f267fefb 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -1549,6 +1549,8 @@ public class ServerLevel extends Level implements WorldGenLevel {
@@ -1381,6 +1381,8 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
final int timerId = isActive ? entity.getType().tickTimerId : entity.getType().inactiveTickTimerId;
final ca.spottedleaf.leafprofiler.RegionizedProfiler.Handle profiler = io.papermc.paper.threadedregions.TickRegionScheduler.getProfiler();
profiler.startTimer(timerId);
+ LevelChunk levelChunk = entity.shouldTickHot() ? this.getChunkIfLoaded(entity.sectionX,entity.sectionZ) : null; // KioCG
+ LevelChunk levelChunk = entity.shouldTickHot() ? this.getChunkIfLoaded(entity.moonrise$getSectionX(),entity.moonrise$getSectionZ()) : null; // KioCG
+ if (levelChunk != null) levelChunk.getChunkHot().startTicking(); try { // KioCG
// Folia end - timer
try {
// Paper end - timings
@@ -1576,6 +1578,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
// Folia end - profiler
if (isActive) { // Paper - EAR 2
@@ -1398,6 +1400,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
} else { entity.inactiveTick(); } // Paper - EAR 2
this.getProfiler().pop();
} finally { timer.stopTiming(); profiler.stopTimer(timerId); } // Paper - timings // Folia - timer
+ } finally { if (levelChunk != null) levelChunk.getChunkHot().stopTickingAndCount(); } // KioCG
gameprofilerfiller.pop();
} finally { profiler.stopTimer(timerId); } // Folia - timer
+ } finally { if (levelChunk != null) levelChunk.getChunkHot().stopTickingAndCount(); } // KioCG
Iterator iterator = entity.getPassengers().iterator();
while (iterator.hasNext()) {
@@ -1604,6 +1607,8 @@ public class ServerLevel extends Level implements WorldGenLevel {
@@ -1420,6 +1423,8 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
final int timerId = isActive ? passenger.getType().tickTimerId : passenger.getType().inactiveTickTimerId;
final ca.spottedleaf.leafprofiler.RegionizedProfiler.Handle profiler = io.papermc.paper.threadedregions.TickRegionScheduler.getProfiler();
profiler.startTimer(timerId);
// Folia end - timer
+ LevelChunk levelChunk = !(passenger instanceof Player) ? this.getChunkIfLoaded(passenger.blockPosition()) : null; // KioCG
+ if (levelChunk != null) levelChunk.getChunkHot().startTicking(); try { // KioCG
try {
// Paper end
// Folia end - profiler
passenger.setOldPosAndRot();
@@ -1644,6 +1649,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
@@ -1460,6 +1465,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
}
} finally { timer.stopTiming(); profiler.stopTimer(timerId); }// Paper - EAR2 timings // Folia - timer
+ } finally { if (levelChunk != null) levelChunk.getChunkHot().stopTickingAndCount(); } // KioCG
} finally { profiler.stopTimer(timerId); } // Folia - profiler
+ } finally { if (levelChunk != null) levelChunk.getChunkHot().stopTickingAndCount(); } // KioCG
}
} else {
passenger.stopRiding();
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 24f4370b35d2cc50340de36d81b6c6d9aa250e4c..c04058a95dc4990cd8034b381f95affcdc77dd93 100644
index 61726ff1fecb1e153a95328c37787dd2070ff0c4..dbf97cb39362e907dcde7b773c902fec3256d56a 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -351,6 +351,25 @@ public class ServerPlayer extends Player {
public boolean handlingMoveEvent = false;
//Luminol end
@@ -361,6 +361,26 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
}
// Paper end - rewrite chunk system
+ // KioCG start - ChunkHot
+ private long nearbyChunkHot = 0;
+ private volatile long nearbyChunkHot = 0;
+
+ public long getNearbyChunkHot() { return this.nearbyChunkHot; }
+
+ private long refreshNearbyChunkHot() {
+ long total = 0L;
+ for (int i = this.sectionX - 4; i <= this.sectionX + 4; ++i) {
+ for (int j = this.sectionZ - 4; j <= this.sectionZ + 4; ++j) {
+ int searchRadius = ((ServerLevel) this.level()).moonrise$getViewDistanceHolder().getViewDistances().tickViewDistance();
+ for (int i = this.moonrise$getSectionX() - searchRadius; i <= this.moonrise$getSectionX() + searchRadius; ++i) {
+ for (int j = this.moonrise$getSectionZ() - searchRadius; j <= this.moonrise$getSectionZ() + searchRadius; ++j) {
+ net.minecraft.world.level.chunk.LevelChunk targetChunk = this.level().getChunkIfLoaded(i, j);
+ if (targetChunk != null) {
+ total += targetChunk.getChunkHot().getAverage();
@@ -212,7 +302,7 @@ index 24f4370b35d2cc50340de36d81b6c6d9aa250e4c..c04058a95dc4990cd8034b381f95affc
public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile, ClientInformation clientOptions) {
super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile);
this.chatVisibility = ChatVisiblity.FULL;
@@ -923,6 +942,12 @@ public class ServerPlayer extends Player {
@@ -1202,6 +1222,12 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
this.trackEnteredOrExitedLavaOnVehicle();
this.updatePlayerAttributes();
this.advancements.flushDirty(this);
@@ -226,12 +316,12 @@ index 24f4370b35d2cc50340de36d81b6c6d9aa250e4c..c04058a95dc4990cd8034b381f95affc
private void updatePlayerAttributes() {
diff --git a/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java b/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java
index ee972fa1a2bc023ed18eaceae21c8c8244754e6a..0fe6afb51246701309c88febeb61aaf7561bd954 100644
index 7eba7c0e7b8d2795abbe96b3d86a9c1a3b6b74a6..9187de83c6639a34b5725ec5c0cb8d6c30b913eb 100644
--- a/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java
+++ b/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java
@@ -440,4 +440,11 @@ public class AreaEffectCloud extends Entity implements TraceableEntity {
public EntityDimensions getDimensions(Pose pose) {
return EntityDimensions.scalable(this.getRadius() * 2.0F, 0.5F);
@@ -465,4 +465,11 @@ public class AreaEffectCloud extends Entity implements TraceableEntity {
public final boolean hurtServer(ServerLevel world, DamageSource source, float amount) {
return false;
}
+
+ // KioCG start
@@ -242,23 +332,23 @@ index ee972fa1a2bc023ed18eaceae21c8c8244754e6a..0fe6afb51246701309c88febeb61aaf7
+ // KioCG end
}
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 546063255bf29cba839d73cf2778a798150658f5..00d801aa1ffce0ccd8e7176f614d831ae09259d3 100644
index 75182b1f12ed5ad0ff541aee28b40a72b783230d..e2b7daa6a9af849b49e75a4329b53cca559d1ea9 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -5957,4 +5957,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return ((net.minecraft.server.level.ServerChunkCache) level.getChunkSource()).isPositionTicking(this);
@@ -6202,4 +6202,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return ((net.minecraft.server.level.ServerLevel) this.level).isPositionEntityTicking(this.blockPosition());
}
// Paper end - Expose entity id counter
+
+ public boolean shouldTickHot() { return this.tickCount > 20 * 10 && this.isAlive(); } // KioCG
}
diff --git a/src/main/java/net/minecraft/world/entity/LightningBolt.java b/src/main/java/net/minecraft/world/entity/LightningBolt.java
index 4f701788bd21b61cad251a3a88f9bc416fb99051..86caa40a91ee0385bc32fd19d0fec6bd2f3634d2 100644
index 12127b14babf646711d3a118416453c4f1ac1460..5929cd58066b1a8f305b411af8ac4abc688a5cc6 100644
--- a/src/main/java/net/minecraft/world/entity/LightningBolt.java
+++ b/src/main/java/net/minecraft/world/entity/LightningBolt.java
@@ -288,4 +288,11 @@ public class LightningBolt extends Entity {
public Stream<Entity> getHitEntities() {
return this.hitEntities.stream().filter(Entity::isAlive);
@@ -302,4 +302,11 @@ public class LightningBolt extends Entity {
public final boolean hurtServer(ServerLevel world, DamageSource source, float amount) {
return false;
}
+
+ // KioCG start
@@ -269,12 +359,12 @@ index 4f701788bd21b61cad251a3a88f9bc416fb99051..86caa40a91ee0385bc32fd19d0fec6bd
+ // KioCG end
}
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 26362c7fa4fcc39f40c2736fd14647542e7161e2..2e9de64ac2cdd5b43b45196565d7e048ac82cfaf 100644
index 0e0b971c93cdfd8cfae8019c4710f72fdd096c6a..983f5c4188db04b98a60a43f9d890335551ab39b 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -1950,4 +1950,11 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Targeti
return itemmonsteregg == null ? null : new ItemStack(itemmonsteregg);
@@ -1861,4 +1861,11 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
public float[] getArmorDropChances() {
return this.armorDropChances;
}
+
+ // KioCG start
@@ -285,10 +375,10 @@ index 26362c7fa4fcc39f40c2736fd14647542e7161e2..2e9de64ac2cdd5b43b45196565d7e048
+ // KioCG end
}
diff --git a/src/main/java/net/minecraft/world/entity/animal/horse/TraderLlama.java b/src/main/java/net/minecraft/world/entity/animal/horse/TraderLlama.java
index bbfc94237bbd546361cc4a7bde773c810e8c5d49..d9f48fe2bcf1a2e317e97046618c056b05643268 100644
index 7b43fcf86984cc200f34c189e7a547996416f379..b4918895a3530836410b56124d9b2ca9091111ba 100644
--- a/src/main/java/net/minecraft/world/entity/animal/horse/TraderLlama.java
+++ b/src/main/java/net/minecraft/world/entity/animal/horse/TraderLlama.java
@@ -166,4 +166,11 @@ public class TraderLlama extends Llama {
@@ -173,4 +173,11 @@ public class TraderLlama extends Llama {
super.start();
}
}
@@ -301,10 +391,10 @@ index bbfc94237bbd546361cc4a7bde773c810e8c5d49..d9f48fe2bcf1a2e317e97046618c056b
+ // KioCG end
}
diff --git a/src/main/java/net/minecraft/world/entity/npc/WanderingTrader.java b/src/main/java/net/minecraft/world/entity/npc/WanderingTrader.java
index 0854e9b7ee2e6b23b6c1ee6a324a5a253c9d4679..26f2e3980cb8ac72db71dd3e91156f16fa9466cf 100644
index 1e77cce428d9e53142aaa2cf780b7f862d536eca..f5bad1a9f274cb5a1bdf54a4c575afaa4ab7328f 100644
--- a/src/main/java/net/minecraft/world/entity/npc/WanderingTrader.java
+++ b/src/main/java/net/minecraft/world/entity/npc/WanderingTrader.java
@@ -326,4 +326,12 @@ public class WanderingTrader extends net.minecraft.world.entity.npc.AbstractVill
@@ -327,4 +327,12 @@ public class WanderingTrader extends net.minecraft.world.entity.npc.AbstractVill
return !pos.closerToCenterThan(this.trader.position(), proximityDistance);
}
}
@@ -318,29 +408,30 @@ index 0854e9b7ee2e6b23b6c1ee6a324a5a253c9d4679..26f2e3980cb8ac72db71dd3e91156f16
+ // KioCG end
}
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
index 448a6c8d73652824157c50cf4883d4d4d9b5db80..8ab86db26ccc0b7d45ce3f657f0b72d99573f3b7 100644
index e00bcd424d500aa4b76d0fd88eb4b9558d3aece5..d8db54d4f7bbffac216d702cb50f066c7a9b89c2 100644
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
@@ -2472,4 +2472,12 @@ public abstract class Player extends LivingEntity {
return this.message;
}
@@ -2420,6 +2420,13 @@ public abstract class Player extends LivingEntity {
return true;
}
+
+
+ // KioCG start
+ @Override
+ public boolean shouldTickHot() {
+ return false;
+ }
+ // KioCG end
}
+
public static enum BedSleepingProblem {
NOT_POSSIBLE_HERE, NOT_POSSIBLE_NOW(Component.translatable("block.minecraft.bed.no_sleep")), TOO_FAR_AWAY(Component.translatable("block.minecraft.bed.too_far_away")), OBSTRUCTED(Component.translatable("block.minecraft.bed.obstructed")), OTHER_PROBLEM, NOT_SAFE(Component.translatable("block.minecraft.bed.not_safe"));
diff --git a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
index 77eee09a301a838f21834319d4962eba1c8dcbed..cd133931de618e5d8ed5062f8ebfde9d8a9e799c 100644
index 3a832be7d14276f38f1a35ca9f9a540be7b7d1b4..c26253fee6eeaca010f9232f387c77e17dd79a9f 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
@@ -400,4 +400,11 @@ public abstract class Projectile extends Entity implements TraceableEntity {
public float getPickRadius() {
return this.isPickable() ? 1.0F : 0.0F;
@@ -578,4 +578,11 @@ public abstract class Projectile extends Entity implements TraceableEntity {
T create(ServerLevel world, LivingEntity shooter, ItemStack stack);
}
+
+ // KioCG start
@@ -351,69 +442,54 @@ index 77eee09a301a838f21834319d4962eba1c8dcbed..cd133931de618e5d8ed5062f8ebfde9d
+ // KioCG end
}
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
index 0c3f095854396da0e5f38234060ba9a190a572de..c15be74b855a7c62f23499143634057e2ac27b7a 100644
index 4bccb94cf953ebd4dfd4f1620ad1784ef235356f..38308b3b25ef421d6379b18506764819aa14ca1d 100644
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
@@ -94,6 +94,7 @@ public class LevelChunk extends ChunkAccess {
@@ -94,6 +94,7 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
private final LevelChunkTicks<Block> blockTicks;
private final LevelChunkTicks<Fluid> fluidTicks;
public volatile FullChunkStatus chunkStatus = FullChunkStatus.INACCESSIBLE; // Paper - rewrite chunk system
private LevelChunk.UnsavedListener unsavedListener;
+ private final com.kiocg.ChunkHot chunkHot = new com.kiocg.ChunkHot(); public com.kiocg.ChunkHot getChunkHot() { return this.chunkHot; } // KioCG
public LevelChunk(Level world, ChunkPos pos) {
this(world, pos, UpgradeData.EMPTY, new LevelChunkTicks<>(), new LevelChunkTicks<>(), 0L, (LevelChunkSection[]) null, (LevelChunk.PostLoadProcessor) null, (BlendingData) null);
@@ -762,6 +763,7 @@ public class LevelChunk extends ChunkAccess {
}
public void onChunkNotTicking(io.papermc.paper.chunk.system.scheduling.NewChunkHolder chunkHolder) {
+ this.chunkHot.clear(); // KioCG
io.papermc.paper.chunk.system.ChunkSystem.onChunkNotTicking(this, chunkHolder.vanillaChunkHolder);
}
@@ -1186,6 +1188,7 @@ public class LevelChunk extends ChunkAccess {
@@ -1080,6 +1081,7 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
ProfilerFiller gameprofilerfiller = Profiler.get();
gameprofilerfiller.push(this::getType);
this.blockEntity.tickTimer.startTiming(); // Spigot
+ LevelChunk.this.chunkHot.startTicking(); // KioCG
profiler.startTimer(timerId); try { // Folia - profiler
BlockState iblockdata = LevelChunk.this.getBlockState(blockposition);
@@ -1216,6 +1219,7 @@ public class LevelChunk extends ChunkAccess {
} finally {
this.blockEntity.tickTimer.stopTiming();
// Spigot end
+ LevelChunk.this.chunkHot.stopTickingAndCount(); // KioCG
}
}
}
@@ -1095,7 +1097,7 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
}
// Paper end - Remove the Block Entity if it's invalid
}
- } finally { profiler.stopTimer(timerId); } // Folia - profiler
+ } finally { profiler.stopTimer(timerId); LevelChunk.this.chunkHot.stopTickingAndCount(); } // Folia - profiler // KioCG
gameprofilerfiller.pop();
} catch (Throwable throwable) {
diff --git a/src/main/java/net/minecraft/world/level/redstone/NeighborUpdater.java b/src/main/java/net/minecraft/world/level/redstone/NeighborUpdater.java
index e679b40b9628b0eb7152978ef641f9c918c4c8b2..bf9ae765242bb61d3e279893b0355d122cb1e985 100644
index e414da8a51bb9b49c28a74eca166046cbee44835..ac22bb47836e97904729bad91ff75ce7abfb30b6 100644
--- a/src/main/java/net/minecraft/world/level/redstone/NeighborUpdater.java
+++ b/src/main/java/net/minecraft/world/level/redstone/NeighborUpdater.java
@@ -63,7 +63,10 @@ public interface NeighborUpdater {
@@ -73,7 +73,10 @@ public interface NeighborUpdater {
}
}
// CraftBukkit end
+ net.minecraft.world.level.chunk.LevelChunk levelChunk = world.getChunkIfLoaded(pos); // KioCG
+ if (levelChunk != null) levelChunk.getChunkHot().startTicking(); try { // KioCG
state.handleNeighborChanged(world, pos, sourceBlock, sourcePos, notify);
state.handleNeighborChanged(world, pos, sourceBlock, orientation, notify);
+ } finally { if (levelChunk != null) levelChunk.getChunkHot().stopTickingAndCount(); } // KioCG
// Spigot Start
} catch (StackOverflowError ex) {
world.lastPhysicsProblem = new BlockPos(pos);
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
index 82b4bd669c57b18fb0b443bcd94495023cd5a528..abd845a124dbe0b9a1868ce378a0b7c7b9b3b818 100644
index 0074bc0e7147dc3a8c538e796f14ac9bf8725896..90b2bfd12236fce24ddcc48b00e0121f40676d88 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
@@ -25,6 +25,7 @@ import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.DataLayer;
import net.minecraft.world.level.chunk.ImposterProtoChunk;
+import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.LevelChunkSection;
import net.minecraft.world.level.chunk.PalettedContainer;
import net.minecraft.world.level.chunk.PalettedContainerRO;
@@ -428,4 +429,12 @@ public class CraftChunk implements Chunk {
@@ -436,4 +436,12 @@ public class CraftChunk implements Chunk {
static {
Arrays.fill(FULL_LIGHT, (byte) 0xFF);
}
@@ -421,19 +497,19 @@ index 82b4bd669c57b18fb0b443bcd94495023cd5a528..abd845a124dbe0b9a1868ce378a0b7c7
+ // KioCG start - ChunkHot
+ @Override
+ public long getChunkHotAvg() {
+ final LevelChunk target = this.worldServer.getChunkIfLoaded(this.x,this.z);
+ final net.minecraft.world.level.chunk.LevelChunk target = this.worldServer.getChunkIfLoaded(this.x,this.z);
+ return target == null ? -1 : target.getChunkHot().getAverage();
+ }
+ // KioCG end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index eb5ec3637aedb643801f369e43d39ef987546ce0..ae53333f8ebffea8874259495026484b003d1ad9 100644
index 01aca615a7fe4baa38d4020f7f3ccd63539fe546..2912d1a4b8b1926429655af76c5da8fde77a1759 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -3544,4 +3544,11 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
public void setSendViewDistance(final int viewDistance) {
this.getHandle().setSendViewDistance(viewDistance);
@@ -3611,4 +3611,11 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundEntityEventPacket(((CraftEntity) target).getHandle(), effect.getData()));
}
// Paper end - entity effect API
+
+ // KioCG start - ChunkHot
+ @Override

View File

@@ -1,14 +1,14 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Fri, 9 Feb 2024 03:32:05 +0000
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 12:31:48 +0800
Subject: [PATCH] Threaded region start tick and finished tick event
diff --git a/src/main/java/io/papermc/paper/threadedregions/TickRegionScheduler.java b/src/main/java/io/papermc/paper/threadedregions/TickRegionScheduler.java
index 865044d40a95d201765435cbc14b0384980eebf6..ab5f832aafc479eca1c5da012e180d6374e32325 100644
index 056fb1ca7b07d5e713dcbd951830b14fc9025f4c..b67a76347f06686d684215c89259e764f8dd1604 100644
--- a/src/main/java/io/papermc/paper/threadedregions/TickRegionScheduler.java
+++ b/src/main/java/io/papermc/paper/threadedregions/TickRegionScheduler.java
@@ -389,7 +389,7 @@ public final class TickRegionScheduler {
@@ -401,7 +401,7 @@ public final class TickRegionScheduler {
final long scheduledStart = this.getScheduledStart();
final long scheduledEnd = scheduledStart + TIME_BETWEEN_TICKS;
@@ -17,7 +17,7 @@ index 865044d40a95d201765435cbc14b0384980eebf6..ab5f832aafc479eca1c5da012e180d63
synchronized (this) {
this.currentTickData = new TickTime(
lastTickStart, scheduledStart, tickStart, cpuStart,
@@ -424,6 +424,7 @@ public final class TickRegionScheduler {
@@ -436,6 +436,7 @@ public final class TickRegionScheduler {
);
this.addTickTime(time);

View File

@@ -1,14 +1,14 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: HaHaWTH <fsjk947@gmail.com>
Date: Fri, 15 Mar 2024 03:32:46 +0800
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 12:33:04 +0800
Subject: [PATCH] Fix-MC-2025
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index d975134fe5dd38a8655406a39821593f055b7381..546063255bf29cba839d73cf2778a798150658f5 100644
index e2b7daa6a9af849b49e75a4329b53cca559d1ea9..e560cf681642252e381a71f5abe8fd2572b163ed 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -2608,6 +2608,16 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -2751,6 +2751,16 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
nbttagcompound.putBoolean("Paper.FreezeLock", true);
}
// Paper end
@@ -25,7 +25,7 @@ index d975134fe5dd38a8655406a39821593f055b7381..546063255bf29cba839d73cf2778a798
return nbttagcompound;
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT");
@@ -2685,6 +2695,13 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -2829,6 +2839,13 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
this.reapplyPosition();
}

View File

@@ -0,0 +1,53 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <wangxyper@163.com>
Date: Sat, 30 Nov 2024 12:33:31 +0800
Subject: [PATCH] FoliaPR Add TPS From Region
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index ac180d082b05f2a5fa557b49e3d34e81e4957766..5cc71c882dba16034c976f8e6eb98a1616b67030 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -3105,6 +3105,42 @@ public final class CraftServer implements Server {
};
}
+ // Folia start
+ @Override
+ public double[] getTPS(org.bukkit.Location location) {
+ final int x = location.blockX() >> 4;
+ final int z = location.blockZ() >> 4;
+ final ServerLevel world = ((CraftWorld) location.getWorld()).getHandle();
+ return getTPSFromRegion(world, x, z);
+ }
+
+ @Override
+ public double[] getTPS(org.bukkit.Chunk chunk) {
+ final int x = chunk.getX();
+ final int z = chunk.getZ();
+ final ServerLevel world = ((CraftWorld) chunk.getWorld()).getHandle();
+ return getTPSFromRegion(world, x, z);
+ }
+
+ private double[] getTPSFromRegion(ServerLevel world, int x, int z) {
+ io.papermc.paper.threadedregions.ThreadedRegionizer.ThreadedRegion<io.papermc.paper.threadedregions.TickRegions.TickRegionData, io.papermc.paper.threadedregions.TickRegions.TickRegionSectionData>
+ region = world.regioniser.getRegionAtSynchronised(x, z);
+ if (region == null) {
+ return null;
+ } else {
+ io.papermc.paper.threadedregions.TickRegions.TickRegionData regionData = region.getData();
+ final long currTime = System.nanoTime();
+ return new double[] {
+ regionData.getRegionSchedulingHandle().getTickReport5s(currTime).tpsData().segmentAll().average(),
+ regionData.getRegionSchedulingHandle().getTickReport15s(currTime).tpsData().segmentAll().average(),
+ regionData.getRegionSchedulingHandle().getTickReport1m(currTime).tpsData().segmentAll().average(),
+ regionData.getRegionSchedulingHandle().getTickReport5m(currTime).tpsData().segmentAll().average(),
+ regionData.getRegionSchedulingHandle().getTickReport15m(currTime).tpsData().segmentAll().average(),
+ };
+ }
+ }
+ // Folia end
+
// Paper start - adventure sounds
@Override
public void playSound(final net.kyori.adventure.sound.Sound sound) {

View File

@@ -1,72 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Tue, 30 Apr 2024 14:02:39 +0000
Subject: [PATCH] Added chunkhot to tpsbar
diff --git a/src/main/java/me/earthme/luminol/config/modules/misc/TpsBarConfig.java b/src/main/java/me/earthme/luminol/config/modules/misc/TpsBarConfig.java
index aafb2f5052c7c8e5971a47308253badb3027093c..9fe7ac7ba83bbcc9a2a851a5cace47641323f4d2 100644
--- a/src/main/java/me/earthme/luminol/config/modules/misc/TpsBarConfig.java
+++ b/src/main/java/me/earthme/luminol/config/modules/misc/TpsBarConfig.java
@@ -12,11 +12,13 @@ public class TpsBarConfig implements IConfigModule {
@ConfigInfo(baseName = "enabled")
public static boolean tpsbarEnabled = false;
@ConfigInfo(baseName = "format")
- public static String tpsBarFormat = "<gray>TPS<yellow>:</yellow> <tps> MSPT<yellow>:</yellow> <mspt> Ping<yellow>:</yellow> <ping>ms";
+ public static String tpsBarFormat = "<gray>TPS<yellow>:</yellow> <tps> MSPT<yellow>:</yellow> <mspt> Ping<yellow>:</yellow> <ping>ms ChunkHot<yellow>:</yellow> <chunkhot>";
@ConfigInfo(baseName = "tps_color_list")
public static List<String> tpsColors = List.of("GREEN","YELLOW","RED","PURPLE");
@ConfigInfo(baseName = "ping_color_list")
public static List<String> pingColors = List.of("GREEN","YELLOW","RED","PURPLE");
+ @ConfigInfo(baseName = "chunkhot_color_list")
+ public static List<String> chunkHotColors = List.of("GREEN","YELLOW","RED","PURPLE");
@ConfigInfo(baseName = "update_interval_ticks")
public static int updateInterval = 15;
diff --git a/src/main/java/me/earthme/luminol/functions/GlobalServerTpsBar.java b/src/main/java/me/earthme/luminol/functions/GlobalServerTpsBar.java
index 3f1478dde900d671c4bfa43df80f629519cd602e..7abde30d420ff66026d1dee017c41bc23df22b26 100644
--- a/src/main/java/me/earthme/luminol/functions/GlobalServerTpsBar.java
+++ b/src/main/java/me/earthme/luminol/functions/GlobalServerTpsBar.java
@@ -139,7 +139,8 @@ public class GlobalServerTpsBar {
TpsBarConfig.tpsBarFormat,
Placeholder.component("tps",getTpsComponent(tps)),
Placeholder.component("mspt",getMsptComponent(mspt)),
- Placeholder.component("ping",getPingComponent(player.getPing()))
+ Placeholder.component("ping",getPingComponent(player.getPing())),
+ Placeholder.component("chunkhot",getChunkHotComponent(player.getNearbyChunkHot()))
));
bar.color(barColorFromTps(tps));
bar.progress((float) Math.min((float)1,Math.max(mspt / 50,0)));
@@ -181,6 +182,32 @@ public class GlobalServerTpsBar {
return MiniMessage.miniMessage().deserialize(replaced,Placeholder.parsed("text", String.format("%.2f", mspt)));
}
+ private static @NotNull Component getChunkHotComponent(long chunkHot){
+ final BossBar.Color colorBukkit = barColorFromChunkHot(chunkHot);
+ final String colorString = colorBukkit.name();
+
+ final String content = "<%s><text></%s>";
+ final String replaced = String.format(content,colorString,colorString);
+
+ return MiniMessage.miniMessage().deserialize(replaced,Placeholder.parsed("text", String.valueOf(chunkHot)));
+ }
+
+ private static BossBar.Color barColorFromChunkHot(long chunkHot){
+ if (chunkHot == -1){
+ return BossBar.Color.valueOf(TpsBarConfig.chunkHotColors.get(3));
+ }
+
+ if (chunkHot <= 300000L){
+ return BossBar.Color.valueOf(TpsBarConfig.chunkHotColors.get(0));
+ }
+
+ if (chunkHot <= 500000L){
+ return BossBar.Color.valueOf(TpsBarConfig.chunkHotColors.get(1));
+ }
+
+ return BossBar.Color.valueOf(TpsBarConfig.chunkHotColors.get(2));
+ }
+
private static BossBar.Color barColorFromMspt(double mspt){
if (mspt == -1){
return BossBar.Color.valueOf(TpsBarConfig.tpsColors.get(3));

View File

@@ -1,129 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Sun, 17 Mar 2024 00:00:45 +0000
Subject: [PATCH] Leaves Replay Mod API
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index b4327a55c422380ca6b3a1dc47c3adbe76de4655..8645a137c6beb5fe9bbb30159317a35a4cd96a50 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -2918,4 +2918,10 @@ public final class Bukkit {
public static Server.Spigot spigot() {
return server.spigot();
}
+
+ // Leaves start - Photographer API
+ public static @NotNull top.leavesmc.leaves.entity.PhotographerManager getPhotographerManager() {
+ return server.getPhotographerManager();
+ }
+ // Leaves end - Photographer API
}
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index 2a888d33eff4487f23463c565c9f75c40fba7d94..3a78bcb6f681b44594c4f5f35120b67adbe6aeb5 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -2546,4 +2546,8 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
*/
public boolean isGlobalTickThread();
// Folia end - region threading API
+
+ // Leaves start - Photographer API
+ @NotNull top.leavesmc.leaves.entity.PhotographerManager getPhotographerManager();
+ // Leaves end - Photographer API
}
diff --git a/src/main/java/top/leavesmc/leaves/entity/Photographer.java b/src/main/java/top/leavesmc/leaves/entity/Photographer.java
new file mode 100644
index 0000000000000000000000000000000000000000..bfa6fe2a0ca095170aa5e073251402cf83a53ba0
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/entity/Photographer.java
@@ -0,0 +1,27 @@
+package top.leavesmc.leaves.entity;
+
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.io.File;
+
+public interface Photographer extends Player {
+
+ @NotNull
+ public String getId();
+
+ public void setRecordFile(@NotNull File file);
+
+ public void stopRecording();
+
+ public void stopRecording(boolean async);
+
+ public void stopRecording(boolean async, boolean save);
+
+ public void pauseRecording();
+
+ public void resumeRecording();
+
+ public void setFollowPlayer(@Nullable Player player);
+}
diff --git a/src/main/java/top/leavesmc/leaves/entity/PhotographerManager.java b/src/main/java/top/leavesmc/leaves/entity/PhotographerManager.java
new file mode 100644
index 0000000000000000000000000000000000000000..2889a4835edea4254a3d35fc7861983644a1dc4b
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/entity/PhotographerManager.java
@@ -0,0 +1,32 @@
+package top.leavesmc.leaves.entity;
+
+import org.bukkit.Location;
+import org.bukkit.util.Consumer;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import top.leavesmc.leaves.replay.BukkitRecorderOption;
+
+import java.util.Collection;
+import java.util.UUID;
+
+public interface PhotographerManager {
+ @Nullable
+ public Photographer getPhotographer(@NotNull UUID uuid);
+
+ @Nullable
+ public Photographer getPhotographer(@NotNull String id);
+
+ @Nullable
+ public Photographer createPhotographer(@NotNull String id, @NotNull Location location);
+
+ @Nullable
+ public Photographer createPhotographer(@NotNull String id, @NotNull Location location, @NotNull BukkitRecorderOption recorderOption);
+
+ public void removePhotographer(@NotNull String id);
+
+ public void removePhotographer(@NotNull UUID uuid);
+
+ public void removeAllPhotographers();
+
+ public Collection<Photographer> getPhotographers();
+}
diff --git a/src/main/java/top/leavesmc/leaves/replay/BukkitRecorderOption.java b/src/main/java/top/leavesmc/leaves/replay/BukkitRecorderOption.java
new file mode 100644
index 0000000000000000000000000000000000000000..3df4a6055b91c28e273d6fb2697b608778f40a9c
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/replay/BukkitRecorderOption.java
@@ -0,0 +1,18 @@
+package top.leavesmc.leaves.replay;
+
+public class BukkitRecorderOption {
+
+ // public int recordDistance = -1;
+ public String serverName = "Leaves";
+ public BukkitRecordWeather forceWeather = BukkitRecordWeather.NULL;
+ public int forceDayTime = -1;
+ public boolean ignoreChat = false;
+ // public boolean ignoreItem = false;
+
+ public enum BukkitRecordWeather {
+ CLEAR,
+ RAIN,
+ THUNDER,
+ NULL
+ }
+}

View File

@@ -0,0 +1,868 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <wangxyper@163.com>
Date: Sun, 4 Aug 2024 09:56:20 +0800
Subject: [PATCH] LinearPurpur Linear region format
diff --git a/build.gradle.kts b/build.gradle.kts
index 7615702d87b04699b2dd381c3b0c7e700602af8b..7b11c45914392c01b4d28b104f80e6ed34eb9955 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -31,6 +31,10 @@ dependencies {
alsoShade(log4jPlugins.output)
implementation("io.netty:netty-codec-haproxy:4.1.97.Final") // Paper - Add support for proxy protocol
// Paper end
+ // LinearPaper start
+ implementation("com.github.luben:zstd-jni:1.5.6-3")
+ implementation("org.lz4:lz4-java:1.8.0")
+ // LinearPaper end
implementation("org.apache.logging.log4j:log4j-iostreams:2.22.1") // Paper - remove exclusion
implementation("org.ow2.asm:asm-commons:9.7.1")
implementation("org.spongepowered:configurate-yaml:4.2.0-SNAPSHOT") // Paper - config files
diff --git a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/io/ChunkSystemRegionFileStorage.java b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/io/ChunkSystemRegionFileStorage.java
index 73df26b27146bbad2106d57b22dd3c792ed3dd1d..d2f209dd61f4412478a4b8fbe3489787d30bf74b 100644
--- a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/io/ChunkSystemRegionFileStorage.java
+++ b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/io/ChunkSystemRegionFileStorage.java
@@ -7,8 +7,8 @@ public interface ChunkSystemRegionFileStorage {
public boolean moonrise$doesRegionFileNotExistNoIO(final int chunkX, final int chunkZ);
- public RegionFile moonrise$getRegionFileIfLoaded(final int chunkX, final int chunkZ);
+ public org.stupidcraft.linearpaper.region.IRegionFile moonrise$getRegionFileIfLoaded(final int chunkX, final int chunkZ); // LinearPaper // Leaf
- public RegionFile moonrise$getRegionFileIfExists(final int chunkX, final int chunkZ) throws IOException;
+ public org.stupidcraft.linearpaper.region.IRegionFile moonrise$getRegionFileIfExists(final int chunkX, final int chunkZ) throws IOException; // LinearPaper // Leaf
}
diff --git a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/io/RegionFileIOThread.java b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/io/RegionFileIOThread.java
index 3218cbf84f54daf06e84442d5eb1a36d8da6b215..ec9b27177dc526510e86d85f48f167b44c01ac62 100644
--- a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/io/RegionFileIOThread.java
+++ b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/io/RegionFileIOThread.java
@@ -1043,9 +1043,9 @@ public final class RegionFileIOThread extends PrioritisedQueueExecutorThread {
return ((ChunkSystemRegionFileStorage)(Object)this.getCache()).moonrise$doesRegionFileNotExistNoIO(chunkX, chunkZ);
}
- public <T> T computeForRegionFile(final int chunkX, final int chunkZ, final boolean existingOnly, final Function<RegionFile, T> function) {
+ public <T> T computeForRegionFile(final int chunkX, final int chunkZ, final boolean existingOnly, final Function<org.stupidcraft.linearpaper.region.IRegionFile, T> function) { // LinearPaper
final RegionFileStorage cache = this.getCache();
- final RegionFile regionFile;
+ final org.stupidcraft.linearpaper.region.IRegionFile regionFile; // LinearPaper
synchronized (cache) {
try {
if (existingOnly) {
@@ -1061,9 +1061,9 @@ public final class RegionFileIOThread extends PrioritisedQueueExecutorThread {
}
}
- public <T> T computeForRegionFileIfLoaded(final int chunkX, final int chunkZ, final Function<RegionFile, T> function) {
+ public <T> T computeForRegionFileIfLoaded(final int chunkX, final int chunkZ, final Function<org.stupidcraft.linearpaper.region.IRegionFile, T> function) { // LinearPaper
final RegionFileStorage cache = this.getCache();
- final RegionFile regionFile;
+ final org.stupidcraft.linearpaper.region.IRegionFile regionFile; // LinearPaper
synchronized (cache) {
regionFile = ((ChunkSystemRegionFileStorage)(Object)cache).moonrise$getRegionFileIfLoaded(chunkX, chunkZ);
diff --git a/src/main/java/me/earthme/luminol/config/modules/misc/RegionFormatConfig.java b/src/main/java/me/earthme/luminol/config/modules/misc/RegionFormatConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..fda9177bc2c5cc0176f816b9774a2b7de3bb57e9
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/misc/RegionFormatConfig.java
@@ -0,0 +1,51 @@
+package me.earthme.luminol.config.modules.misc;
+
+import com.electronwill.nightconfig.core.file.CommentedFileConfig;
+import com.mojang.logging.LogUtils;
+import me.earthme.luminol.config.ConfigInfo;
+import me.earthme.luminol.config.DoNotLoad;
+import me.earthme.luminol.config.EnumConfigCategory;
+import me.earthme.luminol.config.IConfigModule;
+import org.slf4j.Logger;
+import org.stupidcraft.linearpaper.region.EnumRegionFileExtension;
+
+public class RegionFormatConfig implements IConfigModule {
+ @DoNotLoad
+ private static final Logger logger = LogUtils.getLogger();
+ @DoNotLoad
+ public static EnumRegionFileExtension regionFormatType;
+
+ @ConfigInfo(baseName = "region_format_name", comments = "Available names: MCA, LINEAR")
+ public static String regionFormatTypeName = "MCA";
+ @ConfigInfo(baseName = "linear_compression_level", comments = "Compression level for linear region files.Available: 1 - 22")
+ public static int linearCompressionLevel = 1;
+ @ConfigInfo(baseName = "throw_on_unknown_extension_detected")
+ public static boolean throwOnUnknownExtension = false;
+ @ConfigInfo(baseName = "flush_per_seconds", comments = "Flush to disk every n seconds")
+ public static int linearFlushFrequency = 5;
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.MISC;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "region_format_settings";
+ }
+
+ @Override
+ public void onLoaded(CommentedFileConfig config){
+ regionFormatType = EnumRegionFileExtension.fromName(RegionFormatConfig.regionFormatTypeName);
+ if (RegionFormatConfig.regionFormatType == EnumRegionFileExtension.UNKNOWN) {
+ logger.error("Unknown region file type {} ! Falling back to MCA format.", RegionFormatConfig.regionFormatTypeName);
+ RegionFormatConfig.regionFormatType = EnumRegionFileExtension.MCA;
+ }
+
+ if (RegionFormatConfig.linearCompressionLevel > 23 || RegionFormatConfig.linearCompressionLevel < 1) {
+ logger.error("Linear region compression level should be between 1 and 22 in config: {}", RegionFormatConfig.linearCompressionLevel);
+ logger.error("Falling back to compression level 1.");
+ RegionFormatConfig.linearCompressionLevel = 1;
+ }
+ }
+}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index db48812e886bc0110a1e098a98a67a5291e8eed3..29103346dd3e5e69de260c95051c9447fda0da41 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1003,10 +1003,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
while (iterator1.hasNext()) {
ServerLevel worldserver2 = (ServerLevel) iterator1.next();
- MinecraftServer.LOGGER.info("ThreadedAnvilChunkStorage ({}): All chunks are saved", worldserver2.getChunkSource().chunkMap.getStorageName());
+ MinecraftServer.LOGGER.info("ThreadedChunkStorage ({}): All chunks are saved", worldserver2.getChunkSource().chunkMap.getStorageName()); // LinearPaper
}
- MinecraftServer.LOGGER.info("ThreadedAnvilChunkStorage: All dimensions are saved");
+ MinecraftServer.LOGGER.info("ThreadedChunkStorage: All dimensions are saved"); // LinearPaper
}
return flag3;
diff --git a/src/main/java/net/minecraft/util/worldupdate/WorldUpgrader.java b/src/main/java/net/minecraft/util/worldupdate/WorldUpgrader.java
index cb39c629af1827078f35904a373d35a63fea17ff..dc41c7c4616fa925427cd5a862f3923c5fa65902 100644
--- a/src/main/java/net/minecraft/util/worldupdate/WorldUpgrader.java
+++ b/src/main/java/net/minecraft/util/worldupdate/WorldUpgrader.java
@@ -76,7 +76,7 @@ public class WorldUpgrader {
volatile int skipped;
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)$"); // LinearPaper
final DimensionDataStorage overworldDataStorage;
public WorldUpgrader(LevelStorageSource.LevelStorageAccess session, DataFixer dataFixer, RegistryAccess dynamicRegistryManager, boolean eraseCache, boolean recreateRegionFiles) {
@@ -400,7 +400,7 @@ public class WorldUpgrader {
private static List<WorldUpgrader.FileToUpgrade> getAllChunkPositions(RegionStorageInfo key, Path regionDirectory) {
File[] afile = regionDirectory.toFile().listFiles((file, s) -> {
- return s.endsWith(".mca");
+ return s.endsWith(".linear") || s.endsWith(".mca"); // LinearPaper
});
if (afile == null) {
@@ -420,7 +420,7 @@ public class WorldUpgrader {
List<ChunkPos> list1 = Lists.newArrayList();
try {
- RegionFile regionfile = new RegionFile(key, file.toPath(), regionDirectory, true);
+ org.stupidcraft.linearpaper.region.IRegionFile regionfile = org.stupidcraft.linearpaper.region.IRegionFileFactory.getAbstractRegionFile(key, file.toPath(), regionDirectory, true); // LinearPaper
try {
for (int i1 = 0; i1 < 32; ++i1) {
@@ -483,7 +483,7 @@ public class WorldUpgrader {
protected abstract boolean tryProcessOnePosition(T storage, ChunkPos chunkPos, ResourceKey<Level> worldKey);
- private void onFileFinished(RegionFile regionFile) {
+ private void onFileFinished(org.stupidcraft.linearpaper.region.IRegionFile regionFile) { // LinearPaper
if (WorldUpgrader.this.recreateRegionFiles) {
if (this.previousWriteFuture != null) {
this.previousWriteFuture.join();
@@ -508,7 +508,7 @@ public class WorldUpgrader {
}
}
- static record FileToUpgrade(RegionFile file, List<ChunkPos> chunksToUpgrade) {
+ static record FileToUpgrade(org.stupidcraft.linearpaper.region.IRegionFile file, List<ChunkPos> chunksToUpgrade) { // LinearPaper
}
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
index 1e0439cf3f4008fa430acb90b45f5bc4cdd6d7f2..9b217cbfb800df8f72fffaf033ff671c31f3ac98 100644
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
@@ -28,7 +28,7 @@ import net.minecraft.nbt.NbtIo; // Paper
import net.minecraft.world.level.ChunkPos;
import org.slf4j.Logger;
-public class RegionFile implements AutoCloseable {
+public class RegionFile implements org.stupidcraft.linearpaper.region.IRegionFile, AutoCloseable { // LinearPaper
private static final Logger LOGGER = LogUtils.getLogger();
private static final int SECTOR_BYTES = 4096;
@@ -129,7 +129,7 @@ public class RegionFile implements AutoCloseable {
}
// note: only call for CHUNK regionfiles
- boolean recalculateHeader() throws IOException {
+ public boolean recalculateHeader() throws IOException { // LinearPaper - make public
if (!this.canRecalcHeader) {
return false;
}
@@ -928,10 +928,10 @@ public class RegionFile implements AutoCloseable {
private static int getChunkIndex(int x, int z) {
return (x & 31) + (z & 31) * 32;
}
- synchronized boolean isOversized(int x, int z) {
+ public synchronized boolean isOversized(int x, int z) { // LinearPaper - make public
return this.oversized[getChunkIndex(x, z)] == 1;
}
- synchronized void setOversized(int x, int z, boolean oversized) throws IOException {
+ public synchronized void setOversized(int x, int z, boolean oversized) throws IOException { // LinearPaper - make public
final int offset = getChunkIndex(x, z);
boolean previous = this.oversized[offset] == 1;
this.oversized[offset] = (byte) (oversized ? 1 : 0);
@@ -970,7 +970,7 @@ public class RegionFile implements AutoCloseable {
return this.path.getParent().resolve(this.path.getFileName().toString().replaceAll("\\.mca$", "") + "_oversized_" + x + "_" + z + ".nbt");
}
- synchronized CompoundTag getOversizedData(int x, int z) throws IOException {
+ public synchronized CompoundTag getOversizedData(int x, int z) throws IOException { // LinearPaper - make public
Path file = getOversizedFile(x, z);
try (DataInputStream out = new DataInputStream(new java.io.BufferedInputStream(new InflaterInputStream(Files.newInputStream(file))))) {
return NbtIo.read((java.io.DataInput) out);
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
index 40689256711cc94a806ca1da346f4f62eda31526..f6ecb85d6802e4eadc0e487ae2d8cbfbc38d6f65 100644
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
@@ -1,7 +1,7 @@
package net.minecraft.world.level.chunk.storage;
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
-import it.unimi.dsi.fastutil.objects.ObjectIterator;
+
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
@@ -9,6 +9,8 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.file.Path;
import javax.annotation.Nullable;
+
+import me.earthme.luminol.config.modules.misc.RegionFormatConfig;
import net.minecraft.FileUtil;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtAccounter;
@@ -21,7 +23,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
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.stupidcraft.linearpaper.region.IRegionFile> regionCache = new Long2ObjectLinkedOpenHashMap(); // LinearPaper
private final RegionStorageInfo info;
private final Path folder;
private final boolean sync;
@@ -30,7 +32,11 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
private static final int REGION_SHIFT = 5;
private static final int MAX_NON_EXISTING_CACHE = 1024 * 64;
private final it.unimi.dsi.fastutil.longs.LongLinkedOpenHashSet nonExistingRegionFiles = new it.unimi.dsi.fastutil.longs.LongLinkedOpenHashSet(MAX_NON_EXISTING_CACHE+1);
+ // Leaf start - Linear region format
private static String getRegionFileName(final int chunkX, final int chunkZ) {
+ if (RegionFormatConfig.regionFormatType == org.stupidcraft.linearpaper.region.EnumRegionFileExtension.LINEAR) {
+ return "r." + (chunkX >> REGION_SHIFT) + "." + (chunkZ >> REGION_SHIFT) + ".linear";
+ }
return "r." + (chunkX >> REGION_SHIFT) + "." + (chunkZ >> REGION_SHIFT) + ".mca";
}
@@ -66,15 +72,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.stupidcraft.linearpaper.region.IRegionFile moonrise$getRegionFileIfLoaded(final int chunkX, final int chunkZ) { // LinearPaper
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.stupidcraft.linearpaper.region.IRegionFile moonrise$getRegionFileIfExists(final int chunkX, final int chunkZ) throws IOException { // LinearPaper
final long key = ChunkPos.asLong(chunkX >> REGION_SHIFT, chunkZ >> REGION_SHIFT);
- RegionFile ret = this.regionCache.getAndMoveToFirst(key);
+ org.stupidcraft.linearpaper.region.IRegionFile ret = this.regionCache.getAndMoveToFirst(key); // LinearPaper
if (ret != null) {
return ret;
}
@@ -98,7 +104,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.stupidcraft.linearpaper.region.IRegionFileFactory.getAbstractRegionFile(this.info, regionPath, this.folder, this.sync); // LinearPaper
this.regionCache.putAndMoveToFirst(key, ret);
@@ -115,7 +121,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")) { // LinearPaper
return null;
}
@@ -143,7 +149,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
this.isChunkData = isChunkDataFolder(this.folder); // Paper - recalculate region file headers
}
- public RegionFile getRegionFile(ChunkPos chunkcoordintpair, boolean existingOnly) throws IOException { // CraftBukkit // Paper - public
+ public org.stupidcraft.linearpaper.region.IRegionFile getRegionFile(ChunkPos chunkcoordintpair, boolean existingOnly) throws IOException { // CraftBukkit // Paper - public // LinearPaper
// Paper start - rewrite chunk system
if (existingOnly) {
return this.moonrise$getRegionFileIfExists(chunkcoordintpair.x, chunkcoordintpair.z);
@@ -151,7 +157,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
synchronized (this) {
final long key = ChunkPos.asLong(chunkcoordintpair.x >> REGION_SHIFT, chunkcoordintpair.z >> REGION_SHIFT);
- RegionFile ret = this.regionCache.getAndMoveToFirst(key);
+ org.stupidcraft.linearpaper.region.IRegionFile ret = this.regionCache.getAndMoveToFirst(key); // LinearPaper
if (ret != null) {
return ret;
}
@@ -160,13 +166,13 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
this.regionCache.removeLast().close();
}
- final Path regionPath = this.folder.resolve(getRegionFileName(chunkcoordintpair.x, chunkcoordintpair.z));
+ final Path regionPath = this.folder.resolve(getRegionFileName(chunkcoordintpair.x, chunkcoordintpair.z)); // LinearPaper
this.createRegionFile(key);
FileUtil.createDirectoriesSafe(this.folder);
- ret = new RegionFile(this.info, regionPath, this.folder, this.sync);
+ ret = org.stupidcraft.linearpaper.region.IRegionFileFactory.getAbstractRegionFile(this.info, regionPath, this.folder, this.sync); // LinearPaper
this.regionCache.putAndMoveToFirst(key, ret);
@@ -180,7 +186,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 PAPER - You may ask for help on Discord, but do not file an issue. These error messages can not be removed.");
}
- private static CompoundTag readOversizedChunk(RegionFile regionfile, ChunkPos chunkCoordinate) throws IOException {
+ private static CompoundTag readOversizedChunk(org.stupidcraft.linearpaper.region.IRegionFile regionfile, ChunkPos chunkCoordinate) throws IOException { // LinearPaper
synchronized (regionfile) {
try (DataInputStream datainputstream = regionfile.getChunkDataInputStream(chunkCoordinate)) {
CompoundTag oversizedData = regionfile.getOversizedData(chunkCoordinate.x, chunkCoordinate.z);
@@ -215,7 +221,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@Nullable
public CompoundTag read(ChunkPos pos) 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(pos, true);
+ org.stupidcraft.linearpaper.region.IRegionFile regionfile = this.getRegionFile(pos, true); // LinearPaper
if (regionfile == null) {
return null;
}
@@ -279,7 +285,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
public void scanChunk(ChunkPos chunkPos, StreamTagVisitor scanner) 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.stupidcraft.linearpaper.region.IRegionFile regionfile = this.getRegionFile(chunkPos, true); // LinearPaper
if (regionfile == null) {
return;
}
@@ -309,7 +315,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
}
public void write(ChunkPos pos, @Nullable CompoundTag nbt) throws IOException { // Paper - public
- RegionFile regionfile = this.getRegionFile(pos, nbt == null); // CraftBukkit // Paper - rewrite chunk system
+ org.stupidcraft.linearpaper.region.IRegionFile regionfile = this.getRegionFile(pos, nbt == null); // CraftBukkit // Paper - rewrite chunk system // LinearPaper
// Paper start - rewrite chunk system
if (regionfile == null) {
// if the RegionFile doesn't exist, no point in deleting from it
@@ -368,7 +374,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.stupidcraft.linearpaper.region.IRegionFile regionFile : this.regionCache.values()) { // LinearPaper
try {
regionFile.close();
} catch (final IOException ex) {
@@ -385,7 +391,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.stupidcraft.linearpaper.region.IRegionFile regionFile : this.regionCache.values()) { // LinearPaper
try {
regionFile.flush();
} catch (final IOException ex) {
diff --git a/src/main/java/org/stupidcraft/linearpaper/region/EnumRegionFileExtension.java b/src/main/java/org/stupidcraft/linearpaper/region/EnumRegionFileExtension.java
new file mode 100644
index 0000000000000000000000000000000000000000..8eba172be9bce7cccd27d27bee2d6c6f917a9e4e
--- /dev/null
+++ b/src/main/java/org/stupidcraft/linearpaper/region/EnumRegionFileExtension.java
@@ -0,0 +1,56 @@
+package org.stupidcraft.linearpaper.region;
+
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Locale;
+
+public enum EnumRegionFileExtension {
+ LINEAR(".linear"),
+ MCA(".mca"),
+ UNKNOWN(null);
+
+ private final String extensionName;
+
+ EnumRegionFileExtension(String extensionName) {
+ this.extensionName = extensionName;
+ }
+
+ public String getExtensionName() {
+ return this.extensionName;
+ }
+
+ @Contract(pure = true)
+ public static EnumRegionFileExtension fromName(@NotNull String name) {
+ switch (name.toUpperCase(Locale.ROOT)) {
+ default -> {
+ return UNKNOWN;
+ }
+
+ case "MCA" -> {
+ return MCA;
+ }
+
+ case "LINEAR" -> {
+ return LINEAR;
+ }
+ }
+ }
+
+ @Contract(pure = true)
+ public static EnumRegionFileExtension fromExtension(@NotNull String name) {
+ switch (name.toLowerCase()) {
+ case "mca" -> {
+ return MCA;
+ }
+
+ case "linear" -> {
+ return LINEAR;
+ }
+
+ default -> {
+ return UNKNOWN;
+ }
+ }
+ }
+}
diff --git a/src/main/java/org/stupidcraft/linearpaper/region/IRegionFile.java b/src/main/java/org/stupidcraft/linearpaper/region/IRegionFile.java
new file mode 100644
index 0000000000000000000000000000000000000000..6417f5b6daa35044995dd0aa9cfc24acd8ce4287
--- /dev/null
+++ b/src/main/java/org/stupidcraft/linearpaper/region/IRegionFile.java
@@ -0,0 +1,26 @@
+package org.stupidcraft.linearpaper.region;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.file.Path;
+
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.world.level.ChunkPos;
+
+public interface IRegionFile {
+ Path getPath();
+ void flush() throws IOException;
+ void clear(ChunkPos pos) throws IOException;
+ void close() throws IOException;
+ void setOversized(int x, int z, boolean b) throws IOException;
+
+ boolean hasChunk(ChunkPos pos);
+ boolean doesChunkExist(ChunkPos pos) throws Exception;
+ boolean isOversized(int x, int z);
+ boolean recalculateHeader() throws IOException;
+
+ DataOutputStream getChunkDataOutputStream(ChunkPos pos) throws IOException;
+ DataInputStream getChunkDataInputStream(ChunkPos pos) throws IOException;
+ CompoundTag getOversizedData(int x, int z) throws IOException;
+}
diff --git a/src/main/java/org/stupidcraft/linearpaper/region/IRegionFileFactory.java b/src/main/java/org/stupidcraft/linearpaper/region/IRegionFileFactory.java
new file mode 100644
index 0000000000000000000000000000000000000000..4bbce604a0c1650f5584fc16129cdd2da12d28fa
--- /dev/null
+++ b/src/main/java/org/stupidcraft/linearpaper/region/IRegionFileFactory.java
@@ -0,0 +1,52 @@
+package org.stupidcraft.linearpaper.region;
+
+import java.io.IOException;
+import java.nio.file.Path;
+
+import me.earthme.luminol.config.modules.misc.RegionFormatConfig;
+import net.minecraft.world.level.chunk.storage.RegionFile;
+import net.minecraft.world.level.chunk.storage.RegionFileVersion;
+import net.minecraft.world.level.chunk.storage.RegionStorageInfo;
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.annotations.NotNull;
+
+public class IRegionFileFactory {
+ @Contract("_, _, _, _ -> new")
+ public static @NotNull IRegionFile getAbstractRegionFile(RegionStorageInfo storageKey, Path directory, Path path, boolean dsync) throws IOException {
+ return getAbstractRegionFile(storageKey, directory, path, RegionFileVersion.getCompressionFormat(), dsync);
+ }
+
+ @Contract("_, _, _, _, _ -> new")
+ public static @NotNull IRegionFile getAbstractRegionFile(RegionStorageInfo storageKey, Path directory, Path path, boolean dsync, boolean canRecalcHeader) throws IOException {
+ return getAbstractRegionFile(storageKey, directory, path, RegionFileVersion.getCompressionFormat(), dsync, canRecalcHeader);
+ }
+
+ @Contract("_, _, _, _, _ -> new")
+ public static @NotNull IRegionFile getAbstractRegionFile(RegionStorageInfo storageKey, Path path, Path directory, RegionFileVersion compressionFormat, boolean dsync) throws IOException {
+ return getAbstractRegionFile(storageKey, path, directory, compressionFormat, dsync, true);
+ }
+
+ @Contract("_, _, _, _, _, _ -> new")
+ public static @NotNull IRegionFile getAbstractRegionFile(RegionStorageInfo storageKey, @NotNull Path path, Path directory, RegionFileVersion compressionFormat, boolean dsync, boolean canRecalcHeader) throws IOException {
+ final String fullFileName = path.getFileName().toString();
+ final String[] fullNameSplit = fullFileName.split("\\.");
+ final String extensionName = fullNameSplit[fullNameSplit.length - 1];
+ switch (EnumRegionFileExtension.fromExtension(extensionName)) {
+ case UNKNOWN -> {
+ if (RegionFormatConfig.throwOnUnknownExtension) {
+ throw new IllegalArgumentException("Unknown region file extension for file: " + fullFileName + "!");
+ }
+
+ return new RegionFile(storageKey, path, directory, compressionFormat, dsync);
+ }
+
+ case LINEAR -> {
+ return new LinearRegionFile(path, me.earthme.luminol.config.modules.misc.RegionFormatConfig.linearCompressionLevel);
+ }
+
+ default -> {
+ return new RegionFile(storageKey, path, directory, compressionFormat, dsync);
+ }
+ }
+ }
+}
diff --git a/src/main/java/org/stupidcraft/linearpaper/region/LinearRegionFile.java b/src/main/java/org/stupidcraft/linearpaper/region/LinearRegionFile.java
new file mode 100644
index 0000000000000000000000000000000000000000..685c055619f80554a5e8f85554f86faf2b1f53bf
--- /dev/null
+++ b/src/main/java/org/stupidcraft/linearpaper/region/LinearRegionFile.java
@@ -0,0 +1,311 @@
+package org.stupidcraft.linearpaper.region;
+
+import com.github.luben.zstd.ZstdInputStream;
+import com.github.luben.zstd.ZstdOutputStream;
+import com.mojang.logging.LogUtils;
+
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import javax.annotation.Nullable;
+
+import me.earthme.luminol.config.modules.misc.RegionFormatConfig;
+import net.jpountz.lz4.LZ4Compressor;
+import net.jpountz.lz4.LZ4Factory;
+import net.jpountz.lz4.LZ4FastDecompressor;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.world.level.ChunkPos;
+import org.slf4j.Logger;
+
+public class LinearRegionFile implements IRegionFile, AutoCloseable {
+ private static final long SUPERBLOCK = -4323716122432332390L;
+ private static final byte VERSION = 2;
+ private static final int HEADER_SIZE = 32;
+ private static final int FOOTER_SIZE = 8;
+ private static final Logger LOGGER = LogUtils.getLogger();
+ private static final List<Byte> SUPPORTED_VERSIONS = Arrays.asList((byte) 1, (byte) 2);
+ private final byte[][] buffer = new byte[1024][];
+ private final int[] bufferUncompressedSize = new int[1024];
+ private final int[] chunkTimestamps = new int[1024];
+ private final LZ4Compressor compressor;
+ private final LZ4FastDecompressor decompressor;
+ private final int compressionLevel;
+ public boolean closed = false;
+ public Path path;
+ private volatile long lastFlushed = System.nanoTime();
+
+ public LinearRegionFile(Path file, int compression) throws IOException {
+ this.path = file;
+ this.compressionLevel = compression;
+ this.compressor = LZ4Factory.fastestInstance().fastCompressor();
+ this.decompressor = LZ4Factory.fastestInstance().fastDecompressor();
+
+ File regionFile = new File(this.path.toString());
+
+ Arrays.fill(this.bufferUncompressedSize, 0);
+
+ if (!regionFile.canRead()) return;
+
+ try (FileInputStream fileStream = new FileInputStream(regionFile);
+ DataInputStream rawDataStream = new DataInputStream(fileStream)) {
+
+ long superBlock = rawDataStream.readLong();
+ if (superBlock != SUPERBLOCK)
+ throw new RuntimeException("Invalid superblock: " + superBlock + " in " + file);
+
+ byte version = rawDataStream.readByte();
+ if (!SUPPORTED_VERSIONS.contains(version))
+ throw new RuntimeException("Invalid version: " + version + " in " + file);
+
+ // Skip newestTimestamp (Long) + Compression level (Byte) + Chunk count (Short): Unused.
+ rawDataStream.skipBytes(11);
+
+ int dataCount = rawDataStream.readInt();
+ long fileLength = file.toFile().length();
+ if (fileLength != HEADER_SIZE + dataCount + FOOTER_SIZE)
+ throw new IOException("Invalid file length: " + this.path + " " + fileLength + " " + (HEADER_SIZE + dataCount + FOOTER_SIZE));
+
+ rawDataStream.skipBytes(8); // Skip data hash (Long): Unused.
+
+ byte[] rawCompressed = new byte[dataCount];
+ rawDataStream.readFully(rawCompressed, 0, dataCount);
+
+ superBlock = rawDataStream.readLong();
+ if (superBlock != SUPERBLOCK)
+ throw new IOException("Footer superblock invalid " + this.path);
+
+ try (DataInputStream dataStream = new DataInputStream(new ZstdInputStream(new ByteArrayInputStream(rawCompressed)))) {
+
+ int[] starts = new int[1024];
+ for (int i = 0; i < 1024; i++) {
+ starts[i] = dataStream.readInt();
+ dataStream.skipBytes(4); // Skip timestamps (Int): Unused.
+ }
+
+ for (int i = 0; i < 1024; i++) {
+ if (starts[i] > 0) {
+ int size = starts[i];
+ byte[] b = new byte[size];
+ dataStream.readFully(b, 0, size);
+
+ int maxCompressedLength = this.compressor.maxCompressedLength(size);
+ byte[] compressed = new byte[maxCompressedLength];
+ int compressedLength = this.compressor.compress(b, 0, size, compressed, 0, maxCompressedLength);
+ b = new byte[compressedLength];
+ System.arraycopy(compressed, 0, b, 0, compressedLength);
+
+ this.buffer[i] = b;
+ this.bufferUncompressedSize[i] = size;
+ }
+ }
+ }
+ }
+ }
+
+ private static int getChunkIndex(int x, int z) {
+ return (x & 31) + ((z & 31) << 5);
+ }
+
+ private static int getTimestamp() {
+ return (int) (System.currentTimeMillis() / 1000L);
+ }
+
+ public void flush() throws IOException {
+ flushWrapper(); // sync
+ }
+
+ public void flushWrapper() {
+ try {
+ save();
+ } catch (IOException e) {
+ LOGGER.error("Failed to flush region file {}", path.toAbsolutePath(), e);
+ }
+ }
+
+ public boolean doesChunkExist(ChunkPos pos) throws Exception {
+ throw new Exception("doesChunkExist is a stub");
+ }
+
+ private synchronized void save() throws IOException {
+ long timestamp = getTimestamp();
+ short chunkCount = 0;
+
+ File tempFile = new File(path.toString() + ".tmp");
+
+ try (FileOutputStream fileStream = new FileOutputStream(tempFile);
+ ByteArrayOutputStream zstdByteArray = new ByteArrayOutputStream();
+ ZstdOutputStream zstdStream = new ZstdOutputStream(zstdByteArray, this.compressionLevel);
+ DataOutputStream zstdDataStream = new DataOutputStream(zstdStream);
+ DataOutputStream dataStream = new DataOutputStream(fileStream)) {
+
+ dataStream.writeLong(SUPERBLOCK);
+ dataStream.writeByte(VERSION);
+ dataStream.writeLong(timestamp);
+ dataStream.writeByte(this.compressionLevel);
+
+ ArrayList<byte[]> byteBuffers = new ArrayList<>();
+ for (int i = 0; i < 1024; i++) {
+ if (this.bufferUncompressedSize[i] != 0) {
+ chunkCount += 1;
+ byte[] content = new byte[bufferUncompressedSize[i]];
+ this.decompressor.decompress(buffer[i], 0, content, 0, bufferUncompressedSize[i]);
+
+ byteBuffers.add(content);
+ } else byteBuffers.add(null);
+ }
+ for (int i = 0; i < 1024; i++) {
+ zstdDataStream.writeInt(this.bufferUncompressedSize[i]); // Write uncompressed size
+ zstdDataStream.writeInt(this.chunkTimestamps[i]); // Write timestamp
+ }
+ for (int i = 0; i < 1024; i++) {
+ if (byteBuffers.get(i) != null)
+ zstdDataStream.write(byteBuffers.get(i), 0, byteBuffers.get(i).length);
+ }
+ zstdDataStream.close();
+
+ dataStream.writeShort(chunkCount);
+
+ byte[] compressed = zstdByteArray.toByteArray();
+
+ dataStream.writeInt(compressed.length);
+ dataStream.writeLong(0);
+
+ dataStream.write(compressed, 0, compressed.length);
+ dataStream.writeLong(SUPERBLOCK);
+
+ dataStream.flush();
+ fileStream.getFD().sync();
+ fileStream.getChannel().force(true); // Ensure atomicity on Btrfs
+ }
+ Files.move(tempFile.toPath(), this.path, StandardCopyOption.REPLACE_EXISTING);
+ this.lastFlushed = System.nanoTime();
+ }
+
+ private void checkAndSave(){
+ if ((System.nanoTime() - this.lastFlushed) >= TimeUnit.NANOSECONDS.toSeconds(RegionFormatConfig.linearFlushFrequency)) {
+ this.flushWrapper();
+ }
+ }
+
+ public synchronized void write(ChunkPos pos, ByteBuffer buffer) {
+ try {
+ byte[] b = toByteArray(new ByteArrayInputStream(buffer.array()));
+ int uncompressedSize = b.length;
+
+ int maxCompressedLength = this.compressor.maxCompressedLength(b.length);
+ byte[] compressed = new byte[maxCompressedLength];
+ int compressedLength = this.compressor.compress(b, 0, b.length, compressed, 0, maxCompressedLength);
+ b = new byte[compressedLength];
+ System.arraycopy(compressed, 0, b, 0, compressedLength);
+
+ int index = getChunkIndex(pos.x, pos.z);
+ this.buffer[index] = b;
+ this.chunkTimestamps[index] = getTimestamp();
+ this.bufferUncompressedSize[getChunkIndex(pos.x, pos.z)] = uncompressedSize;
+ } catch (IOException e) {
+ LOGGER.error("Chunk write IOException {} {}", e, this.path);
+ }
+
+ this.checkAndSave();
+ }
+
+ public DataOutputStream getChunkDataOutputStream(ChunkPos pos) {
+ try {
+ return new DataOutputStream(new BufferedOutputStream(new ChunkBuffer(pos)));
+ }finally {
+ this.checkAndSave();
+ }
+ }
+
+ private byte[] toByteArray(InputStream in) throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] tempBuffer = new byte[4096];
+
+ int length;
+ while ((length = in.read(tempBuffer)) >= 0) {
+ out.write(tempBuffer, 0, length);
+ }
+
+ return out.toByteArray();
+ }
+
+ @Nullable
+ public synchronized DataInputStream getChunkDataInputStream(ChunkPos pos) {
+ try {
+ if (this.bufferUncompressedSize[getChunkIndex(pos.x, pos.z)] != 0) {
+ byte[] content = new byte[bufferUncompressedSize[getChunkIndex(pos.x, pos.z)]];
+ this.decompressor.decompress(this.buffer[getChunkIndex(pos.x, pos.z)], 0, content, 0, bufferUncompressedSize[getChunkIndex(pos.x, pos.z)]);
+ return new DataInputStream(new ByteArrayInputStream(content));
+ }
+ }finally {
+ this.checkAndSave();
+ }
+ return null;
+ }
+
+ public void clear(ChunkPos pos) {
+ int i = getChunkIndex(pos.x, pos.z);
+ this.buffer[i] = null;
+ this.bufferUncompressedSize[i] = 0;
+ this.chunkTimestamps[i] = getTimestamp();
+ this.flushWrapper();
+ }
+
+ public Path getPath() {
+ return this.path;
+ }
+
+ public boolean hasChunk(ChunkPos pos) {
+ return this.bufferUncompressedSize[getChunkIndex(pos.x, pos.z)] > 0;
+ }
+
+ public void close() throws IOException {
+ if (closed) return;
+ closed = true;
+ flush(); // sync
+ }
+
+ public boolean recalculateHeader() {
+ return false;
+ }
+
+ public void setOversized(int x, int z, boolean something) {
+ }
+
+ public CompoundTag getOversizedData(int x, int z) throws IOException {
+ throw new IOException("getOversizedData is a stub " + this.path);
+ }
+
+ public boolean isOversized(int x, int z) {
+ return false;
+ }
+
+ private class ChunkBuffer extends ByteArrayOutputStream {
+ private final ChunkPos pos;
+
+ public ChunkBuffer(ChunkPos chunkcoordintpair) {
+ super();
+ this.pos = chunkcoordintpair;
+ }
+
+ public void close() {
+ ByteBuffer bytebuffer = ByteBuffer.wrap(this.buf, 0, this.count);
+ LinearRegionFile.this.write(this.pos, bytebuffer);
+ }
+ }
+}

File diff suppressed because it is too large Load Diff