mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
61 lines
3.9 KiB
Diff
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 fb31d17226619a87dd88017dc0b6915b8d1ceecd..cab664f5ae052002ae7258b33495b74164ea0b09 100644
|
|
--- a/net/minecraft/world/entity/Entity.java
|
|
+++ b/net/minecraft/world/entity/Entity.java
|
|
@@ -4844,12 +4844,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
|
|
@@ -4861,7 +4861,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;
|
|
}
|
|
@@ -4918,7 +4918,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()) {
|