mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-01 12:42:05 -07:00
Make despawn distance configs per-category, improve per category spawn limit config (#6717)
Also adds per-world spawn limit config in paper.yml for `underground_water_creature`, and migrates existing spawn limit config options to their Mojang names.
This commit is contained in:
@@ -8,25 +8,60 @@ diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/m
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
||||
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
||||
@@ -0,0 +0,0 @@ package com.destroystokyo.paper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
+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;
|
||||
@@ -0,0 +0,0 @@ public class PaperWorldConfig {
|
||||
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();
|
||||
}
|
||||
@@ -0,0 +0,0 @@ public class PaperWorldConfig {
|
||||
private void nerfedMobsShouldJump() {
|
||||
nerfedMobsShouldJump = getBoolean("spawner-nerfed-mobs-should-jump", false);
|
||||
}
|
||||
+
|
||||
+ public int softDespawnDistance;
|
||||
+ public int hardDespawnDistance;
|
||||
+ public final Reference2IntMap<MobCategory> softDespawnDistances = new Reference2IntOpenHashMap<>(MobCategory.values().length);
|
||||
+ public final Reference2IntMap<MobCategory> hardDespawnDistances = new Reference2IntOpenHashMap<>(MobCategory.values().length);
|
||||
+ private void despawnDistances() {
|
||||
+ softDespawnDistance = getInt("despawn-ranges.soft", 32); // 32^2 = 1024, Minecraft Default
|
||||
+ hardDespawnDistance = getInt("despawn-ranges.hard", 128); // 128^2 = 16384, Minecraft Default
|
||||
+
|
||||
+ if (softDespawnDistance > hardDespawnDistance) {
|
||||
+ softDespawnDistance = hardDespawnDistance;
|
||||
+ 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);
|
||||
+ }
|
||||
+
|
||||
+ log("Living Entity Despawn Ranges: Soft: " + softDespawnDistance + " Hard: " + hardDespawnDistance);
|
||||
+
|
||||
+ softDespawnDistance = softDespawnDistance*softDespawnDistance;
|
||||
+ hardDespawnDistance = hardDespawnDistance*hardDespawnDistance;
|
||||
+ }
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
|
||||
@@ -34,22 +69,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
--- a/src/main/java/net/minecraft/world/entity/Mob.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
|
||||
@@ -0,0 +0,0 @@ public abstract class Mob extends LivingEntity {
|
||||
int i = this.getType().getCategory().getDespawnDistance();
|
||||
|
||||
if (entityhuman != null) {
|
||||
double d0 = entityhuman.distanceToSqr((Entity) this); // CraftBukkit - decompile error
|
||||
- int i = this.getType().getCategory().getDespawnDistance();
|
||||
+ int i = this.level.paperConfig.hardDespawnDistances.getInt(this.getType().getCategory()); // Paper - custom despawn distances
|
||||
int j = i * i;
|
||||
|
||||
- if (d0 > (double) j) { // CraftBukkit - remove isTypeNotPersistent() check
|
||||
+ if (d0 > (double) level.paperConfig.hardDespawnDistance) { // CraftBukkit - remove isTypeNotPersistent() check // Paper - custom despawn distances
|
||||
if (d0 > (double) j) { // CraftBukkit - remove isTypeNotPersistent() check
|
||||
this.discard();
|
||||
}
|
||||
|
||||
int k = this.getType().getCategory().getNoDespawnDistance();
|
||||
- int k = this.getType().getCategory().getNoDespawnDistance();
|
||||
+ int k = this.level.paperConfig.softDespawnDistances.getInt(this.getType().getCategory()); // Paper - custom despawn distances
|
||||
int l = k * k;
|
||||
|
||||
- if (this.noActionTime > 600 && this.random.nextInt(800) == 0 && d0 > (double) l) { // CraftBukkit - remove isTypeNotPersistent() check
|
||||
+ if (this.noActionTime > 600 && this.random.nextInt(800) == 0 && d0 > level.paperConfig.softDespawnDistance) { // CraftBukkit - remove isTypeNotPersistent() check // Paper - custom despawn distances
|
||||
this.discard();
|
||||
- } else if (d0 < (double) l) {
|
||||
+ } else if (d0 < level.paperConfig.softDespawnDistance) { // Paper - custom despawn distances
|
||||
this.noActionTime = 0;
|
||||
}
|
||||
}
|
||||
if (this.noActionTime > 600 && this.random.nextInt(800) == 0 && d0 > (double) l) { // CraftBukkit - remove isTypeNotPersistent() check
|
||||
|
Reference in New Issue
Block a user