mirror of
https://github.com/Dreeam-qwq/Gale.git
synced 2025-12-22 08:19:31 +00:00
Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@681c013 Bundle spark (#11093) PaperMC/Paper@5fee9c6 Move configuration option to a system property PaperMC/Paper@aa3b356 Improve server startup logging (#11110) PaperMC/Paper@9aea240 Properly lookup plugin classes when looked up by spark PaperMC/Paper@7e91a2c Update the bundled spark version
This commit is contained in:
224
patches/server/0040-Reduce-hopper-item-checks.patch
Normal file
224
patches/server/0040-Reduce-hopper-item-checks.patch
Normal file
@@ -0,0 +1,224 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Martijn Muijsers <martijnmuijsers@live.nl>
|
||||
Date: Thu, 24 Nov 2022 23:03:52 +0100
|
||||
Subject: [PATCH] Reduce hopper item checks
|
||||
|
||||
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
|
||||
Gale - https://galemc.org
|
||||
|
||||
This patch is based on the following patch:
|
||||
"Improve Hopper Performance"
|
||||
By: Aikar <aikar@aikar.co>
|
||||
As part of: EmpireCraft (https://github.com/starlis/empirecraft)
|
||||
Licensed under: MIT (https://opensource.org/licenses/MIT)
|
||||
|
||||
* EmpireCraft description *
|
||||
|
||||
Only do an item "suck in" action once per second
|
||||
|
||||
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 ea0d9335446b20073b9aafb9de453097355db79c..c1bb44fd92ee4f3b900f29e3f9069841ca19fa5d 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
|
||||
@@ -22,12 +22,14 @@ import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.MoverType;
|
||||
import net.minecraft.world.entity.SlotAccess;
|
||||
import net.minecraft.world.entity.TraceableEntity;
|
||||
+import net.minecraft.world.entity.vehicle.MinecartHopper;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.gameevent.GameEvent;
|
||||
import net.minecraft.world.level.portal.DimensionTransition;
|
||||
+import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
// CraftBukkit start
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@@ -235,11 +237,31 @@ public class ItemEntity extends Entity implements TraceableEntity {
|
||||
}
|
||||
// CraftBukkit end
|
||||
this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
|
||||
+ return; // Gale - EMC - reduce hopper item checks
|
||||
}
|
||||
+ this.markNearbyHopperCartsAsImmune(); // Gale - EMC - reduce hopper item checks
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+ // Gale start - EMC - reduce hopper item checks
|
||||
+ private void markNearbyHopperCartsAsImmune() {
|
||||
+ var config = level().galeConfig().smallOptimizations.reducedIntervals.checkNearbyItem.hopper.minecart;
|
||||
+ // No need to mark hopper minecarts as immune if they can pull every tick anyway
|
||||
+ if (config.interval <= 1) {
|
||||
+ return;
|
||||
+ }
|
||||
+ if (config.temporaryImmunity.duration > 0 && this.isAlive() && this.onGround && !this.isRemoved() && (config.temporaryImmunity.nearbyItemMaxAge == -1 || this.age <= config.temporaryImmunity.nearbyItemMaxAge) && this.age % Math.max(1, config.temporaryImmunity.checkForMinecartNearItemInterval) == 0 && config.temporaryImmunity.maxItemHorizontalDistance >= 0 && config.temporaryImmunity.maxItemVerticalDistance >= 0) {
|
||||
+ AABB aabb = this.getBoundingBox().inflate(config.temporaryImmunity.maxItemHorizontalDistance, config.temporaryImmunity.maxItemVerticalDistance, config.temporaryImmunity.maxItemHorizontalDistance);
|
||||
+ for (Entity entity : this.level().getEntities(this, aabb)) {
|
||||
+ if (entity instanceof MinecartHopper) {
|
||||
+ ((MinecartHopper) entity).pickupImmunity = MinecraftServer.currentTick + config.temporaryImmunity.duration;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ // Gale end - EMC - reduce hopper item checks
|
||||
+
|
||||
// Spigot start - copied from above
|
||||
@Override
|
||||
public void inactiveTick() {
|
||||
@@ -259,7 +281,13 @@ public class ItemEntity extends Entity implements TraceableEntity {
|
||||
}
|
||||
// CraftBukkit end
|
||||
this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
|
||||
+ return; // Gale - EMC - reduce hopper item checks
|
||||
+ }
|
||||
+ // Gale start - EMC - reduce hopper item checks
|
||||
+ if (level().galeConfig().smallOptimizations.reducedIntervals.checkNearbyItem.hopper.minecart.temporaryImmunity.checkForMinecartNearItemWhileInactive) {
|
||||
+ this.markNearbyHopperCartsAsImmune();
|
||||
}
|
||||
+ // Gale end - EMC - reduce hopper item checks
|
||||
}
|
||||
// Spigot end
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/vehicle/MinecartHopper.java b/src/main/java/net/minecraft/world/entity/vehicle/MinecartHopper.java
|
||||
index d7f8464bf3eed0e42a5fc7f14a5b243d171f8b5e..7b69243130829334c1a592026adf8fce3609f25c 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/vehicle/MinecartHopper.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/vehicle/MinecartHopper.java
|
||||
@@ -17,6 +17,7 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class MinecartHopper extends AbstractMinecartContainer implements Hopper {
|
||||
private boolean enabled = true;
|
||||
+ public int pickupImmunity = 0; // Gale - EMC - reduce hopper item checks
|
||||
|
||||
public MinecartHopper(EntityType<? extends MinecartHopper> type, Level world) {
|
||||
super(type, world);
|
||||
@@ -136,4 +137,12 @@ public class MinecartHopper extends AbstractMinecartContainer implements Hopper
|
||||
}
|
||||
// Paper end
|
||||
|
||||
+ // Gale start - EMC - reduce hopper item checks
|
||||
+ private long tickAttempts = 0;
|
||||
+ @Override
|
||||
+ public long getAndIncrementAttemptCounter() {
|
||||
+ return tickAttempts++;
|
||||
+ }
|
||||
+ // Gale end EMC - - reduce hopper item checks
|
||||
+
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/entity/Hopper.java b/src/main/java/net/minecraft/world/level/block/entity/Hopper.java
|
||||
index 5f042e294db605827000123252b0df646968f897..e1cc15f28fe8da23b74ff4504c5b2da2236fda3f 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/entity/Hopper.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/entity/Hopper.java
|
||||
@@ -11,6 +11,8 @@ public interface Hopper extends Container {
|
||||
return SUCK_AABB;
|
||||
}
|
||||
|
||||
+ long getAndIncrementAttemptCounter(); // Gale - EMC - reduce hopper item checks
|
||||
+
|
||||
double getLevelX();
|
||||
|
||||
double getLevelY();
|
||||
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 415ad627084c35b4c022cff3ce782e2265a78759..a7c7065d3b2016f6e2720e8cd8a0f47ddf7c30e6 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
|
||||
@@ -11,6 +11,7 @@ import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
+import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.CompoundContainer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.ContainerHelper;
|
||||
@@ -20,6 +21,7 @@ import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntitySelector;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
+import net.minecraft.world.entity.vehicle.MinecartHopper;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.HopperMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
@@ -590,7 +592,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
||||
} else {
|
||||
boolean flag = hopper.isGridAligned() && iblockdata.isCollisionShapeFullBlock(world, blockposition) && !iblockdata.is(BlockTags.DOES_NOT_BLOCK_HOPPERS);
|
||||
|
||||
- if (!flag) {
|
||||
+ if (!flag && shouldSuckIn(world, hopper)) { // Gale - EMC - reduce hopper item checks
|
||||
Iterator iterator = HopperBlockEntity.getItemsAtAndAbove(world, hopper).iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
@@ -900,6 +902,31 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
||||
return first.getCount() < first.getMaxStackSize() && ItemStack.isSameItemSameComponents(first, second); // Paper - Perf: Optimize Hoppers; used to return true for full itemstacks?!
|
||||
}
|
||||
|
||||
+ // Gale start - EMC - reduce hopper item checks
|
||||
+ private long tickAttempts = 0;
|
||||
+ @Override
|
||||
+ public long getAndIncrementAttemptCounter() {
|
||||
+ return tickAttempts++;
|
||||
+ }
|
||||
+ private static boolean shouldSuckIn(Level world, Hopper hopper) {
|
||||
+ int suckInterval;
|
||||
+ if (hopper instanceof MinecartHopper minecartHopper) {
|
||||
+ if (minecartHopper.pickupImmunity > MinecraftServer.currentTick) {
|
||||
+ return true;
|
||||
+ }
|
||||
+ suckInterval = world.galeConfig().smallOptimizations.reducedIntervals.checkNearbyItem.hopper.minecart.interval;
|
||||
+ } else {
|
||||
+ suckInterval = world.galeConfig().smallOptimizations.reducedIntervals.checkNearbyItem.hopper.interval;
|
||||
+ }
|
||||
+ if (suckInterval <= 1) {
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ final int hopperId = (int) hopper.getLevelX() + (int) hopper.getLevelY() + (int) hopper.getLevelZ();
|
||||
+ return (hopper.getAndIncrementAttemptCounter() + hopperId) % suckInterval == 0;
|
||||
+ }
|
||||
+ // Gale end - EMC - reduce hopper item checks
|
||||
+
|
||||
@Override
|
||||
public double getLevelX() {
|
||||
return (double) this.worldPosition.getX() + 0.5D;
|
||||
diff --git a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
|
||||
index 00a327bd0e4e0f2def0bb29d5ecff4f0ec4ba1eb..c869a559b67ecdfb8f9617e1f54fb9c28bb3c766 100644
|
||||
--- a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
|
||||
+++ b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
|
||||
@@ -57,6 +57,37 @@ public class GaleWorldConfiguration extends ConfigurationPart {
|
||||
public int acquirePoiForStuckEntity = 60; // Gale - Airplane - reduce acquire POI for stuck entities
|
||||
public int checkStuckInWall = 10; // Gale - Pufferfish - reduce in wall checks
|
||||
|
||||
+ public CheckNearbyItem checkNearbyItem;
|
||||
+ public class CheckNearbyItem extends ConfigurationPart {
|
||||
+
|
||||
+ // Gale start - EMC - reduce hopper item checks
|
||||
+ public Hopper hopper;
|
||||
+ public class Hopper extends ConfigurationPart {
|
||||
+
|
||||
+ public int interval = 20;
|
||||
+
|
||||
+ public Minecart minecart;
|
||||
+ public class Minecart extends ConfigurationPart {
|
||||
+
|
||||
+ public int interval = 20;
|
||||
+
|
||||
+ public TemporaryImmunity temporaryImmunity;
|
||||
+ public class TemporaryImmunity extends ConfigurationPart {
|
||||
+ public int duration = 100;
|
||||
+ public int nearbyItemMaxAge = 1200;
|
||||
+ public int checkForMinecartNearItemInterval = 20;
|
||||
+ public boolean checkForMinecartNearItemWhileInactive = true;
|
||||
+ public double maxItemHorizontalDistance = 24.0;
|
||||
+ public double maxItemVerticalDistance = 4.0;
|
||||
+ }
|
||||
+
|
||||
+ }
|
||||
+
|
||||
+ }
|
||||
+ // Gale end - EMC - reduce hopper item checks
|
||||
+
|
||||
+ }
|
||||
+
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user