9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-21 16:09:19 +00:00
Files
Leaf/patches/unapplied/server/0044-Optimize-item-updates-in-fluid-check.patch
2024-01-19 17:28:22 -05:00

94 lines
4.8 KiB
Diff

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..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 {
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 && this instanceof ItemEntity) {
+ ItemEntity.checkInLiquid(this);
+ if (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 7fce419490b39409f876914ce306f77d11e659b7..2e15896df321c076cf1c3ef78e67cea9188e9ddb 100644
--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
@@ -130,6 +130,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.optimizeItemsInFluidUpdateInterval == 0) {
+ isInLiquid = e.isInLiquid();
+ }
+ }
+ // Leaf end
+
@Override
public void tick() {
if (this.getItem().isEmpty()) {
@@ -202,7 +211,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..82e51da38a66826feb58fd28b39858ef91ddf7ab 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 optimizeItemsInFluidUpdateInterval = 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);
+ optimizeItemsInFluidUpdateInterval = getInt("performance.optimize-items-in-fluid-update.interval", optimizeItemsInFluidUpdateInterval);
+
}
public static boolean jadeProtocol = false;