9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-28 19:39:17 +00:00
Files
Leaf/patches/unapplied/server/0042-Optimize-explosions.patch
2024-01-21 08:41:41 -05:00

87 lines
5.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Thu, 7 Sep 2023 06:21:32 -0400
Subject: [PATCH] Optimize explosions
diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
index d3c20e4ae510028d25a05915e4662b03e6d0b128..fd195f38f239e322114a794e30b7f5032ac2c18c 100644
--- a/src/main/java/net/minecraft/world/level/Explosion.java
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
@@ -82,9 +82,11 @@ public class Explosion {
}
public Explosion(Level world, @Nullable Entity entity, @Nullable DamageSource damageSource, @Nullable ExplosionDamageCalculator behavior, double x, double y, double z, float power, boolean createFire, Explosion.BlockInteraction destructionType) {
- this.random = world == null || world.random == null ? RandomSource.create() : world.random; // Gale - Patina - reduce RandomSource instances
- this.toBlow = new ObjectArrayList();
- this.hitPlayers = Maps.newHashMap();
+ // Leaf start - Optimize explosion
+ this.random = world == null || world.random == null ? RandomSource.createThreadSafe() : world.random; // Gale - Patina - reduce RandomSource instances
+ this.toBlow = new ObjectArrayList<>();
+ this.hitPlayers = Maps.newConcurrentMap();
+ // Leaf end
this.level = world;
this.source = entity;
this.radius = (float) (world == null || world.purpurConfig.explosionClampRadius ? Math.max(power, 0.0) : power); // CraftBukkit - clamp bad values // Purpur
@@ -425,7 +427,7 @@ public class Explosion {
//Purpur end
this.level.gameEvent(this.source, GameEvent.EXPLODE, new Vec3(this.x, this.y, this.z));
- Set<BlockPos> set = Sets.newHashSet();
+ Set<BlockPos> set = Sets.newConcurrentHashSet(); // Leaf - Optimize explosion - Use ConcurrentHashSet
boolean flag = true;
int i;
@@ -757,10 +759,7 @@ public class Explosion {
}
if (this.fire) {
- ObjectListIterator objectlistiterator1 = this.toBlow.iterator();
-
- while (objectlistiterator1.hasNext()) {
- BlockPos blockposition2 = (BlockPos) objectlistiterator1.next();
+ for (BlockPos blockposition2 : this.toBlow) {
if (this.random.nextInt(3) == 0 && this.level.getBlockState(blockposition2).isAir() && this.level.getBlockState(blockposition2.below()).isSolidRender(this.level, blockposition2.below())) {
// CraftBukkit start - Ignition by explosion
@@ -868,11 +867,7 @@ public class Explosion {
return this.getSeenFraction(vec3d, entity, blockCache, blockPos); // Paper - optimise explosions
}
CacheKey key = new CacheKey(this, entity.getBoundingBox());
- Float blockDensity = this.level.explosionDensityCache.get(key);
- if (blockDensity == null) {
- blockDensity = this.getSeenFraction(vec3d, entity, blockCache, blockPos); // Paper - optimise explosions;
- this.level.explosionDensityCache.put(key, blockDensity);
- }
+ Float blockDensity = this.level.explosionDensityCache.computeIfAbsent(key, k -> this.getSeenFraction(vec3d, entity, blockCache, blockPos)); // Paper - optimise explosions; // Leaf - Optimize explosion - Reduce cache key check load
return blockDensity;
}
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index 275557da9faa7f27dd2fbfbdfbda620d4add0f8a..039a0f3af6907974031c2b568b396246aee201f9 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -3,11 +3,13 @@ package net.minecraft.world.level;
import com.destroystokyo.paper.event.server.ServerExceptionEvent;
import com.destroystokyo.paper.exception.ServerInternalException;
import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
import com.mojang.serialization.Codec;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.Supplier;
@@ -181,7 +183,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
private org.spigotmc.TickLimiter entityLimiter;
private org.spigotmc.TickLimiter tileLimiter;
private int tileTickPosition;
- public final Map<Explosion.CacheKey, Float> explosionDensityCache = new HashMap<>(); // Paper - Optimize explosions
+ public final Map<Explosion.CacheKey, Float> explosionDensityCache = Maps.newConcurrentMap(); // Paper - Optimize explosions // Leaf - Optimize explosion
public java.util.ArrayDeque<net.minecraft.world.level.block.RedstoneTorchBlock.Toggle> redstoneUpdateInfos; // Paper - Move from Map in BlockRedstoneTorch to here
public final io.papermc.paper.util.math.ThreadUnsafeRandom randomTickRandom = new io.papermc.paper.util.math.ThreadUnsafeRandom(this.random.nextLong()); // Gale - Pufferfish - move random tick random