diff --git a/patches/server/0019-Petal-reduce-work-done-by-game-event-system.patch b/patches/server/0019-Petal-reduce-work-done-by-game-event-system.patch new file mode 100644 index 00000000..71e6eeae --- /dev/null +++ b/patches/server/0019-Petal-reduce-work-done-by-game-event-system.patch @@ -0,0 +1,199 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: peaches94 +Date: Sun, 10 Jul 2022 13:29:20 -0500 +Subject: [PATCH] Petal: reduce work done by game event system + +Original license: GPL v3 +Original project: https://github.com/Bloom-host/Petal + +1. going into game event dispatching can be expensive so run the checks before dispatching + +2. EuclideanGameEventListenerRegistry is not used concurrently so we ban that usage for improved performance with allays + +diff --git a/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java +index 370a25d2deb54f10a35ee24d9e7e92fbfde60edf..fe0dfa85d0e2edb7f2c3b3a12bb9aa651e7ea852 100644 +--- a/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java ++++ b/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java +@@ -193,7 +193,7 @@ public abstract class BlockEntity { + return new CompoundTag(); + } + +- public boolean isRemoved() { ++ public static boolean isRemoved() { + return this.remove; + } + +diff --git a/src/main/java/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.java +index a606aed406551f4d3cc0bf09d6e231d87fe00f53..64bb89ff273d73d54dbced93f66a0c73c418adf7 100644 +--- a/src/main/java/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.java ++++ b/src/main/java/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.java +@@ -126,6 +126,13 @@ public class SculkCatalystBlockEntity extends BlockEntity implements GameEventLi + world.playSound((Player) null, pos, SoundEvents.SCULK_CATALYST_BLOOM, SoundSource.BLOCKS, 2.0F, 0.6F + random.nextFloat() * 0.4F); + } + ++ // petal start ++ @Override ++ public boolean listensToEvent(GameEvent gameEvent, GameEvent.Context context) { ++ return !isRemoved() && gameEvent == GameEvent.ENTITY_DIE && context.sourceEntity() instanceof LivingEntity; ++ } ++ // petal end ++ + private void tryAwardItSpreadsAdvancement(Level world, LivingEntity deadEntity) { + LivingEntity entityliving1 = deadEntity.getLastHurtByMob(); + +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 901938201c1abee1c88e217d2c1ba1a2d147420e..e0a90ee2c28dc67e33db8f3b599cfb9cef294553 100644 +--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java ++++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java +@@ -80,7 +80,18 @@ public class LevelChunk extends ChunkAccess { + private Supplier fullStatus; + @Nullable + private LevelChunk.PostLoadProcessor postLoad; +- private final Int2ObjectMap gameEventListenerRegistrySections; ++ // petal start ++ private final GameEventListenerRegistry[] gameEventListenerRegistrySections; ++ private static final int GAME_EVENT_DISPATCHER_RADIUS = 2; ++ ++ private static int getGameEventSectionIndex(int sectionIndex) { ++ return sectionIndex + GAME_EVENT_DISPATCHER_RADIUS; ++ } ++ ++ private static int getGameEventSectionLength(int sectionCount) { ++ return sectionCount + (GAME_EVENT_DISPATCHER_RADIUS * 2); ++ } ++ // petal end + private final LevelChunkTicks blockTicks; + private final LevelChunkTicks fluidTicks; + +@@ -108,7 +119,7 @@ public class LevelChunk extends ChunkAccess { + // Paper end - rewrite light engine + this.tickersInLevel = Maps.newHashMap(); + this.level = (ServerLevel) world; // CraftBukkit - type +- this.gameEventListenerRegistrySections = new Int2ObjectOpenHashMap(); ++ this.gameEventListenerRegistrySections = new GameEventListenerRegistry[getGameEventSectionLength(this.getSectionsCount())]; // petal + Heightmap.Types[] aheightmap_type = Heightmap.Types.values(); + int j = aheightmap_type.length; + +@@ -398,9 +409,23 @@ public class LevelChunk extends ChunkAccess { + if (world instanceof ServerLevel) { + ServerLevel worldserver = (ServerLevel) world; + +- return (GameEventListenerRegistry) this.gameEventListenerRegistrySections.computeIfAbsent(ySectionCoord, (j) -> { +- return new EuclideanGameEventListenerRegistry(worldserver, ySectionCoord, this::removeGameEventListenerRegistry); +- }); ++ // petal start ++ int sectionIndex = getGameEventSectionIndex(this.getSectionIndexFromSectionY(ySectionCoord)); ++ ++ // drop game events that are too far away (32 blocks) from loaded sections ++ // this matches the highest radius of game events in the game ++ if (sectionIndex < 0 || sectionIndex >= this.gameEventListenerRegistrySections.length) { ++ return GameEventListenerRegistry.NOOP; ++ } ++ ++ var dispatcher = this.gameEventListenerRegistrySections[sectionIndex]; ++ ++ if (dispatcher == null) { ++ dispatcher = this.gameEventListenerRegistrySections[sectionIndex] = new EuclideanGameEventListenerRegistry(worldserver, ySectionCoord, this::removeGameEventListenerRegistry); ++ } ++ ++ return dispatcher; ++ // petal end + } else { + return super.getListenerRegistry(ySectionCoord); + } +@@ -774,7 +799,7 @@ public class LevelChunk extends ChunkAccess { + } + + private void removeGameEventListenerRegistry(int ySectionCoord) { +- this.gameEventListenerRegistrySections.remove(ySectionCoord); ++ this.gameEventListenerRegistrySections[getGameEventSectionIndex(this.getSectionIndexFromSectionY(ySectionCoord))] = null; // petal + } + + private void removeBlockEntityTicker(BlockPos pos) { +diff --git a/src/main/java/net/minecraft/world/level/gameevent/EuclideanGameEventListenerRegistry.java b/src/main/java/net/minecraft/world/level/gameevent/EuclideanGameEventListenerRegistry.java +index 48132c44ddc147eea0f751c1fc568388730104c5..9307fbf34e7794c1786e08a2045b1356421f554c 100644 +--- a/src/main/java/net/minecraft/world/level/gameevent/EuclideanGameEventListenerRegistry.java ++++ b/src/main/java/net/minecraft/world/level/gameevent/EuclideanGameEventListenerRegistry.java +@@ -12,8 +12,8 @@ import net.minecraft.world.phys.Vec3; + + public class EuclideanGameEventListenerRegistry implements GameEventListenerRegistry { + private final List listeners = Lists.newArrayList(); +- private final Set listenersToRemove = Sets.newHashSet(); +- private final List listenersToAdd = Lists.newArrayList(); ++ //private final Set listenersToRemove = Sets.newHashSet(); // petal - not necessary ++ //private final List listenersToAdd = Lists.newArrayList(); // petal + private boolean processing; + private final ServerLevel level; + private final int sectionY; +@@ -33,7 +33,7 @@ public class EuclideanGameEventListenerRegistry implements GameEventListenerRegi + @Override + public void register(GameEventListener listener) { + if (this.processing) { +- this.listenersToAdd.add(listener); ++ throw new java.util.ConcurrentModificationException(); // petal - disallow concurrent modification + } else { + this.listeners.add(listener); + } +@@ -44,7 +44,7 @@ public class EuclideanGameEventListenerRegistry implements GameEventListenerRegi + @Override + public void unregister(GameEventListener listener) { + if (this.processing) { +- this.listenersToRemove.add(listener); ++ throw new java.util.ConcurrentModificationException(); // petal - disallow concurrent modification + } else { + this.listeners.remove(listener); + } +@@ -65,7 +65,7 @@ public class EuclideanGameEventListenerRegistry implements GameEventListenerRegi + + while(iterator.hasNext()) { + GameEventListener gameEventListener = iterator.next(); +- if (this.listenersToRemove.remove(gameEventListener)) { ++ if (false) { // petal - disallow concurrent modification + iterator.remove(); + } else { + Optional optional = getPostableListenerPosition(this.level, pos, gameEventListener); +@@ -79,6 +79,8 @@ public class EuclideanGameEventListenerRegistry implements GameEventListenerRegi + this.processing = false; + } + ++ // petal start ++ /* + if (!this.listenersToAdd.isEmpty()) { + this.listeners.addAll(this.listenersToAdd); + this.listenersToAdd.clear(); +@@ -88,6 +90,8 @@ public class EuclideanGameEventListenerRegistry implements GameEventListenerRegi + this.listeners.removeAll(this.listenersToRemove); + this.listenersToRemove.clear(); + } ++ */ ++ // petal end + + return bl; + } +diff --git a/src/main/java/net/minecraft/world/level/gameevent/GameEventDispatcher.java b/src/main/java/net/minecraft/world/level/gameevent/GameEventDispatcher.java +index f2d10d58617644a589ecec3e17358c1277795e5d..ea7b3485e81cd1cb8158a1811b78691bb19635fd 100644 +--- a/src/main/java/net/minecraft/world/level/gameevent/GameEventDispatcher.java ++++ b/src/main/java/net/minecraft/world/level/gameevent/GameEventDispatcher.java +@@ -45,6 +45,7 @@ public class GameEventDispatcher { + int k1 = SectionPos.blockToSectionCoord(blockposition.getZ() + i); + List list = new ArrayList(); + GameEventListenerRegistry.ListenerVisitor gameeventlistenerregistry_a = (gameeventlistener, vec3d1) -> { ++ if (!gameeventlistener.listensToEvent(event, emitter)) return; // petal - if they don't listen, ignore + if (gameeventlistener.getDeliveryMode() == GameEventListener.DeliveryMode.BY_DISTANCE) { + list.add(new GameEvent.ListenerInfo(event, emitterPos, emitter, gameeventlistener, vec3d1)); + } else { +diff --git a/src/main/java/net/minecraft/world/level/gameevent/GameEventListener.java b/src/main/java/net/minecraft/world/level/gameevent/GameEventListener.java +index a4148dd326b10b0eb2bc7884691d79dcda60e010..5859d7af9052a150f5d115bb0e2cbd102374f162 100644 +--- a/src/main/java/net/minecraft/world/level/gameevent/GameEventListener.java ++++ b/src/main/java/net/minecraft/world/level/gameevent/GameEventListener.java +@@ -22,4 +22,10 @@ public interface GameEventListener { + public interface Holder { + T getListener(); + } ++ ++ // petal start - add check for seeing if this listener cares about an event ++ default boolean listensToEvent(GameEvent gameEvent, GameEvent.Context context) { ++ return true; ++ } ++ // petal end + } diff --git a/patches/server/0020-Petal-Reduce-sensor-work.patch b/patches/server/0020-Petal-Reduce-sensor-work.patch new file mode 100644 index 00000000..6c29008c --- /dev/null +++ b/patches/server/0020-Petal-Reduce-sensor-work.patch @@ -0,0 +1,47 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: peaches94 +Date: Sun, 10 Jul 2022 15:44:38 -0500 +Subject: [PATCH] Petal: Reduce sensor work + +Original license: GPL v3 +Original project: https://github.com/Bloom-host/Petal + +this patch is focused around the sensors used for ai +delete the line of sight cache less often and use a faster nearby comparison + +diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java +index 07ab60405dfbef46e74911a750ab0a9d067111c9..ef428fa6ae9897981f1c10f4344ec476d2787c03 100644 +--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java ++++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java +@@ -1024,12 +1024,14 @@ public abstract class LivingEntity extends Entity implements Attackable { + } + + if (entity != null) { +- ItemStack itemstack = this.getItemBySlot(EquipmentSlot.HEAD); ++ // petal start - only do itemstack lookup if we need to ++ //ItemStack itemstack = this.getItemBySlot(EquipmentSlot.HEAD); + EntityType entitytypes = entity.getType(); + +- if (entitytypes == EntityType.SKELETON && itemstack.is(Items.SKELETON_SKULL) || entitytypes == EntityType.ZOMBIE && itemstack.is(Items.ZOMBIE_HEAD) || entitytypes == EntityType.PIGLIN && itemstack.is(Items.PIGLIN_HEAD) || entitytypes == EntityType.PIGLIN_BRUTE && itemstack.is(Items.PIGLIN_HEAD) || entitytypes == EntityType.CREEPER && itemstack.is(Items.CREEPER_HEAD)) { ++ if (entitytypes == EntityType.SKELETON && this.getItemBySlot(EquipmentSlot.HEAD).is(Items.SKELETON_SKULL) || entitytypes == EntityType.ZOMBIE && this.getItemBySlot(EquipmentSlot.HEAD).is(Items.ZOMBIE_HEAD) || entitytypes == EntityType.PIGLIN && this.getItemBySlot(EquipmentSlot.HEAD).is(Items.PIGLIN_HEAD) || entitytypes == EntityType.PIGLIN_BRUTE && this.getItemBySlot(EquipmentSlot.HEAD).is(Items.PIGLIN_HEAD) || entitytypes == EntityType.CREEPER && this.getItemBySlot(EquipmentSlot.HEAD).is(Items.CREEPER_HEAD)) { + d0 *= 0.5D; + } ++ // petal end + } + + return d0; +diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java +index 1674f9accbbbb9ecdd99f05da6032398c4d82b38..7cc725b2f4feb3dcbe2fd0556954ab601fbd6e53 100644 +--- a/src/main/java/net/minecraft/world/entity/Mob.java ++++ b/src/main/java/net/minecraft/world/entity/Mob.java +@@ -902,8 +902,8 @@ public abstract class Mob extends LivingEntity implements Targeting { + return; + } + // Paper end); +- this.sensing.tick(); +- int i = this.level().getServer().getTickCount() + this.getId(); ++ int i = this.level().getServer().getTickCount() + this.getId(); // petal - move up ++ if (i % 10 == 0) this.sensing.tick(); // petal - only refresh line of sight cache every half second + + if (i % 2 != 0 && this.tickCount > 1) { + if (this.targetSelector.inactiveTick(this.activatedPriority, false)) // Pufferfish - use this to alternate ticking diff --git a/patches/server/0019-Akarin-Save-Json-list-asynchronously.patch b/patches/server/0021-Akarin-Save-Json-list-asynchronously.patch similarity index 100% rename from patches/server/0019-Akarin-Save-Json-list-asynchronously.patch rename to patches/server/0021-Akarin-Save-Json-list-asynchronously.patch diff --git a/patches/server/0020-Slice-Smooth-Teleports.patch b/patches/server/0022-Slice-Smooth-Teleports.patch similarity index 100% rename from patches/server/0020-Slice-Smooth-Teleports.patch rename to patches/server/0022-Slice-Smooth-Teleports.patch diff --git a/patches/server/0021-PaperPR-Optimize-VarInts.patch b/patches/server/0023-PaperPR-Optimize-VarInts.patch similarity index 100% rename from patches/server/0021-PaperPR-Optimize-VarInts.patch rename to patches/server/0023-PaperPR-Optimize-VarInts.patch diff --git a/patches/server/0022-Parchment-Make-FixLight-use-action-bar.patch b/patches/server/0024-Parchment-Make-FixLight-use-action-bar.patch similarity index 100% rename from patches/server/0022-Parchment-Make-FixLight-use-action-bar.patch rename to patches/server/0024-Parchment-Make-FixLight-use-action-bar.patch diff --git a/patches/server/0023-Leaves-Server-Utils.patch b/patches/server/0025-Leaves-Server-Utils.patch similarity index 99% rename from patches/server/0023-Leaves-Server-Utils.patch rename to patches/server/0025-Leaves-Server-Utils.patch index df4d4139..8c5efb2e 100644 --- a/patches/server/0023-Leaves-Server-Utils.patch +++ b/patches/server/0025-Leaves-Server-Utils.patch @@ -33,7 +33,7 @@ index 46954db7ecd35ac4018fdf476df7c8020d7ce6c8..044c51ebb058fc36074fd178929e3279 public PlayerAreaMap() { super(); diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java -index c6069b70d188a45950be27f9f6c63c8218dea7fa..09332e82647df95f3bdcfb998bff98e8ecfccb90 100644 +index 7652900f88fe778c3855536e8744445704a1f8b1..b34be55f820834ea973a1a007bc8c897d4331db8 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java @@ -407,6 +407,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource { diff --git a/patches/server/0024-Leaves-Jade-Protocol.patch b/patches/server/0026-Leaves-Jade-Protocol.patch similarity index 100% rename from patches/server/0024-Leaves-Jade-Protocol.patch rename to patches/server/0026-Leaves-Jade-Protocol.patch diff --git a/patches/server/0025-Leaves-Appleskin-Protocol.patch b/patches/server/0027-Leaves-Appleskin-Protocol.patch similarity index 100% rename from patches/server/0025-Leaves-Appleskin-Protocol.patch rename to patches/server/0027-Leaves-Appleskin-Protocol.patch diff --git a/patches/server/0026-Leaves-Xaero-Map-Protocol.patch b/patches/server/0028-Leaves-Xaero-Map-Protocol.patch similarity index 97% rename from patches/server/0026-Leaves-Xaero-Map-Protocol.patch rename to patches/server/0028-Leaves-Xaero-Map-Protocol.patch index 85275fc1..cb61a5c7 100644 --- a/patches/server/0026-Leaves-Xaero-Map-Protocol.patch +++ b/patches/server/0028-Leaves-Xaero-Map-Protocol.patch @@ -7,7 +7,7 @@ Original license: GPLv3 Original project: https://github.com/LeavesMC/Leaves diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java -index 72674746a0aa20d79d634c7ac121396c6f1f8268..8534591585dc9b78e936b8fb0f1b26da2fb584b8 100644 +index adba36bcf51617264f1666fecae718ff3b0b87db..404cf159f50134420f85a90cb2a52e777d54b50c 100644 --- a/src/main/java/net/minecraft/server/players/PlayerList.java +++ b/src/main/java/net/minecraft/server/players/PlayerList.java @@ -1315,6 +1315,7 @@ public abstract class PlayerList { diff --git a/patches/server/0027-Fix-Make-log4j-compatible-with-future-release.patch b/patches/server/0029-Fix-Make-log4j-compatible-with-future-release.patch similarity index 90% rename from patches/server/0027-Fix-Make-log4j-compatible-with-future-release.patch rename to patches/server/0029-Fix-Make-log4j-compatible-with-future-release.patch index 50b393a5..2fedf981 100644 --- a/patches/server/0027-Fix-Make-log4j-compatible-with-future-release.patch +++ b/patches/server/0029-Fix-Make-log4j-compatible-with-future-release.patch @@ -6,7 +6,7 @@ Subject: [PATCH] Fix: Make log4j compatible with future release This patch fixes the warnning "WARN StatusConsoleListener The use of package scanning to locate plugins is deprecated and will be removed in a future release" during server launching. diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml -index 74ccc67e3c12dc5182602fb691ef3ddeb5b53280..9804bcae3439aaf9a9d477f9ab2494caa899ec1e 100644 +index 675cd61221e807aadf28322b46c3daa1370241b5..062b62232e9769cdab57b498636ac171ff4f673b 100644 --- a/src/main/resources/log4j2.xml +++ b/src/main/resources/log4j2.xml @@ -1,5 +1,5 @@ diff --git a/patches/server/0028-Fix-compile-error.patch b/patches/server/0030-Fix-compile-error.patch similarity index 100% rename from patches/server/0028-Fix-compile-error.patch rename to patches/server/0030-Fix-compile-error.patch