mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@c032050 Fix command preprocess cancelling and command changing PaperMC/Paper@7044a9c Leave a paper.yml.txt stub pointing to new location (#8090) PaperMC/Paper@4a00cee Readd patch to remove invalid signature on login error PaperMC/Paper@a817697 Add async catcher to PlayerConnection internalTeleport PaperMC/Paper@ef42d2a Fix null profile key breaking nullability contracts for PlayerProfile API (#8233) PaperMC/Paper@3af906b Updated Upstream (Bukkit) PaperMC/Paper@18a0337 [ci skip] Fix grammatical error in README. (#8189) PaperMC/Paper@69950d5 Block Ticking API (#7202)
5839 lines
274 KiB
Diff
5839 lines
274 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Kevin Raneri <kevin.raneri@gmail.com>
|
|
Date: Wed, 3 Feb 2021 23:02:38 -0600
|
|
Subject: [PATCH] Pufferfish Server Changes
|
|
|
|
Pufferfish
|
|
Copyright (C) 2022 Pufferfish Studios LLC
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
diff --git a/build.gradle.kts b/build.gradle.kts
|
|
index 2374cc9bab5039d0a0dc11d4b2ec573ab75778a7..74c91f79576e85618fefb79be8d313ba871701c7 100644
|
|
--- a/build.gradle.kts
|
|
+++ b/build.gradle.kts
|
|
@@ -9,8 +9,12 @@ plugins {
|
|
}
|
|
|
|
dependencies {
|
|
- implementation(project(":paper-api"))
|
|
- implementation(project(":paper-mojangapi"))
|
|
+ implementation(project(":pufferfish-api")) // Pufferfish // Paper
|
|
+ // Pufferfish start
|
|
+ implementation("io.papermc.paper:paper-mojangapi:1.19-R0.1-SNAPSHOT") {
|
|
+ exclude("io.papermc.paper", "paper-api")
|
|
+ }
|
|
+ // Pufferfish end
|
|
// Paper start
|
|
implementation("org.jline:jline-terminal-jansi:3.21.0")
|
|
implementation("net.minecrell:terminalconsoleappender:1.3.0")
|
|
@@ -44,6 +48,14 @@ dependencies {
|
|
runtimeOnly("org.apache.maven.resolver:maven-resolver-connector-basic:1.7.3")
|
|
runtimeOnly("org.apache.maven.resolver:maven-resolver-transport-http:1.7.3")
|
|
|
|
+ // Pufferfish start
|
|
+ implementation("org.yaml:snakeyaml:1.30")
|
|
+ implementation ("me.carleslc.Simple-YAML:Simple-Yaml:1.8") {
|
|
+ exclude(group="org.yaml", module="snakeyaml")
|
|
+ }
|
|
+ // Pufferfish end
|
|
+ implementation("com.github.technove:Flare:34637f3f87") // Pufferfish - flare
|
|
+
|
|
testImplementation("io.github.classgraph:classgraph:4.8.47") // Paper - mob goal test
|
|
testImplementation("junit:junit:4.13.2")
|
|
testImplementation("org.hamcrest:hamcrest-library:1.3")
|
|
@@ -52,6 +64,14 @@ dependencies {
|
|
}
|
|
|
|
val craftbukkitPackageVersion = "1_19_R1" // Paper
|
|
+
|
|
+// Pufferfish Start
|
|
+tasks.withType<JavaCompile> {
|
|
+ val compilerArgs = options.compilerArgs
|
|
+ compilerArgs.add("--add-modules=jdk.incubator.vector")
|
|
+}
|
|
+// Pufferfish End
|
|
+
|
|
tasks.jar {
|
|
archiveClassifier.set("dev")
|
|
|
|
@@ -64,7 +84,7 @@ tasks.jar {
|
|
attributes(
|
|
"Main-Class" to "org.bukkit.craftbukkit.Main",
|
|
"Implementation-Title" to "CraftBukkit",
|
|
- "Implementation-Version" to "git-Paper-$implementationVersion",
|
|
+ "Implementation-Version" to "git-Pufferfish-$implementationVersion", // Pufferfish
|
|
"Implementation-Vendor" to date, // Paper
|
|
"Specification-Title" to "Bukkit",
|
|
"Specification-Version" to project.version,
|
|
diff --git a/src/main/java/co/aikar/timings/TimingsExport.java b/src/main/java/co/aikar/timings/TimingsExport.java
|
|
index 06bff37e4c1fddd3be6343049a66787c63fb420c..2cc44fbf8e5bd436b6d4e19f6c06b351e750cb31 100644
|
|
--- a/src/main/java/co/aikar/timings/TimingsExport.java
|
|
+++ b/src/main/java/co/aikar/timings/TimingsExport.java
|
|
@@ -241,7 +241,8 @@ public class TimingsExport extends Thread {
|
|
parent.put("config", createObject(
|
|
pair("spigot", mapAsJSON(Bukkit.spigot().getSpigotConfig(), null)),
|
|
pair("bukkit", mapAsJSON(Bukkit.spigot().getBukkitConfig(), null)),
|
|
- pair("paper", mapAsJSON(Bukkit.spigot().getPaperConfig(), null))
|
|
+ pair("paper", mapAsJSON(Bukkit.spigot().getPaperConfig(), null)), // Pufferfish
|
|
+ pair("pufferfish", mapAsJSON(gg.pufferfish.pufferfish.PufferfishConfig.getConfigCopy(), null)) // Pufferfish
|
|
));
|
|
|
|
new TimingsExport(listeners, parent, history).start();
|
|
diff --git a/src/main/java/com/destroystokyo/paper/Metrics.java b/src/main/java/com/destroystokyo/paper/Metrics.java
|
|
index 7b1843e16745ca8db2244e17490d291401f22679..061716934ba0a1f01e4d85d664034f72b3c7a765 100644
|
|
--- a/src/main/java/com/destroystokyo/paper/Metrics.java
|
|
+++ b/src/main/java/com/destroystokyo/paper/Metrics.java
|
|
@@ -593,7 +593,7 @@ public class Metrics {
|
|
boolean logFailedRequests = config.getBoolean("logFailedRequests", false);
|
|
// Only start Metrics, if it's enabled in the config
|
|
if (config.getBoolean("enabled", true)) {
|
|
- Metrics metrics = new Metrics("Paper", serverUUID, logFailedRequests, Bukkit.getLogger());
|
|
+ Metrics metrics = new Metrics("Pufferfish", serverUUID, logFailedRequests, Bukkit.getLogger()); // Pufferfish
|
|
|
|
metrics.addCustomChart(new Metrics.SimplePie("minecraft_version", () -> {
|
|
String minecraftVersion = Bukkit.getVersion();
|
|
@@ -603,7 +603,7 @@ public class Metrics {
|
|
|
|
metrics.addCustomChart(new Metrics.SingleLineChart("players", () -> Bukkit.getOnlinePlayers().size()));
|
|
metrics.addCustomChart(new Metrics.SimplePie("online_mode", () -> Bukkit.getOnlineMode() ? "online" : "offline"));
|
|
- metrics.addCustomChart(new Metrics.SimplePie("paper_version", () -> (Metrics.class.getPackage().getImplementationVersion() != null) ? Metrics.class.getPackage().getImplementationVersion() : "unknown"));
|
|
+ metrics.addCustomChart(new Metrics.SimplePie("pufferfish_version", () -> (Metrics.class.getPackage().getImplementationVersion() != null) ? Metrics.class.getPackage().getImplementationVersion() : "unknown"));
|
|
|
|
metrics.addCustomChart(new Metrics.DrilldownPie("java_version", () -> {
|
|
Map<String, Map<String, Integer>> map = new HashMap<>();
|
|
diff --git a/src/main/java/com/destroystokyo/paper/util/misc/AreaMap.java b/src/main/java/com/destroystokyo/paper/util/misc/AreaMap.java
|
|
index c89f6986eda5a132a948732ea1b6923370685317..a69c13e20040c1561d9c2d4d89ec7d4e635134fc 100644
|
|
--- a/src/main/java/com/destroystokyo/paper/util/misc/AreaMap.java
|
|
+++ b/src/main/java/com/destroystokyo/paper/util/misc/AreaMap.java
|
|
@@ -26,7 +26,7 @@ public abstract class AreaMap<E> {
|
|
|
|
// we use linked for better iteration.
|
|
// map of: coordinate to set of objects in coordinate
|
|
- protected final Long2ObjectOpenHashMap<PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<E>> areaMap = new Long2ObjectOpenHashMap<>(1024, 0.7f);
|
|
+ protected Long2ObjectOpenHashMap<PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<E>> areaMap = new Long2ObjectOpenHashMap<>(1024, 0.7f); // Pufferfish - not actually final
|
|
protected final PooledLinkedHashSets<E> pooledHashSets;
|
|
|
|
protected final ChangeCallback<E> addCallback;
|
|
@@ -160,7 +160,8 @@ public abstract class AreaMap<E> {
|
|
protected abstract PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<E> getEmptySetFor(final E object);
|
|
|
|
// expensive op, only for debug
|
|
- protected void validate(final E object, final int viewDistance) {
|
|
+ protected void validate0(final E object, final int viewDistance) { // Pufferfish - rename this thing just in case it gets used I'd rather a compile time error.
|
|
+ if (true) throw new UnsupportedOperationException(); // Pufferfish - not going to put in the effort to fix this if it doesn't ever get used.
|
|
int entiesGot = 0;
|
|
int expectedEntries = (2 * viewDistance + 1);
|
|
expectedEntries *= expectedEntries;
|
|
diff --git a/src/main/java/com/destroystokyo/paper/util/misc/PlayerAreaMap.java b/src/main/java/com/destroystokyo/paper/util/misc/PlayerAreaMap.java
|
|
index 46954db7ecd35ac4018fdf476df7c8020d7ce6c8..1ad890a244bdf6df48a8db68cb43450e08c788a6 100644
|
|
--- a/src/main/java/com/destroystokyo/paper/util/misc/PlayerAreaMap.java
|
|
+++ b/src/main/java/com/destroystokyo/paper/util/misc/PlayerAreaMap.java
|
|
@@ -5,7 +5,7 @@ import net.minecraft.server.level.ServerPlayer;
|
|
/**
|
|
* @author Spottedleaf
|
|
*/
|
|
-public final class PlayerAreaMap extends AreaMap<ServerPlayer> {
|
|
+public class PlayerAreaMap extends AreaMap<ServerPlayer> { // Pufferfish - not actually final
|
|
|
|
public PlayerAreaMap() {
|
|
super();
|
|
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/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/gg/airplane/structs/Long2FloatAgingCache.java b/src/main/java/gg/airplane/structs/Long2FloatAgingCache.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..a7f297ebb569f7c1f205e967ca485be70013a714
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/airplane/structs/Long2FloatAgingCache.java
|
|
@@ -0,0 +1,119 @@
|
|
+package gg.airplane.structs;
|
|
+
|
|
+import it.unimi.dsi.fastutil.HashCommon;
|
|
+
|
|
+/**
|
|
+ * A replacement for the cache used in Biome.
|
|
+ */
|
|
+public class Long2FloatAgingCache {
|
|
+
|
|
+ private static class AgingEntry {
|
|
+ private long data;
|
|
+ private float value;
|
|
+ private int uses = 0;
|
|
+ private int age = 0;
|
|
+
|
|
+ private AgingEntry(long data, float value) {
|
|
+ this.data = data;
|
|
+ this.value = value;
|
|
+ }
|
|
+
|
|
+ public void replace(long data, float flag) {
|
|
+ this.data = data;
|
|
+ this.value = 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 AgingEntry[] entries;
|
|
+ private final int mask;
|
|
+ private final int maxDistance; // the most amount of entries to check for a value
|
|
+
|
|
+ public Long2FloatAgingCache(int size) {
|
|
+ int arraySize = HashCommon.nextPowerOfTwo(size);
|
|
+ this.entries = new AgingEntry[arraySize];
|
|
+ this.mask = arraySize - 1;
|
|
+ this.maxDistance = Math.min(arraySize, 4);
|
|
+ }
|
|
+
|
|
+ public float getValue(long data) {
|
|
+ AgingEntry curr;
|
|
+ int pos;
|
|
+
|
|
+ if ((curr = this.entries[pos = HashCommon.mix(HashCommon.long2int(data)) & this.mask]) == null) {
|
|
+ return Float.NaN;
|
|
+ } else if (data == curr.data) {
|
|
+ curr.incrementUses();
|
|
+ return curr.value;
|
|
+ }
|
|
+
|
|
+ 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 == curr.data) {
|
|
+ curr.incrementUses();
|
|
+ return curr.value;
|
|
+ } else if (++checked >= this.maxDistance) {
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return Float.NaN;
|
|
+ }
|
|
+
|
|
+ public void putValue(long data, float value) {
|
|
+ AgingEntry curr;
|
|
+ int pos;
|
|
+
|
|
+ if ((curr = this.entries[pos = HashCommon.mix(HashCommon.long2int(data)) & this.mask]) == null) {
|
|
+ this.entries[pos] = new AgingEntry(data, value); // add
|
|
+ return;
|
|
+ } else if (data == 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 == curr.data) {
|
|
+ curr.incrementUses();
|
|
+ return;
|
|
+ } else if (++checked >= this.maxDistance) {
|
|
+ this.forceAdd(data, value);
|
|
+ return;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ this.entries[pos] = new AgingEntry(data, value); // add
|
|
+ }
|
|
+
|
|
+ private void forceAdd(long data, float value) {
|
|
+ int expectedPos = HashCommon.mix(HashCommon.long2int(data)) & this.mask;
|
|
+ AgingEntry entryToRemove = this.entries[expectedPos];
|
|
+
|
|
+ for (int i = expectedPos + 1; i < expectedPos + this.maxDistance; i++) {
|
|
+ int pos = i & this.mask;
|
|
+ AgingEntry entry = this.entries[pos];
|
|
+ if (entry.getValue() < entryToRemove.getValue()) {
|
|
+ entryToRemove = entry;
|
|
+ }
|
|
+
|
|
+ entry.incrementAge(); // use this as a mechanism to age the other entries
|
|
+ }
|
|
+
|
|
+ // remove the least used/oldest entry
|
|
+ entryToRemove.replace(data, value);
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/PufferfishCommand.java b/src/main/java/gg/pufferfish/pufferfish/PufferfishCommand.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..020368da69b9a492155f6de6297f74732f4ab6ea
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/PufferfishCommand.java
|
|
@@ -0,0 +1,68 @@
|
|
+package gg.pufferfish.pufferfish;
|
|
+
|
|
+import java.io.IOException;
|
|
+import java.util.Collections;
|
|
+import java.util.List;
|
|
+import java.util.stream.Collectors;
|
|
+import java.util.stream.Stream;
|
|
+import net.kyori.adventure.text.Component;
|
|
+import net.kyori.adventure.text.format.NamedTextColor;
|
|
+import net.md_5.bungee.api.ChatColor;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import org.bukkit.Bukkit;
|
|
+import org.bukkit.Location;
|
|
+import org.bukkit.command.Command;
|
|
+import org.bukkit.command.CommandSender;
|
|
+
|
|
+public class PufferfishCommand extends Command {
|
|
+
|
|
+ public PufferfishCommand() {
|
|
+ super("pufferfish");
|
|
+ this.description = "Pufferfish related commands";
|
|
+ this.usageMessage = "/pufferfish [reload | version]";
|
|
+ this.setPermission("bukkit.command.pufferfish");
|
|
+ }
|
|
+
|
|
+ public static void init() {
|
|
+ MinecraftServer.getServer().server.getCommandMap().register("pufferfish", "Pufferfish", new PufferfishCommand());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public List<String> tabComplete(CommandSender sender, String alias, String[] args, Location location) throws IllegalArgumentException {
|
|
+ if (args.length == 1) {
|
|
+ return Stream.of("reload", "version")
|
|
+ .filter(arg -> arg.startsWith(args[0].toLowerCase()))
|
|
+ .collect(Collectors.toList());
|
|
+ }
|
|
+ return Collections.emptyList();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
|
+ if (!testPermission(sender)) return true;
|
|
+ String prefix = ChatColor.of("#12fff6") + "" + ChatColor.BOLD + "Pufferfish » " + ChatColor.of("#e8f9f9");
|
|
+
|
|
+ if (args.length != 1) {
|
|
+ sender.sendMessage(prefix + "Usage: " + usageMessage);
|
|
+ args = new String[]{"version"};
|
|
+ }
|
|
+
|
|
+ if (args[0].equalsIgnoreCase("reload")) {
|
|
+ MinecraftServer console = MinecraftServer.getServer();
|
|
+ try {
|
|
+ PufferfishConfig.load();
|
|
+ } catch (IOException e) {
|
|
+ sender.sendMessage(Component.text("Failed to reload.", NamedTextColor.RED));
|
|
+ e.printStackTrace();
|
|
+ return true;
|
|
+ }
|
|
+ console.server.reloadCount++;
|
|
+
|
|
+ Command.broadcastCommandMessage(sender, prefix + "Pufferfish configuration has been reloaded.");
|
|
+ } else if (args[0].equalsIgnoreCase("version")) {
|
|
+ Command.broadcastCommandMessage(sender, prefix + "This server is running " + Bukkit.getName() + " version " + Bukkit.getVersion() + " (Implementing API version " + Bukkit.getBukkitVersion() + ")");
|
|
+ }
|
|
+
|
|
+ return true;
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/PufferfishConfig.java b/src/main/java/gg/pufferfish/pufferfish/PufferfishConfig.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..38cb29c646ff496ffaa6553f98a565b71155c464
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/PufferfishConfig.java
|
|
@@ -0,0 +1,337 @@
|
|
+package gg.pufferfish.pufferfish;
|
|
+
|
|
+import gg.pufferfish.pufferfish.simd.SIMDDetection;
|
|
+import java.io.File;
|
|
+import java.io.IOException;
|
|
+import java.util.Collections;
|
|
+import java.util.Locale;
|
|
+import java.util.Map;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import net.minecraft.tags.TagKey;
|
|
+import org.apache.logging.log4j.Level;
|
|
+import org.bukkit.configuration.ConfigurationSection;
|
|
+import net.minecraft.core.Registry;
|
|
+import net.minecraft.world.entity.EntityType;
|
|
+import java.lang.reflect.Method;
|
|
+import java.lang.reflect.Modifier;
|
|
+import java.util.List;
|
|
+import gg.pufferfish.pufferfish.flare.FlareCommand;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import org.apache.logging.log4j.Level;
|
|
+import org.bukkit.configuration.ConfigurationSection;
|
|
+import org.bukkit.configuration.MemoryConfiguration;
|
|
+import org.jetbrains.annotations.Nullable;
|
|
+import org.simpleyaml.configuration.comments.CommentType;
|
|
+import org.simpleyaml.configuration.file.YamlFile;
|
|
+import org.simpleyaml.exceptions.InvalidConfigurationException;
|
|
+import org.bukkit.command.SimpleCommandMap;
|
|
+
|
|
+import java.lang.reflect.Method;
|
|
+import java.lang.reflect.Modifier;
|
|
+import java.util.List;
|
|
+import java.net.URI;
|
|
+import java.util.Collections;
|
|
+
|
|
+public class PufferfishConfig {
|
|
+
|
|
+ private static final YamlFile config = new YamlFile();
|
|
+ private static int updates = 0;
|
|
+
|
|
+ private static ConfigurationSection convertToBukkit(org.simpleyaml.configuration.ConfigurationSection section) {
|
|
+ ConfigurationSection newSection = new MemoryConfiguration();
|
|
+ for (String key : section.getKeys(false)) {
|
|
+ if (section.isConfigurationSection(key)) {
|
|
+ newSection.set(key, convertToBukkit(section.getConfigurationSection(key)));
|
|
+ } else {
|
|
+ newSection.set(key, section.get(key));
|
|
+ }
|
|
+ }
|
|
+ return newSection;
|
|
+ }
|
|
+
|
|
+ public static ConfigurationSection getConfigCopy() {
|
|
+ return convertToBukkit(config);
|
|
+ }
|
|
+
|
|
+ public static int getUpdates() {
|
|
+ return updates;
|
|
+ }
|
|
+
|
|
+ public static void load() throws IOException {
|
|
+ File configFile = new File("pufferfish.yml");
|
|
+
|
|
+ if (configFile.exists()) {
|
|
+ try {
|
|
+ config.load(configFile);
|
|
+ } catch (InvalidConfigurationException e) {
|
|
+ throw new IOException(e);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ getString("info.version", "1.0");
|
|
+ setComment("info",
|
|
+ "Pufferfish Configuration",
|
|
+ "Check out Pufferfish Host for maximum performance server hosting: https://pufferfish.host",
|
|
+ "Join our Discord for support: https://discord.gg/reZw4vQV9H",
|
|
+ "Download new builds at https://ci.pufferfish.host/job/Pufferfish");
|
|
+
|
|
+ for (Method method : PufferfishConfig.class.getDeclaredMethods()) {
|
|
+ if (Modifier.isStatic(method.getModifiers()) && Modifier.isPrivate(method.getModifiers()) && method.getParameterCount() == 0 &&
|
|
+ method.getReturnType() == Void.TYPE && !method.getName().startsWith("lambda")) {
|
|
+ method.setAccessible(true);
|
|
+ try {
|
|
+ method.invoke(null);
|
|
+ } catch (Throwable t) {
|
|
+ MinecraftServer.LOGGER.warn("Failed to load configuration option from " + method.getName(), t);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ updates++;
|
|
+
|
|
+ config.save(configFile);
|
|
+
|
|
+ // Attempt to detect vectorization
|
|
+ try {
|
|
+ SIMDDetection.isEnabled = SIMDDetection.canEnable(PufferfishLogger.LOGGER);
|
|
+ SIMDDetection.versionLimited = SIMDDetection.getJavaVersion() != 17 && SIMDDetection.getJavaVersion() != 18;
|
|
+ } catch (NoClassDefFoundError | Exception ignored) {}
|
|
+
|
|
+ if (SIMDDetection.isEnabled) {
|
|
+ PufferfishLogger.LOGGER.info("SIMD operations detected as functional. Will replace some operations with faster versions.");
|
|
+ } else if (SIMDDetection.versionLimited) {
|
|
+ PufferfishLogger.LOGGER.warning("Will not enable SIMD! These optimizations are only safely supported on Java 17 and Java 18.");
|
|
+ } else {
|
|
+ PufferfishLogger.LOGGER.warning("SIMD operations are available for your server, but are not configured!");
|
|
+ PufferfishLogger.LOGGER.warning("To enable additional optimizations, add \"--add-modules=jdk.incubator.vector\" to your startup flags, BEFORE the \"-jar\".");
|
|
+ PufferfishLogger.LOGGER.warning("If you have already added this flag, then SIMD operations are not supported on your JVM or CPU.");
|
|
+ PufferfishLogger.LOGGER.warning("Debug: Java: " + System.getProperty("java.version") + ", test run: " + SIMDDetection.testRun);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private static void setComment(String key, String... comment) {
|
|
+ if (config.contains(key)) {
|
|
+ config.setComment(key, String.join("\n", comment), CommentType.BLOCK);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private static void ensureDefault(String key, Object defaultValue, String... comment) {
|
|
+ if (!config.contains(key)) {
|
|
+ config.set(key, defaultValue);
|
|
+ config.setComment(key, String.join("\n", comment), CommentType.BLOCK);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private static boolean getBoolean(String key, boolean defaultValue, String... comment) {
|
|
+ return getBoolean(key, null, defaultValue, comment);
|
|
+ }
|
|
+
|
|
+ private static boolean getBoolean(String key, @Nullable String oldKey, boolean defaultValue, String... comment) {
|
|
+ ensureDefault(key, defaultValue, comment);
|
|
+ return config.getBoolean(key, defaultValue);
|
|
+ }
|
|
+
|
|
+ private static int getInt(String key, int defaultValue, String... comment) {
|
|
+ return getInt(key, null, defaultValue, comment);
|
|
+ }
|
|
+
|
|
+ private static int getInt(String key, @Nullable String oldKey, int defaultValue, String... comment) {
|
|
+ ensureDefault(key, defaultValue, comment);
|
|
+ return config.getInt(key, defaultValue);
|
|
+ }
|
|
+
|
|
+ private static double getDouble(String key, double defaultValue, String... comment) {
|
|
+ return getDouble(key, null, defaultValue, comment);
|
|
+ }
|
|
+
|
|
+ private static double getDouble(String key, @Nullable String oldKey, double defaultValue, String... comment) {
|
|
+ ensureDefault(key, defaultValue, comment);
|
|
+ return config.getDouble(key, defaultValue);
|
|
+ }
|
|
+
|
|
+ private static String getString(String key, String defaultValue, String... comment) {
|
|
+ return getOldString(key, null, defaultValue, comment);
|
|
+ }
|
|
+
|
|
+ private static String getOldString(String key, @Nullable String oldKey, String defaultValue, String... comment) {
|
|
+ ensureDefault(key, defaultValue, comment);
|
|
+ return config.getString(key, defaultValue);
|
|
+ }
|
|
+
|
|
+ private static List<String> getStringList(String key, List<String> defaultValue, String... comment) {
|
|
+ return getStringList(key, null, defaultValue, comment);
|
|
+ }
|
|
+
|
|
+ private static List<String> getStringList(String key, @Nullable String oldKey, List<String> defaultValue, String... comment) {
|
|
+ ensureDefault(key, defaultValue, comment);
|
|
+ return config.getStringList(key);
|
|
+ }
|
|
+
|
|
+ public static String sentryDsn;
|
|
+ private static void sentry() {
|
|
+ String sentryEnvironment = System.getenv("SENTRY_DSN");
|
|
+ String sentryConfig = getString("sentry-dsn", "", "Sentry DSN for improved error logging, leave blank to disable", "Obtain from https://sentry.io/");
|
|
+
|
|
+ sentryDsn = sentryEnvironment == null ? sentryConfig : sentryEnvironment;
|
|
+ if (sentryDsn != null && !sentryDsn.isBlank()) {
|
|
+ gg.pufferfish.pufferfish.sentry.SentryManager.init();
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public static boolean enableBooks;
|
|
+ private static void books() {
|
|
+ enableBooks = getBoolean("enable-books", true,
|
|
+ "Whether or not books should be writeable.",
|
|
+ "Servers that anticipate being a target for duping may want to consider",
|
|
+ "disabling this option.",
|
|
+ "This can be overridden per-player with the permission pufferfish.usebooks");
|
|
+ }
|
|
+
|
|
+ public static boolean enableSuffocationOptimization;
|
|
+ private static void suffocationOptimization() {
|
|
+ enableSuffocationOptimization = getBoolean("enable-suffocation-optimization", true,
|
|
+ "Optimizes the suffocation check by selectively skipping",
|
|
+ "the check in a way that still appears vanilla. This should",
|
|
+ "be left enabled on most servers, but is provided as a",
|
|
+ "configuration option if the vanilla deviation is undesirable.");
|
|
+ }
|
|
+
|
|
+ public static boolean enableAsyncMobSpawning;
|
|
+ public static boolean asyncMobSpawningInitialized;
|
|
+ private static void asyncMobSpawning() {
|
|
+ boolean temp = getBoolean("enable-async-mob-spawning", true,
|
|
+ "Whether or not asynchronous mob spawning should be enabled.",
|
|
+ "On servers with many entities, this can improve performance by up to 15%. You must have",
|
|
+ "paper's per-player-mob-spawns setting set to true for this to work.",
|
|
+ "One quick note - this does not actually spawn mobs async (that would be very unsafe).",
|
|
+ "This just offloads some expensive calculations that are required for mob spawning.");
|
|
+
|
|
+ // This prevents us from changing the value during a reload.
|
|
+ if (!asyncMobSpawningInitialized) {
|
|
+ asyncMobSpawningInitialized = true;
|
|
+ enableAsyncMobSpawning = temp;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public static boolean enableAsyncEntityTracker;
|
|
+ public static boolean enableAsyncEntityTrackerInitialized;
|
|
+ private static void asyncEntityTracker() {
|
|
+ boolean temp = getBoolean("enable-async-entity-tracker", false,
|
|
+ "Whether or not async entity tracking should be enabled.");
|
|
+ if (!enableAsyncEntityTrackerInitialized) {
|
|
+ enableAsyncEntityTrackerInitialized = true;
|
|
+ enableAsyncEntityTracker = temp;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public static boolean enableAsyncPathfinding;
|
|
+ public static boolean enableAsyncPathfindingInitialized;
|
|
+ private static void asyncPathfinding() {
|
|
+ boolean temp = getBoolean("enable-async-pathfinding", false,
|
|
+ "Whether or not async pathfinding should be enabled.");
|
|
+ if (!enableAsyncPathfindingInitialized) {
|
|
+ enableAsyncPathfindingInitialized = true;
|
|
+ enableAsyncPathfinding = temp;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public static int maxProjectileLoadsPerTick;
|
|
+ public static int maxProjectileLoadsPerProjectile;
|
|
+ private static void projectileLoading() {
|
|
+ maxProjectileLoadsPerTick = getInt("projectile.max-loads-per-tick", 10, "Controls how many chunks are allowed", "to be sync loaded by projectiles in a tick.");
|
|
+ maxProjectileLoadsPerProjectile = getInt("projectile.max-loads-per-projectile", 10, "Controls how many chunks a projectile", "can load in its lifetime before it gets", "automatically removed.");
|
|
+
|
|
+ setComment("projectile", "Optimizes projectile settings");
|
|
+ }
|
|
+
|
|
+
|
|
+ public static boolean dearEnabled;
|
|
+ public static int startDistance;
|
|
+ public static int startDistanceSquared;
|
|
+ public static int maximumActivationPrio;
|
|
+ public static int activationDistanceMod;
|
|
+
|
|
+ private static void dynamicActivationOfBrains() throws IOException {
|
|
+ dearEnabled = getBoolean("dab.enabled", "activation-range.enabled", true);
|
|
+ startDistance = getInt("dab.start-distance", "activation-range.start-distance", 12,
|
|
+ "This value determines how far away an entity has to be",
|
|
+ "from the player to start being effected by DEAR.");
|
|
+ startDistanceSquared = startDistance * startDistance;
|
|
+ maximumActivationPrio = getInt("dab.max-tick-freq", "activation-range.max-tick-freq", 20,
|
|
+ "This value defines how often in ticks, the furthest entity",
|
|
+ "will get their pathfinders and behaviors ticked. 20 = 1s");
|
|
+ activationDistanceMod = getInt("dab.activation-dist-mod", "activation-range.activation-dist-mod", 8,
|
|
+ "This value defines how much distance modifies an entity's",
|
|
+ "tick frequency. freq = (distanceToPlayer^2) / (2^value)",
|
|
+ "If you want further away entities to tick less often, use 7.",
|
|
+ "If you want further away entities to tick more often, try 9.");
|
|
+
|
|
+ for (EntityType<?> entityType : Registry.ENTITY_TYPE) {
|
|
+ entityType.dabEnabled = true; // reset all, before setting the ones to true
|
|
+ }
|
|
+ getStringList("dab.blacklisted-entities", "activation-range.blacklisted-entities", Collections.emptyList(), "A list of entities to ignore for activation")
|
|
+ .forEach(name -> EntityType.byString(name).ifPresentOrElse(entityType -> {
|
|
+ entityType.dabEnabled = false;
|
|
+ }, () -> MinecraftServer.LOGGER.warn("Unknown entity \"" + name + "\"")));
|
|
+
|
|
+ setComment("dab", "Optimizes entity brains when", "they're far away from the player");
|
|
+ }
|
|
+
|
|
+ public static Map<String, Integer> projectileTimeouts;
|
|
+ private static void projectileTimeouts() {
|
|
+ // Set some defaults
|
|
+ getInt("entity_timeouts.SNOWBALL", -1);
|
|
+ getInt("entity_timeouts.LLAMA_SPIT", -1);
|
|
+ setComment("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 : Registry.ENTITY_TYPE) {
|
|
+ String type = EntityType.getKey(entityType).getPath().toUpperCase(Locale.ROOT);
|
|
+ entityType.ttl = config.getInt("entity_timeouts." + type, -1);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public static boolean throttleInactiveGoalSelectorTick;
|
|
+ private static void inactiveGoalSelectorThrottle() {
|
|
+ getBoolean("inactive-goal-selector-throttle", "inactive-goal-selector-disable", true,
|
|
+ "Throttles the AI goal selector in entity inactive ticks.",
|
|
+ "This can improve performance by a few percent, but has minor gameplay implications.");
|
|
+ }
|
|
+
|
|
+ public static URI profileWebUrl;
|
|
+ private static void profilerOptions() {
|
|
+ profileWebUrl = URI.create(getString("flare.url", "https://flare.airplane.gg", "Sets the server to use for profiles."));
|
|
+
|
|
+ setComment("flare", "Configures Flare, the built-in profiler");
|
|
+ }
|
|
+
|
|
+
|
|
+ public static String accessToken;
|
|
+ private static void airplaneWebServices() {
|
|
+ accessToken = getString("web-services.token", "");
|
|
+ // todo lookup token (off-thread) and let users know if their token is valid
|
|
+ if (accessToken.length() > 0) {
|
|
+ gg.pufferfish.pufferfish.flare.FlareSetup.init(); // Pufferfish
|
|
+ SimpleCommandMap commandMap = MinecraftServer.getServer().server.getCommandMap();
|
|
+ if (commandMap.getCommand("flare") == null) {
|
|
+ commandMap.register("flare", "Pufferfish", new FlareCommand());
|
|
+ }
|
|
+ }
|
|
+
|
|
+ setComment("web-services", "Options for connecting to Pufferfish/Airplane's online utilities");
|
|
+
|
|
+ }
|
|
+
|
|
+
|
|
+ public static boolean disableMethodProfiler;
|
|
+ public static boolean disableOutOfOrderChat;
|
|
+ private static void miscSettings() {
|
|
+ disableMethodProfiler = getBoolean("misc.disable-method-profiler", true);
|
|
+ disableOutOfOrderChat = getBoolean("misc.disable-out-of-order-chat", false);
|
|
+ setComment("misc", "Settings for things that don't belong elsewhere");
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/PufferfishLogger.java b/src/main/java/gg/pufferfish/pufferfish/PufferfishLogger.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..53f2df00c6809618a9ee3d2ea72e85e8052fbcf1
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/PufferfishLogger.java
|
|
@@ -0,0 +1,16 @@
|
|
+package gg.pufferfish.pufferfish;
|
|
+
|
|
+import java.util.logging.Level;
|
|
+import java.util.logging.Logger;
|
|
+import org.bukkit.Bukkit;
|
|
+
|
|
+public class PufferfishLogger extends Logger {
|
|
+ public static final PufferfishLogger LOGGER = new PufferfishLogger();
|
|
+
|
|
+ private PufferfishLogger() {
|
|
+ super("Pufferfish", null);
|
|
+
|
|
+ setParent(Bukkit.getLogger());
|
|
+ setLevel(Level.ALL);
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/PufferfishVersionFetcher.java b/src/main/java/gg/pufferfish/pufferfish/PufferfishVersionFetcher.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..e877921370f6009a4bd204d9b17d2d58834b8822
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/PufferfishVersionFetcher.java
|
|
@@ -0,0 +1,136 @@
|
|
+package gg.pufferfish.pufferfish;
|
|
+
|
|
+import static net.kyori.adventure.text.Component.text;
|
|
+import static net.kyori.adventure.text.format.NamedTextColor.GREEN;
|
|
+import static net.kyori.adventure.text.format.NamedTextColor.RED;
|
|
+
|
|
+import com.destroystokyo.paper.VersionHistoryManager;
|
|
+import com.destroystokyo.paper.util.VersionFetcher;
|
|
+import com.google.gson.Gson;
|
|
+import com.google.gson.JsonObject;
|
|
+import java.io.IOException;
|
|
+import java.net.URI;
|
|
+import java.net.http.HttpClient;
|
|
+import java.net.http.HttpRequest;
|
|
+import java.net.http.HttpResponse;
|
|
+import java.nio.charset.StandardCharsets;
|
|
+import java.util.concurrent.TimeUnit;
|
|
+import java.util.logging.Level;
|
|
+import java.util.logging.Logger;
|
|
+import net.kyori.adventure.text.Component;
|
|
+import net.kyori.adventure.text.JoinConfiguration;
|
|
+import net.kyori.adventure.text.format.NamedTextColor;
|
|
+import net.kyori.adventure.text.format.TextDecoration;
|
|
+import org.bukkit.craftbukkit.CraftServer;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+import org.jetbrains.annotations.Nullable;
|
|
+
|
|
+public class PufferfishVersionFetcher implements VersionFetcher {
|
|
+
|
|
+ private static final Logger LOGGER = Logger.getLogger("PufferfishVersionFetcher");
|
|
+ private static final HttpClient client = HttpClient.newHttpClient();
|
|
+
|
|
+ private static final URI JENKINS_URI = URI.create("https://ci.pufferfish.host/job/Pufferfish-1.19/lastSuccessfulBuild/buildNumber");
|
|
+ private static final String GITHUB_FORMAT = "https://api.github.com/repos/pufferfish-gg/Pufferfish/compare/ver/1.19...%s";
|
|
+
|
|
+ private static final HttpResponse.BodyHandler<JsonObject> JSON_OBJECT_BODY_HANDLER = responseInfo -> HttpResponse.BodySubscribers
|
|
+ .mapping(
|
|
+ HttpResponse.BodySubscribers.ofString(StandardCharsets.UTF_8),
|
|
+ string -> new Gson().fromJson(string, JsonObject.class)
|
|
+ );
|
|
+
|
|
+ @Override
|
|
+ public long getCacheTime() {
|
|
+ return TimeUnit.MINUTES.toMillis(30);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public @NotNull Component getVersionMessage(final @NotNull String serverVersion) {
|
|
+ final String[] parts = CraftServer.class.getPackage().getImplementationVersion().split("-");
|
|
+ @NotNull Component component;
|
|
+
|
|
+ if (parts.length != 3) {
|
|
+ component = text("Unknown server version.", RED);
|
|
+ } else {
|
|
+ final String versionString = parts[2];
|
|
+
|
|
+ try {
|
|
+ component = this.fetchJenkinsVersion(Integer.parseInt(versionString));
|
|
+ } catch (NumberFormatException e) {
|
|
+ component = this.fetchGithubVersion(versionString.substring(1, versionString.length() - 1));
|
|
+ }
|
|
+ }
|
|
+
|
|
+ final @Nullable Component history = this.getHistory();
|
|
+ return history != null ? Component
|
|
+ .join(JoinConfiguration.noSeparators(), component, Component.newline(), this.getHistory()) : component;
|
|
+ }
|
|
+
|
|
+ private @NotNull Component fetchJenkinsVersion(final int versionNumber) {
|
|
+ final HttpRequest request = HttpRequest.newBuilder(JENKINS_URI).build();
|
|
+ try {
|
|
+ final HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
|
+ if (response.statusCode() != 200) {
|
|
+ return text("Received invalid status code (" + response.statusCode() + ") from server.", RED);
|
|
+ }
|
|
+
|
|
+ int latestVersionNumber;
|
|
+ try {
|
|
+ latestVersionNumber = Integer.parseInt(response.body());
|
|
+ } catch (NumberFormatException e) {
|
|
+ LOGGER.log(Level.WARNING, "Received invalid response from Jenkins \"" + response.body() + "\".");
|
|
+ return text("Received invalid response from server.", RED);
|
|
+ }
|
|
+
|
|
+ final int versionDiff = latestVersionNumber - versionNumber;
|
|
+ return this.getResponseMessage(versionDiff);
|
|
+ } catch (IOException | InterruptedException e) {
|
|
+ LOGGER.log(Level.WARNING, "Failed to look up version from Jenkins", e);
|
|
+ return text("Failed to retrieve version from server.", RED);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ // Based off code contributed by Techcable <Techcable@outlook.com> in Paper/GH-65
|
|
+ private @NotNull Component fetchGithubVersion(final @NotNull String hash) {
|
|
+ final URI uri = URI.create(String.format(GITHUB_FORMAT, hash));
|
|
+ final HttpRequest request = HttpRequest.newBuilder(uri).build();
|
|
+ try {
|
|
+ final HttpResponse<JsonObject> response = client.send(request, JSON_OBJECT_BODY_HANDLER);
|
|
+ if (response.statusCode() != 200) {
|
|
+ return text("Received invalid status code (" + response.statusCode() + ") from server.", RED);
|
|
+ }
|
|
+
|
|
+ final JsonObject obj = response.body();
|
|
+ final int versionDiff = obj.get("behind_by").getAsInt();
|
|
+
|
|
+ return this.getResponseMessage(versionDiff);
|
|
+ } catch (IOException | InterruptedException e) {
|
|
+ LOGGER.log(Level.WARNING, "Failed to look up version from GitHub", e);
|
|
+ return text("Failed to retrieve version from server.", RED);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private @NotNull Component getResponseMessage(final int versionDiff) {
|
|
+ return switch (Math.max(-1, Math.min(1, versionDiff))) {
|
|
+ case -1 -> text("You are running an unsupported version of Pufferfish.", RED);
|
|
+ case 0 -> text("You are on the latest version!", GREEN);
|
|
+ default -> text("You are running " + versionDiff + " version" + (versionDiff == 1 ? "" : "s") + " beyond. " +
|
|
+ "Please update your server when possible to maintain stability, security, and receive the latest optimizations.",
|
|
+ RED);
|
|
+ };
|
|
+ }
|
|
+
|
|
+ private @Nullable Component getHistory() {
|
|
+ final VersionHistoryManager.VersionData data = VersionHistoryManager.INSTANCE.getVersionData();
|
|
+ if (data == null) {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ final String oldVersion = data.getOldVersion();
|
|
+ if (oldVersion == null) {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ return Component.text("Previous version: " + oldVersion, NamedTextColor.GRAY, TextDecoration.ITALIC);
|
|
+ }
|
|
+}
|
|
\ No newline at end of file
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/compat/ServerConfigurations.java b/src/main/java/gg/pufferfish/pufferfish/compat/ServerConfigurations.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..4ad189d52b27560424ddb311d0817a334637dc95
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/compat/ServerConfigurations.java
|
|
@@ -0,0 +1,78 @@
|
|
+package gg.pufferfish.pufferfish.compat;
|
|
+
|
|
+import co.aikar.timings.TimingsManager;
|
|
+import com.google.common.io.Files;
|
|
+import org.bukkit.configuration.InvalidConfigurationException;
|
|
+import org.bukkit.configuration.file.YamlConfiguration;
|
|
+
|
|
+import java.io.ByteArrayOutputStream;
|
|
+import java.io.File;
|
|
+import java.io.FileInputStream;
|
|
+import java.io.IOException;
|
|
+import java.nio.charset.StandardCharsets;
|
|
+import java.util.Arrays;
|
|
+import java.util.HashMap;
|
|
+import java.util.List;
|
|
+import java.util.Map;
|
|
+import java.util.Properties;
|
|
+import java.util.stream.Collectors;
|
|
+
|
|
+public class ServerConfigurations {
|
|
+
|
|
+ public static final String[] configurationFiles = new String[]{
|
|
+ "server.properties",
|
|
+ "bukkit.yml",
|
|
+ "spigot.yml",
|
|
+ // "paper.yml", // TODO: Figure out what to do with this.
|
|
+ "pufferfish.yml"
|
|
+ };
|
|
+
|
|
+ public static Map<String, String> getCleanCopies() throws IOException {
|
|
+ Map<String, String> files = new HashMap<>(configurationFiles.length);
|
|
+ for (String file : configurationFiles) {
|
|
+ files.put(file, getCleanCopy(file));
|
|
+ }
|
|
+ return files;
|
|
+ }
|
|
+
|
|
+ public static String getCleanCopy(String configName) throws IOException {
|
|
+ File file = new File(configName);
|
|
+ List<String> hiddenConfigs = TimingsManager.hiddenConfigs;
|
|
+
|
|
+ switch (Files.getFileExtension(configName)) {
|
|
+ case "properties": {
|
|
+ Properties properties = new Properties();
|
|
+ try (FileInputStream inputStream = new FileInputStream(file)) {
|
|
+ properties.load(inputStream);
|
|
+ }
|
|
+ for (String hiddenConfig : hiddenConfigs) {
|
|
+ properties.remove(hiddenConfig);
|
|
+ }
|
|
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
+ properties.store(outputStream, "");
|
|
+ return Arrays.stream(outputStream.toString()
|
|
+ .split("\n"))
|
|
+ .filter(line -> !line.startsWith("#"))
|
|
+ .collect(Collectors.joining("\n"));
|
|
+ }
|
|
+ case "yml": {
|
|
+ YamlConfiguration configuration = new YamlConfiguration();
|
|
+ try {
|
|
+ configuration.load(file);
|
|
+ } catch (InvalidConfigurationException e) {
|
|
+ throw new IOException(e);
|
|
+ }
|
|
+ configuration.options().header(null);
|
|
+ for (String key : configuration.getKeys(true)) {
|
|
+ if (hiddenConfigs.contains(key)) {
|
|
+ configuration.set(key, null);
|
|
+ }
|
|
+ }
|
|
+ return configuration.saveToString();
|
|
+ }
|
|
+ default:
|
|
+ throw new IllegalArgumentException("Bad file type " + configName);
|
|
+ }
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/flare/CustomCategories.java b/src/main/java/gg/pufferfish/pufferfish/flare/CustomCategories.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..401b42e29bccb5251684062f10b2e0f8b091bc95
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/flare/CustomCategories.java
|
|
@@ -0,0 +1,8 @@
|
|
+package gg.pufferfish.pufferfish.flare;
|
|
+
|
|
+import co.technove.flare.live.category.GraphCategory;
|
|
+
|
|
+public class CustomCategories {
|
|
+ public static final GraphCategory MC_PERF = new GraphCategory("MC Performance");
|
|
+ public static final GraphCategory ENTITIES_AND_CHUNKS = new GraphCategory("Entities & Chunks");
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/flare/FlareCommand.java b/src/main/java/gg/pufferfish/pufferfish/flare/FlareCommand.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..3785d1512eb650f91d58903672c059e7449598fc
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/flare/FlareCommand.java
|
|
@@ -0,0 +1,136 @@
|
|
+package gg.pufferfish.pufferfish.flare;
|
|
+
|
|
+import co.technove.flare.exceptions.UserReportableException;
|
|
+import co.technove.flare.internal.profiling.ProfileType;
|
|
+import gg.pufferfish.pufferfish.PufferfishConfig;
|
|
+import net.kyori.adventure.text.Component;
|
|
+import net.kyori.adventure.text.event.ClickEvent;
|
|
+import net.kyori.adventure.text.format.NamedTextColor;
|
|
+import net.kyori.adventure.text.format.TextColor;
|
|
+import net.kyori.adventure.text.format.TextDecoration;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import org.apache.logging.log4j.Level;
|
|
+import org.bukkit.Bukkit;
|
|
+import org.bukkit.command.Command;
|
|
+import org.bukkit.command.CommandSender;
|
|
+import org.bukkit.command.ConsoleCommandSender;
|
|
+import org.bukkit.craftbukkit.scheduler.MinecraftInternalPlugin;
|
|
+import org.bukkit.util.StringUtil;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+
|
|
+import java.time.Duration;
|
|
+import java.util.ArrayList;
|
|
+import java.util.Collections;
|
|
+import java.util.List;
|
|
+
|
|
+public class FlareCommand extends Command {
|
|
+
|
|
+ private static final String BASE_URL = "https://blog.airplane.gg/flare-tutorial/#setting-the-access-token";
|
|
+ private static final TextColor HEX = TextColor.fromHexString("#e3eaea");
|
|
+ private static final Component PREFIX = Component.text()
|
|
+ .append(Component.text("Flare ✈")
|
|
+ .color(TextColor.fromHexString("#6a7eda"))
|
|
+ .decoration(TextDecoration.BOLD, true)
|
|
+ .append(Component.text(" ", HEX)
|
|
+ .decoration(TextDecoration.BOLD, false)))
|
|
+ .asComponent();
|
|
+
|
|
+ public FlareCommand() {
|
|
+ super("flare", "Profile your server with Flare", "/flare", Collections.singletonList("profile"));
|
|
+ this.setPermission("airplane.flare");
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, String @NotNull [] args) {
|
|
+ if (!testPermission(sender)) return true;
|
|
+ if (PufferfishConfig.accessToken.length() == 0) {
|
|
+ Component clickable = Component.text(BASE_URL, HEX, TextDecoration.UNDERLINED).clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL, BASE_URL));
|
|
+
|
|
+ sender.sendMessage(PREFIX.append(Component.text("Flare currently requires an access token to use. To learn more, visit ").color(HEX).append(clickable)));
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ if (!FlareSetup.isSupported()) {
|
|
+ sender.sendMessage(PREFIX.append(
|
|
+ Component.text("Profiling is not supported in this environment, check your startup logs for the error.", NamedTextColor.RED)));
|
|
+ return true;
|
|
+ }
|
|
+ if (ProfilingManager.isProfiling()) {
|
|
+ if (args.length == 1 && args[0].equalsIgnoreCase("status")) {
|
|
+ sender.sendMessage(PREFIX.append(Component.text("Current profile has been ran for " + ProfilingManager.getTimeRan().toString(), HEX)));
|
|
+ return true;
|
|
+ }
|
|
+ if (ProfilingManager.stop()) {
|
|
+ if (!(sender instanceof ConsoleCommandSender)) {
|
|
+ sender.sendMessage(PREFIX.append(Component.text("Profiling has been stopped.", HEX)));
|
|
+ }
|
|
+ } else {
|
|
+ sender.sendMessage(PREFIX.append(Component.text("Profiling has already been stopped.", HEX)));
|
|
+ }
|
|
+ } else {
|
|
+ ProfileType profileType = ProfileType.ITIMER;
|
|
+ if (args.length > 0) {
|
|
+ try {
|
|
+ profileType = ProfileType.valueOf(args[0].toUpperCase());
|
|
+ } catch (Exception e) {
|
|
+ sender.sendMessage(PREFIX.append(Component
|
|
+ .text("Invalid profile type ", HEX)
|
|
+ .append(Component.text(args[0], HEX, TextDecoration.BOLD)
|
|
+ .append(Component.text("!", HEX)))
|
|
+ ));
|
|
+ }
|
|
+ }
|
|
+ ProfileType finalProfileType = profileType;
|
|
+ Bukkit.getScheduler().runTaskAsynchronously(new MinecraftInternalPlugin(), () -> {
|
|
+ try {
|
|
+ if (ProfilingManager.start(finalProfileType)) {
|
|
+ if (!(sender instanceof ConsoleCommandSender)) {
|
|
+ sender.sendMessage(PREFIX.append(Component
|
|
+ .text("Flare has been started: " + ProfilingManager.getProfilingUri(), HEX)
|
|
+ .clickEvent(ClickEvent.openUrl(ProfilingManager.getProfilingUri()))
|
|
+ ));
|
|
+ sender.sendMessage(PREFIX.append(Component.text(" Run /" + commandLabel + " to stop the Flare.", HEX)));
|
|
+ }
|
|
+ } else {
|
|
+ sender.sendMessage(PREFIX.append(Component
|
|
+ .text("Flare has already been started: " + ProfilingManager.getProfilingUri(), HEX)
|
|
+ .clickEvent(ClickEvent.openUrl(ProfilingManager.getProfilingUri()))
|
|
+ ));
|
|
+ }
|
|
+ } catch (UserReportableException e) {
|
|
+ sender.sendMessage(Component.text("Flare failed to start: " + e.getUserError(), NamedTextColor.RED));
|
|
+ if (e.getCause() != null) {
|
|
+ MinecraftServer.LOGGER.warn("Flare failed to start", e);
|
|
+ }
|
|
+ }
|
|
+ });
|
|
+ }
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, String @NotNull [] args) throws IllegalArgumentException {
|
|
+ List<String> list = new ArrayList<>();
|
|
+ if (ProfilingManager.isProfiling()) {
|
|
+ if (args.length == 1) {
|
|
+ String lastWord = args[0];
|
|
+ if (StringUtil.startsWithIgnoreCase("status", lastWord)) {
|
|
+ list.add("status");
|
|
+ }
|
|
+ if (StringUtil.startsWithIgnoreCase("stop", lastWord)) {
|
|
+ list.add("stop");
|
|
+ }
|
|
+ }
|
|
+ } else {
|
|
+ if (args.length <= 1) {
|
|
+ String lastWord = args.length == 0 ? "" : args[0];
|
|
+ for (ProfileType value : ProfileType.values()) {
|
|
+ if (StringUtil.startsWithIgnoreCase(value.getInternalName(), lastWord)) {
|
|
+ list.add(value.name().toLowerCase());
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ return list;
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/flare/FlareSetup.java b/src/main/java/gg/pufferfish/pufferfish/flare/FlareSetup.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..cd22e4dcc8b7b57b10a95ef084637249a98e524f
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/flare/FlareSetup.java
|
|
@@ -0,0 +1,33 @@
|
|
+package gg.pufferfish.pufferfish.flare;
|
|
+
|
|
+import co.technove.flare.FlareInitializer;
|
|
+import co.technove.flare.internal.profiling.InitializationException;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import org.apache.logging.log4j.Level;
|
|
+
|
|
+public class FlareSetup {
|
|
+
|
|
+ private static boolean initialized = false;
|
|
+ private static boolean supported = false;
|
|
+
|
|
+ public static void init() {
|
|
+ if (initialized) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ initialized = true;
|
|
+ try {
|
|
+ for (String warning : FlareInitializer.initialize()) {
|
|
+ MinecraftServer.LOGGER.warn("Flare warning: " + warning);
|
|
+ }
|
|
+ supported = true;
|
|
+ } catch (InitializationException e) {
|
|
+ MinecraftServer.LOGGER.warn("Failed to enable Flare:", e);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public static boolean isSupported() {
|
|
+ return supported;
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/flare/PluginLookup.java b/src/main/java/gg/pufferfish/pufferfish/flare/PluginLookup.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..74aab5eb4b54ffbaf19b8976ffb8ca4a64584006
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/flare/PluginLookup.java
|
|
@@ -0,0 +1,44 @@
|
|
+package gg.pufferfish.pufferfish.flare;
|
|
+
|
|
+import com.google.common.cache.Cache;
|
|
+import com.google.common.cache.CacheBuilder;
|
|
+import org.bukkit.Bukkit;
|
|
+import org.bukkit.plugin.Plugin;
|
|
+import org.bukkit.plugin.java.PluginClassLoader;
|
|
+
|
|
+import java.util.Optional;
|
|
+import java.util.concurrent.TimeUnit;
|
|
+
|
|
+public class PluginLookup {
|
|
+ private static final Cache<String, String> pluginNameCache = CacheBuilder.newBuilder()
|
|
+ .expireAfterAccess(1, TimeUnit.MINUTES)
|
|
+ .maximumSize(1024)
|
|
+ .build();
|
|
+
|
|
+ public static Optional<String> getPluginForClass(String name) {
|
|
+ if (name.startsWith("net.minecraft") || name.startsWith("java.") || name.startsWith("com.mojang") ||
|
|
+ name.startsWith("com.google") || name.startsWith("it.unimi") || name.startsWith("sun")) {
|
|
+ return Optional.empty();
|
|
+ }
|
|
+
|
|
+ String existing = pluginNameCache.getIfPresent(name);
|
|
+ if (existing != null) {
|
|
+ return Optional.ofNullable(existing.isEmpty() ? null : existing);
|
|
+ }
|
|
+
|
|
+ String newValue = "";
|
|
+
|
|
+ for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
|
+ ClassLoader classLoader = plugin.getClass().getClassLoader();
|
|
+ if (classLoader instanceof PluginClassLoader) {
|
|
+ if (((PluginClassLoader) classLoader)._airplane_hasClass(name)) {
|
|
+ newValue = plugin.getName();
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ pluginNameCache.put(name, newValue);
|
|
+ return Optional.ofNullable(newValue.isEmpty() ? null : newValue);
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/flare/ProfilingManager.java b/src/main/java/gg/pufferfish/pufferfish/flare/ProfilingManager.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..e3f76eb11a261c3347f0cd89b5da309bc2dc82f9
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/flare/ProfilingManager.java
|
|
@@ -0,0 +1,151 @@
|
|
+package gg.pufferfish.pufferfish.flare;
|
|
+
|
|
+import co.technove.flare.Flare;
|
|
+import co.technove.flare.FlareAuth;
|
|
+import co.technove.flare.FlareBuilder;
|
|
+import co.technove.flare.exceptions.UserReportableException;
|
|
+import co.technove.flare.internal.profiling.ProfileType;
|
|
+import gg.pufferfish.pufferfish.PufferfishConfig;
|
|
+import gg.pufferfish.pufferfish.PufferfishLogger;
|
|
+import gg.pufferfish.pufferfish.compat.ServerConfigurations;
|
|
+import gg.pufferfish.pufferfish.flare.collectors.GCEventCollector;
|
|
+import gg.pufferfish.pufferfish.flare.collectors.StatCollector;
|
|
+import gg.pufferfish.pufferfish.flare.collectors.TPSCollector;
|
|
+import gg.pufferfish.pufferfish.flare.collectors.WorldCountCollector;
|
|
+import org.bukkit.Bukkit;
|
|
+import org.bukkit.craftbukkit.scheduler.MinecraftInternalPlugin;
|
|
+import org.bukkit.scheduler.BukkitTask;
|
|
+import oshi.SystemInfo;
|
|
+import oshi.hardware.CentralProcessor;
|
|
+import oshi.hardware.GlobalMemory;
|
|
+import oshi.hardware.HardwareAbstractionLayer;
|
|
+import oshi.hardware.VirtualMemory;
|
|
+import oshi.software.os.OperatingSystem;
|
|
+
|
|
+import java.io.IOException;
|
|
+import java.net.URI;
|
|
+import java.time.Duration;
|
|
+import java.util.Objects;
|
|
+import java.util.logging.Level;
|
|
+
|
|
+public class ProfilingManager {
|
|
+
|
|
+ private static Flare currentFlare;
|
|
+ private static BukkitTask currentTask = null;
|
|
+
|
|
+ public static synchronized boolean isProfiling() {
|
|
+ return currentFlare != null && currentFlare.isRunning();
|
|
+ }
|
|
+
|
|
+ public static synchronized String getProfilingUri() {
|
|
+ return Objects.requireNonNull(currentFlare).getURI().map(URI::toString).orElse("Flare is not running");
|
|
+ }
|
|
+
|
|
+ public static Duration getTimeRan() {
|
|
+ Flare flare = currentFlare; // copy reference so no need to sync
|
|
+ if (flare == null) {
|
|
+ return Duration.ofMillis(0);
|
|
+ }
|
|
+ return flare.getCurrentDuration();
|
|
+ }
|
|
+
|
|
+ public static synchronized boolean start(ProfileType profileType) throws UserReportableException {
|
|
+ if (currentFlare != null && !currentFlare.isRunning()) {
|
|
+ currentFlare = null; // errored out
|
|
+ }
|
|
+ if (isProfiling()) {
|
|
+ return false;
|
|
+ }
|
|
+ if (Bukkit.isPrimaryThread()) {
|
|
+ throw new UserReportableException("Profiles should be started off-thread");
|
|
+ }
|
|
+
|
|
+ try {
|
|
+ OperatingSystem os = new SystemInfo().getOperatingSystem();
|
|
+
|
|
+ SystemInfo systemInfo = new SystemInfo();
|
|
+ HardwareAbstractionLayer hardware = systemInfo.getHardware();
|
|
+
|
|
+ CentralProcessor processor = hardware.getProcessor();
|
|
+ CentralProcessor.ProcessorIdentifier processorIdentifier = processor.getProcessorIdentifier();
|
|
+
|
|
+ GlobalMemory memory = hardware.getMemory();
|
|
+ VirtualMemory virtualMemory = memory.getVirtualMemory();
|
|
+
|
|
+ FlareBuilder builder = new FlareBuilder()
|
|
+ .withProfileType(profileType)
|
|
+ .withMemoryProfiling(true)
|
|
+ .withAuth(FlareAuth.fromTokenAndUrl(PufferfishConfig.accessToken, PufferfishConfig.profileWebUrl))
|
|
+
|
|
+ .withFiles(ServerConfigurations.getCleanCopies())
|
|
+ .withVersion("Primary Version", Bukkit.getVersion())
|
|
+ .withVersion("Bukkit Version", Bukkit.getBukkitVersion())
|
|
+ .withVersion("Minecraft Version", Bukkit.getMinecraftVersion())
|
|
+
|
|
+ .withGraphCategories(CustomCategories.ENTITIES_AND_CHUNKS, CustomCategories.MC_PERF)
|
|
+ .withCollectors(new TPSCollector(), new WorldCountCollector(), new GCEventCollector(), new StatCollector())
|
|
+ .withClassIdentifier(PluginLookup::getPluginForClass)
|
|
+
|
|
+ .withHardware(new FlareBuilder.HardwareBuilder()
|
|
+ .setCoreCount(processor.getPhysicalProcessorCount())
|
|
+ .setThreadCount(processor.getLogicalProcessorCount())
|
|
+ .setCpuModel(processorIdentifier.getName())
|
|
+ .setCpuFrequency(processor.getMaxFreq())
|
|
+
|
|
+ .setTotalMemory(memory.getTotal())
|
|
+ .setTotalSwap(virtualMemory.getSwapTotal())
|
|
+ .setTotalVirtual(virtualMemory.getVirtualMax())
|
|
+ )
|
|
+
|
|
+ .withOperatingSystem(new FlareBuilder.OperatingSystemBuilder()
|
|
+ .setManufacturer(os.getManufacturer())
|
|
+ .setFamily(os.getFamily())
|
|
+ .setVersion(os.getVersionInfo().toString())
|
|
+ .setBitness(os.getBitness())
|
|
+ );
|
|
+
|
|
+ currentFlare = builder.build();
|
|
+ } catch (IOException e) {
|
|
+ PufferfishLogger.LOGGER.log(Level.WARNING, "Failed to read configuration files:", e);
|
|
+ throw new UserReportableException("Failed to load configuration files, check logs for further details.");
|
|
+ }
|
|
+
|
|
+ try {
|
|
+ currentFlare.start();
|
|
+ } catch (IllegalStateException e) {
|
|
+ PufferfishLogger.LOGGER.log(Level.WARNING, "Error starting Flare:", e);
|
|
+ throw new UserReportableException("Failed to start Flare, check logs for further details.");
|
|
+ }
|
|
+
|
|
+ currentTask = Bukkit.getScheduler().runTaskLater(new MinecraftInternalPlugin(), ProfilingManager::stop, 20 * 60 * 15);
|
|
+ PufferfishLogger.LOGGER.log(Level.INFO, "Flare has been started: " + getProfilingUri());
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ public static synchronized boolean stop() {
|
|
+ if (!isProfiling()) {
|
|
+ return false;
|
|
+ }
|
|
+ if (!currentFlare.isRunning()) {
|
|
+ currentFlare = null;
|
|
+ return true;
|
|
+ }
|
|
+ PufferfishLogger.LOGGER.log(Level.INFO, "Flare has been stopped: " + getProfilingUri());
|
|
+ try {
|
|
+ currentFlare.stop();
|
|
+ } catch (IllegalStateException e) {
|
|
+ PufferfishLogger.LOGGER.log(Level.WARNING, "Error occurred stopping Flare", e);
|
|
+ }
|
|
+ currentFlare = null;
|
|
+
|
|
+ try {
|
|
+ currentTask.cancel();
|
|
+ } catch (Throwable t) {
|
|
+ PufferfishLogger.LOGGER.log(Level.WARNING, "Error occurred stopping Flare", t);
|
|
+ }
|
|
+
|
|
+ currentTask = null;
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/flare/collectors/GCEventCollector.java b/src/main/java/gg/pufferfish/pufferfish/flare/collectors/GCEventCollector.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..d426575c669020f369960107da1e2de2f11f082f
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/flare/collectors/GCEventCollector.java
|
|
@@ -0,0 +1,66 @@
|
|
+package gg.pufferfish.pufferfish.flare.collectors;
|
|
+
|
|
+import co.technove.flare.Flare;
|
|
+import co.technove.flare.internal.FlareInternal;
|
|
+import co.technove.flare.live.CollectorData;
|
|
+import co.technove.flare.live.EventCollector;
|
|
+import co.technove.flare.live.LiveEvent;
|
|
+import co.technove.flare.live.category.GraphCategory;
|
|
+import co.technove.flare.live.formatter.DataFormatter;
|
|
+import com.google.common.collect.ImmutableMap;
|
|
+import com.sun.management.GarbageCollectionNotificationInfo;
|
|
+
|
|
+import javax.management.ListenerNotFoundException;
|
|
+import javax.management.Notification;
|
|
+import javax.management.NotificationEmitter;
|
|
+import javax.management.NotificationListener;
|
|
+import javax.management.openmbean.CompositeData;
|
|
+import java.lang.management.GarbageCollectorMXBean;
|
|
+import java.lang.management.ManagementFactory;
|
|
+
|
|
+public class GCEventCollector extends EventCollector implements NotificationListener {
|
|
+
|
|
+ private static final CollectorData MINOR_GC = new CollectorData("builtin:gc:minor", "Minor GC", "A small pause in the program to allow Garbage Collection to run.", DataFormatter.MILLISECONDS, GraphCategory.SYSTEM);
|
|
+ private static final CollectorData MAJOR_GC = new CollectorData("builtin:gc:major", "Major GC", "A large pause in the program to allow Garbage Collection to run.", DataFormatter.MILLISECONDS, GraphCategory.SYSTEM);
|
|
+ private static final CollectorData UNKNOWN_GC = new CollectorData("builtin:gc:generic", "Major GC", "A run of the Garbage Collection.", DataFormatter.MILLISECONDS, GraphCategory.SYSTEM);
|
|
+
|
|
+ public GCEventCollector() {
|
|
+ super(MINOR_GC, MAJOR_GC, UNKNOWN_GC);
|
|
+ }
|
|
+
|
|
+ private static CollectorData fromString(String string) {
|
|
+ if (string.endsWith("minor GC")) {
|
|
+ return MINOR_GC;
|
|
+ } else if (string.endsWith("major GC")) {
|
|
+ return MAJOR_GC;
|
|
+ }
|
|
+ return UNKNOWN_GC;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void start(Flare flare) {
|
|
+ for (GarbageCollectorMXBean garbageCollectorBean : ManagementFactory.getGarbageCollectorMXBeans()) {
|
|
+ NotificationEmitter notificationEmitter = (NotificationEmitter) garbageCollectorBean;
|
|
+ notificationEmitter.addNotificationListener(this, null, null);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void stop(Flare flare) {
|
|
+ for (GarbageCollectorMXBean garbageCollectorBean : ManagementFactory.getGarbageCollectorMXBeans()) {
|
|
+ NotificationEmitter notificationEmitter = (NotificationEmitter) garbageCollectorBean;
|
|
+ try {
|
|
+ notificationEmitter.removeNotificationListener(this);
|
|
+ } catch (ListenerNotFoundException e) {
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void handleNotification(Notification notification, Object o) {
|
|
+ if (notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
|
|
+ GarbageCollectionNotificationInfo gcInfo = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());
|
|
+ reportEvent(new LiveEvent(fromString(gcInfo.getGcAction()), System.currentTimeMillis(), (int) gcInfo.getGcInfo().getDuration(), ImmutableMap.of()));
|
|
+ }
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/flare/collectors/StatCollector.java b/src/main/java/gg/pufferfish/pufferfish/flare/collectors/StatCollector.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..a22c6dbae53667e4c72464fa27153aee30c7946e
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/flare/collectors/StatCollector.java
|
|
@@ -0,0 +1,41 @@
|
|
+package gg.pufferfish.pufferfish.flare.collectors;
|
|
+
|
|
+import co.technove.flare.live.CollectorData;
|
|
+import co.technove.flare.live.LiveCollector;
|
|
+import co.technove.flare.live.category.GraphCategory;
|
|
+import co.technove.flare.live.formatter.DataFormatter;
|
|
+import com.sun.management.OperatingSystemMXBean;
|
|
+import oshi.SystemInfo;
|
|
+import oshi.hardware.CentralProcessor;
|
|
+
|
|
+import java.lang.management.ManagementFactory;
|
|
+import java.time.Duration;
|
|
+
|
|
+public class StatCollector extends LiveCollector {
|
|
+
|
|
+ private static final CollectorData CPU = new CollectorData("builtin:stat:cpu", "CPU Load", "The total amount of CPU usage across all cores.", DataFormatter.PERCENT, GraphCategory.SYSTEM);
|
|
+ private static final CollectorData CPU_PROCESS = new CollectorData("builtin:stat:cpu_process", "Process CPU", "The amount of CPU being used by this process.", DataFormatter.PERCENT, GraphCategory.SYSTEM);
|
|
+ private static final CollectorData MEMORY = new CollectorData("builtin:stat:memory_used", "Memory", "The amount of memory being used currently.", DataFormatter.BYTES, GraphCategory.SYSTEM);
|
|
+ private static final CollectorData MEMORY_TOTAL = new CollectorData("builtin:stat:memory_total", "Memory Total", "The total amount of memory allocated.", DataFormatter.BYTES, GraphCategory.SYSTEM);
|
|
+
|
|
+ private final OperatingSystemMXBean bean;
|
|
+ private final CentralProcessor processor;
|
|
+
|
|
+ public StatCollector() {
|
|
+ super(CPU, CPU_PROCESS, MEMORY, MEMORY_TOTAL);
|
|
+ this.interval = Duration.ofSeconds(5);
|
|
+
|
|
+ this.bean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
|
|
+ this.processor = new SystemInfo().getHardware().getProcessor();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void run() {
|
|
+ Runtime runtime = Runtime.getRuntime();
|
|
+
|
|
+ this.report(CPU, this.processor.getSystemLoadAverage(1)[0] / 100); // percentage
|
|
+ this.report(CPU_PROCESS, this.bean.getProcessCpuLoad());
|
|
+ this.report(MEMORY, runtime.totalMemory() - runtime.freeMemory());
|
|
+ this.report(MEMORY_TOTAL, runtime.totalMemory());
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/flare/collectors/TPSCollector.java b/src/main/java/gg/pufferfish/pufferfish/flare/collectors/TPSCollector.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..40447d00aefb5ffedb8a2ee87155a04088f0649f
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/flare/collectors/TPSCollector.java
|
|
@@ -0,0 +1,31 @@
|
|
+package gg.pufferfish.pufferfish.flare.collectors;
|
|
+
|
|
+import co.technove.flare.live.CollectorData;
|
|
+import co.technove.flare.live.LiveCollector;
|
|
+import co.technove.flare.live.formatter.SuffixFormatter;
|
|
+import gg.pufferfish.pufferfish.flare.CustomCategories;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import org.bukkit.Bukkit;
|
|
+
|
|
+import java.time.Duration;
|
|
+import java.util.Arrays;
|
|
+
|
|
+public class TPSCollector extends LiveCollector {
|
|
+ private static final CollectorData TPS = new CollectorData("airplane:tps", "TPS", "Ticks per second, or how fast the server updates. For a smooth server this should be a constant 20TPS.", SuffixFormatter.of("TPS"), CustomCategories.MC_PERF);
|
|
+ private static final CollectorData MSPT = new CollectorData("airplane:mspt", "MSPT", "Milliseconds per tick, which can show how well your server is performing. This value should always be under 50mspt.", SuffixFormatter.of("mspt"), CustomCategories.MC_PERF);
|
|
+
|
|
+ public TPSCollector() {
|
|
+ super(TPS, MSPT);
|
|
+
|
|
+ this.interval = Duration.ofSeconds(5);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void run() {
|
|
+ long[] times = MinecraftServer.getServer().tickTimes5s.getTimes();
|
|
+ double mspt = ((double) Arrays.stream(times).sum() / (double) times.length) * 1.0E-6D;
|
|
+
|
|
+ this.report(TPS, Math.min(20D, Math.round(Bukkit.getServer().getTPS()[0] * 100d) / 100d));
|
|
+ this.report(MSPT, (double) Math.round(mspt * 100d) / 100d);
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/flare/collectors/WorldCountCollector.java b/src/main/java/gg/pufferfish/pufferfish/flare/collectors/WorldCountCollector.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..db15d3fbe2b65fc8035573f5fdbea382055db9b2
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/flare/collectors/WorldCountCollector.java
|
|
@@ -0,0 +1,45 @@
|
|
+package gg.pufferfish.pufferfish.flare.collectors;
|
|
+
|
|
+import co.technove.flare.live.CollectorData;
|
|
+import co.technove.flare.live.LiveCollector;
|
|
+import co.technove.flare.live.formatter.SuffixFormatter;
|
|
+import gg.pufferfish.pufferfish.flare.CustomCategories;
|
|
+import org.bukkit.Bukkit;
|
|
+import org.bukkit.World;
|
|
+import org.bukkit.craftbukkit.CraftWorld;
|
|
+
|
|
+import java.time.Duration;
|
|
+
|
|
+public class WorldCountCollector extends LiveCollector {
|
|
+
|
|
+ private static final CollectorData PLAYER_COUNT = new CollectorData("airplane:world:playercount", "Player Count", "The number of players currently on the server.", new SuffixFormatter(" Player", " Players"), CustomCategories.ENTITIES_AND_CHUNKS);
|
|
+ private static final CollectorData ENTITY_COUNT = new CollectorData("airplane:world:entitycount", "Entity Count", "The number of entities in all worlds", new SuffixFormatter(" Entity", " Entities"), CustomCategories.ENTITIES_AND_CHUNKS);
|
|
+ private static final CollectorData CHUNK_COUNT = new CollectorData("airplane:world:chunkcount", "Chunk Count", "The number of chunks currently loaded.", new SuffixFormatter(" Chunk", " Chunks"), CustomCategories.ENTITIES_AND_CHUNKS);
|
|
+ private static final CollectorData TILE_ENTITY_COUNT = new CollectorData("airplane:world:blockentitycount", "Block Entity Count", "The number of block entities currently loaded.", new SuffixFormatter(" Block Entity", " Block Entities"), CustomCategories.ENTITIES_AND_CHUNKS);
|
|
+
|
|
+ public WorldCountCollector() {
|
|
+ super(PLAYER_COUNT, ENTITY_COUNT, CHUNK_COUNT, TILE_ENTITY_COUNT);
|
|
+
|
|
+ this.interval = Duration.ofSeconds(5);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void run() {
|
|
+ int entities = 0;
|
|
+ int chunkCount = 0;
|
|
+ int tileEntityCount = 0;
|
|
+
|
|
+ if (!Bukkit.isStopping()) {
|
|
+ for (World world : Bukkit.getWorlds()) {
|
|
+ entities += ((CraftWorld) world).getHandle().entityManager.getEntityGetter().getCount();
|
|
+ chunkCount += world.getChunkCount();
|
|
+ tileEntityCount += world.getTileEntityCount();
|
|
+ }
|
|
+ }
|
|
+
|
|
+ this.report(PLAYER_COUNT, Bukkit.getOnlinePlayers().size());
|
|
+ this.report(ENTITY_COUNT, entities);
|
|
+ this.report(CHUNK_COUNT, chunkCount);
|
|
+ this.report(TILE_ENTITY_COUNT, tileEntityCount);
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/path/AsyncPath.java b/src/main/java/gg/pufferfish/pufferfish/path/AsyncPath.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..dcfe6fa538c54417b90a138b26c451f63b408ff6
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/path/AsyncPath.java
|
|
@@ -0,0 +1,282 @@
|
|
+package gg.pufferfish.pufferfish.path;
|
|
+
|
|
+import net.minecraft.core.BlockPos;
|
|
+import net.minecraft.world.entity.Entity;
|
|
+import net.minecraft.world.level.pathfinder.Node;
|
|
+import net.minecraft.world.level.pathfinder.Path;
|
|
+import net.minecraft.world.phys.Vec3;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+import org.jetbrains.annotations.Nullable;
|
|
+
|
|
+import java.util.ArrayList;
|
|
+import java.util.List;
|
|
+import java.util.Set;
|
|
+import java.util.function.Supplier;
|
|
+
|
|
+/**
|
|
+ * i'll be using this to represent a path that not be processed yet!
|
|
+ */
|
|
+public class AsyncPath extends Path {
|
|
+
|
|
+ /**
|
|
+ * marks whether this async path has been processed
|
|
+ */
|
|
+ private volatile boolean processed = false;
|
|
+
|
|
+ /**
|
|
+ * runnables waiting for path to be processed
|
|
+ */
|
|
+ private final @NotNull List<Runnable> postProcessing = new ArrayList<>();
|
|
+
|
|
+ /**
|
|
+ * a list of positions that this path could path towards
|
|
+ */
|
|
+ private final Set<BlockPos> positions;
|
|
+
|
|
+ /**
|
|
+ * the supplier of the real processed path
|
|
+ */
|
|
+ private final Supplier<Path> pathSupplier;
|
|
+
|
|
+ /*
|
|
+ * Processed values
|
|
+ */
|
|
+
|
|
+ /**
|
|
+ * this is a reference to the nodes list in the parent `Path` object
|
|
+ */
|
|
+ private final List<Node> nodes;
|
|
+ /**
|
|
+ * the block we're trying to path to
|
|
+ *
|
|
+ * while processing, we have no idea where this is so consumers of `Path` should check that the path is processed before checking the target block
|
|
+ */
|
|
+ private @Nullable BlockPos target;
|
|
+ /**
|
|
+ * how far we are to the target
|
|
+ *
|
|
+ * while processing, the target could be anywhere but theoretically we're always "close" to a theoretical target so default is 0
|
|
+ */
|
|
+ private float distToTarget = 0;
|
|
+ /**
|
|
+ * whether we can reach the target
|
|
+ *
|
|
+ * while processing we can always theoretically reach the target so default is true
|
|
+ */
|
|
+ private boolean canReach = true;
|
|
+
|
|
+ public AsyncPath(@NotNull List<Node> emptyNodeList, @NotNull Set<BlockPos> positions, @NotNull Supplier<Path> pathSupplier) {
|
|
+ //noinspection ConstantConditions
|
|
+ super(emptyNodeList, null, false);
|
|
+
|
|
+ this.nodes = emptyNodeList;
|
|
+ this.positions = positions;
|
|
+ this.pathSupplier = pathSupplier;
|
|
+
|
|
+ AsyncPathProcessor.queue(this);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean isProcessed() {
|
|
+ return this.processed;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * add a post-processing action
|
|
+ */
|
|
+ public synchronized void postProcessing(@NotNull Runnable runnable) {
|
|
+ if (processed) runnable.run();
|
|
+ else postProcessing.add(runnable);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * an easy way to check if this processing path is the same as an attempted new path
|
|
+ *
|
|
+ * @param positions - the positions to compare against
|
|
+ * @return true if we are processing the same positions
|
|
+ */
|
|
+ public boolean hasSameProcessingPositions(final Set<BlockPos> positions) {
|
|
+ if (this.positions.size() != positions.size()) {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ return this.positions.containsAll(positions);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * starts processing this path
|
|
+ */
|
|
+ public synchronized void process() {
|
|
+ if (this.processed) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ final Path bestPath = this.pathSupplier.get();
|
|
+
|
|
+ this.nodes.addAll(bestPath.nodes); // we mutate this list to reuse the logic in Path
|
|
+ this.target = bestPath.getTarget();
|
|
+ this.distToTarget = bestPath.getDistToTarget();
|
|
+ this.canReach = bestPath.canReach();
|
|
+
|
|
+ this.processed = true;
|
|
+
|
|
+ this.postProcessing.forEach(Runnable::run);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * if this path is accessed while it hasn't processed, just process it in-place
|
|
+ */
|
|
+ private void checkProcessed() {
|
|
+ if (!this.processed) {
|
|
+ this.process();
|
|
+ }
|
|
+ }
|
|
+
|
|
+ /*
|
|
+ * overrides we need for final fields that we cannot modify after processing
|
|
+ */
|
|
+
|
|
+ @Override
|
|
+ public @NotNull BlockPos getTarget() {
|
|
+ this.checkProcessed();
|
|
+
|
|
+ return this.target;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public float getDistToTarget() {
|
|
+ this.checkProcessed();
|
|
+
|
|
+ return this.distToTarget;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean canReach() {
|
|
+ this.checkProcessed();
|
|
+
|
|
+ return this.canReach;
|
|
+ }
|
|
+
|
|
+ /*
|
|
+ * overrides to ensure we're processed first
|
|
+ */
|
|
+
|
|
+ @Override
|
|
+ public boolean isDone() {
|
|
+ return this.isProcessed() && super.isDone();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void advance() {
|
|
+ this.checkProcessed();
|
|
+
|
|
+ super.advance();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean notStarted() {
|
|
+ this.checkProcessed();
|
|
+
|
|
+ return super.notStarted();
|
|
+ }
|
|
+
|
|
+ @Nullable
|
|
+ @Override
|
|
+ public Node getEndNode() {
|
|
+ this.checkProcessed();
|
|
+
|
|
+ return super.getEndNode();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Node getNode(int index) {
|
|
+ this.checkProcessed();
|
|
+
|
|
+ return super.getNode(index);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void truncateNodes(int length) {
|
|
+ this.checkProcessed();
|
|
+
|
|
+ super.truncateNodes(length);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void replaceNode(int index, Node node) {
|
|
+ this.checkProcessed();
|
|
+
|
|
+ super.replaceNode(index, node);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int getNodeCount() {
|
|
+ this.checkProcessed();
|
|
+
|
|
+ return super.getNodeCount();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int getNextNodeIndex() {
|
|
+ this.checkProcessed();
|
|
+
|
|
+ return super.getNextNodeIndex();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setNextNodeIndex(int nodeIndex) {
|
|
+ this.checkProcessed();
|
|
+
|
|
+ super.setNextNodeIndex(nodeIndex);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Vec3 getEntityPosAtNode(Entity entity, int index) {
|
|
+ this.checkProcessed();
|
|
+
|
|
+ return super.getEntityPosAtNode(entity, index);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public BlockPos getNodePos(int index) {
|
|
+ this.checkProcessed();
|
|
+
|
|
+ return super.getNodePos(index);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Vec3 getNextEntityPos(Entity entity) {
|
|
+ this.checkProcessed();
|
|
+
|
|
+ return super.getNextEntityPos(entity);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public BlockPos getNextNodePos() {
|
|
+ this.checkProcessed();
|
|
+
|
|
+ return super.getNextNodePos();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Node getNextNode() {
|
|
+ this.checkProcessed();
|
|
+
|
|
+ return super.getNextNode();
|
|
+ }
|
|
+
|
|
+ @Nullable
|
|
+ @Override
|
|
+ public Node getPreviousNode() {
|
|
+ this.checkProcessed();
|
|
+
|
|
+ return super.getPreviousNode();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean hasNext() {
|
|
+ this.checkProcessed();
|
|
+
|
|
+ return super.hasNext();
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/path/AsyncPathProcessor.java b/src/main/java/gg/pufferfish/pufferfish/path/AsyncPathProcessor.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..6c8035ef7effd0ccdc887b3792ba09ef6b2a74fa
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/path/AsyncPathProcessor.java
|
|
@@ -0,0 +1,44 @@
|
|
+package gg.pufferfish.pufferfish.path;
|
|
+
|
|
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import net.minecraft.world.level.pathfinder.Path;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+import org.jetbrains.annotations.Nullable;
|
|
+
|
|
+import java.util.concurrent.CompletableFuture;
|
|
+import java.util.concurrent.Executor;
|
|
+import java.util.concurrent.Executors;
|
|
+import java.util.function.Consumer;
|
|
+
|
|
+/**
|
|
+ * used to handle the scheduling of async path processing
|
|
+ */
|
|
+public class AsyncPathProcessor {
|
|
+
|
|
+ private static final Executor mainThreadExecutor = MinecraftServer.getServer();
|
|
+ private static final Executor pathProcessingExecutor = Executors.newCachedThreadPool(new ThreadFactoryBuilder()
|
|
+ .setNameFormat("puff-path-processor-%d")
|
|
+ .setPriority(Thread.NORM_PRIORITY - 2)
|
|
+ .build());
|
|
+
|
|
+ protected static CompletableFuture<Void> queue(@NotNull AsyncPath path) {
|
|
+ return CompletableFuture.runAsync(path::process, pathProcessingExecutor);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * takes a possibly unprocessed path, and waits until it is completed
|
|
+ * the consumer will be immediately invoked if the path is already processed
|
|
+ * the consumer will always be called on the main thread
|
|
+ *
|
|
+ * @param path a path to wait on
|
|
+ * @param afterProcessing a consumer to be called
|
|
+ */
|
|
+ public static void awaitProcessing(@Nullable Path path, Consumer<@Nullable Path> afterProcessing) {
|
|
+ if (path != null && !path.isProcessed() && path instanceof AsyncPath asyncPath) {
|
|
+ asyncPath.postProcessing(() -> mainThreadExecutor.execute(() -> afterProcessing.accept(path)));
|
|
+ } else {
|
|
+ afterProcessing.accept(path);
|
|
+ }
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/path/NodeEvaluatorCache.java b/src/main/java/gg/pufferfish/pufferfish/path/NodeEvaluatorCache.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..a18b967d7a7325885c94a1093cc5800012998f1a
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/path/NodeEvaluatorCache.java
|
|
@@ -0,0 +1,43 @@
|
|
+package gg.pufferfish.pufferfish.path;
|
|
+
|
|
+import net.minecraft.world.level.pathfinder.NodeEvaluator;
|
|
+import org.apache.commons.lang.Validate;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+
|
|
+import java.util.Map;
|
|
+import java.util.Queue;
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
+import java.util.concurrent.ConcurrentLinkedQueue;
|
|
+
|
|
+public class NodeEvaluatorCache {
|
|
+ private static final Map<NodeEvaluatorGenerator, ConcurrentLinkedQueue<NodeEvaluator>> threadLocalNodeEvaluators = new ConcurrentHashMap<>();
|
|
+ private static final Map<NodeEvaluator, NodeEvaluatorGenerator> nodeEvaluatorToGenerator = new ConcurrentHashMap<>();
|
|
+
|
|
+ private static @NotNull Queue<NodeEvaluator> getDequeForGenerator(@NotNull NodeEvaluatorGenerator generator) {
|
|
+ return threadLocalNodeEvaluators.computeIfAbsent(generator, (key) -> new ConcurrentLinkedQueue<>());
|
|
+ }
|
|
+
|
|
+ public static @NotNull NodeEvaluator takeNodeEvaluator(@NotNull NodeEvaluatorGenerator generator) {
|
|
+ var nodeEvaluator = getDequeForGenerator(generator).poll();
|
|
+
|
|
+ if (nodeEvaluator == null) {
|
|
+ nodeEvaluator = generator.generate();
|
|
+ }
|
|
+
|
|
+ nodeEvaluatorToGenerator.put(nodeEvaluator, generator);
|
|
+
|
|
+ return nodeEvaluator;
|
|
+ }
|
|
+
|
|
+ public static void returnNodeEvaluator(@NotNull NodeEvaluator nodeEvaluator) {
|
|
+ final var generator = nodeEvaluatorToGenerator.remove(nodeEvaluator);
|
|
+ Validate.notNull(generator, "NodeEvaluator already returned");
|
|
+
|
|
+ getDequeForGenerator(generator).offer(nodeEvaluator);
|
|
+ }
|
|
+
|
|
+ public static void removeNodeEvaluator(@NotNull NodeEvaluator nodeEvaluator) {
|
|
+ nodeEvaluatorToGenerator.remove(nodeEvaluator);
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/path/NodeEvaluatorGenerator.java b/src/main/java/gg/pufferfish/pufferfish/path/NodeEvaluatorGenerator.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..7557f75d2eff3291d5881746ac920d16a241e244
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/path/NodeEvaluatorGenerator.java
|
|
@@ -0,0 +1,10 @@
|
|
+package gg.pufferfish.pufferfish.path;
|
|
+
|
|
+import net.minecraft.world.level.pathfinder.NodeEvaluator;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+
|
|
+public interface NodeEvaluatorGenerator {
|
|
+
|
|
+ @NotNull NodeEvaluator generate();
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/sentry/PufferfishSentryAppender.java b/src/main/java/gg/pufferfish/pufferfish/sentry/PufferfishSentryAppender.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..731ef11c7a025ae95ed8a757b530d834733d0621
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/sentry/PufferfishSentryAppender.java
|
|
@@ -0,0 +1,135 @@
|
|
+package gg.pufferfish.pufferfish.sentry;
|
|
+
|
|
+import com.google.common.reflect.TypeToken;
|
|
+import com.google.gson.Gson;
|
|
+import io.sentry.Breadcrumb;
|
|
+import io.sentry.Sentry;
|
|
+import io.sentry.SentryEvent;
|
|
+import io.sentry.SentryLevel;
|
|
+import io.sentry.protocol.Message;
|
|
+import io.sentry.protocol.User;
|
|
+import java.util.Map;
|
|
+import org.apache.logging.log4j.Level;
|
|
+import org.apache.logging.log4j.LogManager;
|
|
+import org.apache.logging.log4j.Marker;
|
|
+import org.apache.logging.log4j.core.LogEvent;
|
|
+import org.apache.logging.log4j.core.Logger;
|
|
+import org.apache.logging.log4j.core.appender.AbstractAppender;
|
|
+import org.apache.logging.log4j.core.filter.AbstractFilter;
|
|
+
|
|
+public class PufferfishSentryAppender extends AbstractAppender {
|
|
+
|
|
+ private static final org.apache.logging.log4j.Logger logger = LogManager.getLogger(PufferfishSentryAppender.class);
|
|
+ private static final Gson GSON = new Gson();
|
|
+
|
|
+ public PufferfishSentryAppender() {
|
|
+ super("PufferfishSentryAdapter", new SentryFilter(), null);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void append(LogEvent logEvent) {
|
|
+ if (logEvent.getThrown() != null && logEvent.getLevel().isMoreSpecificThan(Level.WARN)) {
|
|
+ try {
|
|
+ logException(logEvent);
|
|
+ } catch (Exception e) {
|
|
+ logger.warn("Failed to log event with sentry", e);
|
|
+ }
|
|
+ } else {
|
|
+ try {
|
|
+ logBreadcrumb(logEvent);
|
|
+ } catch (Exception e) {
|
|
+ logger.warn("Failed to log event with sentry", e);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private void logException(LogEvent e) {
|
|
+ SentryEvent event = new SentryEvent(e.getThrown());
|
|
+
|
|
+ Message sentryMessage = new Message();
|
|
+ sentryMessage.setMessage(e.getMessage().getFormattedMessage());
|
|
+
|
|
+ event.setThrowable(e.getThrown());
|
|
+ event.setLevel(getLevel(e.getLevel()));
|
|
+ event.setLogger(e.getLoggerName());
|
|
+ event.setTransaction(e.getLoggerName());
|
|
+ event.setExtra("thread_name", e.getThreadName());
|
|
+
|
|
+ boolean hasContext = e.getContextData() != null;
|
|
+
|
|
+ if (hasContext && e.getContextData().containsKey("pufferfishsentry_playerid")) {
|
|
+ User user = new User();
|
|
+ user.setId(e.getContextData().getValue("pufferfishsentry_playerid"));
|
|
+ user.setUsername(e.getContextData().getValue("pufferfishsentry_playername"));
|
|
+ event.setUser(user);
|
|
+ }
|
|
+
|
|
+ if (hasContext && e.getContextData().containsKey("pufferfishsentry_pluginname")) {
|
|
+ event.setExtra("plugin.name", e.getContextData().getValue("pufferfishsentry_pluginname"));
|
|
+ event.setExtra("plugin.version", e.getContextData().getValue("pufferfishsentry_pluginversion"));
|
|
+ event.setTransaction(e.getContextData().getValue("pufferfishsentry_pluginname"));
|
|
+ }
|
|
+
|
|
+ if (hasContext && e.getContextData().containsKey("pufferfishsentry_eventdata")) {
|
|
+ Map<String, String> eventFields = GSON.fromJson((String) e.getContextData().getValue("pufferfishsentry_eventdata"), new TypeToken<Map<String, String>>() {}.getType());
|
|
+ if (eventFields != null) {
|
|
+ event.setExtra("event", eventFields);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ Sentry.captureEvent(event);
|
|
+ }
|
|
+
|
|
+ private void logBreadcrumb(LogEvent e) {
|
|
+ Breadcrumb breadcrumb = new Breadcrumb();
|
|
+
|
|
+ breadcrumb.setLevel(getLevel(e.getLevel()));
|
|
+ breadcrumb.setCategory(e.getLoggerName());
|
|
+ breadcrumb.setType(e.getLoggerName());
|
|
+ breadcrumb.setMessage(e.getMessage().getFormattedMessage());
|
|
+
|
|
+ Sentry.addBreadcrumb(breadcrumb);
|
|
+ }
|
|
+
|
|
+ private SentryLevel getLevel(Level level) {
|
|
+ switch (level.getStandardLevel()) {
|
|
+ case TRACE:
|
|
+ case DEBUG:
|
|
+ return SentryLevel.DEBUG;
|
|
+ case WARN:
|
|
+ return SentryLevel.WARNING;
|
|
+ case ERROR:
|
|
+ return SentryLevel.ERROR;
|
|
+ case FATAL:
|
|
+ return SentryLevel.FATAL;
|
|
+ case INFO:
|
|
+ default:
|
|
+ return SentryLevel.INFO;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private static class SentryFilter extends AbstractFilter {
|
|
+
|
|
+ @Override
|
|
+ public Result filter(Logger logger, org.apache.logging.log4j.Level level, Marker marker, String msg,
|
|
+ Object... params) {
|
|
+ return this.filter(logger.getName());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Result filter(Logger logger, org.apache.logging.log4j.Level level, Marker marker, Object msg, Throwable t) {
|
|
+ return this.filter(logger.getName());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Result filter(LogEvent event) {
|
|
+ return this.filter(event == null ? null : event.getLoggerName());
|
|
+ }
|
|
+
|
|
+ private Result filter(String loggerName) {
|
|
+ return loggerName != null && loggerName.startsWith("gg.castaway.pufferfish.sentry") ? Result.DENY
|
|
+ : Result.NEUTRAL;
|
|
+ }
|
|
+
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/sentry/SentryManager.java b/src/main/java/gg/pufferfish/pufferfish/sentry/SentryManager.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..1b29210ad0bbb4ada150f23357f0c80d331c996d
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/sentry/SentryManager.java
|
|
@@ -0,0 +1,40 @@
|
|
+package gg.pufferfish.pufferfish.sentry;
|
|
+
|
|
+import gg.pufferfish.pufferfish.PufferfishConfig;
|
|
+import io.sentry.Sentry;
|
|
+import org.apache.logging.log4j.LogManager;
|
|
+import org.apache.logging.log4j.Logger;
|
|
+
|
|
+public class SentryManager {
|
|
+
|
|
+ private static final Logger logger = LogManager.getLogger(SentryManager.class);
|
|
+
|
|
+ private SentryManager() {
|
|
+
|
|
+ }
|
|
+
|
|
+ private static boolean initialized = false;
|
|
+
|
|
+ public static synchronized void init() {
|
|
+ if (initialized) {
|
|
+ return;
|
|
+ }
|
|
+ try {
|
|
+ initialized = true;
|
|
+
|
|
+ Sentry.init(options -> {
|
|
+ options.setDsn(PufferfishConfig.sentryDsn);
|
|
+ options.setMaxBreadcrumbs(100);
|
|
+ });
|
|
+
|
|
+ PufferfishSentryAppender appender = new PufferfishSentryAppender();
|
|
+ appender.start();
|
|
+ ((org.apache.logging.log4j.core.Logger) LogManager.getRootLogger()).addAppender(appender);
|
|
+ logger.info("Sentry logging started!");
|
|
+ } catch (Exception e) {
|
|
+ logger.warn("Failed to initialize sentry!", e);
|
|
+ initialized = false;
|
|
+ }
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/tracker/MultithreadedTracker.java b/src/main/java/gg/pufferfish/pufferfish/tracker/MultithreadedTracker.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..ac541ddf1594ae865de02fd40940e39285043b1f
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/tracker/MultithreadedTracker.java
|
|
@@ -0,0 +1,127 @@
|
|
+package gg.pufferfish.pufferfish.tracker;
|
|
+
|
|
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
|
+import io.papermc.paper.util.maplist.IteratorSafeOrderedReferenceSet;
|
|
+import io.papermc.paper.world.ChunkEntitySlices;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import net.minecraft.server.level.ChunkMap;
|
|
+import net.minecraft.world.entity.Entity;
|
|
+import net.minecraft.world.level.chunk.LevelChunk;
|
|
+
|
|
+import java.util.concurrent.ConcurrentLinkedQueue;
|
|
+import java.util.concurrent.Executor;
|
|
+import java.util.concurrent.Executors;
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
+
|
|
+public class MultithreadedTracker {
|
|
+
|
|
+ private static final int parallelism = Math.max(4, Runtime.getRuntime().availableProcessors());
|
|
+ private static final Executor trackerExecutor = Executors.newFixedThreadPool(parallelism, new ThreadFactoryBuilder()
|
|
+ .setNameFormat("puff-tracker-%d")
|
|
+ .setPriority(Thread.NORM_PRIORITY - 2)
|
|
+ .build());
|
|
+
|
|
+ private final IteratorSafeOrderedReferenceSet<LevelChunk> entityTickingChunks;
|
|
+ private final AtomicInteger taskIndex = new AtomicInteger();
|
|
+
|
|
+ private final ConcurrentLinkedQueue<Runnable> mainThreadTasks;
|
|
+ private final AtomicInteger finishedTasks = new AtomicInteger();
|
|
+
|
|
+ public MultithreadedTracker(IteratorSafeOrderedReferenceSet<LevelChunk> entityTickingChunks, ConcurrentLinkedQueue<Runnable> mainThreadTasks) {
|
|
+ this.entityTickingChunks = entityTickingChunks;
|
|
+ this.mainThreadTasks = mainThreadTasks;
|
|
+ }
|
|
+
|
|
+ public void tick() {
|
|
+ int iterator = this.entityTickingChunks.createRawIterator();
|
|
+
|
|
+ if (iterator == -1) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ try {
|
|
+ this.taskIndex.set(iterator);
|
|
+ this.finishedTasks.set(0);
|
|
+
|
|
+ for (int i = 0; i < parallelism; i++) {
|
|
+ trackerExecutor.execute(this::run);
|
|
+ }
|
|
+
|
|
+ while (this.taskIndex.get() < this.entityTickingChunks.getListSize()) {
|
|
+ this.runMainThreadTasks();
|
|
+ this.handleTasks(5); // assist
|
|
+ }
|
|
+
|
|
+ while (this.finishedTasks.get() != parallelism) {
|
|
+ this.runMainThreadTasks();
|
|
+ }
|
|
+
|
|
+ this.runMainThreadTasks(); // finish any remaining tasks
|
|
+ } finally {
|
|
+ this.entityTickingChunks.finishRawIterator();
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private void runMainThreadTasks() {
|
|
+ try {
|
|
+ Runnable task;
|
|
+ while ((task = this.mainThreadTasks.poll()) != null) {
|
|
+ task.run();
|
|
+ }
|
|
+ } catch (Throwable throwable) {
|
|
+ MinecraftServer.LOGGER.warn("Tasks failed while ticking track queue", throwable);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private void run() {
|
|
+ try {
|
|
+ while (handleTasks(10));
|
|
+ } finally {
|
|
+ this.finishedTasks.incrementAndGet();
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private boolean handleTasks(int tasks) {
|
|
+ int index;
|
|
+ while ((index = this.taskIndex.getAndAdd(tasks)) < this.entityTickingChunks.getListSize()) {
|
|
+ for (int i = index; i < index + tasks && i < this.entityTickingChunks.getListSize(); i++) {
|
|
+ LevelChunk chunk = this.entityTickingChunks.rawGet(i);
|
|
+ if (chunk != null) {
|
|
+ try {
|
|
+ this.processChunk(chunk);
|
|
+ } catch (Throwable throwable) {
|
|
+ MinecraftServer.LOGGER.warn("Ticking tracker failed", throwable);
|
|
+ }
|
|
+
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ private void processChunk(LevelChunk chunk) {
|
|
+ final ChunkEntitySlices entitySlices = chunk.level.entityManager.entitySliceManager.getChunk(chunk.locX, chunk.locZ);
|
|
+ if (entitySlices == null) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ final Entity[] rawEntities = entitySlices.entities.getRawData();
|
|
+ final ChunkMap chunkMap = chunk.level.chunkSource.chunkMap;
|
|
+
|
|
+ for (int i = 0; i < rawEntities.length; i++) {
|
|
+ Entity entity = rawEntities[i];
|
|
+ if (entity != null) {
|
|
+ ChunkMap.TrackedEntity entityTracker = chunkMap.entityMap.get(entity.getId());
|
|
+ if (entityTracker != null) {
|
|
+ entityTracker.updatePlayers(entityTracker.entity.getPlayersInTrackRange());
|
|
+
|
|
+ this.mainThreadTasks.offer(entityTracker.serverEntity::sendChanges);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/util/AsyncExecutor.java b/src/main/java/gg/pufferfish/pufferfish/util/AsyncExecutor.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..9d6dc2c80945bec9bea74714c657c7a2e0bdde9e
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/util/AsyncExecutor.java
|
|
@@ -0,0 +1,51 @@
|
|
+package gg.pufferfish.pufferfish.util;
|
|
+
|
|
+import com.google.common.collect.Queues;
|
|
+import gg.pufferfish.pufferfish.PufferfishLogger;
|
|
+import java.util.Queue;
|
|
+import java.util.concurrent.locks.LockSupport;
|
|
+import java.util.function.BooleanSupplier;
|
|
+import java.util.logging.Level;
|
|
+
|
|
+public class AsyncExecutor implements Runnable {
|
|
+
|
|
+ private Queue<Runnable> jobs = Queues.newConcurrentLinkedQueue();
|
|
+ private final Thread thread;
|
|
+ private final BooleanSupplier shouldRun;
|
|
+ private volatile boolean killswitch = false;
|
|
+
|
|
+ public AsyncExecutor(String threadName, BooleanSupplier shouldRun) {
|
|
+ this.thread = new Thread(this, threadName);
|
|
+ this.shouldRun = shouldRun;
|
|
+ }
|
|
+
|
|
+ public void start() {
|
|
+ thread.start();
|
|
+ }
|
|
+
|
|
+ public void kill() {
|
|
+ killswitch = true;
|
|
+ }
|
|
+
|
|
+ public void submit(Runnable runnable) {
|
|
+ jobs.offer(runnable);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void run() {
|
|
+ while (!killswitch) {
|
|
+ if (shouldRun.getAsBoolean()) {
|
|
+ try {
|
|
+ Runnable runnable;
|
|
+ while ((runnable = jobs.poll()) != null) {
|
|
+ runnable.run();
|
|
+ }
|
|
+ } catch (Exception e) {
|
|
+ PufferfishLogger.LOGGER.log(Level.SEVERE, e, () -> "Failed to execute async job for thread " + thread.getName());
|
|
+ }
|
|
+ }
|
|
+ LockSupport.parkNanos("executing tasks", 1000L);
|
|
+ }
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/util/AsyncPlayerAreaMap.java b/src/main/java/gg/pufferfish/pufferfish/util/AsyncPlayerAreaMap.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..fdcb62d12164024a5f354d60cc863821a18d1b2a
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/util/AsyncPlayerAreaMap.java
|
|
@@ -0,0 +1,31 @@
|
|
+package gg.pufferfish.pufferfish.util;
|
|
+
|
|
+import com.destroystokyo.paper.util.misc.PlayerAreaMap;
|
|
+import com.destroystokyo.paper.util.misc.PooledLinkedHashSets;
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
+import net.minecraft.server.level.ServerPlayer;
|
|
+
|
|
+public final class AsyncPlayerAreaMap extends PlayerAreaMap {
|
|
+
|
|
+ public AsyncPlayerAreaMap() {
|
|
+ super();
|
|
+ this.areaMap = new Long2ObjectOpenHashMapWrapper<>(new ConcurrentHashMap<>(1024, 0.7f));
|
|
+ }
|
|
+
|
|
+ public AsyncPlayerAreaMap(final PooledLinkedHashSets<ServerPlayer> pooledHashSets) {
|
|
+ super(pooledHashSets);
|
|
+ this.areaMap = new Long2ObjectOpenHashMapWrapper<>(new ConcurrentHashMap<>(1024, 0.7f));
|
|
+ }
|
|
+
|
|
+ public AsyncPlayerAreaMap(final PooledLinkedHashSets<ServerPlayer> pooledHashSets, final ChangeCallback<ServerPlayer> addCallback,
|
|
+ final ChangeCallback<ServerPlayer> removeCallback) {
|
|
+ this(pooledHashSets, addCallback, removeCallback, null);
|
|
+ }
|
|
+
|
|
+ public AsyncPlayerAreaMap(final PooledLinkedHashSets<ServerPlayer> pooledHashSets, final ChangeCallback<ServerPlayer> addCallback,
|
|
+ final ChangeCallback<ServerPlayer> removeCallback, final ChangeSourceCallback<ServerPlayer> changeSourceCallback) {
|
|
+ super(pooledHashSets, addCallback, removeCallback, changeSourceCallback);
|
|
+ this.areaMap = new Long2ObjectOpenHashMapWrapper<>(new ConcurrentHashMap<>(1024, 0.7f));
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/util/IterableWrapper.java b/src/main/java/gg/pufferfish/pufferfish/util/IterableWrapper.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..c1929840254a3e6d721816f4a20415bea1742580
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/util/IterableWrapper.java
|
|
@@ -0,0 +1,20 @@
|
|
+package gg.pufferfish.pufferfish.util;
|
|
+
|
|
+import java.util.Iterator;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+
|
|
+public class IterableWrapper<T> implements Iterable<T> {
|
|
+
|
|
+ private final Iterator<T> iterator;
|
|
+
|
|
+ public IterableWrapper(Iterator<T> iterator) {
|
|
+ this.iterator = iterator;
|
|
+ }
|
|
+
|
|
+ @NotNull
|
|
+ @Override
|
|
+ public Iterator<T> iterator() {
|
|
+ return iterator;
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/util/Long2ObjectOpenHashMapWrapper.java b/src/main/java/gg/pufferfish/pufferfish/util/Long2ObjectOpenHashMapWrapper.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..facd55463d44cb7e3d2ca6892982f5497b8dded1
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/util/Long2ObjectOpenHashMapWrapper.java
|
|
@@ -0,0 +1,40 @@
|
|
+package gg.pufferfish.pufferfish.util;
|
|
+
|
|
+import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
|
+import java.util.Map;
|
|
+import org.jetbrains.annotations.Nullable;
|
|
+
|
|
+public class Long2ObjectOpenHashMapWrapper<V> extends Long2ObjectOpenHashMap<V> {
|
|
+
|
|
+ private final Map<Long, V> backingMap;
|
|
+
|
|
+ public Long2ObjectOpenHashMapWrapper(Map<Long, V> map) {
|
|
+ backingMap = map;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public V put(Long key, V value) {
|
|
+ return backingMap.put(key, value);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public V get(Object key) {
|
|
+ return backingMap.get(key);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public V remove(Object key) {
|
|
+ return backingMap.remove(key);
|
|
+ }
|
|
+
|
|
+ @Nullable
|
|
+ @Override
|
|
+ public V putIfAbsent(Long key, V value) {
|
|
+ return backingMap.putIfAbsent(key, value);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int size() {
|
|
+ return backingMap.size();
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
|
|
index 456595e4b7e0c7f50617aa2694b0d2dfc368ab81..bc72131afa1ae9986ee311a9b371e97c8feb38f8 100644
|
|
--- a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
|
|
+++ b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
|
|
@@ -8,6 +8,7 @@ import net.kyori.adventure.text.Component;
|
|
import net.kyori.adventure.text.format.NamedTextColor;
|
|
import net.minecraft.network.protocol.Packet;
|
|
import net.minecraft.network.protocol.game.ServerboundPlaceRecipePacket;
|
|
+import org.bukkit.Bukkit; // Pufferfish
|
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
|
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
|
@@ -17,6 +18,7 @@ import org.spongepowered.configurate.objectmapping.meta.Setting;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Objects;
|
|
+import java.util.logging.Level; // Pufferfish
|
|
|
|
@SuppressWarnings({"CanBeFinal", "FieldCanBeLocal", "FieldMayBeFinal", "NotNullFieldNotInitialized", "InnerClassMayBeStatic"})
|
|
public class GlobalConfiguration extends ConfigurationPart {
|
|
@@ -52,6 +54,7 @@ public class GlobalConfiguration extends ConfigurationPart {
|
|
|
|
public class Timings extends ConfigurationPart.Post {
|
|
public boolean enabled = true;
|
|
+ public boolean reallyEnabled = false;
|
|
public boolean verbose = true;
|
|
public String url = "https://timings.aikar.co/";
|
|
public boolean serverNamePrivacy = false;
|
|
@@ -65,6 +68,14 @@ public class GlobalConfiguration extends ConfigurationPart {
|
|
|
|
@Override
|
|
public void postProcess() {
|
|
+ // Pufferfish start
|
|
+ if (enabled && !reallyEnabled) {
|
|
+ Bukkit.getLogger().log(Level.WARNING, "[Pufferfish] To improve performance, timings have been disabled by default");
|
|
+ Bukkit.getLogger().log(Level.WARNING, "[Pufferfish] You can still use timings by using /timings on, but they will not start on server startup unless you set timings.really-enabled to true in paper.yml");
|
|
+ Bukkit.getLogger().log(Level.WARNING, "[Pufferfish] If you would like to disable this message, either set timings.really-enabled to true or timings.enabled to false.");
|
|
+ }
|
|
+ enabled = reallyEnabled;
|
|
+ // Pufferfish end
|
|
MinecraftTimings.processConfig(this);
|
|
}
|
|
}
|
|
diff --git a/src/main/java/io/papermc/paper/util/maplist/IteratorSafeOrderedReferenceSet.java b/src/main/java/io/papermc/paper/util/maplist/IteratorSafeOrderedReferenceSet.java
|
|
index 0fd814f1d65c111266a2b20f86561839a4cef755..ffc217df0649e85d4a7b3d4b1c2c6a8287de1104 100644
|
|
--- a/src/main/java/io/papermc/paper/util/maplist/IteratorSafeOrderedReferenceSet.java
|
|
+++ b/src/main/java/io/papermc/paper/util/maplist/IteratorSafeOrderedReferenceSet.java
|
|
@@ -15,7 +15,7 @@ public final class IteratorSafeOrderedReferenceSet<E> {
|
|
|
|
/* list impl */
|
|
protected E[] listElements;
|
|
- protected int listSize;
|
|
+ protected int listSize; public int getListSize() { return this.listSize; } // Pufferfish - expose listSize
|
|
|
|
protected final double maxFragFactor;
|
|
|
|
diff --git a/src/main/java/io/papermc/paper/world/ChunkEntitySlices.java b/src/main/java/io/papermc/paper/world/ChunkEntitySlices.java
|
|
index 47b5f75d9f27cf3ab947fd1f69cbd609fb9f2749..85882eeb86d7b74db0219aa65783946d8083885d 100644
|
|
--- a/src/main/java/io/papermc/paper/world/ChunkEntitySlices.java
|
|
+++ b/src/main/java/io/papermc/paper/world/ChunkEntitySlices.java
|
|
@@ -27,7 +27,7 @@ public final class ChunkEntitySlices {
|
|
protected final EntityCollectionBySection allEntities;
|
|
protected final EntityCollectionBySection hardCollidingEntities;
|
|
protected final Reference2ObjectOpenHashMap<Class<? extends Entity>, EntityCollectionBySection> entitiesByClass;
|
|
- protected final EntityList entities = new EntityList();
|
|
+ public final EntityList entities = new EntityList();
|
|
|
|
public ChunkHolder.FullChunkStatus status;
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java
|
|
index 7034af8ad42940c5af6b9032b9873ce36c55a2a7..c0fdc5a79107f8694a514a12d5526bd431fc45e9 100644
|
|
--- a/src/main/java/net/minecraft/server/MCUtil.java
|
|
+++ b/src/main/java/net/minecraft/server/MCUtil.java
|
|
@@ -209,7 +209,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) {
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index f23be38ef96a81ce3867a3b6fdccf632fe285f31..96ce3c0f5f17bb5c3b8be5dc137de3d457304a78 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -298,6 +298,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
public volatile Thread shutdownThread; // Paper
|
|
public volatile boolean abnormalExit = false; // Paper
|
|
public boolean isIteratingOverLevels = false; // Paper
|
|
+
|
|
+ public gg.pufferfish.pufferfish.util.AsyncExecutor mobSpawnExecutor = new gg.pufferfish.pufferfish.util.AsyncExecutor("MobSpawning", () -> true); // Pufferfish - optimize mob spawning
|
|
|
|
public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
|
|
AtomicReference<S> atomicreference = new AtomicReference();
|
|
@@ -1655,7 +1657,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
|
|
@DontObfuscate
|
|
public String getServerModName() {
|
|
- return "Paper"; // Paper - Paper > // Spigot - Spigot > // CraftBukkit - cb > vanilla!
|
|
+ return "Pufferfish"; // Pufferfish - Pufferfish > // Paper - Paper > // Spigot - Spigot > // CraftBukkit - cb > vanilla!
|
|
}
|
|
|
|
public SystemReport fillSystemReport(SystemReport details) {
|
|
@@ -2234,6 +2236,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
}
|
|
|
|
public ProfilerFiller getProfiler() {
|
|
+ if (gg.pufferfish.pufferfish.PufferfishConfig.disableMethodProfiler) return net.minecraft.util.profiling.InactiveProfiler.INSTANCE;
|
|
return this.profiler;
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
index bdd6560fe85950b0a857a949cb38c044da44ca6b..519883c5549744e047a8a96afee142746fcb49cd 100644
|
|
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
@@ -226,6 +226,8 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
|
com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // load version history now
|
|
io.papermc.paper.brigadier.PaperBrigadierProviderImpl.INSTANCE.getClass(); // init PaperBrigadierProvider
|
|
// Paper end
|
|
+ gg.pufferfish.pufferfish.PufferfishConfig.load(); // Pufferfish
|
|
+ gg.pufferfish.pufferfish.PufferfishCommand.init(); // Pufferfish
|
|
|
|
this.setPvpAllowed(dedicatedserverproperties.pvp);
|
|
this.setFlightAllowed(dedicatedserverproperties.allowFlight);
|
|
@@ -338,6 +340,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
|
DedicatedServer.LOGGER.info("JMX monitoring enabled");
|
|
}
|
|
|
|
+ if (gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncMobSpawning) mobSpawnExecutor.start(); // Pufferfish
|
|
return true;
|
|
}
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
index 77c89376495d90d0e7cbf6cd02c9a1c8d9a4340b..87518f6ff223ca211727c3002d107bc9bcaa36f9 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
@@ -471,7 +471,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
this.dataRegionManager = new io.papermc.paper.chunk.SingleThreadChunkRegionManager(this.level, 2, (1.0 / 3.0), 1, 6, "Data", DataRegionData::new, DataRegionSectionData::new);
|
|
this.regionManagers.add(this.dataRegionManager);
|
|
// Paper end
|
|
- this.playerMobDistanceMap = this.level.paperConfig().entities.spawning.perPlayerMobSpawns ? new com.destroystokyo.paper.util.misc.PlayerAreaMap(this.pooledLinkedPlayerHashSets) : null; // Paper
|
|
+ this.playerMobDistanceMap = this.level.paperConfig().entities.spawning.perPlayerMobSpawns ? new gg.pufferfish.pufferfish.util.AsyncPlayerAreaMap(this.pooledLinkedPlayerHashSets) : null; // Paper // Pufferfish
|
|
// Paper start - use distance map to optimise entity tracker
|
|
this.playerEntityTrackerTrackMaps = new com.destroystokyo.paper.util.misc.PlayerAreaMap[TRACKING_RANGE_TYPES.length];
|
|
this.entityTrackerTrackRanges = new int[TRACKING_RANGE_TYPES.length];
|
|
@@ -2079,8 +2079,36 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
entity.tracker = null; // Paper - We're no longer tracked
|
|
}
|
|
|
|
+ // Pufferfish start - multithreaded tracker
|
|
+ private @Nullable gg.pufferfish.pufferfish.tracker.MultithreadedTracker multithreadedTracker;
|
|
+ private final java.util.concurrent.ConcurrentLinkedQueue<Runnable> trackerMainThreadTasks = new java.util.concurrent.ConcurrentLinkedQueue<>();
|
|
+ private boolean multithreadedTrackingInProgress;
|
|
+
|
|
+ public void runOnTrackerMainThread(final Runnable runnable) {
|
|
+ if (multithreadedTrackingInProgress) {
|
|
+ this.trackerMainThreadTasks.add(runnable);
|
|
+ } else {
|
|
+ runnable.run();
|
|
+ }
|
|
+ }
|
|
+
|
|
// Paper start - optimised tracker
|
|
private final void processTrackQueue() {
|
|
+ if (gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncEntityTracker) {
|
|
+ if (this.multithreadedTracker == null) {
|
|
+ this.multithreadedTracker = new gg.pufferfish.pufferfish.tracker.MultithreadedTracker(this.level.chunkSource.entityTickingChunks, this.trackerMainThreadTasks);
|
|
+ }
|
|
+
|
|
+ try {
|
|
+ multithreadedTrackingInProgress = true;
|
|
+ this.multithreadedTracker.tick();
|
|
+ } finally {
|
|
+ multithreadedTrackingInProgress = false;
|
|
+ }
|
|
+ return;
|
|
+ }
|
|
+ // Pufferfish end
|
|
+
|
|
this.level.timings.tracker1.startTiming();
|
|
try {
|
|
for (TrackedEntity tracker : this.entityMap.values()) {
|
|
@@ -2272,11 +2300,11 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
|
|
public class TrackedEntity {
|
|
|
|
- final ServerEntity serverEntity;
|
|
- final Entity entity;
|
|
+ public final ServerEntity serverEntity; // Pufferfish - package->public
|
|
+ public final Entity entity; // Pufferfish -> public
|
|
private final int range;
|
|
SectionPos lastSectionPos;
|
|
- public final Set<ServerPlayerConnection> seenBy = new ReferenceOpenHashSet<>(); // Paper - optimise map impl
|
|
+ public final Set<ServerPlayerConnection> seenBy = it.unimi.dsi.fastutil.objects.ReferenceSets.synchronize(new ReferenceOpenHashSet<>()); // Paper - optimise map impl // Pufferfish - sync
|
|
|
|
public TrackedEntity(Entity entity, int i, int j, boolean flag) {
|
|
this.serverEntity = new ServerEntity(ChunkMap.this.level, entity, j, flag, this::broadcast, this.seenBy); // CraftBukkit
|
|
@@ -2288,7 +2316,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
// Paper start - use distance map to optimise tracker
|
|
com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> lastTrackerCandidates;
|
|
|
|
- final void updatePlayers(com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> newTrackerCandidates) {
|
|
+ public final void updatePlayers(com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> newTrackerCandidates) { // Pufferfish -> public
|
|
com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> oldTrackerCandidates = this.lastTrackerCandidates;
|
|
this.lastTrackerCandidates = newTrackerCandidates;
|
|
|
|
@@ -2360,7 +2388,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
}
|
|
|
|
public void removePlayer(ServerPlayer player) {
|
|
- org.spigotmc.AsyncCatcher.catchOp("player tracker clear"); // Spigot
|
|
+ //org.spigotmc.AsyncCatcher.catchOp("player tracker clear"); // Spigot // Pufferfish - we can remove async too
|
|
if (this.seenBy.remove(player.connection)) {
|
|
this.serverEntity.removePairing(player);
|
|
}
|
|
@@ -2368,7 +2396,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
}
|
|
|
|
public void updatePlayer(ServerPlayer player) {
|
|
- org.spigotmc.AsyncCatcher.catchOp("player tracker update"); // Spigot
|
|
+ //org.spigotmc.AsyncCatcher.catchOp("player tracker update"); // Spigot // Pufferfish - we can update async
|
|
if (player != this.entity) {
|
|
// Paper start - remove allocation of Vec3D here
|
|
// Vec3 vec3d = player.position().subtract(this.entity.position());
|
|
@@ -2400,8 +2428,28 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
return ChunkMap.this.level.getServer().getScaledTrackingDistance(initialDistance);
|
|
}
|
|
|
|
+ private static int getHighestRange(Entity parent, int highest) {
|
|
+ List<Entity> passengers = parent.getPassengers();
|
|
+
|
|
+ for (int i = 0, size = passengers.size(); i < size; i++) {
|
|
+ Entity entity = passengers.get(i);
|
|
+ int range = entity.getType().clientTrackingRange() * 16;
|
|
+ range = org.spigotmc.TrackingRange.getEntityTrackingRange(entity, range); // Paper
|
|
+
|
|
+ if (range > highest) { // Paper - we need the lowest range thanks to the fact that our tracker doesn't account for passenger logic // Tuinity - not anymore!
|
|
+ highest = range;
|
|
+ }
|
|
+
|
|
+ highest = getHighestRange(entity, highest);
|
|
+ }
|
|
+
|
|
+ return highest;
|
|
+ }
|
|
+
|
|
private int getEffectiveRange() {
|
|
int i = this.range;
|
|
+ // Pufferfish start - remove iterators and streams
|
|
+ /*
|
|
Iterator iterator = this.entity.getIndirectPassengers().iterator();
|
|
|
|
while (iterator.hasNext()) {
|
|
@@ -2413,6 +2461,9 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
i = j;
|
|
}
|
|
}
|
|
+ */
|
|
+ i = getHighestRange(this.entity, i);
|
|
+ // Pufferfish end
|
|
|
|
return this.scaledRange(i);
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerBossEvent.java b/src/main/java/net/minecraft/server/level/ServerBossEvent.java
|
|
index ca42c2642a729b90d22b968af7258f3aee72e14b..7613510e5f4c22ee15651f162fe1bca1cfc81be0 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerBossEvent.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerBossEvent.java
|
|
@@ -13,7 +13,7 @@ import net.minecraft.util.Mth;
|
|
import net.minecraft.world.BossEvent;
|
|
|
|
public class ServerBossEvent extends BossEvent {
|
|
- private final Set<ServerPlayer> players = Sets.newHashSet();
|
|
+ private final Set<ServerPlayer> players = Sets.newConcurrentHashSet(); // Pufferfish - players can be removed in async tracking
|
|
private final Set<ServerPlayer> unmodifiablePlayers = Collections.unmodifiableSet(this.players);
|
|
public boolean visible = true;
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
|
index 59acbf6249f8f5285504c0ddea448a3433d1d68d..378cc1f9e19eb9b18037ab8af92f65897e15a405 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
|
@@ -75,6 +75,9 @@ public class ServerChunkCache extends ChunkSource {
|
|
final it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap<LevelChunk> loadedChunkMap = new it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap<>(8192, 0.5f);
|
|
|
|
private final LevelChunk[] lastLoadedChunks = new LevelChunk[4 * 4];
|
|
+
|
|
+ public boolean firstRunSpawnCounts = true; // Pufferfish
|
|
+ public final java.util.concurrent.atomic.AtomicBoolean _pufferfish_spawnCountsReady = new java.util.concurrent.atomic.AtomicBoolean(false); // Pufferfish - optimize countmobs
|
|
|
|
private static int getChunkCacheKey(int x, int z) {
|
|
return x & 3 | ((z & 3) << 2);
|
|
@@ -962,6 +965,7 @@ public class ServerChunkCache extends ChunkSource {
|
|
ProfilerFiller gameprofilerfiller = this.level.getProfiler();
|
|
|
|
gameprofilerfiller.push("pollingChunks");
|
|
+ this.level.resetIceAndSnowTick(); // Pufferfish - reset ice & snow tick random
|
|
int k = this.level.getGameRules().getInt(GameRules.RULE_RANDOMTICKING);
|
|
boolean flag1 = level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) != 0L && worlddata.getGameTime() % level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) == 0L; // CraftBukkit
|
|
|
|
@@ -971,18 +975,25 @@ public class ServerChunkCache extends ChunkSource {
|
|
// Paper start - per player mob spawning
|
|
NaturalSpawner.SpawnState spawnercreature_d; // moved down
|
|
if ((this.spawnFriendlies || this.spawnEnemies) && this.chunkMap.playerMobDistanceMap != null) { // don't count mobs when animals and monsters are disabled
|
|
- // re-set mob counts
|
|
- for (ServerPlayer player : this.level.players) {
|
|
- Arrays.fill(player.mobCounts, 0);
|
|
+ // Pufferfish start - moved down when async processing
|
|
+ if (!gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncMobSpawning) {
|
|
+ // re-set mob counts
|
|
+ for (ServerPlayer player : this.level.players) {
|
|
+ Arrays.fill(player.mobCounts, 0);
|
|
+ }
|
|
+ lastSpawnState = NaturalSpawner.createState(l, this.level.getAllEntities(), this::getFullChunk, null, true);
|
|
}
|
|
- spawnercreature_d = NaturalSpawner.createState(l, this.level.getAllEntities(), this::getFullChunk, null, true);
|
|
+ // Pufferfish end
|
|
} else {
|
|
- spawnercreature_d = NaturalSpawner.createState(l, this.level.getAllEntities(), this::getFullChunk, this.chunkMap.playerMobDistanceMap == null ? new LocalMobCapCalculator(this.chunkMap) : null, false);
|
|
+ // Pufferfish start - this is only implemented for per-player mob spawning so this makes everything work if this setting is disabled.
|
|
+ lastSpawnState = NaturalSpawner.createState(l, this.level.getAllEntities(), this::getFullChunk, this.chunkMap.playerMobDistanceMap == null ? new LocalMobCapCalculator(this.chunkMap) : null, false);
|
|
+ _pufferfish_spawnCountsReady.set(true);
|
|
+ // Pufferfish end
|
|
}
|
|
// Paper end
|
|
this.level.timings.countNaturalMobs.stopTiming(); // Paper - timings
|
|
|
|
- this.lastSpawnState = spawnercreature_d;
|
|
+ //this.lastSpawnState = spawnercreature_d; // Pufferfish - this is managed asynchronously
|
|
gameprofilerfiller.popPush("filteringLoadedChunks");
|
|
// Paper - moved down
|
|
this.level.timings.chunkTicks.startTiming(); // Paper
|
|
@@ -1020,8 +1031,8 @@ public class ServerChunkCache extends ChunkSource {
|
|
|
|
if ((true || this.level.isNaturalSpawningAllowed(chunkcoordintpair)) && this.chunkMap.anyPlayerCloseEnoughForSpawning(holder, chunkcoordintpair, false)) { // Paper - optimise anyPlayerCloseEnoughForSpawning // Paper - replace player chunk loader system
|
|
chunk1.incrementInhabitedTime(j);
|
|
- if (flag2 && (this.spawnEnemies || this.spawnFriendlies) && this.level.getWorldBorder().isWithinBounds(chunkcoordintpair) && this.chunkMap.anyPlayerCloseEnoughForSpawning(holder, chunkcoordintpair, true)) { // Spigot // Paper - optimise anyPlayerCloseEnoughForSpawning & optimise chunk tick iteration
|
|
- NaturalSpawner.spawnForChunk(this.level, chunk1, spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag1);
|
|
+ if (flag2 && (!gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncMobSpawning || _pufferfish_spawnCountsReady.get()) && (this.spawnEnemies || this.spawnFriendlies) && this.level.getWorldBorder().isWithinBounds(chunkcoordintpair) && this.chunkMap.anyPlayerCloseEnoughForSpawning(holder, chunkcoordintpair, true)) { // Spigot // Paper - optimise anyPlayerCloseEnoughForSpawning & optimise chunk tick iteration
|
|
+ NaturalSpawner.spawnForChunk(this.level, chunk1, lastSpawnState, this.spawnFriendlies, this.spawnEnemies, flag1); // Pufferfish
|
|
}
|
|
|
|
if (true || this.level.shouldTickBlocksAt(chunkcoordintpair.toLong())) { // Paper - replace player chunk loader system
|
|
@@ -1083,6 +1094,30 @@ public class ServerChunkCache extends ChunkSource {
|
|
}
|
|
// Paper end - controlled flush for entity tracker packets
|
|
}
|
|
+
|
|
+ // Pufferfish start - optimize mob spawning
|
|
+ if (gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncMobSpawning) {
|
|
+ for (ServerPlayer player : this.level.players) {
|
|
+ Arrays.fill(player.mobCounts, 0);
|
|
+ }
|
|
+ if (firstRunSpawnCounts) {
|
|
+ firstRunSpawnCounts = false;
|
|
+ _pufferfish_spawnCountsReady.set(true);
|
|
+ }
|
|
+ if (chunkMap.playerMobDistanceMap != null && _pufferfish_spawnCountsReady.getAndSet(false)) {
|
|
+ net.minecraft.server.MinecraftServer.getServer().mobSpawnExecutor.submit(() -> {
|
|
+ int mapped = distanceManager.getNaturalSpawnChunkCount();
|
|
+ io.papermc.paper.util.maplist.IteratorSafeOrderedReferenceSet.Iterator<Entity> objectiterator =
|
|
+ level.entityTickList.entities.iterator(io.papermc.paper.util.maplist.IteratorSafeOrderedReferenceSet.ITERATOR_FLAG_SEE_ADDITIONS);
|
|
+ gg.pufferfish.pufferfish.util.IterableWrapper<Entity> wrappedIterator =
|
|
+ new gg.pufferfish.pufferfish.util.IterableWrapper<>(objectiterator);
|
|
+ lastSpawnState = NaturalSpawner.createState(mapped, wrappedIterator, this::getFullChunk, null, true);
|
|
+ objectiterator.finishedIterating();
|
|
+ _pufferfish_spawnCountsReady.set(true);
|
|
+ });
|
|
+ }
|
|
+ }
|
|
+ // Pufferfish end
|
|
}
|
|
|
|
private void getFullChunk(long pos, Consumer<LevelChunk> chunkConsumer) {
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
index 3b144c820531122eb37d41be06c182b5f5dc0724..88152988425b7b02ec5ce229ba4c24b40e030329 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
@@ -165,6 +165,7 @@ public class ServerEntity {
|
|
boolean flag4 = k < -32768L || k > 32767L || l < -32768L || l > 32767L || i1 < -32768L || i1 > 32767L;
|
|
|
|
if (!flag4 && this.teleportDelay <= 400 && !this.wasRiding && this.wasOnGround == this.entity.isOnGround() && !(io.papermc.paper.configuration.GlobalConfiguration.get().collisions.sendFullPosForHardCollidingEntities && this.entity.hardCollides())) { // Paper - send full pos for hard colliding entities to prevent collision problems due to desync
|
|
+ if (flag2 || flag3 || this.entity instanceof AbstractArrow) { // Pufferfish
|
|
if ((!flag2 || !flag3) && !(this.entity instanceof AbstractArrow)) {
|
|
if (flag2) {
|
|
packet1 = new ClientboundMoveEntityPacket.Pos(this.entity.getId(), (short) ((int) k), (short) ((int) l), (short) ((int) i1), this.entity.isOnGround());
|
|
@@ -174,6 +175,7 @@ public class ServerEntity {
|
|
} else {
|
|
packet1 = new ClientboundMoveEntityPacket.PosRot(this.entity.getId(), (short) ((int) k), (short) ((int) l), (short) ((int) i1), (byte) i, (byte) j, this.entity.isOnGround());
|
|
}
|
|
+ } // Pufferfish
|
|
} else {
|
|
this.wasOnGround = this.entity.isOnGround();
|
|
this.teleportDelay = 0;
|
|
@@ -247,14 +249,18 @@ public class ServerEntity {
|
|
|
|
public void removePairing(ServerPlayer player) {
|
|
this.entity.stopSeenByPlayer(player);
|
|
- player.connection.send(new ClientboundRemoveEntitiesPacket(new int[]{this.entity.getId()}));
|
|
+ // Pufferfish start - ensure main thread
|
|
+ ((ServerLevel) this.entity.level).chunkSource.chunkMap.runOnTrackerMainThread(() ->
|
|
+ player.connection.send(new ClientboundRemoveEntitiesPacket(new int[]{this.entity.getId()}))
|
|
+ );
|
|
+ // Pufferfish end
|
|
}
|
|
|
|
public void addPairing(ServerPlayer player) {
|
|
ServerGamePacketListenerImpl playerconnection = player.connection;
|
|
|
|
Objects.requireNonNull(player.connection);
|
|
- this.sendPairingData(playerconnection::send, player); // CraftBukkit - add player
|
|
+ ((ServerLevel) this.entity.level).chunkSource.chunkMap.runOnTrackerMainThread(() -> this.sendPairingData(playerconnection::send, player)); // CraftBukkit - add player // Pufferfish - main thread
|
|
this.entity.startSeenByPlayer(player);
|
|
}
|
|
|
|
@@ -360,19 +366,26 @@ public class ServerEntity {
|
|
SynchedEntityData datawatcher = this.entity.getEntityData();
|
|
|
|
if (datawatcher.isDirty()) {
|
|
- this.broadcastAndSend(new ClientboundSetEntityDataPacket(this.entity.getId(), datawatcher, false));
|
|
+ ((ServerLevel) this.entity.level).chunkSource.chunkMap.runOnTrackerMainThread(() -> // Pufferfish
|
|
+ this.broadcastAndSend(new ClientboundSetEntityDataPacket(this.entity.getId(), datawatcher, false))
|
|
+ ); // Pufferfish
|
|
}
|
|
|
|
if (this.entity instanceof LivingEntity) {
|
|
Set<AttributeInstance> set = ((LivingEntity) this.entity).getAttributes().getDirtyAttributes();
|
|
|
|
if (!set.isEmpty()) {
|
|
+ // Pufferfish start
|
|
+ List<AttributeInstance> attributesCopy = Lists.newArrayList(set);
|
|
+ ((ServerLevel) this.entity.level).chunkSource.chunkMap.runOnTrackerMainThread(() -> {
|
|
// CraftBukkit start - Send scaled max health
|
|
if (this.entity instanceof ServerPlayer) {
|
|
- ((ServerPlayer) this.entity).getBukkitEntity().injectScaledMaxHealth(set, false);
|
|
+ ((ServerPlayer) this.entity).getBukkitEntity().injectScaledMaxHealth(attributesCopy, false); // Pufferfish
|
|
}
|
|
// CraftBukkit end
|
|
- this.broadcastAndSend(new ClientboundUpdateAttributesPacket(this.entity.getId(), set));
|
|
+ this.broadcastAndSend(new ClientboundUpdateAttributesPacket(this.entity.getId(), attributesCopy)); // Pufferfish
|
|
+ });
|
|
+ // Pufferfish end
|
|
}
|
|
|
|
set.clear();
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
index 083349794d5ceb50322c5a645dd33fbfcc1c8155..f58873ef4362bfcc618ead099be94ba2dd4d86ed 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -690,7 +690,20 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
|
}
|
|
|
|
gameprofilerfiller.push("tick");
|
|
- this.guardEntityTick(this::tickNonPassenger, entity);
|
|
+ // Pufferfish start - copied from this.guardEntityTick
|
|
+ try {
|
|
+ this.tickNonPassenger(entity); // Pufferfish - changed
|
|
+ MinecraftServer.getServer().executeMidTickTasks(); // Tuinity - execute chunk tasks mid tick
|
|
+ } catch (Throwable throwable) {
|
|
+ if (throwable instanceof ThreadDeath) throw throwable; // Paper
|
|
+ // Paper start - Prevent tile 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);
|
|
+ getCraftServer().getPluginManager().callEvent(new com.destroystokyo.paper.event.server.ServerExceptionEvent(new com.destroystokyo.paper.exception.ServerInternalException(msg, throwable)));
|
|
+ entity.discard();
|
|
+ // Paper end
|
|
+ }
|
|
+ // Pufferfish end
|
|
gameprofilerfiller.pop();
|
|
}
|
|
}
|
|
@@ -757,9 +770,11 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
|
}
|
|
// Paper start - optimise random block ticking
|
|
private final BlockPos.MutableBlockPos chunkTickMutablePosition = new BlockPos.MutableBlockPos();
|
|
- private final io.papermc.paper.util.math.ThreadUnsafeRandom randomTickRandom = new io.papermc.paper.util.math.ThreadUnsafeRandom(this.random.nextLong());
|
|
+ // private final io.papermc.paper.util.math.ThreadUnsafeRandom randomTickRandom = new io.papermc.paper.util.math.ThreadUnsafeRandom(); // Pufferfish - moved to super
|
|
// Paper end
|
|
|
|
+ private int currentIceAndSnowTick = 0; protected void resetIceAndSnowTick() { this.currentIceAndSnowTick = this.randomTickRandom.nextInt(16); } // Pufferfish
|
|
+
|
|
public void tickChunk(LevelChunk chunk, int randomTickSpeed) {
|
|
ChunkPos chunkcoordintpair = chunk.getPos();
|
|
boolean flag = this.isRaining();
|
|
@@ -770,7 +785,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
|
gameprofilerfiller.push("thunder");
|
|
final BlockPos.MutableBlockPos blockposition = this.chunkTickMutablePosition; // Paper - use mutable to reduce allocation rate, final to force compile fail on change
|
|
|
|
- if (!this.paperConfig().environment.disableThunder && flag && this.isThundering() && this.spigotConfig.thunderChance > 0 && this.random.nextInt(this.spigotConfig.thunderChance) == 0) { // Spigot // Paper - disable thunder
|
|
+ if (!this.paperConfig().environment.disableThunder && flag && this.isThundering() && this.spigotConfig.thunderChance > 0 && /*this.random.nextInt(this.spigotConfig.thunderChance) == 0 &&*/ chunk.shouldDoLightning(this.random)) { // Spigot // Paper - disable thunder // Pufferfish - replace random with shouldDoLightning
|
|
blockposition.set(this.findLightningTargetAround(this.getBlockRandomPos(j, 0, k, 15))); // Paper
|
|
if (this.isRainingAt(blockposition)) {
|
|
DifficultyInstance difficultydamagescaler = this.getCurrentDifficultyAt(blockposition);
|
|
@@ -794,7 +809,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
|
}
|
|
|
|
gameprofilerfiller.popPush("iceandsnow");
|
|
- if (!this.paperConfig().environment.disableIceAndSnow && this.random.nextInt(16) == 0) { // Paper - Disable ice and snow
|
|
+ if (!this.paperConfig().environment.disableIceAndSnow && (this.currentIceAndSnowTick++ & 15) == 0) { // Paper - Disable ice and snow // Paper - optimise random ticking // Pufferfish - optimize further random ticking
|
|
// Paper start - optimise chunk ticking
|
|
this.getRandomBlockPosition(j, 0, k, 15, blockposition);
|
|
int normalY = chunk.getHeight(Heightmap.Types.MOTION_BLOCKING, blockposition.getX() & 15, blockposition.getZ() & 15) + 1;
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
index 2fab929b6775238d031ca3305b61af3cbe920a06..c74a7b993a2e0bc0b993b269b90926b2e3673fe7 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -1219,6 +1219,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
|
|
|
|
@Override
|
|
public void handleEditBook(ServerboundEditBookPacket packet) {
|
|
+ if (!gg.pufferfish.pufferfish.PufferfishConfig.enableBooks && !this.player.getBukkitEntity().hasPermission("pufferfish.usebooks")) return; // Pufferfish
|
|
// Paper start
|
|
if (!this.cserver.isPrimaryThread()) {
|
|
List<String> pageList = packet.getPages();
|
|
@@ -2372,6 +2373,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
|
|
}
|
|
|
|
private boolean updateChatOrder(Instant timestamp) {
|
|
+ if (gg.pufferfish.pufferfish.PufferfishConfig.disableOutOfOrderChat) return true;
|
|
Instant instant1;
|
|
|
|
do {
|
|
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 540bc9500c35c0db719b00aa26f6fb3a1b08ed9f..806cb760822a99316b08ad95ff8922df717050e2 100644
|
|
--- a/src/main/java/net/minecraft/world/Container.java
|
|
+++ b/src/main/java/net/minecraft/world/Container.java
|
|
@@ -2,6 +2,8 @@ package net.minecraft.world;
|
|
|
|
import java.util.Set;
|
|
import java.util.function.Predicate;
|
|
+
|
|
+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;
|
|
@@ -10,6 +12,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
|
|
|
|
int LARGE_MAX_STACK_SIZE = 64;
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index f925a8d550ecbf2044a37bfe58b30d6578c5f6af..9630d95ad2d47bb4a043dcb143bb58cd183c00c1 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -292,7 +292,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
public double yo;
|
|
public double zo;
|
|
private Vec3 position;
|
|
- private BlockPos blockPosition;
|
|
+ public BlockPos blockPosition; // Pufferfish - private->public
|
|
private ChunkPos chunkPosition;
|
|
private Vec3 deltaMovement;
|
|
public float yRot; // Paper - private->public
|
|
@@ -414,6 +414,11 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
return this.originWorld;
|
|
}
|
|
// Paper end
|
|
+ // Pufferfish start
|
|
+ public int activatedPriority = gg.pufferfish.pufferfish.PufferfishConfig.maximumActivationPrio; // golf score
|
|
+ public final BlockPos.MutableBlockPos cachedBlockPos = new BlockPos.MutableBlockPos(); // used where needed
|
|
+ // Pufferfish end
|
|
+
|
|
public float getBukkitYaw() {
|
|
return this.yRot;
|
|
}
|
|
@@ -437,17 +442,36 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
this.isLegacyTrackingEntity = isLegacyTrackingEntity;
|
|
}
|
|
|
|
+ private org.spigotmc.TrackingRange.TrackingRangeType getFurthestEntity(Entity entity, net.minecraft.server.level.ChunkMap chunkMap, org.spigotmc.TrackingRange.TrackingRangeType type, int range) {
|
|
+ List<Entity> passengers = entity.getPassengers();
|
|
+ for (int i = 0, size = passengers.size(); i < size; i++) {
|
|
+ Entity passenger = passengers.get(i);
|
|
+ org.spigotmc.TrackingRange.TrackingRangeType passengerType = passenger.trackingRangeType;
|
|
+ int passengerRange = chunkMap.getEntityTrackerRange(passengerType.ordinal());
|
|
+ if (passengerRange > range) {
|
|
+ type = passengerType;
|
|
+ range = passengerRange;
|
|
+ }
|
|
+
|
|
+ type = this.getFurthestEntity(passenger, chunkMap, type, range);
|
|
+ }
|
|
+
|
|
+ return type;
|
|
+ }
|
|
+
|
|
public final com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> getPlayersInTrackRange() {
|
|
// determine highest range of passengers
|
|
if (this.passengers.isEmpty()) {
|
|
return ((ServerLevel)this.level).getChunkSource().chunkMap.playerEntityTrackerTrackMaps[this.trackingRangeType.ordinal()]
|
|
.getObjectsInRange(MCUtil.getCoordinateKey(this));
|
|
}
|
|
- Iterable<Entity> passengers = this.getIndirectPassengers();
|
|
+ //Iterable<Entity> passengers = this.getIndirectPassengers(); // Pufferfish
|
|
net.minecraft.server.level.ChunkMap chunkMap = ((ServerLevel)this.level).getChunkSource().chunkMap;
|
|
org.spigotmc.TrackingRange.TrackingRangeType type = this.trackingRangeType;
|
|
int range = chunkMap.getEntityTrackerRange(type.ordinal());
|
|
|
|
+ // Pufferfish start - use getFurthestEntity to skip getIndirectPassengers
|
|
+ /*
|
|
for (Entity passenger : passengers) {
|
|
org.spigotmc.TrackingRange.TrackingRangeType passengerType = passenger.trackingRangeType;
|
|
int passengerRange = chunkMap.getEntityTrackerRange(passengerType.ordinal());
|
|
@@ -456,6 +480,9 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
range = passengerRange;
|
|
}
|
|
}
|
|
+ */
|
|
+ type = this.getFurthestEntity(this, chunkMap, type, range);
|
|
+ // Pufferfish end
|
|
|
|
return chunkMap.playerEntityTrackerTrackMaps[type.ordinal()].getObjectsInRange(MCUtil.getCoordinateKey(this));
|
|
}
|
|
@@ -787,6 +814,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
// CraftBukkit end
|
|
|
|
public void baseTick() {
|
|
+ // Pufferfish start - entity TTL
|
|
+ if (type != EntityType.PLAYER && type.ttl >= 0 && this.tickCount >= type.ttl) {
|
|
+ remove(RemovalReason.DISCARDED);
|
|
+ return;
|
|
+ }
|
|
+ // Pufferfish end - entity TTL
|
|
this.level.getProfiler().push("entityBaseTick");
|
|
if (firstTick && this instanceof net.minecraft.world.entity.NeutralMob neutralMob) neutralMob.tickInitialPersistentAnger(level); // Paper - Update last hurt when ticking
|
|
this.feetBlockState = null;
|
|
@@ -3991,16 +4024,18 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
}
|
|
|
|
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;
|
|
@@ -4008,14 +4043,61 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
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;
|
|
@@ -4037,9 +4119,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
// CraftBukkit end
|
|
}
|
|
}
|
|
+ }
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
+ // Pufferfish end
|
|
|
|
if (vec3d.length() > 0.0D) {
|
|
if (k1 > 0) {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java
|
|
index ac0f0a4da4282c13f6e1f37710cb615d66b8ef2c..ec0319dd4b115e18b368027cc5dbe4d4d9c64840 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
|
|
@@ -305,6 +305,8 @@ public class EntityType<T extends Entity> implements EntityTypeTest<Entity, T> {
|
|
return Registry.ENTITY_TYPE.getOptional(ResourceLocation.tryParse(id));
|
|
}
|
|
|
|
+ public boolean dabEnabled = false; // Pufferfish
|
|
+ public int ttl = -1; // Pufferfish
|
|
// Paper start - add id
|
|
public final String id;
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
index cff7993bdafd2f69e46c9985c7601a69ae47f452..8a0e566aa0124480481b17b5b31691849c3ee7cd 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -142,7 +142,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 {
|
|
|
|
@@ -398,8 +397,7 @@ public abstract class LivingEntity extends Entity {
|
|
|
|
if (this.isAlive()) {
|
|
boolean flag = this instanceof net.minecraft.world.entity.player.Player;
|
|
-
|
|
- if (this.isInWall()) {
|
|
+ if ((!gg.pufferfish.pufferfish.PufferfishConfig.enableSuffocationOptimization || (tickCount % 10 == 0 && couldPossiblyBeHurt(1.0F))) && this.isInWall()) { // Pufferfish - optimize suffocation
|
|
this.hurt(DamageSource.IN_WALL, 1.0F);
|
|
} else if (flag && !this.level.getWorldBorder().isWithinBounds(this.getBoundingBox())) {
|
|
double d0 = this.level.getWorldBorder().getDistanceToBorder(this) + this.level.getWorldBorder().getDamageSafeZone();
|
|
@@ -1313,6 +1311,15 @@ public abstract class LivingEntity extends Entity {
|
|
return this.getHealth() <= 0.0F;
|
|
}
|
|
|
|
+ // Pufferfish start - optimize suffocation
|
|
+ public boolean couldPossiblyBeHurt(float amount) {
|
|
+ if ((float) this.invulnerableTime > (float) this.invulnerableDuration / 2.0F && amount <= this.lastHurt) {
|
|
+ return false;
|
|
+ }
|
|
+ return true;
|
|
+ }
|
|
+ // Pufferfish end
|
|
+
|
|
@Override
|
|
public boolean hurt(DamageSource source, float amount) {
|
|
if (this.isInvulnerableTo(source)) {
|
|
@@ -1881,6 +1888,20 @@ public abstract class LivingEntity extends Entity {
|
|
return this.lastClimbablePos;
|
|
}
|
|
|
|
+
|
|
+ // Pufferfish start
|
|
+ private boolean cachedOnClimable = false;
|
|
+ private BlockPos lastClimbingPosition = null;
|
|
+
|
|
+ public boolean onClimableCached() {
|
|
+ if (!this.blockPosition().equals(this.lastClimbingPosition)) {
|
|
+ this.cachedOnClimable = this.onClimbable();
|
|
+ this.lastClimbingPosition = this.blockPosition();
|
|
+ }
|
|
+ return this.cachedOnClimable;
|
|
+ }
|
|
+ // Pufferfish end
|
|
+
|
|
public boolean onClimbable() {
|
|
if (this.isSpectator()) {
|
|
return false;
|
|
@@ -3583,7 +3604,10 @@ public abstract class LivingEntity extends Entity {
|
|
Vec3 vec3d1 = new Vec3(entity.getX(), entity.getEyeY(), entity.getZ());
|
|
|
|
// Paper - diff on change - used in CraftLivingEntity#hasLineOfSight(Location) and CraftWorld#lineOfSightExists
|
|
- return vec3d1.distanceToSqr(vec3d) > 128D * 128D ? false : this.level.clip(new ClipContext(vec3d, vec3d1, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)).getType() == HitResult.Type.MISS; // Paper - use distanceToSqr
|
|
+ // Pufferfish start
|
|
+ //return vec3d1.distanceToSqr(vec3d) > 128D * 128D ? false : this.level.clip(new ClipContext(vec3d, vec3d1, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)).getType() == HitResult.Type.MISS; // Paper - use distanceToSqr
|
|
+ return vec3d1.distanceToSqr(vec3d) > 128D * 128D ? false : this.level.rayTraceDirect(vec3d, vec3d1, net.minecraft.world.phys.shapes.CollisionContext.of(this)) == net.minecraft.world.phys.BlockHitResult.Type.MISS;
|
|
+ // Pufferfish end
|
|
}
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
|
|
index 3646b969fa51b9683ab4137e530c3a6f6fc6c465..e8e60ea8b9e97ed87be78752f398ab25ba8e9a1b 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Mob.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
|
|
@@ -210,14 +210,16 @@ public abstract class Mob extends LivingEntity {
|
|
return this.lookControl;
|
|
}
|
|
|
|
+ int _pufferfish_inactiveTickDisableCounter = 0; // Pufferfish - throttle inactive goal selector ticking
|
|
// Paper start
|
|
@Override
|
|
public void inactiveTick() {
|
|
super.inactiveTick();
|
|
- if (this.goalSelector.inactiveTick()) {
|
|
+ boolean isThrottled = gg.pufferfish.pufferfish.PufferfishConfig.throttleInactiveGoalSelectorTick && _pufferfish_inactiveTickDisableCounter++ % 20 != 0; // Pufferfish - throttle inactive goal selector ticking
|
|
+ if (this.goalSelector.inactiveTick(this.activatedPriority, true) && !isThrottled) { // Pufferfish - pass activated priroity // Pufferfish - throttle inactive goal selector ticking
|
|
this.goalSelector.tick();
|
|
}
|
|
- if (this.targetSelector.inactiveTick()) {
|
|
+ if (this.targetSelector.inactiveTick(this.activatedPriority, true)) { // Pufferfish - pass activated priority
|
|
this.targetSelector.tick();
|
|
}
|
|
}
|
|
@@ -854,16 +856,20 @@ public abstract class Mob extends LivingEntity {
|
|
|
|
if (i % 2 != 0 && this.tickCount > 1) {
|
|
this.level.getProfiler().push("targetSelector");
|
|
+ if (this.targetSelector.inactiveTick(this.activatedPriority, false)) // Pufferfish - use this to alternate ticking
|
|
this.targetSelector.tickRunningGoals(false);
|
|
this.level.getProfiler().pop();
|
|
this.level.getProfiler().push("goalSelector");
|
|
+ if (this.goalSelector.inactiveTick(this.activatedPriority, false)) // Pufferfish - use this to alternate ticking
|
|
this.goalSelector.tickRunningGoals(false);
|
|
this.level.getProfiler().pop();
|
|
} else {
|
|
this.level.getProfiler().push("targetSelector");
|
|
+ if (this.targetSelector.inactiveTick(this.activatedPriority, false)) // Pufferfish - use this to alternate ticking
|
|
this.targetSelector.tick();
|
|
this.level.getProfiler().pop();
|
|
this.level.getProfiler().push("goalSelector");
|
|
+ if (this.goalSelector.inactiveTick(this.activatedPriority, false)) // Pufferfish - use this to alternate ticking
|
|
this.goalSelector.tick();
|
|
this.level.getProfiler().pop();
|
|
}
|
|
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 c770ee21b7b699522941f6a1584d532001c04082..9bce290eb0c2cfef4896a3f2076c80bf3d76bd56 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<Attribute, AttributeInstance> attributes = Maps.newHashMap();
|
|
private final Set<AttributeInstance> dirtyAttributes = Sets.newHashSet();
|
|
private final AttributeSupplier supplier;
|
|
+ private final java.util.function.Function<Attribute, AttributeInstance> createInstance; // Pufferfish
|
|
|
|
public AttributeMap(AttributeSupplier defaultAttributes) {
|
|
this.supplier = defaultAttributes;
|
|
+ this.createInstance = attribute -> this.supplier.createInstance(this::onAttributeModified, attribute); // Pufferfish
|
|
}
|
|
|
|
private void onAttributeModified(AttributeInstance instance) {
|
|
@@ -44,11 +46,10 @@ public class AttributeMap {
|
|
}).collect(Collectors.toList());
|
|
}
|
|
|
|
+
|
|
@Nullable
|
|
public AttributeInstance getInstance(Attribute attribute) {
|
|
- return this.attributes.computeIfAbsent(attribute, (attributex) -> {
|
|
- return 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(Attribute attribute) {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/AcquirePoi.java b/src/main/java/net/minecraft/world/entity/ai/behavior/AcquirePoi.java
|
|
index 43243537b765a2d270be6de3f053fea77ff67d18..b56bb0ac37a6d51d645b6189af0ae7da01a353fd 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/AcquirePoi.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/AcquirePoi.java
|
|
@@ -72,6 +72,7 @@ public class AcquirePoi extends Behavior<PathfinderMob> {
|
|
@Override
|
|
protected void start(ServerLevel world, PathfinderMob entity, long time) {
|
|
this.nextScheduledStart = time + 20L + (long)world.getRandom().nextInt(20);
|
|
+ if (entity.getNavigation().isStuck()) this.nextScheduledStart += 200L; // Pufferfish - wait an additional 10s to check again if they're stuck
|
|
PoiManager poiManager = world.getPoiManager();
|
|
this.batchCache.long2ObjectEntrySet().removeIf((entry) -> {
|
|
return !entry.getValue().isStillValid(time);
|
|
@@ -92,27 +93,60 @@ public class AcquirePoi extends Behavior<PathfinderMob> {
|
|
io.papermc.paper.util.PoiAccess.findNearestPoiPositions(poiManager, this.poiType, predicate, entity.blockPosition(), 48, 48*48, PoiManager.Occupancy.HAS_SPACE, false, 5, poiposes);
|
|
Set<Pair<Holder<PoiType>, BlockPos>> set = new java.util.HashSet<>(poiposes);
|
|
// Paper end - optimise POI access
|
|
- Path path = findPathToPois(entity, set);
|
|
- if (path != null && path.canReach()) {
|
|
- BlockPos blockPos = path.getTarget();
|
|
- poiManager.getType(blockPos).ifPresent((holder) -> {
|
|
- poiManager.take(this.poiType, (holderx, blockPos2) -> {
|
|
- return blockPos2.equals(blockPos);
|
|
- }, blockPos, 1);
|
|
- entity.getBrain().setMemory(this.memoryToAcquire, GlobalPos.of(world.dimension(), blockPos));
|
|
- this.onPoiAcquisitionEvent.ifPresent((byte_) -> {
|
|
- world.broadcastEntityEvent(entity, byte_);
|
|
+ // Pufferfish start - await on path async
|
|
+ if (gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding) {
|
|
+ Path possiblePath = findPathToPois(entity, set);
|
|
+
|
|
+ // Pufferfish - wait on the path to be processed
|
|
+ gg.pufferfish.pufferfish.path.AsyncPathProcessor.awaitProcessing(possiblePath, path -> {
|
|
+ // Pufferfish - readd canReach check
|
|
+ if (path == null || !path.canReach()) {
|
|
+ for(Pair<Holder<PoiType>, BlockPos> pair : set) {
|
|
+ this.batchCache.computeIfAbsent(pair.getSecond().asLong(), (m) -> {
|
|
+ return new AcquirePoi.JitteredLinearRetry(entity.level.random, time);
|
|
+ });
|
|
+ }
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ BlockPos blockPos = path.getTarget();
|
|
+ poiManager.getType(blockPos).ifPresent((holder) -> {
|
|
+ poiManager.take(this.poiType, (holderx, blockPos2) -> {
|
|
+ return blockPos2.equals(blockPos);
|
|
+ }, blockPos, 1);
|
|
+ entity.getBrain().setMemory(this.memoryToAcquire, GlobalPos.of(world.dimension(), blockPos));
|
|
+ this.onPoiAcquisitionEvent.ifPresent((byte_) -> {
|
|
+ world.broadcastEntityEvent(entity, byte_);
|
|
+ });
|
|
+ this.batchCache.clear();
|
|
+ DebugPackets.sendPoiTicketCountPacket(world, blockPos);
|
|
});
|
|
- this.batchCache.clear();
|
|
- DebugPackets.sendPoiTicketCountPacket(world, blockPos);
|
|
});
|
|
} else {
|
|
- for(Pair<Holder<PoiType>, BlockPos> pair : set) {
|
|
- this.batchCache.computeIfAbsent(pair.getSecond().asLong(), (m) -> {
|
|
- return new AcquirePoi.JitteredLinearRetry(entity.level.random, time);
|
|
+ Path path = findPathToPois(entity, set);
|
|
+ if (path != null && path.canReach()) {
|
|
+ BlockPos blockPos = path.getTarget();
|
|
+ poiManager.getType(blockPos).ifPresent((holder) -> {
|
|
+ poiManager.take(this.poiType, (holderx, blockPos2) -> {
|
|
+ return blockPos2.equals(blockPos);
|
|
+ }, blockPos, 1);
|
|
+ entity.getBrain().setMemory(this.memoryToAcquire, GlobalPos.of(world.dimension(), blockPos));
|
|
+ this.onPoiAcquisitionEvent.ifPresent((byte_) -> {
|
|
+ world.broadcastEntityEvent(entity, byte_);
|
|
+ });
|
|
+ this.batchCache.clear();
|
|
+ DebugPackets.sendPoiTicketCountPacket(world, blockPos);
|
|
});
|
|
+ } else {
|
|
+ for(Pair<Holder<PoiType>, BlockPos> pair : set) {
|
|
+ this.batchCache.computeIfAbsent(pair.getSecond().asLong(), (m) -> {
|
|
+ return new AcquirePoi.JitteredLinearRetry(entity.level.random, time);
|
|
+ });
|
|
+ }
|
|
}
|
|
}
|
|
+
|
|
+ // Pufferfish end
|
|
|
|
}
|
|
|
|
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 18364ce4c60172529b10bc9e3a813dcedc4b766f..72dfb58a7f4586387c2d32cf54fff137b2d26666 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
|
|
@@ -21,6 +21,7 @@ public class MoveToTargetSink extends Behavior<Mob> {
|
|
private int remainingCooldown;
|
|
@Nullable
|
|
private Path path;
|
|
+ private boolean finishedProcessing; // Pufferfish
|
|
@Nullable
|
|
private BlockPos lastTargetPos;
|
|
private float speedModifier;
|
|
@@ -42,9 +43,10 @@ public class MoveToTargetSink extends Behavior<Mob> {
|
|
Brain<?> brain = entity.getBrain();
|
|
WalkTarget walkTarget = brain.getMemory(MemoryModuleType.WALK_TARGET).get();
|
|
boolean bl = this.reachedTarget(entity, walkTarget);
|
|
- if (!bl && this.tryComputePath(entity, walkTarget, world.getGameTime())) {
|
|
+ if (!bl && (!gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding && this.tryComputePath(entity, walkTarget, world.getGameTime()))) { // Pufferfish
|
|
this.lastTargetPos = walkTarget.getTarget().currentBlockPosition();
|
|
return true;
|
|
+ } else if (!bl) { return true; // Pufferfish
|
|
} else {
|
|
brain.eraseMemory(MemoryModuleType.WALK_TARGET);
|
|
if (bl) {
|
|
@@ -58,6 +60,7 @@ public class MoveToTargetSink extends Behavior<Mob> {
|
|
|
|
@Override
|
|
protected boolean canStillUse(ServerLevel serverLevel, Mob mob, long l) {
|
|
+ if (gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding && !finishedProcessing) return true; // Pufferfish - wait for path to process
|
|
if (this.path != null && this.lastTargetPos != null) {
|
|
Optional<WalkTarget> optional = mob.getBrain().getMemory(MemoryModuleType.WALK_TARGET);
|
|
PathNavigation pathNavigation = mob.getNavigation();
|
|
@@ -81,28 +84,96 @@ public class MoveToTargetSink extends Behavior<Mob> {
|
|
|
|
@Override
|
|
protected void start(ServerLevel serverLevel, Mob mob, long l) {
|
|
+ if (!gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding) { // Pufferfish
|
|
mob.getBrain().setMemory(MemoryModuleType.PATH, this.path);
|
|
mob.getNavigation().moveTo(this.path, (double)this.speedModifier);
|
|
+ // Pufferfish start
|
|
+ } else {
|
|
+ Brain<?> brain = mob.getBrain();
|
|
+ WalkTarget walkTarget = brain.getMemory(MemoryModuleType.WALK_TARGET).get();
|
|
+
|
|
+ this.finishedProcessing = false;
|
|
+ this.lastTargetPos = walkTarget.getTarget().currentBlockPosition();
|
|
+ this.path = this.computePath(mob, walkTarget);
|
|
+ }
|
|
+ // Pufferfish end
|
|
}
|
|
|
|
@Override
|
|
protected void tick(ServerLevel world, Mob entity, long time) {
|
|
+ if (gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding && this.path != null && !this.path.isProcessed()) return; // Pufferfish - wait for processing
|
|
+
|
|
+ // Pufferfish start
|
|
+ if (gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding && !finishedProcessing) {
|
|
+ this.finishedProcessing = true;
|
|
+ Brain<?> brain = entity.getBrain();
|
|
+ boolean canReach = this.path != null && this.path.canReach();
|
|
+ if (canReach) {
|
|
+ brain.eraseMemory(MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE);
|
|
+ } else if (brain.hasMemoryValue(MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE)) {
|
|
+ brain.setMemory(MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE, time);
|
|
+ }
|
|
+
|
|
+ if (!canReach) {
|
|
+ Optional<WalkTarget> walkTarget = brain.getMemory(MemoryModuleType.WALK_TARGET);
|
|
+
|
|
+ if (walkTarget.isPresent()) {
|
|
+ BlockPos blockPos = walkTarget.get().getTarget().currentBlockPosition();
|
|
+ Vec3 vec3 = DefaultRandomPos.getPosTowards((PathfinderMob)entity, 10, 7, Vec3.atBottomCenterOf(blockPos), (double)((float)Math.PI / 2F));
|
|
+ if (vec3 != null) {
|
|
+ // try recalculating the path using a random position
|
|
+ this.path = entity.getNavigation().createPath(vec3.x, vec3.y, vec3.z, 0);
|
|
+ this.finishedProcessing = false;
|
|
+ return;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ brain.eraseMemory(MemoryModuleType.WALK_TARGET);
|
|
+ this.path = null;
|
|
+
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ entity.getBrain().setMemory(MemoryModuleType.PATH, this.path);
|
|
+ entity.getNavigation().moveTo(this.path, (double)this.speedModifier);
|
|
+ }
|
|
+ // Pufferfish end
|
|
+
|
|
Path path = entity.getNavigation().getPath();
|
|
Brain<?> brain = entity.getBrain();
|
|
- if (this.path != path) {
|
|
+ if (!gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding && this.path != path) { // Pufferfish
|
|
this.path = path;
|
|
brain.setMemory(MemoryModuleType.PATH, path);
|
|
}
|
|
|
|
- if (path != null && this.lastTargetPos != null) {
|
|
+ if (path != null && this.lastTargetPos != null && (!gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding || brain.hasMemoryValue(MemoryModuleType.WALK_TARGET))) { // Pufferfish
|
|
WalkTarget walkTarget = brain.getMemory(MemoryModuleType.WALK_TARGET).get();
|
|
+ if (!gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding) { // Pufferfish
|
|
if (walkTarget.getTarget().currentBlockPosition().distSqr(this.lastTargetPos) > 4.0D && this.tryComputePath(entity, walkTarget, world.getGameTime())) {
|
|
this.lastTargetPos = walkTarget.getTarget().currentBlockPosition();
|
|
this.start(world, entity, time);
|
|
}
|
|
+ // Pufferfish start
|
|
+ } else {
|
|
+ if (walkTarget.getTarget().currentBlockPosition().distSqr(this.lastTargetPos) > 4.0D) this.start(world, entity, time);
|
|
+ }
|
|
+ // Pufferfish end
|
|
+
|
|
+ }
|
|
+ }
|
|
|
|
+ // Pufferfish start
|
|
+ private Path computePath(Mob entity, WalkTarget walkTarget) {
|
|
+ BlockPos blockPos = walkTarget.getTarget().currentBlockPosition();
|
|
+ this.speedModifier = walkTarget.getSpeedModifier();
|
|
+ Brain<?> brain = entity.getBrain();
|
|
+ if (this.reachedTarget(entity, walkTarget)) {
|
|
+ brain.eraseMemory(MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE);
|
|
}
|
|
+
|
|
+ return entity.getNavigation().createPath(blockPos, 0);
|
|
}
|
|
+ // Pufferfish end
|
|
|
|
private boolean tryComputePath(Mob entity, WalkTarget walkTarget, long time) {
|
|
BlockPos blockPos = walkTarget.getTarget().currentBlockPosition();
|
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/SetClosestHomeAsWalkTarget.java b/src/main/java/net/minecraft/world/entity/ai/behavior/SetClosestHomeAsWalkTarget.java
|
|
index 9bd6d4f7b86daaaa9cfbad454dde06b797e3f667..2402a8c1067a74a21d9812561df5fb6284670571 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/SetClosestHomeAsWalkTarget.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/SetClosestHomeAsWalkTarget.java
|
|
@@ -71,19 +71,41 @@ public class SetClosestHomeAsWalkTarget extends Behavior<LivingEntity> {
|
|
Set<Pair<Holder<PoiType>, BlockPos>> set = poiManager.findAllWithType((poiType) -> {
|
|
return poiType.is(PoiTypes.HOME);
|
|
}, predicate, entity.blockPosition(), 48, PoiManager.Occupancy.ANY).collect(Collectors.toSet());
|
|
- Path path = AcquirePoi.findPathToPois(pathfinderMob, set);
|
|
- if (path != null && path.canReach()) {
|
|
- BlockPos blockPos = path.getTarget();
|
|
- Optional<Holder<PoiType>> optional = poiManager.getType(blockPos);
|
|
- if (optional.isPresent()) {
|
|
- entity.getBrain().setMemory(MemoryModuleType.WALK_TARGET, new WalkTarget(blockPos, this.speedModifier, 1));
|
|
- DebugPackets.sendPoiTicketCountPacket(world, blockPos);
|
|
- }
|
|
- } else if (this.triedCount < 5) {
|
|
- this.batchCache.long2LongEntrySet().removeIf((entry) -> {
|
|
- return entry.getLongValue() < this.lastUpdate;
|
|
+ // Pufferfish start - await on path async
|
|
+ if (gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding) {
|
|
+ Path possiblePath = AcquirePoi.findPathToPois(pathfinderMob, set);
|
|
+
|
|
+ // Pufferfish - wait on the path to be processed
|
|
+ gg.pufferfish.pufferfish.path.AsyncPathProcessor.awaitProcessing(possiblePath, path -> {
|
|
+ if (path == null || !path.canReach() || this.triedCount < 5) { // Pufferfish - readd canReach check
|
|
+ this.batchCache.long2LongEntrySet().removeIf((entry) -> {
|
|
+ return entry.getLongValue() < this.lastUpdate;
|
|
+ });
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ BlockPos blockPos = path.getTarget();
|
|
+ Optional<Holder<PoiType>> optional = poiManager.getType(blockPos);
|
|
+ if (optional.isPresent()) {
|
|
+ entity.getBrain().setMemory(MemoryModuleType.WALK_TARGET, new WalkTarget(blockPos, this.speedModifier, 1));
|
|
+ DebugPackets.sendPoiTicketCountPacket(world, blockPos);
|
|
+ }
|
|
});
|
|
+ } else {
|
|
+ Path path = AcquirePoi.findPathToPois(pathfinderMob, set);
|
|
+ if (path != null && path.canReach()) {
|
|
+ BlockPos blockPos = path.getTarget();
|
|
+ Optional<Holder<PoiType>> optional = poiManager.getType(blockPos);
|
|
+ if (optional.isPresent()) {
|
|
+ entity.getBrain().setMemory(MemoryModuleType.WALK_TARGET, new WalkTarget(blockPos, this.speedModifier, 1));
|
|
+ DebugPackets.sendPoiTicketCountPacket(world, blockPos);
|
|
+ }
|
|
+ } else if (this.triedCount < 5) {
|
|
+ this.batchCache.long2LongEntrySet().removeIf((entry) -> {
|
|
+ return entry.getLongValue() < this.lastUpdate;
|
|
+ });
|
|
+ }
|
|
}
|
|
-
|
|
+ // Pufferfish end
|
|
}
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/VillagerPanicTrigger.java b/src/main/java/net/minecraft/world/entity/ai/behavior/VillagerPanicTrigger.java
|
|
index 42d466f7f162943886078eba3db18f2dfc2d7bee..6c0dda1ce018ec6bb2ebb97147045fffae0a89d5 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/VillagerPanicTrigger.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/VillagerPanicTrigger.java
|
|
@@ -37,7 +37,11 @@ public class VillagerPanicTrigger extends Behavior<Villager> {
|
|
|
|
@Override
|
|
protected void tick(ServerLevel serverLevel, Villager villager, long l) {
|
|
- if (l % 100L == 0L) {
|
|
+ // Pufferfish start
|
|
+ if (villager.nextGolemPanic < 0) villager.nextGolemPanic = l + 100;
|
|
+ if (--villager.nextGolemPanic < l) {
|
|
+ villager.nextGolemPanic = -1;
|
|
+ // Pufferfish end
|
|
villager.spawnGolemIfNeeded(serverLevel, l, 3);
|
|
}
|
|
|
|
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 a910189177da0c1134c954b3d81b9e9bc4bc1420..0cc0d719e95e108263683b7a40f4ce3a8ca9465b 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
|
|
@@ -50,9 +50,12 @@ public class GoalSelector {
|
|
}
|
|
|
|
// Paper start
|
|
- public boolean inactiveTick() {
|
|
+ public boolean inactiveTick(int tickRate, boolean inactive) { // Pufferfish start
|
|
+ if (inactive && !gg.pufferfish.pufferfish.PufferfishConfig.dearEnabled) tickRate = 4; // reset to Paper's
|
|
+ tickRate = Math.min(tickRate, this.newGoalRate);
|
|
this.curRate++;
|
|
- return this.curRate % this.newGoalRate == 0;
|
|
+ return this.curRate % tickRate == 0;
|
|
+ // Pufferfish end
|
|
}
|
|
public boolean hasTasks() {
|
|
for (WrappedGoal task : this.availableGoals) {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java b/src/main/java/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java
|
|
index 26bf383caea68834c654b25653ced9017f1b1b22..615eb55e24d365d994fbfe9d45d2be387fd5d561 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java
|
|
@@ -119,6 +119,7 @@ public abstract class MoveToBlockGoal extends Goal {
|
|
for(int m = 0; m <= l; m = m > 0 ? -m : 1 - m) {
|
|
for(int n = m < l && m > -l ? l : 0; n <= l; n = n > 0 ? -n : 1 - n) {
|
|
mutableBlockPos.setWithOffset(blockPos, m, k - 1, n);
|
|
+ if (!this.mob.level.hasChunkAt(mutableBlockPos)) continue; // Pufferfish - if this block isn't loaded, continue
|
|
if (this.mob.isWithinRestriction(mutableBlockPos) && this.isValidTarget(this.mob.level, mutableBlockPos)) {
|
|
this.blockPos = mutableBlockPos;
|
|
setTargetPosition(mutableBlockPos.immutable()); // Paper
|
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/AmphibiousPathNavigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/AmphibiousPathNavigation.java
|
|
index 29a872393f2f995b13b4ed26b42c6464ab27ca73..6fda4eebe743dcc88aa253c4d0e539b20ed27a7e 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/ai/navigation/AmphibiousPathNavigation.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/ai/navigation/AmphibiousPathNavigation.java
|
|
@@ -8,6 +8,14 @@ import net.minecraft.world.level.pathfinder.PathFinder;
|
|
import net.minecraft.world.phys.Vec3;
|
|
|
|
public class AmphibiousPathNavigation extends PathNavigation {
|
|
+ // Pufferfish start
|
|
+ private static final gg.pufferfish.pufferfish.path.NodeEvaluatorGenerator nodeEvaluatorGenerator = () -> {
|
|
+ var nodeEvaluator = new AmphibiousNodeEvaluator(false);
|
|
+ nodeEvaluator.setCanPassDoors(true);
|
|
+ return nodeEvaluator;
|
|
+ };
|
|
+ // Pufferfish end
|
|
+
|
|
public AmphibiousPathNavigation(Mob mob, Level world) {
|
|
super(mob, world);
|
|
}
|
|
@@ -16,7 +24,13 @@ public class AmphibiousPathNavigation extends PathNavigation {
|
|
protected PathFinder createPathFinder(int range) {
|
|
this.nodeEvaluator = new AmphibiousNodeEvaluator(false);
|
|
this.nodeEvaluator.setCanPassDoors(true);
|
|
- return new PathFinder(this.nodeEvaluator, range);
|
|
+ // Pufferfish start
|
|
+ if (gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding) {
|
|
+ return new PathFinder(this.nodeEvaluator, range, nodeEvaluatorGenerator);
|
|
+ } else {
|
|
+ return new PathFinder(this.nodeEvaluator, range);
|
|
+ }
|
|
+ // Pufferfish end
|
|
}
|
|
|
|
@Override
|
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/FlyingPathNavigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/FlyingPathNavigation.java
|
|
index 27cd393e81f6ef9b5690c051624d8d2af50acd34..33bee4233ba159d72a851d67b99836f8f2d66b64 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/ai/navigation/FlyingPathNavigation.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/ai/navigation/FlyingPathNavigation.java
|
|
@@ -12,6 +12,15 @@ import net.minecraft.world.level.pathfinder.PathFinder;
|
|
import net.minecraft.world.phys.Vec3;
|
|
|
|
public class FlyingPathNavigation extends PathNavigation {
|
|
+
|
|
+ // Pufferfish start
|
|
+ private static final gg.pufferfish.pufferfish.path.NodeEvaluatorGenerator nodeEvaluatorGenerator = () -> {
|
|
+ var nodeEvaluator = new FlyNodeEvaluator();
|
|
+ nodeEvaluator.setCanPassDoors(true);
|
|
+ return nodeEvaluator;
|
|
+ };
|
|
+ // Pufferfish end
|
|
+
|
|
public FlyingPathNavigation(Mob entity, Level world) {
|
|
super(entity, world);
|
|
}
|
|
@@ -20,7 +29,13 @@ public class FlyingPathNavigation extends PathNavigation {
|
|
protected PathFinder createPathFinder(int range) {
|
|
this.nodeEvaluator = new FlyNodeEvaluator();
|
|
this.nodeEvaluator.setCanPassDoors(true);
|
|
- return new PathFinder(this.nodeEvaluator, range);
|
|
+ // Pufferfish start
|
|
+ if (gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding) {
|
|
+ return new PathFinder(this.nodeEvaluator, range, nodeEvaluatorGenerator);
|
|
+ } else {
|
|
+ return new PathFinder(this.nodeEvaluator, range);
|
|
+ }
|
|
+ // Pufferfish end
|
|
}
|
|
|
|
@Override
|
|
@@ -45,9 +60,11 @@ public class FlyingPathNavigation extends PathNavigation {
|
|
this.recomputePath();
|
|
}
|
|
|
|
+ if (gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding && this.path != null && !this.path.isProcessed()) return; // Pufferfish
|
|
+
|
|
if (!this.isDone()) {
|
|
if (this.canUpdatePath()) {
|
|
- this.followThePath();
|
|
+ this.followThePathSuper(); // Pufferfish
|
|
} else if (this.path != null && !this.path.isDone()) {
|
|
Vec3 vec3 = this.path.getNextEntityPos(this.mob);
|
|
if (this.mob.getBlockX() == Mth.floor(vec3.x) && this.mob.getBlockY() == Mth.floor(vec3.y) && this.mob.getBlockZ() == Mth.floor(vec3.z)) {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java
|
|
index f610c06d7bb51ec2c63863dd46711712986a106a..4842c0c0fb0e69bcb62b8335c65fc2fd944c83a7 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java
|
|
@@ -15,6 +15,15 @@ import net.minecraft.world.level.pathfinder.WalkNodeEvaluator;
|
|
import net.minecraft.world.phys.Vec3;
|
|
|
|
public class GroundPathNavigation extends PathNavigation {
|
|
+
|
|
+ // Pufferfish start
|
|
+ private static final gg.pufferfish.pufferfish.path.NodeEvaluatorGenerator nodeEvaluatorGenerator = () -> {
|
|
+ var nodeEvaluator = new WalkNodeEvaluator();
|
|
+ nodeEvaluator.setCanPassDoors(true);
|
|
+ return nodeEvaluator;
|
|
+ };
|
|
+ // Pufferfish end
|
|
+
|
|
private boolean avoidSun;
|
|
|
|
public GroundPathNavigation(Mob entity, Level world) {
|
|
@@ -25,7 +34,13 @@ public class GroundPathNavigation extends PathNavigation {
|
|
protected PathFinder createPathFinder(int range) {
|
|
this.nodeEvaluator = new WalkNodeEvaluator();
|
|
this.nodeEvaluator.setCanPassDoors(true);
|
|
- return new PathFinder(this.nodeEvaluator, range);
|
|
+ // Pufferfish start
|
|
+ if (gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding) {
|
|
+ return new PathFinder(this.nodeEvaluator, range, nodeEvaluatorGenerator);
|
|
+ } else {
|
|
+ return new PathFinder(this.nodeEvaluator, range);
|
|
+ }
|
|
+ // Pufferfish end
|
|
}
|
|
|
|
@Override
|
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
|
|
index 3f672d7c2377fca16a6d8d31cf7aaae4f009fdce..aa3fbdaffd69d65d9522f82fab45d0475cae024f 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
|
|
@@ -151,6 +151,9 @@ public abstract class PathNavigation {
|
|
return null;
|
|
} else if (!this.canUpdatePath()) {
|
|
return null;
|
|
+ } else if (this.path instanceof gg.pufferfish.pufferfish.path.AsyncPath asyncPath && !asyncPath.isProcessed() && asyncPath.hasSameProcessingPositions(positions)) { // Pufferfish start - catch early if it's still processing these positions let it keep processing
|
|
+ return this.path;
|
|
+ // Pufferfish end
|
|
} else if (this.path != null && !this.path.isDone() && positions.contains(this.targetPos)) {
|
|
return this.path;
|
|
} else {
|
|
@@ -177,11 +180,28 @@ public abstract class PathNavigation {
|
|
PathNavigationRegion pathNavigationRegion = new PathNavigationRegion(this.level, blockPos.offset(-i, -i, -i), blockPos.offset(i, i, i));
|
|
Path path = this.pathFinder.findPath(pathNavigationRegion, this.mob, positions, followRange, distance, this.maxVisitedNodesMultiplier);
|
|
this.level.getProfiler().pop();
|
|
- if (path != null && path.getTarget() != null) {
|
|
+
|
|
+ // Pufferfish start
|
|
+ if (!gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding) {
|
|
+ if (path != null && path.getTarget() != null) {
|
|
this.targetPos = path.getTarget();
|
|
this.reachRange = distance;
|
|
this.resetStuckTimeout();
|
|
+ }
|
|
+ } else {
|
|
+ if (!positions.isEmpty()) this.targetPos = positions.iterator().next(); // Pufferfish - assign early a target position. most calls will only have 1 position
|
|
+
|
|
+ gg.pufferfish.pufferfish.path.AsyncPathProcessor.awaitProcessing(path, processedPath -> {
|
|
+ if (processedPath != this.path) return; // Pufferfish - check that processing didn't take so long that we calculated a new path
|
|
+
|
|
+ if (processedPath != null && processedPath.getTarget() != null) {
|
|
+ this.targetPos = processedPath.getTarget();
|
|
+ this.reachRange = distance;
|
|
+ this.resetStuckTimeout();
|
|
+ }
|
|
+ });
|
|
}
|
|
+ // Pufferfish end
|
|
|
|
return path;
|
|
}
|
|
@@ -228,8 +248,8 @@ public abstract class PathNavigation {
|
|
if (this.isDone()) {
|
|
return false;
|
|
} else {
|
|
- this.trimPath();
|
|
- if (this.path.getNodeCount() <= 0) {
|
|
+ if (!gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding || path.isProcessed()) this.trimPath(); // Pufferfish - only trim if processed
|
|
+ if ((!gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding || path.isProcessed()) && this.path.getNodeCount() <= 0) { // Pufferfish - only check node count if processed
|
|
return false;
|
|
} else {
|
|
this.speedModifier = speed;
|
|
@@ -253,9 +273,11 @@ public abstract class PathNavigation {
|
|
this.recomputePath();
|
|
}
|
|
|
|
+ if (gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding && this.path != null && !this.path.isProcessed()) return; // Pufferfish - skip pathfinding if we're still processing
|
|
+
|
|
if (!this.isDone()) {
|
|
if (this.canUpdatePath()) {
|
|
- this.followThePath();
|
|
+ this.followThePathSuper(); // Pufferfish
|
|
} else if (this.path != null && !this.path.isDone()) {
|
|
Vec3 vec3 = this.getTempMobPos();
|
|
Vec3 vec32 = this.path.getNextEntityPos(this.mob);
|
|
@@ -276,6 +298,13 @@ public abstract class PathNavigation {
|
|
BlockPos blockPos = new BlockPos(pos);
|
|
return this.level.getBlockState(blockPos.below()).isAir() ? pos.y : WalkNodeEvaluator.getFloorLevel(this.level, blockPos);
|
|
}
|
|
+
|
|
+ // Pufferfish start - this fixes plugin compat by ensuring the isProcessed check is completed properly.
|
|
+ protected final void followThePathSuper() {
|
|
+ if (gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding && !this.path.isProcessed()) return; // Pufferfish
|
|
+ followThePath();
|
|
+ }
|
|
+ // Pufferfish end
|
|
|
|
protected void followThePath() {
|
|
Vec3 vec3 = this.getTempMobPos();
|
|
@@ -440,7 +469,7 @@ public abstract class PathNavigation {
|
|
// Paper start
|
|
public boolean isViableForPathRecalculationChecking() {
|
|
return !this.needsPathRecalculation() &&
|
|
- (this.path != null && !this.path.isDone() && this.path.getNodeCount() != 0);
|
|
+ (this.path != null && (!gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding || this.path.isProcessed()) && !this.path.isDone() && this.path.getNodeCount() != 0); // Pufferfish
|
|
}
|
|
// Paper end
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/sensing/NearestBedSensor.java b/src/main/java/net/minecraft/world/entity/ai/sensing/NearestBedSensor.java
|
|
index 8db20db72cd51046213625fac46c35854c59ec5d..52768c8797bf8b03e92840d68b91239835e6c467 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/ai/sensing/NearestBedSensor.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/ai/sensing/NearestBedSensor.java
|
|
@@ -57,20 +57,42 @@ public class NearestBedSensor extends Sensor<Mob> {
|
|
java.util.List<Pair<Holder<PoiType>, BlockPos>> poiposes = new java.util.ArrayList<>();
|
|
// don't ask me why it's unbounded. ask mojang.
|
|
io.papermc.paper.util.PoiAccess.findAnyPoiPositions(poiManager, type -> type.is(PoiTypes.HOME), predicate, entity.blockPosition(), 48, PoiManager.Occupancy.ANY, false, Integer.MAX_VALUE, poiposes);
|
|
- Path path = AcquirePoi.findPathToPois(entity, new java.util.HashSet<>(poiposes));
|
|
- // Paper end - optimise POI access
|
|
- if (path != null && path.canReach()) {
|
|
- BlockPos blockPos = path.getTarget();
|
|
- Optional<Holder<PoiType>> optional = poiManager.getType(blockPos);
|
|
- if (optional.isPresent()) {
|
|
- entity.getBrain().setMemory(MemoryModuleType.NEAREST_BED, blockPos);
|
|
- }
|
|
- } else if (this.triedCount < 5) {
|
|
- this.batchCache.long2LongEntrySet().removeIf((entry) -> {
|
|
- return entry.getLongValue() < this.lastUpdate;
|
|
+
|
|
+ // Pufferfish start - await on path async
|
|
+ if (gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding) {
|
|
+ Path possiblePath = AcquirePoi.findPathToPois(entity, new java.util.HashSet<>(poiposes));
|
|
+ // Paper end - optimise POI access
|
|
+ // Pufferfish - wait on the path to be processed
|
|
+ gg.pufferfish.pufferfish.path.AsyncPathProcessor.awaitProcessing(possiblePath, path -> {
|
|
+ // Pufferfish - readd canReach check
|
|
+ if (path == null || !path.canReach()) {
|
|
+ this.batchCache.long2LongEntrySet().removeIf((entry) -> {
|
|
+ return entry.getLongValue() < this.lastUpdate;
|
|
+ });
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ BlockPos blockPos = path.getTarget();
|
|
+ Optional<Holder<PoiType>> optional = poiManager.getType(blockPos);
|
|
+ if (optional.isPresent()) {
|
|
+ entity.getBrain().setMemory(MemoryModuleType.NEAREST_BED, blockPos);
|
|
+ }
|
|
});
|
|
+ } else {
|
|
+ Path path = AcquirePoi.findPathToPois(entity, new java.util.HashSet<>(poiposes));
|
|
+ if (path != null && path.canReach()) {
|
|
+ BlockPos blockPos = path.getTarget();
|
|
+ Optional<Holder<PoiType>> optional = poiManager.getType(blockPos);
|
|
+ if (optional.isPresent()) {
|
|
+ entity.getBrain().setMemory(MemoryModuleType.NEAREST_BED, blockPos);
|
|
+ }
|
|
+ } else if (this.triedCount < 5) {
|
|
+ this.batchCache.long2LongEntrySet().removeIf((entry) -> {
|
|
+ return entry.getLongValue() < this.lastUpdate;
|
|
+ });
|
|
+ }
|
|
}
|
|
-
|
|
+ // Pufferfish end
|
|
}
|
|
}
|
|
}
|
|
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 a7575b5ef56af6f53448d391abb4956e130148ca..e752c83df50fb9b670ecea2abc95426c2a009b6f 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
|
|
@@ -75,9 +75,18 @@ public class TargetingConditions {
|
|
}
|
|
|
|
if (this.range > 0.0D) {
|
|
- double d = this.testInvisible ? targetEntity.getVisibilityPercent(baseEntity) : 1.0D;
|
|
- double e = Math.max((this.useFollowRange ? this.getFollowRange(baseEntity) : this.range) * d, 2.0D); // Paper
|
|
+ // 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.0D;
|
|
+ double e = Math.max((followRangeRaw) * d, 2.0D); // Paper
|
|
+ // Pufferfish end
|
|
if (f > e * e) {
|
|
return false;
|
|
}
|
|
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 50d4595b81f24949011c7565c5e3fc8c26c86019..234ad92d666775dcf5a29a60551b17cbb1d8e6ec 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/ambient/Bat.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/ambient/Bat.java
|
|
@@ -253,13 +253,22 @@ public class Bat extends AmbientCreature {
|
|
}
|
|
}
|
|
|
|
+ // Pufferfish start - only check for spooky season once an hour
|
|
+ private static boolean isSpookySeason = false;
|
|
+ private static final int ONE_HOUR = 20 * 60 * 60;
|
|
+ private static int lastSpookyCheck = -ONE_HOUR;
|
|
private static boolean isHalloween() {
|
|
+ if (net.minecraft.server.MinecraftServer.currentTick - lastSpookyCheck > ONE_HOUR) {
|
|
LocalDate localdate = LocalDate.now();
|
|
int i = localdate.get(ChronoField.DAY_OF_MONTH);
|
|
int j = localdate.get(ChronoField.MONTH_OF_YEAR);
|
|
|
|
- return j == 10 && i >= 20 || j == 11 && i <= 3;
|
|
+ isSpookySeason = j == 10 && i >= 20 || j == 11 && i <= 3;
|
|
+ lastSpookyCheck = net.minecraft.server.MinecraftServer.currentTick;
|
|
+ }
|
|
+ return isSpookySeason;
|
|
}
|
|
+ // Pufferfish end
|
|
|
|
@Override
|
|
protected float getStandingEyeHeight(Pose pose, EntityDimensions dimensions) {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/animal/Bee.java b/src/main/java/net/minecraft/world/entity/animal/Bee.java
|
|
index a9cdf9034ad269f7a71358443acc053288cfbe6d..dbeb70913d3933164e997ce5d662b4890ffe4f36 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/animal/Bee.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/animal/Bee.java
|
|
@@ -1071,7 +1071,7 @@ public class Bee extends Animal implements NeutralMob, FlyingAnimal {
|
|
} else {
|
|
Bee.this.pathfindRandomlyTowards(Bee.this.hivePos);
|
|
}
|
|
- } else {
|
|
+ } else if (!gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding || (navigation.getPath() != null && navigation.getPath().isProcessed())) { // Pufferfish - check processing
|
|
boolean flag = this.pathfindDirectlyTowards(Bee.this.hivePos);
|
|
|
|
if (!flag) {
|
|
@@ -1133,7 +1133,7 @@ public class Bee extends Animal implements NeutralMob, FlyingAnimal {
|
|
} else {
|
|
Path pathentity = Bee.this.navigation.getPath();
|
|
|
|
- return pathentity != null && pathentity.getTarget().equals(pos) && pathentity.canReach() && pathentity.isDone();
|
|
+ return pathentity != null && (!gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding || pathentity.isProcessed()) && pathentity.getTarget().equals(pos) && pathentity.canReach() && pathentity.isDone(); // Pufferfish - ensure path is processed
|
|
}
|
|
}
|
|
}
|
|
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 da5e6141f548539cac720aba558e1b6f3a87e474..fdd2c63ff0017bafa544a3cff2ee6d2d62c92cb3 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
|
|
@@ -283,9 +283,11 @@ public class Axolotl extends Animal implements LerpingModel, Bucketable {
|
|
return true;
|
|
}
|
|
|
|
+ private int behaviorTick = 0; // Pufferfish
|
|
@Override
|
|
protected void customServerAiStep() {
|
|
this.level.getProfiler().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");
|
|
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 bb6063ae7f4438916306ce876057f7488537b444..9a2d1285c207290946ae664915a77b8f9dc00ad7 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
|
|
@@ -411,6 +411,14 @@ public class Frog extends Animal {
|
|
}
|
|
|
|
static class FrogPathNavigation extends AmphibiousPathNavigation {
|
|
+ // Pufferfish start
|
|
+ private static final gg.pufferfish.pufferfish.path.NodeEvaluatorGenerator nodeEvaluatorGenerator = () -> {
|
|
+ var nodeEvaluator = new Frog.FrogNodeEvaluator(true);
|
|
+ nodeEvaluator.setCanPassDoors(true);
|
|
+ return nodeEvaluator;
|
|
+ };
|
|
+ // Pufferfish end
|
|
+
|
|
FrogPathNavigation(Frog frog, Level world) {
|
|
super(frog, world);
|
|
}
|
|
@@ -419,7 +427,13 @@ public class Frog extends Animal {
|
|
protected PathFinder createPathFinder(int range) {
|
|
this.nodeEvaluator = new Frog.FrogNodeEvaluator(true);
|
|
this.nodeEvaluator.setCanPassDoors(true);
|
|
- return new PathFinder(this.nodeEvaluator, range);
|
|
+ // Pufferfish start
|
|
+ if (gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding) {
|
|
+ return new PathFinder(this.nodeEvaluator, range, nodeEvaluatorGenerator);
|
|
+ } else {
|
|
+ return new PathFinder(this.nodeEvaluator, range);
|
|
+ }
|
|
+ // Pufferfish end
|
|
}
|
|
}
|
|
}
|
|
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 31be36e6b7b6bd0c0d7fda4e1b03ecd38947f3a5..362f952888f63a453a4352a9f1dc7df799244a3c 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
|
|
@@ -163,9 +163,11 @@ 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");
|
|
+ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish
|
|
this.getBrain().tick((ServerLevel) this.level, this);
|
|
this.level.getProfiler().pop();
|
|
this.level.getProfiler().push("goatActivityUpdate");
|
|
diff --git a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
|
|
index fcc5444a1268931a0fd2df1e6bbbc17cfd5a61e0..16a55f94bda9f959548772c8916b4dc3eb045d47 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
|
|
@@ -252,10 +252,16 @@ public class ItemEntity extends Entity {
|
|
if (entityitem.isMergable()) {
|
|
// Paper Start - Fix items merging through walls
|
|
if (this.level.paperConfig().fixes.fixItemsMergingThroughWalls) {
|
|
+ // Pufferfish start - skip the allocations
|
|
+ /*
|
|
net.minecraft.world.level.ClipContext rayTrace = new net.minecraft.world.level.ClipContext(this.position(), entityitem.position(),
|
|
net.minecraft.world.level.ClipContext.Block.COLLIDER, net.minecraft.world.level.ClipContext.Fluid.NONE, this);
|
|
net.minecraft.world.phys.BlockHitResult rayTraceResult = level.clip(rayTrace);
|
|
if (rayTraceResult.getType() == net.minecraft.world.phys.HitResult.Type.BLOCK) continue;
|
|
+ */
|
|
+ if (level.rayTraceDirect(this.position(), entityitem.position(), net.minecraft.world.phys.shapes.CollisionContext.of(this)) ==
|
|
+ net.minecraft.world.phys.HitResult.Type.BLOCK) continue;
|
|
+ // Pufferfish end
|
|
}
|
|
// Paper End
|
|
this.tryToMerge(entityitem);
|
|
diff --git a/src/main/java/net/minecraft/world/entity/monster/Drowned.java b/src/main/java/net/minecraft/world/entity/monster/Drowned.java
|
|
index 1b1305f5eaf5710b72c57ab4c3953e703a23f1e0..30a67a1eef9238e12e54c57a0608387cc0f763ef 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/monster/Drowned.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/monster/Drowned.java
|
|
@@ -222,7 +222,7 @@ public class Drowned extends Zombie implements RangedAttackMob {
|
|
protected boolean closeToNextPos() {
|
|
Path pathentity = this.getNavigation().getPath();
|
|
|
|
- if (pathentity != null) {
|
|
+ if (pathentity != null && (!gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding || pathentity.isProcessed())) { // Pufferfish - ensure path is processed
|
|
BlockPos blockposition = pathentity.getTarget();
|
|
|
|
if (blockposition != null) {
|
|
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 f22e615dba31619c97bf58930da060476a52facf..f5bb64f9f683cf21e772035e9be100ed2ddf8bc6 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/monster/EnderMan.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/monster/EnderMan.java
|
|
@@ -317,11 +317,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).getMaterial().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).getMaterial().blocksMotion()) { // Pufferfish
|
|
blockposition_mutableblockposition.move(Direction.DOWN);
|
|
}
|
|
|
|
- BlockState iblockdata = this.level.getBlockState(blockposition_mutableblockposition);
|
|
+ BlockState iblockdata = chunk.getBlockState(blockposition_mutableblockposition); // Pufferfish
|
|
boolean flag = iblockdata.getMaterial().blocksMotion();
|
|
boolean flag1 = iblockdata.getFluidState().is(FluidTags.WATER);
|
|
|
|
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 45741410a13cffe3419e34b5607b048bbcf1c3ff..5d487f1613b1fc5807283c20e5cc23a432d08f42 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
|
|
@@ -126,9 +126,11 @@ public class Hoglin extends Animal implements Enemy, HoglinBase {
|
|
return (Brain<Hoglin>) super.getBrain(); // Paper - decompile fix
|
|
}
|
|
|
|
+ private int behaviorTick; // Pufferfish
|
|
@Override
|
|
protected void customServerAiStep() {
|
|
this.level.getProfiler().push("hoglinBrain");
|
|
+ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish
|
|
this.getBrain().tick((ServerLevel)this.level, this);
|
|
this.level.getProfiler().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 793576928dad6752dddd86e62d4c0800d8515fc4..9bde52b723237b1f0f945bc564009e3507993508 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
|
|
@@ -289,9 +289,11 @@ public class Piglin extends AbstractPiglin implements CrossbowAttackMob, Invento
|
|
return !this.cannotHunt;
|
|
}
|
|
|
|
+ private int behaviorTick; // Pufferfish
|
|
@Override
|
|
protected void customServerAiStep() {
|
|
this.level.getProfiler().push("piglinBrain");
|
|
+ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish
|
|
this.getBrain().tick((ServerLevel) this.level, this);
|
|
this.level.getProfiler().pop();
|
|
PiglinAi.updateActivity(this);
|
|
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 10b45ec24a5a0867106d1694312385ad1e267f43..93077e8c6b5a35adc6febb749d1d08be172402f1 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/npc/Villager.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/npc/Villager.java
|
|
@@ -140,6 +140,8 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
|
|
return holder.is(PoiTypes.MEETING);
|
|
});
|
|
|
|
+ public long nextGolemPanic = -1; // Pufferfish
|
|
+
|
|
public Villager(EntityType<? extends Villager> entityType, Level world) {
|
|
this(entityType, world, VillagerType.PLAINS);
|
|
}
|
|
@@ -243,11 +245,17 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
|
|
}
|
|
// Spigot End
|
|
|
|
+ private int behaviorTick = 0; // Pufferfish
|
|
@Override
|
|
protected void customServerAiStep() { mobTick(false); }
|
|
protected void mobTick(boolean inactive) {
|
|
this.level.getProfiler().push("villagerBrain");
|
|
- if (!inactive) this.getBrain().tick((ServerLevel) this.level, this); // Paper
|
|
+ // Pufferfish start
|
|
+ if (!inactive) {
|
|
+ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish
|
|
+ this.getBrain().tick((ServerLevel) this.level, this); // Paper
|
|
+ }
|
|
+ // Pufferfish end
|
|
this.level.getProfiler().pop();
|
|
if (this.assignProfessionWhenSpawned) {
|
|
this.assignProfessionWhenSpawned = false;
|
|
diff --git a/src/main/java/net/minecraft/world/entity/player/Inventory.java b/src/main/java/net/minecraft/world/entity/player/Inventory.java
|
|
index a1a625a8dacf4d2bbf75ddd90dce1b1be663c919..23e375c9a6955d03e0fc9be91ff0403251c8216c 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Inventory.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Inventory.java
|
|
@@ -681,6 +681,8 @@ public class Inventory implements Container, Nameable {
|
|
}
|
|
|
|
public boolean contains(ItemStack stack) {
|
|
+ // Pufferfish start - don't allocate iterators
|
|
+ /*
|
|
Iterator iterator = this.compartments.iterator();
|
|
|
|
while (iterator.hasNext()) {
|
|
@@ -695,6 +697,18 @@ public class Inventory implements Container, Nameable {
|
|
}
|
|
}
|
|
}
|
|
+ */
|
|
+ for (int i = 0; i < this.compartments.size(); i++) {
|
|
+ List<ItemStack> list = this.compartments.get(i);
|
|
+ for (int j = 0; j < list.size(); j++) {
|
|
+ ItemStack itemstack1 = list.get(j);
|
|
+
|
|
+ if (!itemstack1.isEmpty() && itemstack1.sameItem(stack)) {
|
|
+ return true;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ // Pufferfish end
|
|
|
|
return false;
|
|
}
|
|
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 66c3f374a779cd3a4548393ba23e9219f1caf6d3..39ba6ca32b827daee300e1240bd76fd8f680ea02 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
|
|
@@ -42,6 +42,36 @@ public abstract class Projectile extends Entity {
|
|
super(type, world);
|
|
}
|
|
|
|
+ // Pufferfish start
|
|
+ private static int loadedThisTick = 0;
|
|
+ private static int loadedTick;
|
|
+
|
|
+ private int loadedLifetime = 0;
|
|
+ @Override
|
|
+ public void setPos(double x, double y, double z) {
|
|
+ int currentTick = net.minecraft.server.MinecraftServer.currentTick;
|
|
+ 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 > gg.pufferfish.pufferfish.PufferfishConfig.maxProjectileLoadsPerTick) {
|
|
+ if (++this.loadedLifetime > gg.pufferfish.pufferfish.PufferfishConfig.maxProjectileLoadsPerProjectile) {
|
|
+ this.discard();
|
|
+ }
|
|
+ return;
|
|
+ }
|
|
+ Projectile.loadedThisTick++;
|
|
+ }
|
|
+ }
|
|
+ super.setPos(x, y, z);
|
|
+ }
|
|
+ // Pufferfish start
|
|
+
|
|
public void setOwner(@Nullable Entity entity) {
|
|
if (entity != null) {
|
|
this.ownerUUID = entity.getUUID();
|
|
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 b8fb7b5a347298ada16bc8b818edf1863e3f6040..43b4c4f9630bfa451d135139236ac6fce034ec15 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecartContainer.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecartContainer.java
|
|
@@ -27,7 +27,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 ResourceLocation lootTable;
|
|
public long lootTableSeed;
|
|
@@ -89,12 +92,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
|
|
@@ -156,6 +165,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);
|
|
}
|
|
|
|
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 ffe5476d8ed15ee4384b679c341688787205ce59..9051559e78851257a56a998b4b882ebbcc394639 100644
|
|
--- a/src/main/java/net/minecraft/world/item/crafting/ShapelessRecipe.java
|
|
+++ b/src/main/java/net/minecraft/world/item/crafting/ShapelessRecipe.java
|
|
@@ -25,8 +25,13 @@ public class ShapelessRecipe implements CraftingRecipe {
|
|
final String group;
|
|
final ItemStack result;
|
|
final NonNullList<Ingredient> ingredients;
|
|
+ private final boolean isBukkit; // Pufferfish
|
|
|
|
+ // Pufferfish start
|
|
public ShapelessRecipe(ResourceLocation id, String group, ItemStack output, NonNullList<Ingredient> input) {
|
|
+ this(id, group, output, input, false);
|
|
+ }
|
|
+ public ShapelessRecipe(ResourceLocation id, String group, ItemStack output, NonNullList<Ingredient> input, boolean isBukkit) { this.isBukkit = isBukkit; // Pufferfish end
|
|
this.id = id;
|
|
this.group = group;
|
|
this.result = output;
|
|
@@ -73,6 +78,28 @@ public class ShapelessRecipe implements CraftingRecipe {
|
|
}
|
|
|
|
public boolean matches(CraftingContainer inventory, 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 < inventory.getContainerSize(); index++) {
|
|
+ ItemStack itemStack = inventory.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
|
|
+
|
|
StackedContents autorecipestackmanager = new StackedContents();
|
|
int i = 0;
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/BlockGetter.java b/src/main/java/net/minecraft/world/level/BlockGetter.java
|
|
index d1eefa6ef3e9abfe7af4d8310aa64465fa2d5463..0f4aa330e5b179bb706a31917c671f165e22b9cd 100644
|
|
--- a/src/main/java/net/minecraft/world/level/BlockGetter.java
|
|
+++ b/src/main/java/net/minecraft/world/level/BlockGetter.java
|
|
@@ -73,6 +73,16 @@ public interface BlockGetter extends LevelHeightAccessor {
|
|
});
|
|
}
|
|
|
|
+ // Pufferfish start - broken down variant of below rayTraceBlock, used by World#rayTraceDirect
|
|
+ default net.minecraft.world.phys.BlockHitResult.Type rayTraceBlockDirect(Vec3 vec3d, Vec3 vec3d1, BlockPos blockposition, BlockState iblockdata, net.minecraft.world.phys.shapes.CollisionContext voxelshapecoll) {
|
|
+ if (iblockdata.isAir()) return null; // Tuinity - optimise air cases
|
|
+ VoxelShape voxelshape = ClipContext.Block.COLLIDER.get(iblockdata, this, blockposition, voxelshapecoll);
|
|
+ net.minecraft.world.phys.BlockHitResult movingobjectpositionblock = this.clipWithInteractionOverride(vec3d, vec3d1, blockposition, voxelshape, iblockdata);
|
|
+
|
|
+ return movingobjectpositionblock == null ? null : movingobjectpositionblock.getType();
|
|
+ }
|
|
+ // Pufferfish end
|
|
+
|
|
// CraftBukkit start - moved block handling into separate method for use by Block#rayTrace
|
|
default BlockHitResult clip(ClipContext raytrace1, BlockPos blockposition) {
|
|
// Paper start - Prevent raytrace from loading chunks
|
|
diff --git a/src/main/java/net/minecraft/world/level/GameRules.java b/src/main/java/net/minecraft/world/level/GameRules.java
|
|
index 468c635d31cfa8051666bbefce8df4b448e9ed93..17e869074b8cf29a8c3280499a27e95179896750 100644
|
|
--- a/src/main/java/net/minecraft/world/level/GameRules.java
|
|
+++ b/src/main/java/net/minecraft/world/level/GameRules.java
|
|
@@ -91,6 +91,7 @@ public class GameRules {
|
|
public static final GameRules.Key<GameRules.BooleanValue> RULE_UNIVERSAL_ANGER = GameRules.register("universalAnger", GameRules.Category.MOBS, GameRules.BooleanValue.create(false));
|
|
public static final GameRules.Key<GameRules.IntegerValue> RULE_PLAYERS_SLEEPING_PERCENTAGE = GameRules.register("playersSleepingPercentage", GameRules.Category.PLAYER, GameRules.IntegerValue.create(100));
|
|
private final Map<GameRules.Key<?>, GameRules.Value<?>> rules;
|
|
+ private final GameRules.Value<?>[] gameruleArray;
|
|
|
|
private static <T extends GameRules.Value<T>> GameRules.Key<T> register(String name, GameRules.Category category, GameRules.Type<T> type) {
|
|
GameRules.Key<T> gamerules_gamerulekey = new GameRules.Key<>(name, category);
|
|
@@ -109,17 +110,33 @@ public class GameRules {
|
|
}
|
|
|
|
public GameRules() {
|
|
- this.rules = (Map) GameRules.GAME_RULE_TYPES.entrySet().stream().collect(ImmutableMap.toImmutableMap(Entry::getKey, (entry) -> {
|
|
+ // Pufferfish start - use this to ensure gameruleArray is initialized
|
|
+ this((Map) GameRules.GAME_RULE_TYPES.entrySet().stream().collect(ImmutableMap.toImmutableMap(Entry::getKey, (entry) -> {
|
|
return ((GameRules.Type) entry.getValue()).createRule();
|
|
- }));
|
|
+ })));
|
|
+ // Pufferfish end
|
|
}
|
|
|
|
private GameRules(Map<GameRules.Key<?>, GameRules.Value<?>> rules) {
|
|
this.rules = rules;
|
|
+
|
|
+ // Pufferfish start
|
|
+ int arraySize = rules.keySet().stream().mapToInt(key -> key.gameRuleIndex).max().orElse(-1) + 1;
|
|
+ GameRules.Value<?>[] values = new GameRules.Value[arraySize];
|
|
+
|
|
+ for (Entry<GameRules.Key<?>, GameRules.Value<?>> entry : rules.entrySet()) {
|
|
+ values[entry.getKey().gameRuleIndex] = entry.getValue();
|
|
+ }
|
|
+
|
|
+ this.gameruleArray = values;
|
|
+ // Pufferfish end
|
|
}
|
|
|
|
public <T extends GameRules.Value<T>> T getRule(GameRules.Key<T> key) {
|
|
- return (T) this.rules.get(key); // CraftBukkit - decompile error
|
|
+ // Pufferfish start
|
|
+ return key == null ? null : (T) this.gameruleArray[key.gameRuleIndex];
|
|
+ //return (T) this.rules.get(key); // CraftBukkit - decompile error
|
|
+ // Pufferfish end
|
|
}
|
|
|
|
public CompoundTag createTag() {
|
|
@@ -178,6 +195,10 @@ public class GameRules {
|
|
}
|
|
|
|
public static final class Key<T extends GameRules.Value<T>> {
|
|
+ // Pufferfish start
|
|
+ private static int lastGameRuleIndex = 0;
|
|
+ public final int gameRuleIndex = lastGameRuleIndex++;
|
|
+ // Pufferfish end
|
|
|
|
final String id;
|
|
private final GameRules.Category category;
|
|
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
|
|
index 5a2a1d394852d39ea576624586f7fa736dec807c..0681a7499755b573c191804b38ac8783eb7d0f32 100644
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
|
@@ -271,6 +271,17 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
|
|
|
public abstract ResourceKey<LevelStem> getTypeKey();
|
|
|
|
+ protected final io.papermc.paper.util.math.ThreadUnsafeRandom randomTickRandom = new io.papermc.paper.util.math.ThreadUnsafeRandom(java.util.concurrent.ThreadLocalRandom.current().nextLong()); public net.minecraft.util.RandomSource getThreadUnsafeRandom() { return this.randomTickRandom; } // Pufferfish - move thread unsafe random initialization // Pufferfish - getter
|
|
+
|
|
+ // Pufferfish start - ensure these get inlined
|
|
+ private final int minBuildHeight, minSection, height, maxBuildHeight, maxSection;
|
|
+ @Override public final int getMaxBuildHeight() { return this.maxBuildHeight; }
|
|
+ @Override public final int getMinSection() { return this.minSection; }
|
|
+ @Override public final int getMaxSection() { return this.maxSection; }
|
|
+ @Override public final int getMinBuildHeight() { return this.minBuildHeight; }
|
|
+ @Override public final int getHeight() { return this.height; }
|
|
+ // Pufferfish end
|
|
+
|
|
protected Level(WritableLevelData worlddatamutable, ResourceKey<Level> resourcekey, Holder<DimensionType> holder, Supplier<ProfilerFiller> supplier, boolean flag, boolean flag1, long i, int j, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider, org.bukkit.World.Environment env, java.util.function.Function<org.spigotmc.SpigotWorldConfig, io.papermc.paper.configuration.WorldConfiguration> paperWorldConfigCreator, java.util.concurrent.Executor executor) { // Paper - Async-Anti-Xray - Pass executor
|
|
this.spigotConfig = new org.spigotmc.SpigotWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) worlddatamutable).getLevelName()); // Spigot
|
|
this.paperConfig = paperWorldConfigCreator.apply(this.spigotConfig); // Paper
|
|
@@ -293,6 +304,13 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
|
});
|
|
final DimensionType dimensionmanager = (DimensionType) holder.value();
|
|
|
|
+ // Pufferfish start
|
|
+ this.minBuildHeight = dimensionmanager.minY();
|
|
+ this.minSection = SectionPos.blockToSectionCoord(this.minBuildHeight);
|
|
+ this.height = dimensionmanager.height();
|
|
+ this.maxBuildHeight = this.minBuildHeight + this.height;
|
|
+ this.maxSection = SectionPos.blockToSectionCoord(this.maxBuildHeight - 1) + 1;
|
|
+ // Pufferfish end
|
|
this.dimension = resourcekey;
|
|
this.isClientSide = flag;
|
|
if (dimensionmanager.coordinateScale() != 1.0D) {
|
|
@@ -409,6 +427,91 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
|
return null;
|
|
}
|
|
|
|
+ // Pufferfish start - broken down method of raytracing for EntityLiving#hasLineOfSight, replaces IBlockAccess#rayTrace(RayTrace)
|
|
+ public net.minecraft.world.phys.BlockHitResult.Type rayTraceDirect(net.minecraft.world.phys.Vec3 vec3d, net.minecraft.world.phys.Vec3 vec3d1, net.minecraft.world.phys.shapes.CollisionContext voxelshapecoll) {
|
|
+ // most of this code comes from IBlockAccess#a(RayTrace, BiFunction, Function), but removes the needless functions
|
|
+ if (vec3d.equals(vec3d1)) {
|
|
+ return net.minecraft.world.phys.BlockHitResult.Type.MISS;
|
|
+ }
|
|
+
|
|
+ double endX = Mth.lerp(-1.0E-7D, vec3d1.x, vec3d.x);
|
|
+ double endY = Mth.lerp(-1.0E-7D, vec3d1.y, vec3d.y);
|
|
+ double endZ = Mth.lerp(-1.0E-7D, vec3d1.z, vec3d.z);
|
|
+
|
|
+ double startX = Mth.lerp(-1.0E-7D, vec3d.x, vec3d1.x);
|
|
+ double startY = Mth.lerp(-1.0E-7D, vec3d.y, vec3d1.y);
|
|
+ double startZ = Mth.lerp(-1.0E-7D, vec3d.z, vec3d1.z);
|
|
+
|
|
+ int currentX = Mth.floor(startX);
|
|
+ int currentY = Mth.floor(startY);
|
|
+ int currentZ = Mth.floor(startZ);
|
|
+
|
|
+ BlockPos.MutableBlockPos currentBlock = new BlockPos.MutableBlockPos(currentX, currentY, currentZ);
|
|
+
|
|
+ LevelChunk chunk = this.getChunkIfLoaded(currentBlock);
|
|
+ if (chunk == null) {
|
|
+ return net.minecraft.world.phys.BlockHitResult.Type.MISS;
|
|
+ }
|
|
+
|
|
+ net.minecraft.world.phys.BlockHitResult.Type initialCheck = this.rayTraceBlockDirect(vec3d, vec3d1, currentBlock, chunk.getBlockState(currentBlock), voxelshapecoll);
|
|
+
|
|
+ if (initialCheck != null) {
|
|
+ return initialCheck;
|
|
+ }
|
|
+
|
|
+ double diffX = endX - startX;
|
|
+ double diffY = endY - startY;
|
|
+ double diffZ = endZ - startZ;
|
|
+
|
|
+ int xDirection = Mth.sign(diffX);
|
|
+ int yDirection = Mth.sign(diffY);
|
|
+ int zDirection = Mth.sign(diffZ);
|
|
+
|
|
+ double normalizedX = xDirection == 0 ? Double.MAX_VALUE : (double) xDirection / diffX;
|
|
+ double normalizedY = yDirection == 0 ? Double.MAX_VALUE : (double) yDirection / diffY;
|
|
+ double normalizedZ = zDirection == 0 ? Double.MAX_VALUE : (double) zDirection / diffZ;
|
|
+
|
|
+ double normalizedXDirection = normalizedX * (xDirection > 0 ? 1.0D - Mth.frac(startX) : Mth.frac(startX));
|
|
+ double normalizedYDirection = normalizedY * (yDirection > 0 ? 1.0D - Mth.frac(startY) : Mth.frac(startY));
|
|
+ double normalizedZDirection = normalizedZ * (zDirection > 0 ? 1.0D - Mth.frac(startZ) : Mth.frac(startZ));
|
|
+
|
|
+ net.minecraft.world.phys.BlockHitResult.Type result;
|
|
+
|
|
+ do {
|
|
+ if (normalizedXDirection > 1.0D && normalizedYDirection > 1.0D && normalizedZDirection > 1.0D) {
|
|
+ return net.minecraft.world.phys.BlockHitResult.Type.MISS;
|
|
+ }
|
|
+
|
|
+ if (normalizedXDirection < normalizedYDirection) {
|
|
+ if (normalizedXDirection < normalizedZDirection) {
|
|
+ currentX += xDirection;
|
|
+ normalizedXDirection += normalizedX;
|
|
+ } else {
|
|
+ currentZ += zDirection;
|
|
+ normalizedZDirection += normalizedZ;
|
|
+ }
|
|
+ } else if (normalizedYDirection < normalizedZDirection) {
|
|
+ currentY += yDirection;
|
|
+ normalizedYDirection += normalizedY;
|
|
+ } else {
|
|
+ currentZ += zDirection;
|
|
+ normalizedZDirection += normalizedZ;
|
|
+ }
|
|
+
|
|
+ currentBlock.set(currentX, currentY, currentZ);
|
|
+ if (chunk.getPos().x != currentBlock.getX() >> 4 || chunk.getPos().z != currentBlock.getZ() >> 4) {
|
|
+ chunk = this.getChunkIfLoaded(currentBlock);
|
|
+ if (chunk == null) {
|
|
+ return net.minecraft.world.phys.BlockHitResult.Type.MISS;
|
|
+ }
|
|
+ }
|
|
+ result = this.rayTraceBlockDirect(vec3d, vec3d1, currentBlock, chunk.getBlockState(currentBlock), voxelshapecoll);
|
|
+ } while (result == null);
|
|
+
|
|
+ return result;
|
|
+ }
|
|
+ // Pufferfish end
|
|
+
|
|
public boolean isInWorldBounds(BlockPos pos) {
|
|
return pos.isInsideBuildHeightAndWorldBoundsHorizontal(this); // Paper - use better/optimized check
|
|
}
|
|
@@ -896,13 +999,13 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
|
try {
|
|
tickConsumer.accept(entity);
|
|
MinecraftServer.getServer().executeMidTickTasks(); // Paper - execute chunk tasks mid tick
|
|
- } catch (Throwable throwable) {
|
|
+ } catch (Throwable throwable) { // Pufferfish - diff on change ServerLevel.tick
|
|
if (throwable instanceof ThreadDeath) throw throwable; // Paper
|
|
// Paper start - Prevent tile 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);
|
|
getCraftServer().getPluginManager().callEvent(new ServerExceptionEvent(new ServerInternalException(msg, throwable)));
|
|
- entity.discard();
|
|
+ entity.discard(); // Pufferfish - diff on change ServerLevel.tick
|
|
// Paper end
|
|
}
|
|
}
|
|
@@ -1388,6 +1491,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
|
}
|
|
|
|
public ProfilerFiller getProfiler() {
|
|
+ if (gg.pufferfish.pufferfish.PufferfishConfig.disableMethodProfiler) return net.minecraft.util.profiling.InactiveProfiler.INSTANCE; // Pufferfish
|
|
return (ProfilerFiller) this.profiler.get();
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/NaturalSpawner.java b/src/main/java/net/minecraft/world/level/NaturalSpawner.java
|
|
index e31a2eea9a62ab2c0bed1a97dab6bae231b8cd8b..1f4acc1a2605f1e9051126fc811a5479351fc61a 100644
|
|
--- a/src/main/java/net/minecraft/world/level/NaturalSpawner.java
|
|
+++ b/src/main/java/net/minecraft/world/level/NaturalSpawner.java
|
|
@@ -414,12 +414,12 @@ public final class NaturalSpawner {
|
|
}
|
|
}
|
|
|
|
- private static BlockPos getRandomPosWithin(Level world, LevelChunk chunk) {
|
|
+ private static BlockPos getRandomPosWithin(ServerLevel world, LevelChunk chunk) { // Pufferfish - accept serverlevel
|
|
ChunkPos chunkcoordintpair = chunk.getPos();
|
|
- int i = chunkcoordintpair.getMinBlockX() + world.random.nextInt(16);
|
|
- int j = chunkcoordintpair.getMinBlockZ() + world.random.nextInt(16);
|
|
+ int i = chunkcoordintpair.getMinBlockX() + world.getThreadUnsafeRandom().nextInt(16); // Pufferfish - use thread unsafe random
|
|
+ int j = chunkcoordintpair.getMinBlockZ() + world.getThreadUnsafeRandom().nextInt(16); // Pufferfish
|
|
int k = chunk.getHeight(Heightmap.Types.WORLD_SURFACE, i, j) + 1;
|
|
- int l = Mth.randomBetweenInclusive(world.random, world.getMinBuildHeight(), k);
|
|
+ int l = Mth.randomBetweenInclusive(world.getThreadUnsafeRandom(), world.getMinBuildHeight(), k); // Pufferfish
|
|
|
|
return new BlockPos(i, l, j);
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/level/biome/Biome.java b/src/main/java/net/minecraft/world/level/biome/Biome.java
|
|
index ca259e278ad10347567c021376abca0287610432..021f7c44285b13a0904c09ea7210f2a5d10c7c61 100644
|
|
--- a/src/main/java/net/minecraft/world/level/biome/Biome.java
|
|
+++ b/src/main/java/net/minecraft/world/level/biome/Biome.java
|
|
@@ -66,14 +66,20 @@ public final class Biome {
|
|
private final BiomeGenerationSettings generationSettings;
|
|
private final MobSpawnSettings mobSettings;
|
|
private final BiomeSpecialEffects specialEffects;
|
|
- private final ThreadLocal<Long2FloatLinkedOpenHashMap> temperatureCache = ThreadLocal.withInitial(() -> {
|
|
+ // Pufferfish start - use our cache
|
|
+ private final ThreadLocal<gg.airplane.structs.Long2FloatAgingCache> temperatureCache = ThreadLocal.withInitial(() -> {
|
|
return Util.make(() -> {
|
|
+ /*
|
|
Long2FloatLinkedOpenHashMap long2FloatLinkedOpenHashMap = new Long2FloatLinkedOpenHashMap(1024, 0.25F) {
|
|
protected void rehash(int i) {
|
|
}
|
|
};
|
|
long2FloatLinkedOpenHashMap.defaultReturnValue(Float.NaN);
|
|
return long2FloatLinkedOpenHashMap;
|
|
+
|
|
+ */
|
|
+ return new gg.airplane.structs.Long2FloatAgingCache(TEMPERATURE_CACHE_SIZE);
|
|
+ // Pufferfish end
|
|
});
|
|
});
|
|
|
|
@@ -114,17 +120,15 @@ public final class Biome {
|
|
@Deprecated
|
|
public float getTemperature(BlockPos blockPos) {
|
|
long l = blockPos.asLong();
|
|
- Long2FloatLinkedOpenHashMap long2FloatLinkedOpenHashMap = this.temperatureCache.get();
|
|
- float f = long2FloatLinkedOpenHashMap.get(l);
|
|
+ // Pufferfish start
|
|
+ gg.airplane.structs.Long2FloatAgingCache cache = this.temperatureCache.get();
|
|
+ float f = cache.getValue(l);
|
|
if (!Float.isNaN(f)) {
|
|
return f;
|
|
} else {
|
|
float g = this.getHeightAdjustedTemperature(blockPos);
|
|
- if (long2FloatLinkedOpenHashMap.size() == 1024) {
|
|
- long2FloatLinkedOpenHashMap.removeFirstFloat();
|
|
- }
|
|
-
|
|
- long2FloatLinkedOpenHashMap.put(l, g);
|
|
+ cache.putValue(l, g);
|
|
+ // Pufferfish end
|
|
return g;
|
|
}
|
|
}
|
|
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 a71414397bd45ee7bcacfeef0041d80dfa25f114..d66806565770cb03a21794f99e5c4b0f3040b26a 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
|
|
@@ -31,7 +31,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;
|
|
|
|
@@ -65,9 +68,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) {
|
|
@@ -98,6 +105,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);
|
|
}
|
|
@@ -115,7 +139,10 @@ public class ChestBlockEntity extends RandomizableContainerBlockEntity implement
|
|
@Override
|
|
public void load(CompoundTag nbt) {
|
|
super.load(nbt);
|
|
- 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);
|
|
}
|
|
@@ -187,7 +214,10 @@ public class ChestBlockEntity extends RandomizableContainerBlockEntity implement
|
|
|
|
@Override
|
|
protected void setItems(NonNullList<ItemStack> list) {
|
|
- this.items = list;
|
|
+ // Pufferfish start
|
|
+ this.optimizedItems = gg.airplane.structs.ItemListWithBitset.fromList(list);
|
|
+ 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 ccad692aba2ed77259f6814d88f01b91ed9d229b..698a0ac71cf9fb409d609a81cc2958121260a46d 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
|
|
@@ -43,7 +43,10 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
|
|
|
public static final int MOVE_ITEM_SPEED = 8;
|
|
public static final int HOPPER_CONTAINER_SIZE = 5;
|
|
+ // Pufferfish start
|
|
private NonNullList<ItemStack> items;
|
|
+ private gg.airplane.structs.ItemListWithBitset optimizedItems; // Pufferfish
|
|
+ // Pufferfish end
|
|
private int cooldownTime;
|
|
private long tickedGameTime;
|
|
|
|
@@ -79,14 +82,37 @@ 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;
|
|
}
|
|
|
|
+ // 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
|
|
public void load(CompoundTag nbt) {
|
|
super.load(nbt);
|
|
- 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);
|
|
}
|
|
@@ -158,7 +184,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
|
flag = HopperBlockEntity.ejectItems(world, pos, state, (Container) blockEntity, blockEntity); // CraftBukkit
|
|
}
|
|
|
|
- if (!blockEntity.inventoryFull()) {
|
|
+ if (!blockEntity.optimizedItems.hasFullStacks() || !blockEntity.inventoryFull()) { // Pufferfish - use bitset first
|
|
flag |= booleansupplier.getAsBoolean();
|
|
}
|
|
|
|
@@ -197,7 +223,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
|
skipPushModeEventFire = skipHopperEvents;
|
|
boolean foundItem = false;
|
|
for (int i = 0; i < hopper.getContainerSize(); ++i) {
|
|
- ItemStack item = hopper.getItem(i);
|
|
+ ItemStack item = hopper.getItem(i); // Pufferfish
|
|
if (!item.isEmpty()) {
|
|
foundItem = true;
|
|
ItemStack origItemStack = item;
|
|
@@ -400,12 +426,18 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
|
}
|
|
|
|
private static boolean isFullContainer(Container inventory, Direction direction) {
|
|
- return allMatch(inventory, direction, STACK_SIZE_TEST); // Paper - no streams
|
|
+ // Pufferfish start - use bitsets
|
|
+ //return allMatch(inventory, direction, STACK_SIZE_TEST); // Paper - no streams
|
|
+ return inventory.isCompletelyFull(direction);
|
|
+ // Pufferfish end
|
|
}
|
|
|
|
private static boolean isEmptyContainer(Container inv, Direction facing) {
|
|
// Paper start
|
|
- return allMatch(inv, facing, IS_EMPTY_TEST);
|
|
+ // Pufferfish start - use bitsets
|
|
+ //return allMatch(inv, facing, IS_EMPTY_TEST);
|
|
+ return inv.isCompletelyEmpty(facing);
|
|
+ // Pufferfish end
|
|
}
|
|
private static boolean allMatch(Container iinventory, Direction enumdirection, java.util.function.BiPredicate<ItemStack, Integer> test) {
|
|
if (iinventory instanceof WorldlyContainer) {
|
|
@@ -582,7 +614,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
|
|
@@ -730,7 +762,10 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
|
|
|
@Override
|
|
protected void setItems(NonNullList<ItemStack> list) {
|
|
- this.items = list;
|
|
+ // Pufferfish start
|
|
+ this.optimizedItems = gg.airplane.structs.ItemListWithBitset.fromList(list);
|
|
+ this.items = this.optimizedItems.nonNullList;
|
|
+ // Pufferfish end
|
|
}
|
|
|
|
public static void entityInside(Level world, BlockPos pos, BlockState state, Entity entity, HopperBlockEntity blockEntity) {
|
|
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 d559f93a9a09bac414dd5d58afccad42c127f09b..13e749a3c40f0b2cc002f13675a9a56eedbefdac 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
|
|
@@ -96,13 +96,8 @@ public abstract class RandomizableContainerBlockEntity extends BaseContainerBloc
|
|
public boolean isEmpty() {
|
|
this.unpackLootTable((Player)null);
|
|
// Paper start
|
|
- for (ItemStack itemStack : this.getItems()) {
|
|
- if (!itemStack.isEmpty()) {
|
|
- return false;
|
|
- }
|
|
- }
|
|
+ return this.isCompletelyEmpty(null); // Pufferfish - use super
|
|
// Paper end
|
|
- return true;
|
|
}
|
|
|
|
@Override
|
|
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 2292cb0e0c1a3e0ed34b941f028136bfb0bff13e..0b08a91ae9dc73c011dbb5f517becac7d08fd1e9 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,18 @@ public class LevelChunk extends ChunkAccess {
|
|
}
|
|
// Paper end
|
|
|
|
+ // Pufferfish start - instead of using a random every time the chunk is ticked, define when lightning strikes preemptively
|
|
+ private int lightningTick;
|
|
+ // shouldDoLightning compiles down to 29 bytes, which with the default of 35 byte inlining should guarantee an inline
|
|
+ public final boolean shouldDoLightning(net.minecraft.util.RandomSource random) {
|
|
+ if (this.lightningTick-- <= 0) {
|
|
+ this.lightningTick = random.nextInt(this.level.spigotConfig.thunderChance) << 1;
|
|
+ return true;
|
|
+ }
|
|
+ return false;
|
|
+ }
|
|
+ // Pufferfish end
|
|
+
|
|
public LevelChunk(Level world, ChunkPos pos) {
|
|
this(world, pos, UpgradeData.EMPTY, new LevelChunkTicks<>(), new LevelChunkTicks<>(), 0L, (LevelChunkSection[]) null, (LevelChunk.PostLoadProcessor) null, (BlendingData) null);
|
|
}
|
|
@@ -124,6 +136,7 @@ public class LevelChunk extends ChunkAccess {
|
|
this.fluidTicks = fluidTickScheduler;
|
|
// CraftBukkit start
|
|
this.bukkitChunk = new org.bukkit.craftbukkit.CraftChunk(this);
|
|
+ this.lightningTick = this.level.getThreadUnsafeRandom().nextInt(100000) << 1; // Pufferfish - initialize lightning tick
|
|
}
|
|
|
|
public org.bukkit.Chunk bukkitChunk;
|
|
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 b0c9fce9d4e06cac139e341d218d0b6aac1f1943..f25467ad1c5bac7eaef4b63b2845ad04d7c76e4e 100644
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
|
|
@@ -27,6 +27,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
|
|
|
|
public LevelChunkSection(int i, PalettedContainer<BlockState> datapaletteblock, PalettedContainer<Holder<Biome>> palettedcontainerro) {
|
|
@@ -198,6 +199,7 @@ public class LevelChunkSection {
|
|
|
|
if (!fluid.isEmpty()) {
|
|
--this.tickingFluidCount;
|
|
+ --this.fluidStateCount; // Pufferfish
|
|
}
|
|
|
|
if (!state.isAir()) {
|
|
@@ -212,6 +214,7 @@ public class LevelChunkSection {
|
|
|
|
if (!fluid1.isEmpty()) {
|
|
++this.tickingFluidCount;
|
|
+ ++this.fluidStateCount; // Pufferfish
|
|
}
|
|
|
|
this.updateKnownBlockInfo(x | (z << 4) | (y << 8), iblockdata1, state); // Paper
|
|
@@ -260,6 +263,7 @@ public class LevelChunkSection {
|
|
if (fluid.isRandomlyTicking()) {
|
|
this.tickingFluidCount = (short) (this.tickingFluidCount + 1);
|
|
}
|
|
+ this.fluidStateCount++; // Pufferfish
|
|
}
|
|
|
|
});
|
|
diff --git a/src/main/java/net/minecraft/world/level/entity/EntityTickList.java b/src/main/java/net/minecraft/world/level/entity/EntityTickList.java
|
|
index 4cdfc433df67afcd455422e9baf56f167dd712ae..57fcf3910f45ce371ac2e237b277b1034caaac4e 100644
|
|
--- a/src/main/java/net/minecraft/world/level/entity/EntityTickList.java
|
|
+++ b/src/main/java/net/minecraft/world/level/entity/EntityTickList.java
|
|
@@ -8,7 +8,7 @@ import javax.annotation.Nullable;
|
|
import net.minecraft.world.entity.Entity;
|
|
|
|
public class EntityTickList {
|
|
- private final io.papermc.paper.util.maplist.IteratorSafeOrderedReferenceSet<Entity> entities = new io.papermc.paper.util.maplist.IteratorSafeOrderedReferenceSet<>(true); // Paper - rewrite this, always keep this updated - why would we EVER tick an entity that's not ticking?
|
|
+ public final io.papermc.paper.util.maplist.IteratorSafeOrderedReferenceSet<Entity> entities = new io.papermc.paper.util.maplist.IteratorSafeOrderedReferenceSet<>(true); // Paper - rewrite this, always keep this updated - why would we EVER tick an entity that's not ticking? // Pufferfish - private->public
|
|
|
|
private void ensureActiveIsNotIterated() {
|
|
// Paper - replace with better logic, do not delay removals
|
|
diff --git a/src/main/java/net/minecraft/world/level/entity/LevelEntityGetter.java b/src/main/java/net/minecraft/world/level/entity/LevelEntityGetter.java
|
|
index da1ad0b2679e392ed81b50c15f012c63cb5c939e..9c6ab057dccd6331e9c577e0c6192c0d84718906 100644
|
|
--- a/src/main/java/net/minecraft/world/level/entity/LevelEntityGetter.java
|
|
+++ b/src/main/java/net/minecraft/world/level/entity/LevelEntityGetter.java
|
|
@@ -6,6 +6,8 @@ import javax.annotation.Nullable;
|
|
import net.minecraft.world.phys.AABB;
|
|
|
|
public interface LevelEntityGetter<T extends EntityAccess> {
|
|
+ int getCount(); // Pufferfish
|
|
+
|
|
@Nullable
|
|
T get(int id);
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/entity/LevelEntityGetterAdapter.java b/src/main/java/net/minecraft/world/level/entity/LevelEntityGetterAdapter.java
|
|
index 3b13f6ea36a3bfecabe09221eb5c48dddab119db..563b6c47df0c5ae9efcb91fd53a065b1da1cdb94 100644
|
|
--- a/src/main/java/net/minecraft/world/level/entity/LevelEntityGetterAdapter.java
|
|
+++ b/src/main/java/net/minecraft/world/level/entity/LevelEntityGetterAdapter.java
|
|
@@ -14,6 +14,8 @@ public class LevelEntityGetterAdapter<T extends EntityAccess> implements LevelEn
|
|
this.sectionStorage = cache;
|
|
}
|
|
|
|
+ @Override public int getCount() { return this.visibleEntities.count(); } // Pufferfish
|
|
+
|
|
@Nullable
|
|
@Override
|
|
public T get(int id) {
|
|
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 ff40fe323964f173561a6838fb443e79abf9df38..c2c3ed6ba79f9f41497e042571f699a0fc6e9335 100644
|
|
--- a/src/main/java/net/minecraft/world/level/material/FlowingFluid.java
|
|
+++ b/src/main/java/net/minecraft/world/level/material/FlowingFluid.java
|
|
@@ -43,6 +43,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) {}
|
|
@@ -51,6 +53,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() {}
|
|
@@ -239,6 +249,8 @@ public abstract class FlowingFluid extends Fluid {
|
|
}
|
|
|
|
private boolean canPassThroughWall(Direction face, BlockGetter world, BlockPos pos, BlockState state, BlockPos fromPos, BlockState fromState) {
|
|
+ // Pufferfish start - modify to use our cache
|
|
+ /*
|
|
Object2ByteLinkedOpenHashMap object2bytelinkedopenhashmap;
|
|
|
|
if (!state.getBlock().hasDynamicShape() && !fromState.getBlock().hasDynamicShape()) {
|
|
@@ -246,9 +258,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);
|
|
@@ -259,11 +278,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();
|
|
@@ -271,6 +301,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;
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/level/pathfinder/Path.java b/src/main/java/net/minecraft/world/level/pathfinder/Path.java
|
|
index 2a335f277bd0e4b8ad0f60d8226eb8aaa80a871f..228b11a21735885055d2fb5e0568e21aed32a6cb 100644
|
|
--- a/src/main/java/net/minecraft/world/level/pathfinder/Path.java
|
|
+++ b/src/main/java/net/minecraft/world/level/pathfinder/Path.java
|
|
@@ -30,6 +30,17 @@ public class Path {
|
|
this.reached = reachesTarget;
|
|
}
|
|
|
|
+ // Pufferfish start
|
|
+ /**
|
|
+ * checks if the path is completely processed in the case of it being computed async
|
|
+ *
|
|
+ * @return true if the path is processed
|
|
+ */
|
|
+ public boolean isProcessed() {
|
|
+ return true;
|
|
+ }
|
|
+ // Pufferfish end
|
|
+
|
|
public void advance() {
|
|
++this.nextNodeIndex;
|
|
}
|
|
@@ -104,6 +115,8 @@ public class Path {
|
|
}
|
|
|
|
public boolean sameAs(@Nullable Path o) {
|
|
+ if (o == this) return true; // Pufferfish - short circuit
|
|
+
|
|
if (o == null) {
|
|
return false;
|
|
} else if (o.nodes.size() != this.nodes.size()) {
|
|
diff --git a/src/main/java/net/minecraft/world/level/pathfinder/PathFinder.java b/src/main/java/net/minecraft/world/level/pathfinder/PathFinder.java
|
|
index d23481453717f715124156b5d83f6448f720d049..0455c8a7da880da4f0b7ae9d57e83e281a55f0ae 100644
|
|
--- a/src/main/java/net/minecraft/world/level/pathfinder/PathFinder.java
|
|
+++ b/src/main/java/net/minecraft/world/level/pathfinder/PathFinder.java
|
|
@@ -25,36 +25,75 @@ public class PathFinder {
|
|
private static final boolean DEBUG = false;
|
|
private final BinaryHeap openSet = new BinaryHeap();
|
|
|
|
- public PathFinder(NodeEvaluator pathNodeMaker, int range) {
|
|
+ private final @Nullable gg.pufferfish.pufferfish.path.NodeEvaluatorGenerator nodeEvaluatorGenerator; // Pufferfish - we use this later to generate an evaluator
|
|
+
|
|
+ // Pufferfish start - add nodeEvaluatorGenerator as optional param
|
|
+ public PathFinder(NodeEvaluator pathNodeMaker, int range, @Nullable gg.pufferfish.pufferfish.path.NodeEvaluatorGenerator nodeEvaluatorGenerator) {
|
|
this.nodeEvaluator = pathNodeMaker;
|
|
this.maxVisitedNodes = range;
|
|
+ this.nodeEvaluatorGenerator = nodeEvaluatorGenerator;
|
|
+ }
|
|
+
|
|
+ public PathFinder(NodeEvaluator pathNodeMaker, int range) {
|
|
+ this(pathNodeMaker, range, null);
|
|
}
|
|
+ // Pufferfish end
|
|
|
|
@Nullable
|
|
public Path findPath(PathNavigationRegion world, Mob mob, Set<BlockPos> positions, float followRange, int distance, float rangeMultiplier) {
|
|
- this.openSet.clear();
|
|
- this.nodeEvaluator.prepare(world, mob);
|
|
- Node node = this.nodeEvaluator.getStart();
|
|
+ if (!gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncPathfinding) this.openSet.clear(); // Pufferfish - it's always cleared in processPath
|
|
+ // Pufferfish start - use a generated evaluator if we have one otherwise run sync
|
|
+ var nodeEvaluator = this.nodeEvaluatorGenerator == null ? this.nodeEvaluator : gg.pufferfish.pufferfish.path.NodeEvaluatorCache.takeNodeEvaluator(this.nodeEvaluatorGenerator);
|
|
+ nodeEvaluator.prepare(world, mob);
|
|
+ Node node = nodeEvaluator.getStart();
|
|
if (node == null) {
|
|
+ gg.pufferfish.pufferfish.path.NodeEvaluatorCache.removeNodeEvaluator(nodeEvaluator);
|
|
return null;
|
|
} else {
|
|
// Paper start - remove streams - and optimize collection
|
|
List<Map.Entry<Target, BlockPos>> map = Lists.newArrayList();
|
|
for (BlockPos pos : positions) {
|
|
- map.add(new java.util.AbstractMap.SimpleEntry<>(this.nodeEvaluator.getGoal(pos.getX(), pos.getY(), pos.getZ()), pos));
|
|
+ map.add(new java.util.AbstractMap.SimpleEntry<>(nodeEvaluator.getGoal(pos.getX(), pos.getY(), pos.getZ()), pos));
|
|
}
|
|
// Paper end
|
|
- Path path = this.findPath(world.getProfiler(), node, map, followRange, distance, rangeMultiplier);
|
|
- this.nodeEvaluator.done();
|
|
- return path;
|
|
+
|
|
+ // Pufferfish start
|
|
+ if (this.nodeEvaluatorGenerator == null) {
|
|
+ // run sync :(
|
|
+ gg.pufferfish.pufferfish.path.NodeEvaluatorCache.removeNodeEvaluator(nodeEvaluator);
|
|
+ return this.findPath(world.getProfiler(), node, map, followRange, distance, rangeMultiplier);
|
|
+ }
|
|
+
|
|
+ return new gg.pufferfish.pufferfish.path.AsyncPath(Lists.newArrayList(), positions, () -> {
|
|
+ try {
|
|
+ return this.processPath(nodeEvaluator, node, map, followRange, distance, rangeMultiplier);
|
|
+ } finally {
|
|
+ nodeEvaluator.done();
|
|
+ gg.pufferfish.pufferfish.path.NodeEvaluatorCache.returnNodeEvaluator(nodeEvaluator);
|
|
+ }
|
|
+ });
|
|
+ // Pufferfish end
|
|
}
|
|
}
|
|
|
|
- @Nullable
|
|
+ // Pufferfish start - split pathfinding into the original sync method for compat and processing for delaying
|
|
// Paper start - optimize collection
|
|
private Path findPath(ProfilerFiller profiler, Node startNode, List<Map.Entry<Target, BlockPos>> positions, float followRange, int distance, float rangeMultiplier) {
|
|
+ // readd the profiler code for sync
|
|
profiler.push("find_path");
|
|
profiler.markForCharting(MetricCategory.PATH_FINDING);
|
|
+
|
|
+ try {
|
|
+ return this.processPath(this.nodeEvaluator, startNode, positions, followRange, distance, rangeMultiplier);
|
|
+ } finally {
|
|
+ this.nodeEvaluator.done();
|
|
+ }
|
|
+ }
|
|
+ // Pufferfish end
|
|
+
|
|
+ private synchronized @org.jetbrains.annotations.NotNull Path processPath(NodeEvaluator nodeEvaluator, Node startNode, List<Map.Entry<Target, BlockPos>> positions, float followRange, int distance, float rangeMultiplier) { // Pufferfish - sync to only use the caching functions in this class on a single thread
|
|
+ org.apache.commons.lang3.Validate.isTrue(!positions.isEmpty()); // ensure that we have at least one position, which means we'll always return a path
|
|
+
|
|
// Set<Target> set = positions.keySet();
|
|
startNode.g = 0.0F;
|
|
startNode.h = this.getBestH(startNode, positions); // Paper - optimize collection
|
|
@@ -91,7 +130,7 @@ public class PathFinder {
|
|
}
|
|
|
|
if (!(node.distanceTo(startNode) >= followRange)) {
|
|
- int k = this.nodeEvaluator.getNeighbors(this.neighbors, node);
|
|
+ int k = nodeEvaluator.getNeighbors(this.neighbors, node);
|
|
|
|
for(int l = 0; l < k; ++l) {
|
|
Node node2 = this.neighbors[l];
|
|
@@ -123,9 +162,14 @@ public class PathFinder {
|
|
if (best == null || comparator.compare(path, best) < 0)
|
|
best = path;
|
|
}
|
|
+
|
|
+ // Pufferfish start - ignore this warning, we know that the above loop always runs at least once since positions is not empty
|
|
+ //noinspection ConstantConditions
|
|
return best;
|
|
// Paper end
|
|
+ // Pufferfish end
|
|
}
|
|
+ // Pufferfish end
|
|
|
|
protected float distance(Node a, Node b) {
|
|
return a.distanceTo(b);
|
|
diff --git a/src/main/java/net/minecraft/world/level/storage/loot/LootContext.java b/src/main/java/net/minecraft/world/level/storage/loot/LootContext.java
|
|
index 35f9b11a3a61976c952a2c1c64bb2a932538f54f..9e9ac64764cf0a84e25e75d8d6f516cde6047284 100644
|
|
--- a/src/main/java/net/minecraft/world/level/storage/loot/LootContext.java
|
|
+++ b/src/main/java/net/minecraft/world/level/storage/loot/LootContext.java
|
|
@@ -41,8 +41,10 @@ public class LootContext {
|
|
this.level = world;
|
|
this.lootTables = tableGetter;
|
|
this.conditions = conditionGetter;
|
|
- this.params = ImmutableMap.copyOf(parameters);
|
|
- this.dynamicDrops = ImmutableMap.copyOf(drops);
|
|
+ // Pufferfish start - use unmodifiable maps instead of immutable ones to skip the copy
|
|
+ this.params = java.util.Collections.unmodifiableMap(parameters);
|
|
+ this.dynamicDrops = java.util.Collections.unmodifiableMap(drops);
|
|
+ // Pufferfish end
|
|
}
|
|
|
|
public boolean hasParam(LootContextParam<?> parameter) {
|
|
diff --git a/src/main/java/net/minecraft/world/phys/shapes/EntityCollisionContext.java b/src/main/java/net/minecraft/world/phys/shapes/EntityCollisionContext.java
|
|
index b1992ed5136cc7dcf04219868b94b3c37ae36b4b..5b5339cba819368f4d6b7eaf404fa59bca4c0518 100644
|
|
--- a/src/main/java/net/minecraft/world/phys/shapes/EntityCollisionContext.java
|
|
+++ b/src/main/java/net/minecraft/world/phys/shapes/EntityCollisionContext.java
|
|
@@ -19,47 +19,66 @@ public class EntityCollisionContext implements CollisionContext {
|
|
return defaultValue;
|
|
}
|
|
};
|
|
- private final boolean descending;
|
|
- private final double entityBottom;
|
|
- private final ItemStack heldItem;
|
|
- private final Predicate<FluidState> canStandOnFluid;
|
|
+ // Pufferfish start - remove these and pray no plugin uses them
|
|
+ // private final boolean descending;
|
|
+ // private final double entityBottom;
|
|
+ // private final ItemStack heldItem;
|
|
+ // private final Predicate<FluidState> canStandOnFluid;
|
|
+ // Pufferfish end
|
|
@Nullable
|
|
private final Entity entity;
|
|
|
|
protected EntityCollisionContext(boolean descending, double minY, ItemStack heldItem, Predicate<FluidState> walkOnFluidPredicate, @Nullable Entity entity) {
|
|
- this.descending = descending;
|
|
- this.entityBottom = minY;
|
|
- this.heldItem = heldItem;
|
|
- this.canStandOnFluid = walkOnFluidPredicate;
|
|
+ // Pufferfish start - remove these
|
|
+ // this.descending = descending;
|
|
+ // this.entityBottom = minY;
|
|
+ // this.heldItem = heldItem;
|
|
+ // this.canStandOnFluid = walkOnFluidPredicate;
|
|
+ // Pufferfish end
|
|
this.entity = entity;
|
|
}
|
|
|
|
/** @deprecated */
|
|
@Deprecated
|
|
protected EntityCollisionContext(Entity entity) {
|
|
- this(entity.isDescending(), entity.getY(), entity instanceof LivingEntity ? ((LivingEntity)entity).getMainHandItem() : ItemStack.EMPTY, entity instanceof LivingEntity ? ((LivingEntity)entity)::canStandOnFluid : (fluidState) -> {
|
|
- return false;
|
|
- }, entity);
|
|
+ // Pufferfish start - remove this
|
|
+ // this(entity.isDescending(), entity.getY(), entity instanceof LivingEntity ? ((LivingEntity)entity).getMainHandItem() : ItemStack.EMPTY, entity instanceof LivingEntity ? ((LivingEntity)entity)::canStandOnFluid : (fluidState) -> {
|
|
+ // return false;
|
|
+ // }, entity);
|
|
+ // Pufferfish end
|
|
+ this.entity = entity;
|
|
}
|
|
|
|
@Override
|
|
public boolean isHoldingItem(Item item) {
|
|
- return this.heldItem.is(item);
|
|
+ // Pufferfish start
|
|
+ Entity entity = this.entity;
|
|
+ if (entity instanceof LivingEntity livingEntity) {
|
|
+ return livingEntity.getMainHandItem().is(item);
|
|
+ }
|
|
+ return ItemStack.EMPTY.is(item);
|
|
+ // Pufferfish end
|
|
}
|
|
|
|
@Override
|
|
public boolean canStandOnFluid(FluidState state, FluidState fluidState) {
|
|
- return this.canStandOnFluid.test(fluidState) && !state.getType().isSame(fluidState.getType());
|
|
+ // Pufferfish start
|
|
+ Entity entity = this.entity;
|
|
+ if (entity instanceof LivingEntity livingEntity) {
|
|
+ return livingEntity.canStandOnFluid(fluidState) && !state.getType().isSame(fluidState.getType());
|
|
+ }
|
|
+ return false;
|
|
+ // Pufferfish end
|
|
}
|
|
|
|
@Override
|
|
public boolean isDescending() {
|
|
- return this.descending;
|
|
+ return this.entity != null && this.entity.isDescending(); // Pufferfish
|
|
}
|
|
|
|
@Override
|
|
public boolean isAbove(VoxelShape shape, BlockPos pos, boolean defaultValue) {
|
|
- return this.entityBottom > (double)pos.getY() + shape.max(Direction.Axis.Y) - (double)1.0E-5F;
|
|
+ return (this.entity == null ? -Double.MAX_VALUE : entity.getY()) > (double)pos.getY() + shape.max(Direction.Axis.Y) - (double)1.0E-5F; // Pufferfish
|
|
}
|
|
|
|
@Nullable
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
index bfde5bbcccfaa754ec6bdf4f3817981a93e465bd..9a8a7eff47d40d6de558f0946c450531b3984f44 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -246,7 +246,7 @@ import javax.annotation.Nullable; // Paper
|
|
import javax.annotation.Nonnull; // Paper
|
|
|
|
public final class CraftServer implements Server {
|
|
- private final String serverName = "Paper"; // Paper
|
|
+ private final String serverName = "Pufferfish"; // Paper // Pufferfish
|
|
private final String serverVersion;
|
|
private final String bukkitVersion = Versioning.getBukkitVersion();
|
|
private final Logger logger = Logger.getLogger("Minecraft");
|
|
@@ -1045,6 +1045,11 @@ public final class CraftServer implements Server {
|
|
plugin.getDescription().getName(),
|
|
"This plugin is not properly shutting down its async tasks when it is being shut down. This task may throw errors during the final shutdown logs and might not complete before process dies."
|
|
));
|
|
+ getLogger().log(Level.SEVERE, String.format("%s Stacktrace", worker.getThread().getName()));
|
|
+ StackTraceElement[] stackTrace = worker.getThread().getStackTrace();
|
|
+ for (StackTraceElement element : stackTrace) {
|
|
+ getLogger().log(Level.SEVERE, " " + element.toString());
|
|
+ }
|
|
}
|
|
}
|
|
// Paper end
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java
|
|
index 0b3b46348ac9195bff1492ffc11fcbff7d3f5c6f..4010052c53f3a2831b4d5aa1c041d85897856acb 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java
|
|
@@ -43,6 +43,6 @@ public class CraftShapelessRecipe extends ShapelessRecipe implements CraftRecipe
|
|
data.set(i, toNMS(ingred.get(i), true));
|
|
}
|
|
|
|
- MinecraftServer.getServer().getRecipeManager().addRecipe(new net.minecraft.world.item.crafting.ShapelessRecipe(CraftNamespacedKey.toMinecraft(this.getKey()), this.getGroup(), CraftItemStack.asNMSCopy(this.getResult()), data));
|
|
+ MinecraftServer.getServer().getRecipeManager().addRecipe(new net.minecraft.world.item.crafting.ShapelessRecipe(CraftNamespacedKey.toMinecraft(this.getKey()), this.getGroup(), CraftItemStack.asNMSCopy(this.getResult()), data, true));
|
|
}
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/MinecraftInternalPlugin.java b/src/main/java/org/bukkit/craftbukkit/scheduler/MinecraftInternalPlugin.java
|
|
index 909b2c98e7a9117d2f737245e4661792ffafb744..0d9e2b3728f9ab500bd5e44702718535d338e9a5 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/MinecraftInternalPlugin.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/MinecraftInternalPlugin.java
|
|
@@ -22,7 +22,8 @@ public class MinecraftInternalPlugin extends PluginBase {
|
|
private boolean enabled = true;
|
|
|
|
private final String pluginName;
|
|
- private PluginDescriptionFile pdf;
|
|
+ private org.bukkit.plugin.PluginLogger logger;
|
|
+ private PluginDescriptionFile pdf; // Pufferfish
|
|
|
|
public MinecraftInternalPlugin() {
|
|
this.pluginName = "Minecraft";
|
|
@@ -75,7 +76,12 @@ public class MinecraftInternalPlugin extends PluginBase {
|
|
|
|
@Override
|
|
public PluginLogger getLogger() {
|
|
- throw new UnsupportedOperationException("Not supported.");
|
|
+ // Pufferfish start
|
|
+ if (this.logger == null) {
|
|
+ this.logger = new org.bukkit.plugin.PluginLogger(this); // Pufferfish
|
|
+ }
|
|
+ return this.logger;
|
|
+ // Pufferfish end
|
|
}
|
|
|
|
@Override
|
|
@@ -85,7 +91,7 @@ public class MinecraftInternalPlugin extends PluginBase {
|
|
|
|
@Override
|
|
public Server getServer() {
|
|
- throw new UnsupportedOperationException("Not supported.");
|
|
+ return org.bukkit.Bukkit.getServer(); // Pufferfish - impl
|
|
}
|
|
|
|
@Override
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
index 8961da579b114cbafb329c00aadf1cf75e70cf97..a912b96a4e099c7e90cbba37218972f830188d24 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
@@ -430,7 +430,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|
|
|
@Override
|
|
public com.destroystokyo.paper.util.VersionFetcher getVersionFetcher() {
|
|
- return new com.destroystokyo.paper.PaperVersionFetcher();
|
|
+ return new gg.pufferfish.pufferfish.PufferfishVersionFetcher(); // Pufferfish
|
|
}
|
|
|
|
@Override
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java b/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java
|
|
index e948ec5a573b22645664eb53bc3e9932246544e4..e3845dc3357bbb74885ae3a1a08525adde581235 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java
|
|
@@ -11,6 +11,7 @@ public class ServerShutdownThread extends Thread {
|
|
|
|
@Override
|
|
public void run() {
|
|
+ try { gg.pufferfish.pufferfish.flare.ProfilingManager.stop(); } catch (Throwable t) {} // Pufferfish - shut down Flare if it's running
|
|
try {
|
|
// Paper start - try to shutdown on main
|
|
server.safeShutdown(false, false);
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/Versioning.java b/src/main/java/org/bukkit/craftbukkit/util/Versioning.java
|
|
index 774556a62eb240da42e84db4502e2ed43495be17..80553face9c70c2a3d897681e7761df85b22d464 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/Versioning.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/Versioning.java
|
|
@@ -11,7 +11,7 @@ public final class Versioning {
|
|
public static String getBukkitVersion() {
|
|
String result = "Unknown-Version";
|
|
|
|
- InputStream stream = Bukkit.class.getClassLoader().getResourceAsStream("META-INF/maven/io.papermc.paper/paper-api/pom.properties");
|
|
+ InputStream stream = Bukkit.class.getClassLoader().getResourceAsStream("META-INF/maven/gg.pufferfish.pufferfish/pufferfish-api/pom.properties"); // Pufferfish
|
|
Properties properties = new Properties();
|
|
|
|
if (stream != null) {
|
|
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
|
|
index 40b382c2e0e33fe5c24a51b211cd2f9557a60c5e..70b5b307193dc288a6257d90ca96762cb4a8345a 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;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.phys.AABB;
|
|
+// Pufferfish start
|
|
+import net.minecraft.world.phys.Vec3;
|
|
+import java.util.List;
|
|
+// Pufferfish end
|
|
|
|
public class ActivationRange
|
|
{
|
|
@@ -216,6 +220,21 @@ public class ActivationRange
|
|
for (int i = 0; i < entities.size(); i++) {
|
|
Entity entity = entities.get(i);
|
|
ActivationRange.activateEntity(entity);
|
|
+
|
|
+ // Pufferfish start
|
|
+ if (gg.pufferfish.pufferfish.PufferfishConfig.dearEnabled && entity.getType().dabEnabled) {
|
|
+ Vec3 playerVec = player.position();
|
|
+ Vec3 entityVec = entity.position();
|
|
+ double diffX = playerVec.x - entityVec.x, diffY = playerVec.y - entityVec.y, diffZ = playerVec.z - entityVec.z;
|
|
+ int squaredDistance = (int) (diffX * diffX + diffY * diffY + diffZ * diffZ);
|
|
+ entity.activatedPriority = squaredDistance > gg.pufferfish.pufferfish.PufferfishConfig.startDistanceSquared ?
|
|
+ Math.max(1, Math.min(squaredDistance >> gg.pufferfish.pufferfish.PufferfishConfig.activationDistanceMod, gg.pufferfish.pufferfish.PufferfishConfig.maximumActivationPrio)) :
|
|
+ 1;
|
|
+ } else {
|
|
+ entity.activatedPriority = 1;
|
|
+ }
|
|
+ // Pufferfish end
|
|
+
|
|
}
|
|
// Paper end
|
|
}
|
|
@@ -232,12 +251,12 @@ public class ActivationRange
|
|
if ( MinecraftServer.currentTick > entity.activatedTick )
|
|
{
|
|
if ( entity.defaultActivationState )
|
|
- {
|
|
+ { // Pufferfish - diff on change
|
|
entity.activatedTick = MinecraftServer.currentTick;
|
|
return;
|
|
}
|
|
if ( entity.activationType.boundingBox.intersects( entity.getBoundingBox() ) )
|
|
- {
|
|
+ { // Pufferfish - diff on change
|
|
entity.activatedTick = MinecraftServer.currentTick;
|
|
}
|
|
}
|
|
@@ -291,7 +310,7 @@ public class ActivationRange
|
|
if ( entity instanceof LivingEntity )
|
|
{
|
|
LivingEntity living = (LivingEntity) entity;
|
|
- if ( living.onClimbable() || living.jumping || living.hurtTime > 0 || living.activeEffects.size() > 0 ) // Paper
|
|
+ if ( living.onClimableCached() || living.jumping || living.hurtTime > 0 || living.activeEffects.size() > 0 ) // Paper // Pufferfish - use cached
|
|
{
|
|
return 1; // Paper
|
|
}
|