-
-
Notifications
You must be signed in to change notification settings - Fork 136
Prevent move into weakloaded chunks #597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
HaHaWTH
wants to merge
11
commits into
ver/1.21.11
Choose a base branch
from
prevent-move-into-weakloaded-chunks
base: ver/1.21.11
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+245
−0
Open
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6046717
Prevents entities from moving into weak loaded chunks
HaHaWTH edbdb1b
skip for ender pearls
HaHaWTH b06f2bb
Fix config
HaHaWTH 3bf4a7a
move to fixes section
HaHaWTH d07478b
Add check for HurtingProjectile
HaHaWTH ceba13c
[ci skip] pat pat
HaHaWTH 48acf27
Special case for AbstractHurtingProjectiles
HaHaWTH 1c39ba4
Improve config comments
Dreeam-qwq 335eac2
Final cleanup
HaHaWTH 924588a
[ci skip] Change remove reason
HaHaWTH 97c56cd
[ci skip] correct config comment
HaHaWTH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
169 changes: 169 additions & 0 deletions
169
...inecraft-patches/features/0295-Prevent-entities-from-moving-into-weak-loaded-chunks.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
35 changes: 35 additions & 0 deletions
35
...r/src/main/java/org/dreeam/leaf/config/modules/fixes/PreventMoveIntoWeakLoadedChunks.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.", | ||
| "阻止投掷物进入弱加载区块." | ||
| )); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.