Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: HaHaWTH <[email protected]>
Date: Tue, 9 Nov 2077 00:00:00 +0800
Subject: [PATCH] Prevent entities from moving into weak loaded chunks


diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
index cf2a365bcbb1a278e5553c16ffef6d9ae81f4d41..1a37a469924da67cfc34a9564a346fee9f3dbe7e 100644
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -250,7 +250,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
}

// Paper start
- public final boolean areChunksLoadedForMove(AABB box) {
+ public final boolean areChunksLoadedForMove(AABB box) { // Leaf - diff on change - update areChunksLoadedForEntityMove if this changed
// copied code from collision methods, so that we can guarantee that they won't load chunks (we don't override
// CollisionGetter methods for VoxelShapes)
// be more strict too, add a block (dumb plugins in move events?)
@@ -276,8 +276,40 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
}
}

+ return true;
+ } // Leaf - diff on change - update areChunksLoadedForEntityMove if this changed
+
+ // Leaf start - Prevent entity from moving into weak loaded chunks
+ public final boolean areChunksLoadedForEntityMove(AABB box) {
+ // copied code from collision methods, so that we can guarantee that they won't load chunks (we don't override
+ // CollisionGetter methods for VoxelShapes)
+ // be more strict too, add a block (dumb plugins in move events?)
+ int minBlockX = Mth.floor(box.minX - 1.0E-7D) - 3;
+ int maxBlockX = Mth.floor(box.maxX + 1.0E-7D) + 3;
+
+ int minBlockZ = Mth.floor(box.minZ - 1.0E-7D) - 3;
+ int maxBlockZ = Mth.floor(box.maxZ + 1.0E-7D) + 3;
+
+ int minChunkX = minBlockX >> 4;
+ int maxChunkX = maxBlockX >> 4;
+
+ int minChunkZ = minBlockZ >> 4;
+ int maxChunkZ = maxBlockZ >> 4;
+
+ ServerChunkCache chunkProvider = this.getChunkSource();
+
+ for (int cx = minChunkX; cx <= maxChunkX; ++cx) {
+ for (int cz = minChunkZ; cz <= maxChunkZ; ++cz) {
+ LevelChunk chunk = chunkProvider.getChunkAtIfLoadedImmediately(cx, cz);
+ if (chunk == null || !chunk.getFullStatus().isOrAfter(FullChunkStatus.ENTITY_TICKING)) { // check chunk status
+ return false;
+ }
+ }
+ }
+
return true;
}
+ // Leaf end - Prevent entity from moving into weak loaded chunks

