Skip to content

Commit

Permalink
Update last lava contact
Browse files Browse the repository at this point in the history
  • Loading branch information
Doc94 committed Jan 19, 2025
1 parent 5f49c9b commit 1945546
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -28725,7 +28725,7 @@ index 33db4187899d98381155c3f30b7f416e7e7edad8..77b4a8e24a3ecdcf53b9d0c1215764d6
}

private static float[] collectCandidateStepUpHeights(AABB box, List<VoxelShape> 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() {
Expand Down Expand Up @@ -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<Entity> getIndirectPassengers() {
Expand All @@ -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);
}

Expand Down Expand Up @@ -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();
+
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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();
}

Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -1643,6 +1651,94 @@
);
}

@@ -3279,6 +_,87 @@
this.yRotO = this.getYRot();
}

+ // Paper start - add last fluid contact
+ @Nullable
+ public BlockPos getLastFluidContact(final TagKey<Fluid> 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<net.minecraft.world.level.block.state.BlockState> 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++;
Expand Down

0 comments on commit 1945546

Please sign in to comment.