9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-26 02:19:19 +00:00
This commit is contained in:
Dreeam
2024-01-17 06:10:27 -05:00
parent 2053ad6fc3
commit 92078d29b4
2 changed files with 17 additions and 20 deletions

View File

@@ -1,19 +1,19 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Mon, 15 Jan 2024 10:53:10 -0500
Subject: [PATCH] Reduce item checks for finding MinecartHopper
Subject: [PATCH] Reduce items finding hopper nearby check
This patch add a toggle for checking MinecraftHopper nearby items,
This patch add a toggle for items checking MinecraftHopper nearby,
and add a time throttler and MinecraftHopper pre-cehck for items checking
But still recommend to turn-off `checkForMinecartNearItemWhileInactive`
But still recommend to turn-off `checkForMinecartNearItemWhileActive`
Since `Reduce-hopper-item-checks.patch` will cause lag under massive dropped items
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 0fe02df86483809cef22fca2e2ce0af7b4a5c6d5..d6ab766ae4affb26cb8a26da113d3e70bd4b402b 100644
index 0fe02df86483809cef22fca2e2ce0af7b4a5c6d5..7fce419490b39409f876914ce306f77d11e659b7 100644
--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
@@ -1,9 +1,12 @@
@@ -1,7 +1,9 @@
package net.minecraft.world.entity.item;
+import java.util.HashMap;
@@ -22,34 +22,31 @@ index 0fe02df86483809cef22fca2e2ce0af7b4a5c6d5..d6ab766ae4affb26cb8a26da113d3e70
+import java.util.Map;
import java.util.Objects;
import java.util.UUID;
+import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import net.minecraft.tags.DamageTypeTags;
import net.minecraft.tags.FluidTags;
@@ -219,7 +222,9 @@ public class ItemEntity extends Entity implements TraceableEntity {
@@ -219,7 +221,9 @@ public class ItemEntity extends Entity implements TraceableEntity {
this.discard();
return; // Gale - EMC - reduce hopper item checks
}
- this.markNearbyHopperCartsAsImmune(); // Gale - EMC - reduce hopper item checks
+ if (level().galeConfig().smallOptimizations.reducedIntervals.checkNearbyItem.hopper.minecart.temporaryImmunity.checkForMinecartNearItemWhileActive) {
+ if (level().galeConfig().smallOptimizations.reducedIntervals.checkNearbyItem.hopper.minecart.temporaryImmunity.checkForMinecartNearItemWhileActive) { // Leaf - Reduce items finding hopper nearby check
+ this.markNearbyHopperCartsAsImmune(); // Gale - EMC - reduce hopper item checks
+ }
}
}
@@ -231,17 +236,53 @@ public class ItemEntity extends Entity implements TraceableEntity {
@@ -231,17 +235,53 @@ public class ItemEntity extends Entity implements TraceableEntity {
if (config.interval <= 1) {
return;
}
+
+ // Leaf start - Reduce item checks for finding MinecartHopper
+ // Leaf start - Reduce items finding hopper nearby check
+ BlockPos pos = new BlockPos(this.getBlockX(), this.getBlockY(), this.getBlockZ());
+ if (this.shouldCheckItem(pos)) {
+ cachedResults.putIfAbsent(pos, true);
+
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);
+ if (this.level().getEntities(this, aabb).stream().noneMatch(entity -> entity instanceof MinecartHopper)) {// Leaf TODO - getEntities still take a lot of TPS
+ if (this.level().getEntities(this, aabb).stream().noneMatch(entity -> entity instanceof MinecartHopper)) {
+ return;
+ }
+
@@ -63,7 +60,7 @@ index 0fe02df86483809cef22fca2e2ce0af7b4a5c6d5..d6ab766ae4affb26cb8a26da113d3e70
}
// Gale end - EMC - reduce hopper item checks
+ // Leaf start - Reduce item checks for finding MinecartHopper
+ // Leaf start - Reduce items finding hopper nearby check
+ private Map<BlockPos, Boolean> cachedResults = new HashMap<>();
+ private long startTime = System.nanoTime();
+

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Optimize item updates in fluid check
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 3cf07a2d82ec9f0d6666fb27aee9acc9d9823ead..813a02601110245161ae157f4054512d6f117cd9 100644
index 3cf07a2d82ec9f0d6666fb27aee9acc9d9823ead..3aa0ad4fad1b44817f484cce13642ed7d3f3a4c6 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -864,9 +864,20 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
@@ -16,9 +16,9 @@ index 3cf07a2d82ec9f0d6666fb27aee9acc9d9823ead..813a02601110245161ae157f4054512d
- this.updateFluidOnEyes();
- this.updateSwimming();
+ // Leaf start - Optimize item updates in fluid check
+ if (org.dreeam.leaf.LeafConfig.optimizeItemsInFluidUpdateEnabled) {
+ if (org.dreeam.leaf.LeafConfig.optimizeItemsInFluidUpdateEnabled && this instanceof ItemEntity) {
+ ItemEntity.checkInLiquid(this);
+ if (this instanceof ItemEntity && ItemEntity.isInLiquid) {
+ if (ItemEntity.isInLiquid) {
+ this.updateInWaterStateAndDoFluidPushing();
+ this.updateFluidOnEyes();
+ this.updateSwimming();
@@ -33,10 +33,10 @@ index 3cf07a2d82ec9f0d6666fb27aee9acc9d9823ead..813a02601110245161ae157f4054512d
this.clearFire();
} else if (this.remainingFireTicks > 0) {
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 d6ab766ae4affb26cb8a26da113d3e70bd4b402b..d521b44325c202f9671f0b7a34aafe112cf7edbc 100644
index 7fce419490b39409f876914ce306f77d11e659b7..065f63825627466ddd59bc68edfa72cd2ceef1c7 100644
--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
@@ -131,6 +131,15 @@ public class ItemEntity extends Entity implements TraceableEntity {
@@ -130,6 +130,15 @@ public class ItemEntity extends Entity implements TraceableEntity {
this.getEntityData().define(ItemEntity.DATA_ITEM, ItemStack.EMPTY);
}
@@ -52,7 +52,7 @@ index d6ab766ae4affb26cb8a26da113d3e70bd4b402b..d521b44325c202f9671f0b7a34aafe11
@Override
public void tick() {
if (this.getItem().isEmpty()) {
@@ -203,7 +212,14 @@ public class ItemEntity extends Entity implements TraceableEntity {
@@ -202,7 +211,14 @@ public class ItemEntity extends Entity implements TraceableEntity {
}
// CraftBukkit end */