public final void loadChunksForMoveAsync(AABB box, ca.spottedleaf.concurrentutil.util.Priority priority,
java.util.function.Consumer<List<net.minecraft.world.level.chunk.ChunkAccess>> onLoad) {
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 8d092716cdcc48b829a1c0ee2e5416d648143a37..259b9dae8fbf115e31da5e8f8b5d127e07b95372 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -387,6 +387,7 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
public boolean isTemporarilyActive;
public long activatedImmunityTick = Integer.MIN_VALUE;
public @Nullable Boolean immuneToFire = null; // Purpur - Fire immune API
+ protected boolean preventMoveIntoWeakLoadedChunks = false;

public void inactiveTick() {
}
diff --git a/net/minecraft/world/entity/projectile/ThrowableProjectile.java b/net/minecraft/world/entity/projectile/ThrowableProjectile.java
index 47f2e940b68738cb02719cd82a5c0fff56fba062..b36d6de4a8f9817dd942884c5288bd43493e4014 100644
--- a/net/minecraft/world/entity/projectile/ThrowableProjectile.java
+++ b/net/minecraft/world/entity/projectile/ThrowableProjectile.java
@@ -15,6 +15,7 @@ public abstract class ThrowableProjectile extends Projectile {

protected ThrowableProjectile(EntityType<? extends ThrowableProjectile> type, Level level) {
super(type, level);
+ this.preventMoveIntoWeakLoadedChunks = org.dreeam.leaf.config.modules.fixes.PreventMoveIntoWeakLoadedChunks.isProjectileEnabled(); // Leaf - Prevent entity from moving into weak loaded chunks
}

protected ThrowableProjectile(EntityType<? extends ThrowableProjectile> type, double x, double y, double z, Level level) {
@@ -57,7 +58,20 @@ public abstract class ThrowableProjectile extends Projectile {
if (hitResultOnMoveVector.getType() != HitResult.Type.MISS) {
location = hitResultOnMoveVector.getLocation();
} else {
- location = this.position().add(this.getDeltaMovement());
+ // Leaf start - Prevent entity from moving into weak loaded chunks
+ if (preventMoveIntoWeakLoadedChunks) {
+ Vec3 previousLocation = this.position();
+ location = this.position().add(this.getDeltaMovement());
+ if (this.level() instanceof net.minecraft.server.level.ServerLevel serverLevel) {
+ if (!serverLevel.areChunksLoadedForEntityMove(this.getBoundingBox().expandTowards(location.subtract(previousLocation)))) {
+ location = previousLocation;
+ this.setDeltaMovement(Vec3.ZERO);
+ }
+ }
+ } else {
+ location = this.position().add(this.getDeltaMovement());
+ }
+ // Leaf end - Prevent entity from moving into weak loaded chunks
}

this.setPos(location);
diff --git a/net/minecraft/world/entity/projectile/hurtingprojectile/AbstractHurtingProjectile.java b/net/minecraft/world/entity/projectile/hurtingprojectile/AbstractHurtingProjectile.java
index 6edff432866ae72db657b47bf9726be9a4ef1562..bdc56b878cc052f159db1e229850019c22b8f2ec 100644
--- a/net/minecraft/world/entity/projectile/hurtingprojectile/AbstractHurtingProjectile.java
+++ b/net/minecraft/world/entity/projectile/hurtingprojectile/AbstractHurtingProjectile.java
@@ -24,9 +24,11 @@ public abstract class AbstractHurtingProjectile extends Projectile {
public double accelerationPower = 0.1;
public float bukkitYield = 1; // CraftBukkit
public boolean isIncendiary = true; // CraftBukkit
+ private boolean scheduleForRemoval = false; // Leaf - Prevent entity from moving into weak loaded chunks

protected AbstractHurtingProjectile(EntityType<? extends AbstractHurtingProjectile> type, Level level) {
super(type, level);
+ this.preventMoveIntoWeakLoadedChunks = org.dreeam.leaf.config.modules.fixes.PreventMoveIntoWeakLoadedChunks.isProjectileEnabled(); // Leaf - Prevent entity from moving into weak loaded chunks
}

protected AbstractHurtingProjectile(EntityType<? extends AbstractHurtingProjectile> type, double x, double y, double z, Level level) {
@@ -70,13 +72,27 @@ public abstract class AbstractHurtingProjectile extends Projectile {
public void tick() {
Entity owner = this.getOwner();
this.applyInertia();
- if (this.level().isClientSide() || (owner == null || !owner.isRemoved()) && this.level().hasChunkAt(this.blockPosition())) {
+ if (this.level().isClientSide() || (owner == null || !owner.isRemoved()) && this.level().hasChunkAt(this.blockPosition()) && !this.scheduleForRemoval) { // Leaf - Prevent entity from moving into weak loaded chunks
HitResult hitResultOnMoveVector = ProjectileUtil.getHitResultOnMoveVector(this, this::canHitEntity, this.getClipType());
Vec3 location;
if (hitResultOnMoveVector.getType() != HitResult.Type.MISS) {
location = hitResultOnMoveVector.getLocation();
} else {
- location = this.position().add(this.getDeltaMovement());
+ // Leaf start - Prevent entity from moving into weak loaded chunks
+ if (preventMoveIntoWeakLoadedChunks) {
+ Vec3 previousLocation = this.position();
+ location = this.position().add(this.getDeltaMovement());
+ if (this.level() instanceof net.minecraft.server.level.ServerLevel serverLevel) {
+ if (!serverLevel.areChunksLoadedForEntityMove(this.getBoundingBox().expandTowards(location.subtract(previousLocation)))) {
+ location = previousLocation;
+ this.setDeltaMovement(Vec3.ZERO);
+ this.scheduleForRemoval = true;
+ }
+ }
+ } else {
+ location = this.position().add(this.getDeltaMovement());
+ }
+ // Leaf end - Prevent entity from moving into weak loaded chunks
}

ProjectileUtil.rotateTowardsMovement(this, 0.2F);
diff --git a/net/minecraft/world/entity/projectile/throwableitemprojectile/ThrownEnderpearl.java b/net/minecraft/world/entity/projectile/throwableitemprojectile/ThrownEnderpearl.java
index 4d416d3a8402a78b8ad6383d842f589a821ddbe9..2fe748ab39602b1f3d2c4f9982375e582806828c 100644
--- a/net/minecraft/world/entity/projectile/throwableitemprojectile/ThrownEnderpearl.java
+++ b/net/minecraft/world/entity/projectile/throwableitemprojectile/ThrownEnderpearl.java
@@ -33,10 +33,12 @@ public class ThrownEnderpearl extends ThrowableItemProjectile {

public ThrownEnderpearl(EntityType<? extends ThrownEnderpearl> type, Level level) {
super(type, level);
+ this.preventMoveIntoWeakLoadedChunks = false; // Leaf - Prevent entity from moving into weak loaded chunks
}

public ThrownEnderpearl(Level level, LivingEntity owner, ItemStack item) {
super(EntityType.ENDER_PEARL, owner, level, item);
+ this.preventMoveIntoWeakLoadedChunks = false; // Leaf - Prevent entity from moving into weak loaded chunks
}

@Override
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.dreeam.leaf.config.modules.fixes;

import org.dreeam.leaf.config.ConfigModules;
import org.dreeam.leaf.config.EnumConfigCategory;

public class PreventMoveIntoWeakLoadedChunks extends ConfigModules {
public String getBasePath() {
return EnumConfigCategory.FIXES.getBaseKeyName() + ".prevent-moving-into-weak-loaded-chunks";
}

public static boolean enabled = false;
public static boolean projectiles = false;

public static boolean isProjectileEnabled() {
return enabled && projectiles;
}

@Override
public void onLoaded() {
config.addCommentRegionBased(getBasePath(),
"Prevents entities from moving into weak loaded chunks.",
"阻止实体进入弱加载区块."
);

enabled = config.getBoolean(getBasePath() + ".enabled", enabled, config().pickStringRegionBased(
"Set to true to enable features below.",
"设置为 true 以启用以下功能."
));

projectiles = config.getBoolean(getBasePath() + ".projectiles", projectiles, config().pickStringRegionBased(
"Prevents projectiles from moving into weak loaded chunks.",
"阻止投掷物进入弱加载区块."
));
}
}