mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-21 15:59: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 a7ac1afc9db4daba86a492aea3a528806605231b..21b0c3f32e1a3837f040390514a30756497c2303 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -1260,6 +1260,11 @@ public class ServerLevel extends Level implements WorldGenLevel, ca.spottedleaf.
|
|
if (isActive) { // Paper - EAR 2
|
|
TimingHistory.activatedEntityTicks++;
|
|
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
|
|
this.getProfiler().pop();
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index cb3202e3cc4f87f606d8b2eb2a7a59bacae2077d..e8914a99346a4551888ef0ad2633cf68a364d891 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -620,6 +620,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();
|
|
@@ -669,6 +682,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) {
|