mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2026-01-04 15:41:40 +00:00
[ci skip] Rebase
This commit is contained in:
@@ -7,39 +7,41 @@ Original code by CobbleSword, licensed under GPL v3
|
||||
You can find the original code on https://github.com/CobbleSword/NachoSpigot
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
index 0f3e73414ec946915c0a048c3174d516c1c93d38..b4a7f9cc14118be03e164341597c22eca2e7c8a9 100644
|
||||
index 8ca3f0e06f163d9ae2910c9fb2475af70b39b943..6f0f56a5ae2edbe25cc061b64289a1c00cfb6c0d 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
@@ -1013,6 +1013,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
@@ -1020,6 +1020,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
}
|
||||
// Spigot end
|
||||
|
||||
+ org.dreeam.leaf.async.AsyncExplosions.stopExecutor(); // Nacho
|
||||
+ org.dreeam.leaf.async.AsyncExplosions.stopExecutor(); // Leaf - Nacho - Async Explosion
|
||||
+
|
||||
// Paper start - move final shutdown items here
|
||||
LOGGER.info("Flushing Chunk IO");
|
||||
// Paper end - move final shutdown items here
|
||||
diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
|
||||
index 29873fbde90bf86dfff9c2063adb76ac2b833250..c170dbb7196898742a819b003cdfe2a2cbd44784 100644
|
||||
index e5d53f7b16f37032bf75e9af276cdb098f343563..3457bb811f2fdd39eacbc2d5238fdc77b32a6e54 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/Explosion.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
|
||||
@@ -11,6 +11,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
+import java.util.concurrent.CompletableFuture;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.BlockPos;
|
||||
@@ -45,6 +46,7 @@ import org.bukkit.craftbukkit.event.CraftEventFactory;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.block.BlockExplodeEvent;
|
||||
+import org.dreeam.leaf.async.AsyncExplosions;
|
||||
// CraftBukkit end
|
||||
@@ -151,7 +151,7 @@ public class Explosion {
|
||||
// resistance = (res + 0.3F) * 0.3F;
|
||||
// so for resistance = 0, we need res = -0.3F
|
||||
private static final Float ZERO_RESISTANCE = Float.valueOf(-0.3f);
|
||||
- private it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap<ExplosionBlockCache> blockCache = null;
|
||||
+ private java.util.concurrent.ConcurrentHashMap<Long, ExplosionBlockCache> blockCache = null;
|
||||
|
||||
public class Explosion {
|
||||
@@ -568,13 +570,10 @@ public class Explosion {
|
||||
public static final class ExplosionBlockCache {
|
||||
|
||||
@@ -457,7 +457,7 @@ public class Explosion {
|
||||
int j;
|
||||
|
||||
// Paper start - optimise explosions
|
||||
- this.blockCache = new it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap<>();
|
||||
+ this.blockCache = new java.util.concurrent.ConcurrentHashMap<>(); // Leaf
|
||||
|
||||
this.chunkPosCache = new long[CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH];
|
||||
java.util.Arrays.fill(this.chunkPosCache, ChunkPos.INVALID_CHUNK_POS);
|
||||
@@ -571,13 +571,10 @@ public class Explosion {
|
||||
int k1 = Mth.floor(this.z + (double) f2 + 1.0D);
|
||||
List<Entity> list = this.level.getEntities(this.source, new AABB((double) i, (double) l, (double) j1, (double) j, (double) i1, (double) k1), (com.google.common.base.Predicate<Entity>) entity -> entity.isAlive() && !entity.isSpectator()); // Paper - Fix lag from explosions processing dead entities
|
||||
Vec3 vec3d = new Vec3(this.x, this.y, this.z);
|
||||
@@ -54,13 +56,13 @@ index 29873fbde90bf86dfff9c2063adb76ac2b833250..c170dbb7196898742a819b003cdfe2a2
|
||||
if (!entity.ignoreExplosion(this)) {
|
||||
double d7 = Math.sqrt(entity.distanceToSqr(vec3d)) / (double) f2;
|
||||
|
||||
@@ -620,21 +619,26 @@ public class Explosion {
|
||||
@@ -623,21 +620,25 @@ public class Explosion {
|
||||
// CraftBukkit end
|
||||
}
|
||||
|
||||
- double d12 = (1.0D - d7) * this.getBlockDensity(vec3d, entity, blockCache, blockPos); // Paper - Optimize explosions
|
||||
- double d12 = (1.0D - d7) * this.getBlockDensity(vec3d, entity, blockCache, blockPos) * (double) this.damageCalculator.getKnockbackMultiplier(entity); // Paper - Optimize explosions
|
||||
+ // Leaf start - Nacho - Async explosion
|
||||
+ //double d12 = (1.0D - d7) * this.getBlockDensity(vec3d, entity, blockCache, blockPos); // Paper - Optimize explosions
|
||||
+ //double d12 = (1.0D - d7) * this.getBlockDensity(vec3d, entity, blockCache, blockPos) * (double) this.damageCalculator.getKnockbackMultiplier(entity); // Paper - Optimize explosions
|
||||
+ double finalD8 = d8;
|
||||
+ double finalD9 = d9;
|
||||
+ double finalD10 = d10;
|
||||
@@ -71,7 +73,7 @@ index 29873fbde90bf86dfff9c2063adb76ac2b833250..c170dbb7196898742a819b003cdfe2a2
|
||||
- if (entity instanceof LivingEntity) {
|
||||
- LivingEntity entityliving = (LivingEntity) entity;
|
||||
-
|
||||
+ if (entity instanceof LivingEntity entityliving) { // Leaf - Improve readability
|
||||
+ if (entity instanceof LivingEntity entityliving) {
|
||||
d13 = entity instanceof Player && level.paperConfig().environment.disableExplosionKnockback ? 0 : ProtectionEnchantment.getExplosionKnockbackAfterDampener(entityliving, d12); // Paper - Option to disable explosion knockback
|
||||
} else {
|
||||
d13 = d12;
|
||||
@@ -81,7 +83,6 @@ index 29873fbde90bf86dfff9c2063adb76ac2b833250..c170dbb7196898742a819b003cdfe2a2
|
||||
- d9 *= d13;
|
||||
- d10 *= d13;
|
||||
- Vec3 vec3d1 = new Vec3(d8, d9, d10);
|
||||
+ // Leaf start - Nacho - Async explosion
|
||||
+ //d8 *= d13;
|
||||
+ //d9 *= d13;
|
||||
+ //d10 *= d13;
|
||||
@@ -89,82 +90,60 @@ index 29873fbde90bf86dfff9c2063adb76ac2b833250..c170dbb7196898742a819b003cdfe2a2
|
||||
|
||||
// CraftBukkit start - Call EntityKnockbackEvent
|
||||
if (entity instanceof LivingEntity) {
|
||||
@@ -645,13 +649,11 @@ public class Explosion {
|
||||
@@ -648,13 +649,11 @@ public class Explosion {
|
||||
}
|
||||
// CraftBukkit end
|
||||
entity.setDeltaMovement(entity.getDeltaMovement().add(vec3d1));
|
||||
- if (entity instanceof Player) {
|
||||
- Player entityhuman = (Player) entity;
|
||||
-
|
||||
+ if (entity instanceof Player entityhuman) { // Leaf - Improve readability
|
||||
+ if (entity instanceof Player entityhuman) {
|
||||
if (!entityhuman.isSpectator() && (!entityhuman.isCreative() || !entityhuman.getAbilities().flying) && !level.paperConfig().environment.disableExplosionKnockback) { // Paper - Option to disable explosion knockback
|
||||
this.hitPlayers.put(entityhuman, vec3d1);
|
||||
}
|
||||
- }
|
||||
+ }}));// Leaf - Nacho end
|
||||
+ }}));// Leaf end - Nacho - Async explosion
|
||||
|
||||
entity.onExplosionHit(this.source);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -871,7 +873,9 @@ public class Explosion {
|
||||
@@ -878,7 +877,9 @@ public class Explosion {
|
||||
private BlockInteraction() {}
|
||||
}
|
||||
// Paper start - Optimize explosions
|
||||
- private float getBlockDensity(Vec3 vec3d, Entity entity, ExplosionBlockCache[] blockCache, BlockPos.MutableBlockPos blockPos) { // Paper - optimise explosions
|
||||
+ // Leaf start - Nacho - Async explosion
|
||||
+ private CompletableFuture<Float> getBlockDensity(Vec3 vec3d, Entity entity, ExplosionBlockCache[] blockCache, BlockPos.MutableBlockPos blockPos) { // Paper - optimise explosions
|
||||
+ return CompletableFuture.supplyAsync(() -> {
|
||||
+ private java.util.concurrent.CompletableFuture<Float> getBlockDensity(Vec3 vec3d, Entity entity, ExplosionBlockCache[] blockCache, BlockPos.MutableBlockPos blockPos) { // Paper - optimise explosions
|
||||
+ return java.util.concurrent.CompletableFuture.supplyAsync(() -> {
|
||||
if (!this.level.paperConfig().environment.optimizeExplosions) {
|
||||
return this.getSeenFraction(vec3d, entity, blockCache, blockPos); // Paper - optimise explosions
|
||||
}
|
||||
@@ -883,6 +887,8 @@ public class Explosion {
|
||||
@@ -890,6 +891,8 @@ public class Explosion {
|
||||
}
|
||||
|
||||
return blockDensity;
|
||||
+ }, AsyncExplosions.EXECUTOR);
|
||||
+ // Leaf - Nacho end
|
||||
+ }, org.dreeam.leaf.async.AsyncExplosions.EXECUTOR);
|
||||
+ // Leaf end - Nacho - Async explosion
|
||||
}
|
||||
|
||||
static class CacheKey {
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
index a1317e374066d2abe20064bc47e20f4b19db9705..e42ad816ebf76d543c0f21f027f43e86d4898bec 100644
|
||||
index 4b00b6d66ebe578778e103335747183b9e44c94c..63f9cfaac4a3b1e7e3a5cceedd9cb58be3a5b139 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
@@ -483,6 +483,7 @@ public final class CraftServer implements Server {
|
||||
}
|
||||
@@ -490,6 +490,7 @@ public final class CraftServer implements Server {
|
||||
this.potionBrewer = new io.papermc.paper.potion.PaperPotionBrewer(console); // Paper - custom potion mixes
|
||||
datapackManager = new io.papermc.paper.datapack.PaperDatapackManager(console.getPackRepository()); // Paper
|
||||
top.leavesmc.leaves.protocol.core.LeavesProtocolManager.init(); // Leaves - protocol
|
||||
+ org.dreeam.leaf.async.AsyncExplosions.initExecutor(org.dreeam.leaf.LeafConfig.useFixedPoolForTNT, org.dreeam.leaf.LeafConfig.fixedPoolSize); // Leaf - Nacho - Async explosion
|
||||
org.leavesmc.leaves.protocol.core.LeavesProtocolManager.init(); // Leaves - protocol
|
||||
+ org.dreeam.leaf.async.AsyncExplosions.initExecutor(org.dreeam.leaf.config.modules.async.AsyncExplosion.useFixedPoolForTNT, org.dreeam.leaf.config.modules.async.AsyncExplosion.fixedPoolSize); // Leaf - Nacho - Async explosion
|
||||
}
|
||||
|
||||
public boolean getCommandBlockOverride(String command) {
|
||||
diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
index f798dcc331e9251ccb1161b251f7f2d5a94fa7a3..0c8c5f970221ef72c5d7139fc18568608f528d16 100644
|
||||
--- a/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
+++ b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
@@ -207,6 +207,8 @@ public class LeafConfig {
|
||||
public static int asyncPathfindingKeepalive = 60;
|
||||
public static boolean cacheMinecartCollision = false;
|
||||
public static boolean skipMapItemDataUpdatesIfMapDoesNotHaveCraftMapRenderer = true;
|
||||
+ public static boolean useFixedPoolForTNT = false;
|
||||
+ public static int fixedPoolSize = 500;
|
||||
private static void performance() {
|
||||
boolean asyncMobSpawning = getBoolean("performance.enable-async-mob-spawning", enableAsyncMobSpawning,
|
||||
"Whether or not asynchronous mob spawning should be enabled.",
|
||||
@@ -270,6 +272,8 @@ public class LeafConfig {
|
||||
cacheMinecartCollision = getBoolean("performance.cache-minecart-collision", cacheMinecartCollision,
|
||||
"Cache the minecart collision result to prevent massive stacked minecart lag the server.");
|
||||
skipMapItemDataUpdatesIfMapDoesNotHaveCraftMapRenderer = getBoolean("performance.skip-map-item-data-updates-if-map-does-not-have-craftmaprenderer", skipMapItemDataUpdatesIfMapDoesNotHaveCraftMapRenderer);
|
||||
+ useFixedPoolForTNT = getBoolean("performance.async-explosion.use-fixed-pools-for-explosions", useFixedPoolForTNT);
|
||||
+ fixedPoolSize = getInt("performance.async-explosion.fixed-pools-size", fixedPoolSize);
|
||||
}
|
||||
|
||||
public static boolean jadeProtocol = false;
|
||||
diff --git a/src/main/java/org/dreeam/leaf/async/AsyncExplosions.java b/src/main/java/org/dreeam/leaf/async/AsyncExplosions.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..880f2f8abc3c28bda1feec24a876693bbf6810e9
|
||||
index 0000000000000000000000000000000000000000..3a755d81e252355d38f1e7dac624225c72a81d78
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/dreeam/leaf/async/AsyncExplosions.java
|
||||
@@ -0,0 +1,22 @@
|
||||
@@ -0,0 +1,23 @@
|
||||
+package org.dreeam.leaf.async;
|
||||
+
|
||||
+import java.util.concurrent.ExecutorService;
|
||||
@@ -180,10 +159,44 @@ index 0000000000000000000000000000000000000000..880f2f8abc3c28bda1feec24a876693b
|
||||
+ public static void stopExecutor() {
|
||||
+ if (EXECUTOR != null) {
|
||||
+ try {
|
||||
+ EXECUTOR.shutdownNow();
|
||||
+ EXECUTOR.shutdown();
|
||||
+ } catch (Exception e) {
|
||||
+ e.printStackTrace();
|
||||
+ EXECUTOR.shutdownNow();
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/org/dreeam/leaf/config/modules/async/AsyncExplosion.java b/src/main/java/org/dreeam/leaf/config/modules/async/AsyncExplosion.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..f31538b219b942cf74ed826aa2768554bc8a1a72
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/dreeam/leaf/config/modules/async/AsyncExplosion.java
|
||||
@@ -0,0 +1,27 @@
|
||||
+package org.dreeam.leaf.config.modules.async;
|
||||
+
|
||||
+import com.electronwill.nightconfig.core.file.CommentedFileConfig;
|
||||
+import org.dreeam.leaf.config.ConfigInfo;
|
||||
+import org.dreeam.leaf.config.DoNotLoad;
|
||||
+import org.dreeam.leaf.config.EnumConfigCategory;
|
||||
+import org.dreeam.leaf.config.IConfigModule;
|
||||
+
|
||||
+public class AsyncExplosion implements IConfigModule {
|
||||
+
|
||||
+ @Override
|
||||
+ public EnumConfigCategory getCategory() {
|
||||
+ return EnumConfigCategory.ASYNC;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public String getBaseName() {
|
||||
+ return "async_explosion";
|
||||
+ }
|
||||
+
|
||||
+ @ConfigInfo(baseName = "enabled")
|
||||
+ public static boolean enabled = true;
|
||||
+ @ConfigInfo(baseName = "use-fixed-pool")
|
||||
+ public static boolean useFixedPoolForTNT = true;
|
||||
+ @ConfigInfo(baseName = "fixed-pool-size")
|
||||
+ public static int fixedPoolSize = 500;
|
||||
+}
|
||||
|
||||
Reference in New Issue
Block a user