9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0288-optimize-entity-in-fluid.patch
Dreeam 35ac5d48ed Cleanup PWT (#533)
* Unify comment format
* More configurable
* Remove one extra execute mid-tick task call in level tick when PWT is disabled

This may cause extremely rare, weird, strange, magic, mysterious issues with plugins, or potentially more.

One example is that it may cause boss mob duplication issue when `ONE MOB ONLY` was enabled in plugin SupremeBosses
2025-10-25 07:41:43 -04:00

61 lines
3.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: hayanesuru <hayanesuru@outlook.jp>
Date: Sat, 9 Aug 2025 15:44:06 +0900
Subject: [PATCH] optimize entity in fluid
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index ecfd852e64ffdb9e5eaebe7b1eeef4e99dda3b15..4689764a580d7dca468cdfa2b0fef7e70c57687f 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -4860,12 +4860,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
final int minChunkZ = minBlockZ >> 4;
final int maxChunkZ = maxBlockZ >> 4;
- final net.minecraft.world.level.chunk.ChunkSource chunkSource = world.getChunkSource();
+ final net.minecraft.server.level.ServerChunkCache chunkSource = ((ServerLevel) world).chunkSource; // Leaf - optimize entity in fluid
for (int currChunkZ = minChunkZ; currChunkZ <= maxChunkZ; ++currChunkZ) {
for (int currChunkX = minChunkX; currChunkX <= maxChunkX; ++currChunkX) {
// Leaf start - Prevent double chunk retrieving in entity fluid pushing check and fluid height updating
- final net.minecraft.world.level.chunk.ChunkAccess chunk = chunkSource.getChunk(currChunkX, currChunkZ, net.minecraft.world.level.chunk.status.ChunkStatus.FULL, false);
+ final net.minecraft.world.level.chunk.LevelChunk chunk = chunkSource.fullChunksNonSync.get(ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkKey(currChunkX, currChunkZ)); // Leaf - optimize entity in fluid
if (chunk == null) continue;
final net.minecraft.world.level.chunk.LevelChunkSection[] sections = chunk.getSections();
// Leaf end - Prevent double chunk retrieving in entity fluid pushing check and fluid height updating
@@ -4877,7 +4877,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
continue;
}
final net.minecraft.world.level.chunk.LevelChunkSection section = sections[sectionIdx];
- if (section.hasOnlyAir()) {
+ if (section.hasOnlyAir() || (fluid == FluidTags.WATER && section.waterFluidCount == 0) || (fluid == FluidTags.LAVA && section.lavaFluidCount == 0)) { // Leaf - optimize entity in fluid
// empty
continue;
}
@@ -4934,7 +4934,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
this.fluidHeight.put(fluid, maxHeightDiff);
- if (pushVector.lengthSqr() == 0.0) {
+ if (pushVector == Vec3.ZERO || pushVector.lengthSqr() == 0.0) { // Leaf - optimize entity in fluid
return inFluid;
}
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
index 4277c798ceee0ca329d332f8d1354dde312f0c29..efbad651cd6fa1ea73265761f8e91f84c07316d5 100644
--- a/net/minecraft/world/entity/LivingEntity.java
+++ b/net/minecraft/world/entity/LivingEntity.java
@@ -3091,7 +3091,11 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
}
public void travel(Vec3 travelVector) {
- FluidState fluidState = this.level().getFluidState(this.blockPosition());
+ // Leaf start - optimize entity in fluid
+ BlockPos blockPos = this.blockPosition();
+ FluidState fluidState = this.level().getFluidStateIfLoadedUnchecked(blockPos.getX(), blockPos.getY(), blockPos.getZ());
+ if (fluidState == null) { this.level().getFluidState(blockPos); }
+ // Leaf end - optimize entity in fluid
if ((this.isInWater() || this.isInLava()) && this.isAffectedByFluids() && !this.canStandOnFluid(fluidState)) {
this.travelInFluid(travelVector);
} else if (this.isFallFlying()) {