Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-16 04:50:05 +01:00
88 Zeilen
4.4 KiB
Diff
88 Zeilen
4.4 KiB
Diff
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
|
|
index a6f0e2193f930cf4f1e38ac30e92a7f7cafb8413..6d1a880737c90da743fd772426b4050036bdb926 100644
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
|
@@ -2,6 +2,9 @@ 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;
|
|
@@ -40,6 +43,13 @@ 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();
|
|
}
|
|
@@ -122,4 +132,31 @@ public class PaperWorldConfig {
|
|
private void nerfedMobsShouldJump() {
|
|
nerfedMobsShouldJump = getBoolean("spawner-nerfed-mobs-should-jump", false);
|
|
}
|
|
+
|
|
+ public final Reference2IntMap<MobCategory> softDespawnDistances = new Reference2IntOpenHashMap<>(MobCategory.values().length);
|
|
+ public final Reference2IntMap<MobCategory> hardDespawnDistances = new Reference2IntOpenHashMap<>(MobCategory.values().length);
|
|
+ private void despawnDistances() {
|
|
+ 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);
|
|
+ }
|
|
+ }
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
|
|
index 9cc9c11f2ef5aa386711a0ebc70b6a2d8e5c5b97..d5d79927aeab04d24010b53f9b527fa7b05d8a47 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Mob.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
|
|
@@ -778,14 +778,14 @@ public abstract class Mob extends LivingEntity {
|
|
|
|
if (entityhuman != null) {
|
|
double d0 = entityhuman.distanceToSqr((Entity) this);
|
|
- 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
|
|
this.discard();
|
|
}
|
|
|
|
- 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
|