From 19455469b052515aa7f2f4fff224b888950d5ed8 Mon Sep 17 00:00:00 2001 From: Doc Date: Sun, 19 Jan 2025 12:36:48 -0300 Subject: [PATCH] Update last lava contact --- .../0016-Moonrise-optimisation-patches.patch | 24 ++--- .../minecraft/world/entity/Entity.java.patch | 96 +++++++++++++++++++ 2 files changed, 108 insertions(+), 12 deletions(-) diff --git a/paper-server/patches/features/0016-Moonrise-optimisation-patches.patch b/paper-server/patches/features/0016-Moonrise-optimisation-patches.patch index dfb138eb8f21..a2d2fb409955 100644 --- a/paper-server/patches/features/0016-Moonrise-optimisation-patches.patch +++ b/paper-server/patches/features/0016-Moonrise-optimisation-patches.patch @@ -28372,7 +28372,7 @@ index 8cc5c0716392ba06501542ff5cbe71ee43979e5d..09fd99c9cbd23b5f3c899bfb00c9b896 + // Paper end - block counting } diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java -index 33db4187899d98381155c3f30b7f416e7e7edad8..77b4a8e24a3ecdcf53b9d0c1215764d6ce26d328 100644 +index ef0319171374ac61a16b06d1e3e1f5ca501c70cc..ac5e8e72395a5b40a2bab040f15f8c1c7a364560 100644 --- a/net/minecraft/world/entity/Entity.java +++ b/net/minecraft/world/entity/Entity.java @@ -135,7 +135,7 @@ import net.minecraft.world.scores.ScoreHolder; @@ -28725,7 +28725,7 @@ index 33db4187899d98381155c3f30b7f416e7e7edad8..77b4a8e24a3ecdcf53b9d0c1215764d6 } private static float[] collectCandidateStepUpHeights(AABB box, List colliders, float deltaY, float maxUpStep) { -@@ -2663,23 +2811,110 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess +@@ -2664,23 +2812,110 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess } public boolean isInWall() { @@ -28849,7 +28849,7 @@ index 33db4187899d98381155c3f30b7f416e7e7edad8..77b4a8e24a3ecdcf53b9d0c1215764d6 } public InteractionResult interact(Player player, InteractionHand hand) { -@@ -4103,15 +4338,17 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess +@@ -4104,15 +4339,17 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess } public Iterable getIndirectPassengers() { @@ -28875,7 +28875,7 @@ index 33db4187899d98381155c3f30b7f416e7e7edad8..77b4a8e24a3ecdcf53b9d0c1215764d6 } public int countPlayerPassengers() { -@@ -4249,77 +4486,136 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess +@@ -4331,77 +4568,136 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess return Mth.lerp(partialTick, this.yRotO, this.yRot); } @@ -28929,7 +28929,9 @@ index 33db4187899d98381155c3f30b7f416e7e7edad8..77b4a8e24a3ecdcf53b9d0c1215764d6 + final int maxBlockX = Mth.ceil(boundingBox.maxX) - 1; + final int maxBlockY = Math.min((ca.spottedleaf.moonrise.common.util.WorldUtil.getMaxSection(world) << 4) | 15, Mth.ceil(boundingBox.maxY) - 1); + final int maxBlockZ = Mth.ceil(boundingBox.maxZ) - 1; -+ + +- vec3 = vec3.add(flow); +- i++; + final boolean isPushable = this.isPushedByFluid(); + final BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos(); + @@ -28973,9 +28975,7 @@ index 33db4187899d98381155c3f30b7f416e7e7edad8..77b4a8e24a3ecdcf53b9d0c1215764d6 + final int maxZIterate = currChunkZ == maxChunkZ ? (maxBlockZ & 15) : 15; + final int minYIterate = currChunkY == minChunkY ? (minBlockY & 15) : 0; + final int maxYIterate = currChunkY == maxChunkY ? (maxBlockY & 15) : 15; - -- vec3 = vec3.add(flow); -- i++; ++ + for (int currY = minYIterate; currY <= maxYIterate; ++currY) { + for (int currZ = minZIterate; currZ <= maxZIterate; ++currZ) { + for (int currX = minXIterate; currX <= maxXIterate; ++currX) { @@ -29066,7 +29066,7 @@ index 33db4187899d98381155c3f30b7f416e7e7edad8..77b4a8e24a3ecdcf53b9d0c1215764d6 public boolean touchingUnloadedChunk() { AABB aabb = this.getBoundingBox().inflate(1.0); -@@ -4472,6 +4768,15 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess +@@ -4554,6 +4850,15 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess this.setPosRaw(x, y, z, false); } public final void setPosRaw(double x, double y, double z, boolean forceBoundingBoxUpdate) { @@ -29082,7 +29082,7 @@ index 33db4187899d98381155c3f30b7f416e7e7edad8..77b4a8e24a3ecdcf53b9d0c1215764d6 if (!checkPosition(this, x, y, z)) { return; } -@@ -4602,6 +4907,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess +@@ -4684,6 +4989,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess @Override public final void setRemoved(Entity.RemovalReason removalReason, org.bukkit.event.entity.EntityRemoveEvent.Cause cause) { @@ -29095,7 +29095,7 @@ index 33db4187899d98381155c3f30b7f416e7e7edad8..77b4a8e24a3ecdcf53b9d0c1215764d6 org.bukkit.craftbukkit.event.CraftEventFactory.callEntityRemoveEvent(this, cause); // CraftBukkit end final boolean alreadyRemoved = this.removalReason != null; // Paper - Folia schedulers -@@ -4613,7 +4924,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess +@@ -4695,7 +5006,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess this.stopRiding(); } @@ -29104,7 +29104,7 @@ index 33db4187899d98381155c3f30b7f416e7e7edad8..77b4a8e24a3ecdcf53b9d0c1215764d6 this.levelCallback.onRemove(removalReason); this.onRemoval(removalReason); // Paper start - Folia schedulers -@@ -4647,7 +4958,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess +@@ -4729,7 +5040,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess public boolean shouldBeSaved() { return (this.removalReason == null || this.removalReason.shouldSave()) && !this.isPassenger() diff --git a/paper-server/patches/sources/net/minecraft/world/entity/Entity.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/Entity.java.patch index 8531036fcc6b..6207495602d6 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/Entity.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/Entity.java.patch @@ -619,6 +619,14 @@ public void recordMovementThroughBlocks(Vec3 oldPosition, Vec3 position) { this.movementThisTick.add(new Entity.Movement(oldPosition, position)); } +@@ -1330,6 +_,7 @@ + this.updateInWaterStateAndDoWaterCurrentPushing(); + double d = this.level().dimensionType().ultraWarm() ? 0.007 : 0.0023333333333333335; + boolean flag = this.updateFluidHeightAndDoFluidPushing(FluidTags.LAVA, d); ++ this.lastLavaContact = this.getLastFluidContact(FluidTags.LAVA); // Paper - update lastLavaContact + return this.isInWater() || flag; + } + @@ -1485,6 +_,7 @@ this.setXRot(Mth.clamp(xRot, -90.0F, 90.0F) % 360.0F); this.yRotO = this.getYRot(); @@ -1643,6 +1651,94 @@ ); } +@@ -3279,6 +_,87 @@ + this.yRotO = this.getYRot(); + } + ++ // Paper start - add last fluid contact ++ @Nullable ++ public BlockPos getLastFluidContact(final TagKey fluid) { ++ if (this.touchingUnloadedChunk()) { ++ return null; ++ } ++ ++ final AABB boundingBox = this.getBoundingBox().deflate(1.0E-3); ++ ++ final Level world = this.level; ++ final int minSection = ca.spottedleaf.moonrise.common.util.WorldUtil.getMinSection(world); ++ ++ final int minBlockX = Mth.floor(boundingBox.minX); ++ final int minBlockY = Math.max((minSection << 4), Mth.floor(boundingBox.minY)); ++ final int minBlockZ = Mth.floor(boundingBox.minZ); ++ ++ // note: bounds are exclusive in Vanilla, so we subtract 1 - our loop expects bounds to be inclusive ++ final int maxBlockX = Mth.ceil(boundingBox.maxX) - 1; ++ final int maxBlockY = Math.min((ca.spottedleaf.moonrise.common.util.WorldUtil.getMaxSection(world) << 4) | 15, Mth.ceil(boundingBox.maxY) - 1); ++ final int maxBlockZ = Mth.ceil(boundingBox.maxZ) - 1; ++ ++ final BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos(); ++ ++ final int minChunkX = minBlockX >> 4; ++ final int maxChunkX = maxBlockX >> 4; ++ ++ final int minChunkY = minBlockY >> 4; ++ final int maxChunkY = maxBlockY >> 4; ++ ++ final int minChunkZ = minBlockZ >> 4; ++ final int maxChunkZ = maxBlockZ >> 4; ++ ++ final net.minecraft.world.level.chunk.ChunkSource chunkSource = world.getChunkSource(); ++ ++ for (int currChunkZ = minChunkZ; currChunkZ <= maxChunkZ; ++currChunkZ) { ++ for (int currChunkX = minChunkX; currChunkX <= maxChunkX; ++currChunkX) { ++ final net.minecraft.world.level.chunk.LevelChunkSection[] sections = chunkSource.getChunk(currChunkX, currChunkZ, net.minecraft.world.level.chunk.status.ChunkStatus.FULL, false).getSections(); ++ ++ // bound y ++ for (int currChunkY = minChunkY; currChunkY <= maxChunkY; ++currChunkY) { ++ final int sectionIdx = currChunkY - minSection; ++ if (sectionIdx < 0 || sectionIdx >= sections.length) { ++ continue; ++ } ++ final net.minecraft.world.level.chunk.LevelChunkSection section = sections[sectionIdx]; ++ if (section.hasOnlyAir()) { ++ // empty ++ continue; ++ } ++ ++ final net.minecraft.world.level.chunk.PalettedContainer blocks = section.states; ++ ++ final int minXIterate = currChunkX == minChunkX ? (minBlockX & 15) : 0; ++ final int maxXIterate = currChunkX == maxChunkX ? (maxBlockX & 15) : 15; ++ final int minZIterate = currChunkZ == minChunkZ ? (minBlockZ & 15) : 0; ++ final int maxZIterate = currChunkZ == maxChunkZ ? (maxBlockZ & 15) : 15; ++ final int minYIterate = currChunkY == minChunkY ? (minBlockY & 15) : 0; ++ final int maxYIterate = currChunkY == maxChunkY ? (maxBlockY & 15) : 15; ++ ++ for (int currY = minYIterate; currY <= maxYIterate; ++currY) { ++ for (int currZ = minZIterate; currZ <= maxZIterate; ++currZ) { ++ for (int currX = minXIterate; currX <= maxXIterate; ++currX) { ++ final FluidState fluidState = blocks.get((currX) | (currZ << 4) | ((currY) << 8)).getFluidState(); ++ ++ if (fluidState.isEmpty() || !fluidState.is(fluid)) { ++ continue; ++ } ++ ++ mutablePos.set(currX | (currChunkX << 4), currY | (currChunkY << 4), currZ | (currChunkZ << 4)); ++ ++ return mutablePos; ++ } ++ } ++ } ++ } ++ } ++ } ++ return null; ++ } ++ // Paper end ++ + public float getPreciseBodyRotation(float partialTick) { + return Mth.lerp(partialTick, this.yRotO, this.yRot); + } @@ -3320,6 +_,11 @@ vec3 = vec3.add(flow); i++;