2021-06-11 12:02:28 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Suddenly <suddenly@suddenly.coffee>
|
|
|
|
Date: Tue, 1 Mar 2016 13:51:54 -0600
|
|
|
|
Subject: [PATCH] Add configurable despawn distances for living entities
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
2022-06-06 00:17:27 +00:00
|
|
|
index d2ac0123812224181afae8fca96058ddc8cdff1e..3afadc8d916714398974d77aa0f1093729e008ca 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
2021-11-24 17:58:26 +00:00
|
|
|
@@ -3,6 +3,9 @@ package com.destroystokyo.paper;
|
2021-11-09 07:59:15 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
2021-11-24 17:58:26 +00:00
|
|
|
import java.util.stream.Collectors;
|
2021-11-09 07:59:15 +00:00
|
|
|
+import it.unimi.dsi.fastutil.objects.Reference2IntMap;
|
|
|
|
+import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap;
|
|
|
|
+import net.minecraft.world.entity.MobCategory;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
|
|
import org.spigotmc.SpigotWorldConfig;
|
2022-05-07 16:47:28 +00:00
|
|
|
@@ -46,6 +49,13 @@ public class PaperWorldConfig {
|
2021-11-09 07:59:15 +00:00
|
|
|
public void removeOldValues() {
|
|
|
|
boolean needsSave = false;
|
|
|
|
|
|
|
|
+ if (PaperConfig.version < 24) {
|
|
|
|
+ needsSave = true;
|
|
|
|
+
|
|
|
|
+ set("despawn-ranges.soft", null);
|
|
|
|
+ set("despawn-ranges.hard", null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
if (needsSave) {
|
|
|
|
saveConfig();
|
|
|
|
}
|
2022-06-06 00:17:27 +00:00
|
|
|
@@ -137,4 +147,31 @@ public class PaperWorldConfig {
|
2021-06-11 12:02:28 +00:00
|
|
|
private void nerfedMobsShouldJump() {
|
|
|
|
nerfedMobsShouldJump = getBoolean("spawner-nerfed-mobs-should-jump", false);
|
|
|
|
}
|
|
|
|
+
|
2021-11-09 07:59:15 +00:00
|
|
|
+ public final Reference2IntMap<MobCategory> softDespawnDistances = new Reference2IntOpenHashMap<>(MobCategory.values().length);
|
|
|
|
+ public final Reference2IntMap<MobCategory> hardDespawnDistances = new Reference2IntOpenHashMap<>(MobCategory.values().length);
|
2021-06-11 12:02:28 +00:00
|
|
|
+ private void despawnDistances() {
|
2021-11-09 07:59:15 +00:00
|
|
|
+ if (PaperConfig.version < 24) {
|
|
|
|
+ int softDistance = getInt("despawn-ranges.soft", 32, false); // 32^2 = 1024, Minecraft Default
|
|
|
|
+ int hardDistance = getInt("despawn-ranges.hard", 128, false); // 128^2 = 16384, Minecraft Default
|
|
|
|
+ for (MobCategory value : MobCategory.values()) {
|
|
|
|
+ if (softDistance != 32) {
|
|
|
|
+ softDespawnDistances.put(value, softDistance);
|
|
|
|
+ }
|
|
|
|
+ if (hardDistance != 128) {
|
|
|
|
+ hardDespawnDistances.put(value, hardDistance);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (MobCategory category : MobCategory.values()) {
|
|
|
|
+ int softDistance = getInt("despawn-ranges." + category.getName() + ".soft", softDespawnDistances.getOrDefault(category, category.getNoDespawnDistance()));
|
|
|
|
+ int hardDistance = getInt("despawn-ranges." + category.getName() + ".hard", hardDespawnDistances.getOrDefault(category, category.getDespawnDistance()));
|
|
|
|
+ if (softDistance > hardDistance) {
|
|
|
|
+ softDistance = hardDistance;
|
|
|
|
+ }
|
|
|
|
+ log("Mobs in " + category.getName() + " Despawn Ranges: Soft" + softDistance + " Hard: " + hardDistance);
|
|
|
|
+ softDespawnDistances.put(category, softDistance);
|
|
|
|
+ hardDespawnDistances.put(category, hardDistance);
|
2021-06-11 12:02:28 +00:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
|
2022-06-07 19:15:06 +00:00
|
|
|
index 4f58fae1b3738e7e0507a46df275a258c94fcec4..88b021b7d1b71bd3fa64b54ca0fd52fef93ea9f0 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/Mob.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
|
2022-06-07 19:15:06 +00:00
|
|
|
@@ -788,14 +788,14 @@ public abstract class Mob extends LivingEntity {
|
2021-11-09 07:59:15 +00:00
|
|
|
|
|
|
|
if (entityhuman != null) {
|
2021-11-23 11:27:39 +00:00
|
|
|
double d0 = entityhuman.distanceToSqr((Entity) this);
|
2021-11-09 07:59:15 +00:00
|
|
|
- int i = this.getType().getCategory().getDespawnDistance();
|
|
|
|
+ int i = this.level.paperConfig.hardDespawnDistances.getInt(this.getType().getCategory()); // Paper - custom despawn distances
|
2021-06-11 12:02:28 +00:00
|
|
|
int j = i * i;
|
|
|
|
|
2022-05-09 09:03:07 +00:00
|
|
|
if (d0 > (double) j && this.removeWhenFarAway(d0)) {
|
2021-06-11 22:37:16 +00:00
|
|
|
this.discard();
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 07:59:15 +00:00
|
|
|
- int k = this.getType().getCategory().getNoDespawnDistance();
|
|
|
|
+ int k = this.level.paperConfig.softDespawnDistances.getInt(this.getType().getCategory()); // Paper - custom despawn distances
|
2021-06-11 12:02:28 +00:00
|
|
|
int l = k * k;
|
|
|
|
|
2022-05-09 09:03:07 +00:00
|
|
|
if (this.noActionTime > 600 && this.random.nextInt(800) == 0 && d0 > (double) l && this.removeWhenFarAway(d0)) {
|