mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-26 10:29:13 +00:00
Make checkNearbyItem for MinecraftHopper configurable & Optimize items for fluid update check
This commit is contained in:
@@ -5,7 +5,7 @@ Subject: [PATCH] Fix sprint glitch
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
index d811a2456b7c2b8c4766f4b7943eeb438e88e3fd..1a9eb22266c83a6fb49f53f34190d661fa0be53a 100644
|
||||
index d811a2456b7c2b8c4766f4b7943eeb438e88e3fd..b648f7054bc649c0f166f846d3b3f33b0b0a13ee 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
@@ -1430,7 +1430,8 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
||||
@@ -13,8 +13,8 @@ index d811a2456b7c2b8c4766f4b7943eeb438e88e3fd..1a9eb22266c83a6fb49f53f34190d661
|
||||
}
|
||||
|
||||
- player.updateScaledHealth(false);
|
||||
+ this.entityData.set(LivingEntity.DATA_HEALTH_ID, player.getScaledHealth()); // Sprint glitch Fix by pafias
|
||||
+ // player.updateScaledHealth(false); // Commented out to fix sprint glitch
|
||||
+ this.entityData.set(LivingEntity.DATA_HEALTH_ID, player.getScaledHealth()); // Leaf - Sprint glitch Fix by pafias
|
||||
+ //player.updateScaledHealth(false); // Leaf - Commented out to fix sprint glitch
|
||||
return;
|
||||
}
|
||||
// CraftBukkit end
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
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
|
||||
|
||||
This patch add a toggle for checking MinecraftHopper nearby items,
|
||||
and add a time throttler and MinecraftHopper pre-cehck for items checking
|
||||
|
||||
But still recommend to turn-off `checkForMinecartNearItemWhileInactive`
|
||||
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
|
||||
--- 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 @@
|
||||
package net.minecraft.world.entity.item;
|
||||
|
||||
+import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
+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 {
|
||||
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) {
|
||||
+ this.markNearbyHopperCartsAsImmune(); // Gale - EMC - reduce hopper item checks
|
||||
+ }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -231,17 +236,53 @@ public class ItemEntity extends Entity implements TraceableEntity {
|
||||
if (config.interval <= 1) {
|
||||
return;
|
||||
}
|
||||
+
|
||||
+ // Leaf start - Reduce item checks for finding MinecartHopper
|
||||
+ 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
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
for (Entity entity : this.level().getEntities(this, aabb)) {
|
||||
if (entity instanceof MinecartHopper) {
|
||||
((MinecartHopper) entity).pickupImmunity = MinecraftServer.currentTick + config.temporaryImmunity.duration;
|
||||
}
|
||||
}
|
||||
}
|
||||
+ }// Leaf end
|
||||
}
|
||||
// Gale end - EMC - reduce hopper item checks
|
||||
|
||||
+ // Leaf start - Reduce item checks for finding MinecartHopper
|
||||
+ private Map<BlockPos, Boolean> cachedResults = new HashMap<>();
|
||||
+ private long startTime = System.nanoTime();
|
||||
+
|
||||
+ private boolean shouldCheckItem(BlockPos pos) {
|
||||
+ long now = System.nanoTime();
|
||||
+ long timeElapsed = (now - startTime) / 1000000L;
|
||||
+
|
||||
+ // Throttle
|
||||
+ if (timeElapsed < 20000L) {
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ // Check in cache
|
||||
+ if (cachedResults.containsKey(pos)) {
|
||||
+ return cachedResults.get(pos);
|
||||
+ }
|
||||
+
|
||||
+ // Reset timer
|
||||
+ startTime = now;
|
||||
+
|
||||
+ return true;
|
||||
+ }
|
||||
+ // Leaf end
|
||||
+
|
||||
// Spigot start - copied from above
|
||||
@Override
|
||||
public void inactiveTick() {
|
||||
diff --git a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
|
||||
index 1b1bf657993c2a96d7168e3b1161872839a6e67a..32e4fda2807aa68ba07e2c40881a451848bebd77 100644
|
||||
--- a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
|
||||
+++ b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
|
||||
@@ -76,10 +76,11 @@ public class GaleWorldConfiguration extends ConfigurationPart {
|
||||
|
||||
public TemporaryImmunity temporaryImmunity;
|
||||
public class TemporaryImmunity extends ConfigurationPart {
|
||||
+ public boolean checkForMinecartNearItemWhileActive = false; // Leaf - Make it configurable and reorder code
|
||||
+ public boolean checkForMinecartNearItemWhileInactive = true;
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
||||
Date: Mon, 15 Jan 2024 23:02:33 -0500
|
||||
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
|
||||
--- 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 {
|
||||
|
||||
this.wasInPowderSnow = this.isInPowderSnow;
|
||||
this.isInPowderSnow = false;
|
||||
- this.updateInWaterStateAndDoFluidPushing();
|
||||
- this.updateFluidOnEyes();
|
||||
- this.updateSwimming();
|
||||
+ // Leaf start - Optimize item updates in fluid check
|
||||
+ if (org.dreeam.leaf.LeafConfig.optimizeItemsInFluidUpdateEnabled) {
|
||||
+ ItemEntity.checkInLiquid(this);
|
||||
+ if (this instanceof ItemEntity && ItemEntity.isInLiquid) {
|
||||
+ this.updateInWaterStateAndDoFluidPushing();
|
||||
+ this.updateFluidOnEyes();
|
||||
+ this.updateSwimming();
|
||||
+ }
|
||||
+ } else {
|
||||
+ this.updateInWaterStateAndDoFluidPushing();
|
||||
+ this.updateFluidOnEyes();
|
||||
+ this.updateSwimming();
|
||||
+ }
|
||||
+ // Leaf end
|
||||
if (this.level().isClientSide) {
|
||||
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
|
||||
--- 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 {
|
||||
this.getEntityData().define(ItemEntity.DATA_ITEM, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
+ // Leaf start - Optimize item updates in fluid check
|
||||
+ public static boolean isInLiquid = false;
|
||||
+ public static void checkInLiquid(Entity e) {
|
||||
+ if (e.tickCount % org.dreeam.leaf.LeafConfig.optimizeItemsInFluidUpdateTickCount == 0) {
|
||||
+ isInLiquid = e.isInLiquid();
|
||||
+ }
|
||||
+ }
|
||||
+ // Leaf end
|
||||
+
|
||||
@Override
|
||||
public void tick() {
|
||||
if (this.getItem().isEmpty()) {
|
||||
@@ -203,7 +212,14 @@ public class ItemEntity extends Entity implements TraceableEntity {
|
||||
}
|
||||
// CraftBukkit end */
|
||||
|
||||
- this.hasImpulse |= this.updateInWaterStateAndDoFluidPushing();
|
||||
+ // Leaf - Optimize item updates in fluid check
|
||||
+ if (org.dreeam.leaf.LeafConfig.optimizeItemsInFluidUpdateEnabled) {
|
||||
+ checkInLiquid(this);
|
||||
+ if (isInLiquid) this.hasImpulse |= this.updateInWaterStateAndDoFluidPushing();
|
||||
+ } else {
|
||||
+ this.hasImpulse |= this.updateInWaterStateAndDoFluidPushing();
|
||||
+ }
|
||||
+ // Leaf end
|
||||
if (!this.level().isClientSide) {
|
||||
double d0 = this.getDeltaMovement().subtract(vec3d).lengthSqr();
|
||||
|
||||
diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
index 53bde816ca9bf8b704fb2e9794de260a9eba402f..98723f55a5557f10b75a299c586bf2caf31887f3 100644
|
||||
--- a/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
+++ b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
@@ -202,6 +202,8 @@ public class LeafConfig {
|
||||
public static int asyncPathfindingMaxThreads = 0;
|
||||
public static int asyncPathfindingKeepalive = 60;
|
||||
public static boolean cacheMinecartCollision = false;
|
||||
+ public static boolean optimizeItemsInFluidUpdateEnabled = false;
|
||||
+ public static int optimizeItemsInFluidUpdateTickCount = 20;
|
||||
private static void performance() {
|
||||
boolean asyncMobSpawning = getBoolean("performance.enable-async-mob-spawning", enableAsyncMobSpawning,
|
||||
"Whether or not asynchronous mob spawning should be enabled.",
|
||||
@@ -265,6 +267,9 @@ public class LeafConfig {
|
||||
cacheMinecartCollision = getBoolean("performance.cache-minecart-collision", cacheMinecartCollision,
|
||||
"Cache the minecart collision result to prevent massive stacked minecart lag the server.",
|
||||
"The known issue: entity can't enter the minecart after enabling this!");
|
||||
+ optimizeItemsInFluidUpdateEnabled = getBoolean("performance.optimize-items-in-fluid-update.enabled", optimizeItemsInFluidUpdateEnabled);
|
||||
+ optimizeItemsInFluidUpdateTickCount = getInt("performance.optimize-items-in-fluid-update.tick-count", optimizeItemsInFluidUpdateTickCount);
|
||||
+
|
||||
}
|
||||
|
||||
public static boolean jadeProtocol = false;
|
||||
Reference in New Issue
Block a user