mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-22 08:19:26 +00:00
55 lines
2.8 KiB
Diff
55 lines
2.8 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Samsuik <kfian294ma4@gmail.com>
|
|
Date: Tue, 20 Feb 2024 19:16:16 +0000
|
|
Subject: [PATCH] Add entity travel distance limits
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
index e39f4e4716b8794e506d3ffcbc35ae88d0fbc23a..a3c8ed82e46056be1a3ca002664e6fe6fa46bc2e 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -1328,6 +1328,11 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
final boolean isActive = org.spigotmc.ActivationRange.checkIfActive(entity); // Paper - EAR 2
|
|
if (isActive) { // Paper - EAR 2
|
|
entity.tick();
|
|
+ // Sakura start - entity travel distance limits
|
|
+ if (entity.isPastTravelDistanceLimit()) {
|
|
+ entity.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DESPAWN);
|
|
+ }
|
|
+ // Sakura end - entity travel distance limits
|
|
entity.postTick(); // CraftBukkit
|
|
} else { entity.inactiveTick(); } // Paper - EAR 2
|
|
gameprofilerfiller.pop();
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index ef81c093377c0cae5d729a17a0dc89ba9b0b118a..ee8816ec238a38667cdf0f0f749c02b78a6477bd 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -681,6 +681,19 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
return this.physics;
|
|
}
|
|
// Sakura end - physics version api
|
|
+ // Sakura start - entity travel distance limits
|
|
+ private final double travelDistanceLimit;
|
|
+
|
|
+ public final boolean isPastTravelDistanceLimit() {
|
|
+ if (this.origin == null) {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ double x = Math.pow(this.origin.getX() - this.position.x(), 2);
|
|
+ double z = Math.pow(this.origin.getZ() - this.position.z(), 2);
|
|
+ return Math.max(x, z) >= this.travelDistanceLimit;
|
|
+ }
|
|
+ // Sakura end - entity travel distance limits
|
|
|
|
public Entity(EntityType<?> type, Level world) {
|
|
this.id = Entity.ENTITY_COUNTER.incrementAndGet();
|
|
@@ -733,6 +746,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
this.entityData = datawatcher_a.build();
|
|
this.setPos(0.0D, 0.0D, 0.0D);
|
|
this.eyeHeight = this.dimensions.eyeHeight();
|
|
+ this.travelDistanceLimit = Math.pow(this.level.sakuraConfig().entity.chunkTravelLimit.getOrDefault(type, Integer.MAX_VALUE) * 16.0, 2); // Sakura - entity travel distance limits
|
|
}
|
|
|
|
public boolean isColliding(BlockPos pos, BlockState state) {
|