mirror of
https://github.com/Dreeam-qwq/Gale.git
synced 2025-12-19 14:59:29 +00:00
150 lines
7.7 KiB
Diff
150 lines
7.7 KiB
Diff
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/net/minecraft/world/entity/item/ItemEntity.java b/net/minecraft/world/entity/item/ItemEntity.java
|
|
index 52a7ed0d991758bad0dcedcb7f97fb15ac6c6d04..45c152856c46d11f3bd790a01fac89a7c3b68af1 100644
|
|
--- a/net/minecraft/world/entity/item/ItemEntity.java
|
|
+++ b/net/minecraft/world/entity/item/ItemEntity.java
|
|
@@ -143,7 +143,13 @@ public class ItemEntity extends Entity implements TraceableEntity {
|
|
}
|
|
// CraftBukkit end
|
|
this.discard(org.bukkit.event.entity.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
|
|
}
|
|
// Paper end - EAR 2
|
|
|
|
@@ -227,9 +233,29 @@ public class ItemEntity extends Entity implements TraceableEntity {
|
|
}
|
|
// CraftBukkit end
|
|
this.discard(org.bukkit.event.entity.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 = this.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) {
|
|
+ net.minecraft.world.phys.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 net.minecraft.world.entity.vehicle.MinecartHopper hopper) {
|
|
+ hopper.pickupImmunity = net.minecraft.server.MinecraftServer.currentTick + config.temporaryImmunity.duration;
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
+ // Gale end - EMC - reduce hopper item checks
|
|
|
|
@Override
|
|
public BlockPos getBlockPosBelowThatAffectsMyMovement() {
|
|
diff --git a/net/minecraft/world/entity/vehicle/MinecartHopper.java b/net/minecraft/world/entity/vehicle/MinecartHopper.java
|
|
index 8341e7f01606fca90e69384c16fc19bb9e20d1b7..c5a3dc3e704a9f6d67d9049e49cd1b33b6994766 100644
|
|
--- a/net/minecraft/world/entity/vehicle/MinecartHopper.java
|
|
+++ b/net/minecraft/world/entity/vehicle/MinecartHopper.java
|
|
@@ -21,6 +21,7 @@ import net.minecraft.world.level.block.state.properties.RailShape;
|
|
public class MinecartHopper extends AbstractMinecartContainer implements Hopper {
|
|
private boolean enabled = true;
|
|
private boolean consumedItemThisFrame = false;
|
|
+ public int pickupImmunity = 0; // Gale - EMC - reduce hopper item checks
|
|
|
|
public MinecartHopper(EntityType<? extends MinecartHopper> entityType, Level level) {
|
|
super(entityType, level);
|
|
@@ -149,4 +150,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/net/minecraft/world/level/block/entity/Hopper.java b/net/minecraft/world/level/block/entity/Hopper.java
|
|
index 5f042e294db605827000123252b0df646968f897..e1cc15f28fe8da23b74ff4504c5b2da2236fda3f 100644
|
|
--- a/net/minecraft/world/level/block/entity/Hopper.java
|
|
+++ b/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/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
|
index 5cd1326ad5d046c88b2b3449d610a78fa880b4cd..276cb0dffaa253a6c13b4c68d8c703732118d0d1 100644
|
|
--- a/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
|
+++ b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
|
@@ -540,7 +540,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
|
return false;
|
|
} else {
|
|
boolean flag = hopper.isGridAligned() && blockState.isCollisionShapeFullBlock(level, blockPos) && !blockState.is(BlockTags.DOES_NOT_BLOCK_HOPPERS);
|
|
- if (!flag) {
|
|
+ if (!flag && shouldSuckIn(level, hopper)) { // Gale - EMC - reduce hopper item checks
|
|
for (ItemEntity itemEntity : getItemsAtAndAbove(level, hopper)) {
|
|
if (addItem(hopper, itemEntity)) {
|
|
return true;
|
|
@@ -816,6 +816,31 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
|
return stack1.getCount() < stack1.getMaxStackSize() && ItemStack.isSameItemSameComponents(stack1, stack2); // 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 level, Hopper hopper) {
|
|
+ int suckInterval;
|
|
+ if (hopper instanceof net.minecraft.world.entity.vehicle.MinecartHopper minecartHopper) {
|
|
+ if (minecartHopper.pickupImmunity > net.minecraft.server.MinecraftServer.currentTick) {
|
|
+ return true;
|
|
+ }
|
|
+ suckInterval = level.galeConfig().smallOptimizations.reducedIntervals.checkNearbyItem.hopper.minecart.interval;
|
|
+ } else {
|
|
+ suckInterval = level.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 this.worldPosition.getX() + 0.5;
|