Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Configuration for vertical Despawn Ranges #10440

Merged
merged 4 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 104 additions & 12 deletions patches/server/0005-Paper-config-files.patch
Original file line number Diff line number Diff line change
Expand Up @@ -854,10 +854,10 @@ index 0000000000000000000000000000000000000000..69add4a7f1147015806bc9b63a8340d1
+}
diff --git a/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java
new file mode 100644
index 0000000000000000000000000000000000000000..783eac6e458c6f1a0584301fb84a2fe341868f34
index 0000000000000000000000000000000000000000..1cee7ba88f8cd03009d9a3a01c1128eff598833c
--- /dev/null
+++ b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java
@@ -0,0 +1,466 @@
@@ -0,0 +1,463 @@
+package io.papermc.paper.configuration;
+
+import com.google.common.base.Suppliers;
Expand All @@ -866,11 +866,7 @@ index 0000000000000000000000000000000000000000..783eac6e458c6f1a0584301fb84a2fe3
+import io.leangen.geantyref.TypeToken;
+import io.papermc.paper.configuration.legacy.RequiresSpigotInitialization;
+import io.papermc.paper.configuration.mapping.InnerClassFieldDiscoverer;
+import io.papermc.paper.configuration.serializer.ComponentSerializer;
+import io.papermc.paper.configuration.serializer.EnumValueSerializer;
+import io.papermc.paper.configuration.serializer.NbtPathSerializer;
+import io.papermc.paper.configuration.serializer.PacketClassSerializer;
+import io.papermc.paper.configuration.serializer.StringRepresentableSerializer;
+import io.papermc.paper.configuration.serializer.*;
+import io.papermc.paper.configuration.serializer.collections.FastutilMapSerializer;
+import io.papermc.paper.configuration.serializer.collections.MapSerializer;
+import io.papermc.paper.configuration.serializer.collections.TableSerializer;
Expand Down Expand Up @@ -1095,6 +1091,7 @@ index 0000000000000000000000000000000000000000..783eac6e458c6f1a0584301fb84a2fe3
+ .register(new TypeToken<Reference2IntMap<?>>() {}, new FastutilMapSerializer.SomethingToPrimitive<Reference2IntMap<?>>(Reference2IntOpenHashMap::new, Integer.TYPE))
+ .register(new TypeToken<Reference2LongMap<?>>() {}, new FastutilMapSerializer.SomethingToPrimitive<Reference2LongMap<?>>(Reference2LongOpenHashMap::new, Long.TYPE))
+ .register(new TypeToken<Table<?, ?, ?>>() {}, new TableSerializer())
+ .register(new TypeToken<WorldConfiguration.Entities.Spawning.DespawnRange>() {}, new DespawnRangeSerializer())
+ .register(StringRepresentableSerializer::isValidFor, new StringRepresentableSerializer())
+ .register(IntOr.Default.SERIALIZER)
+ .register(IntOr.Disabled.SERIALIZER)
Expand Down Expand Up @@ -1414,10 +1411,10 @@ index 0000000000000000000000000000000000000000..990d1bb46e0f9719f4e9af928d80ac6f
+}
diff --git a/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java b/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java
new file mode 100644
index 0000000000000000000000000000000000000000..4bcf27f98765abf693e535cfc1756c27a10cb316
index 0000000000000000000000000000000000000000..b5f1c369f727161fba8ae6a820cf1f901953d6f8
--- /dev/null
+++ b/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java
@@ -0,0 +1,554 @@
@@ -0,0 +1,556 @@
+package io.papermc.paper.configuration;
+
+import com.google.common.collect.HashBasedTable;
Expand Down Expand Up @@ -1603,12 +1600,14 @@ index 0000000000000000000000000000000000000000..4bcf27f98765abf693e535cfc1756c27
+ @MergeMap
+ public Reference2IntMap<MobCategory> spawnLimits = Util.make(new Reference2IntOpenHashMap<>(NaturalSpawner.SPAWNING_CATEGORIES.length), map -> Arrays.stream(NaturalSpawner.SPAWNING_CATEGORIES).forEach(mobCategory -> map.put(mobCategory, -1)));
+ @MergeMap
+ public Map<MobCategory, DespawnRange> despawnRanges = Arrays.stream(MobCategory.values()).collect(Collectors.toMap(Function.identity(), category -> new DespawnRange(category.getNoDespawnDistance(), category.getDespawnDistance())));
+ public Map<MobCategory, DespawnRange> despawnRanges = Arrays.stream(MobCategory.values()).collect(Collectors.toMap(Function.identity(), category -> new DespawnRange(category.getDespawnDistance(), category.getNoDespawnDistance())));
+ @MergeMap
+ public Reference2IntMap<MobCategory> ticksPerSpawn = Util.make(new Reference2IntOpenHashMap<>(NaturalSpawner.SPAWNING_CATEGORIES.length), map -> Arrays.stream(NaturalSpawner.SPAWNING_CATEGORIES).forEach(mobCategory -> map.put(mobCategory, -1)));
+
+ @ConfigSerializable
+ public record DespawnRange(@Required int soft, @Required int hard) {
+ public record DespawnRange(@Required int xzLimit, @Required int yLimit, @Required int xzSoftLimit, @Required int ySoftLimit, @Required boolean longSyntax, @Required boolean softLongSyntax) {
+ public DespawnRange(int hard, int soft) {
+ this(hard, hard, soft, soft, false, false);
+ }
+ }
+
+ public WaterAnimalSpawnHeight wateranimalSpawnHeight;
Expand Down Expand Up @@ -2461,6 +2460,99 @@ index 0000000000000000000000000000000000000000..9c339ef178ebc3b0251095f320e4a7a3
+ return MiniMessage.miniMessage().serialize(component);
+ }
+}
diff --git a/src/main/java/io/papermc/paper/configuration/serializer/DespawnRangeSerializer.java b/src/main/java/io/papermc/paper/configuration/serializer/DespawnRangeSerializer.java
new file mode 100644
index 0000000000000000000000000000000000000000..35b27ce8857338d846e00d49bb2645f97785a0e9
--- /dev/null
+++ b/src/main/java/io/papermc/paper/configuration/serializer/DespawnRangeSerializer.java
@@ -0,0 +1,86 @@
+package io.papermc.paper.configuration.serializer;
+
+import io.papermc.paper.configuration.WorldConfiguration.Entities.Spawning.DespawnRange;
+import net.minecraft.world.entity.MobCategory;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.spongepowered.configurate.ConfigurationNode;
+import org.spongepowered.configurate.serialize.SerializationException;
+import org.spongepowered.configurate.serialize.TypeSerializer;
+import java.lang.reflect.Type;
+
+public class DespawnRangeSerializer implements TypeSerializer<DespawnRange> {
+
+ @Override
+ public DespawnRange deserialize(final Type type, final ConfigurationNode node) throws SerializationException {
+ ConfigurationNode hard = node.node("hard");
+ ConfigurationNode soft = node.node("soft");
+
+ int xzLimit;
+ int xzSoftLimit;
+ int yLimit;
+ int ySoftLimit;
+ boolean longSyntax = false;
+ boolean softLongSyntax = false;
+
+ MobCategory category = MobCategory.valueOf(node.key().toString().toUpperCase());
+
+ if (hard.hasChild("horizontal") && hard.hasChild("vertical")) {
+ xzLimit = ifPresent(hard.node("horizontal"), category.getDespawnDistance());
+ yLimit = ifPresent(hard.node("vertical"), category.getDespawnDistance());
+ longSyntax = true;
+ } else if (hard.hasChild("horizontal") || hard.hasChild("vertical")) {
+ throw new RuntimeException(new SerializationException(node, DespawnRange.class, "Expected both horizontal and vertical despawn ranges to be defined"));
+ } else {
+ xzLimit = yLimit = ifPresent(hard, category.getDespawnDistance());
+ }
+
+ if (soft.hasChild("horizontal") && soft.hasChild("vertical")) {
+ xzSoftLimit = ifPresent(soft.node("horizontal"), category.getNoDespawnDistance());
+ ySoftLimit = ifPresent(soft.node("vertical"), category.getNoDespawnDistance());
+ softLongSyntax = true;
+ } else if (soft.hasChild("horizontal") || soft.hasChild("vertical")) {
+ throw new RuntimeException(new SerializationException(node, DespawnRange.class, "Expected both horizontal and vertical despawn ranges to be defined"));
+ } else {
+ xzSoftLimit = ySoftLimit = ifPresent(soft, category.getNoDespawnDistance());
+ }
+ return new DespawnRange(xzLimit, yLimit, xzSoftLimit, ySoftLimit, longSyntax, softLongSyntax);
+ }
+
+ @Override
+ public void serialize(final Type type, @Nullable final DespawnRange despawnRange, final ConfigurationNode node) throws SerializationException {
+ if (despawnRange == null) {
+ node.raw(null);
+ return;
+ }
+
+ ConfigurationNode hard = node.node("hard");
+ ConfigurationNode soft = node.node("soft");
+
+ int xzLimit = despawnRange.xzLimit();
+ int xzSoftLimit = despawnRange.xzSoftLimit();
+ int yLimit = despawnRange.yLimit();
+ int ySoftLimit = despawnRange.ySoftLimit();
+
+ if (despawnRange.longSyntax()) {
+ hard.node("horizontal").set(xzLimit);
+ hard.node("vertical").set(yLimit);
+ } else {
+ hard.set(xzLimit);
+ }
+ if (despawnRange.softLongSyntax()) {
+ soft.node("horizontal").set(xzSoftLimit);
+ soft.node("vertical").set(ySoftLimit);
+ } else {
+ soft.set(xzSoftLimit);
+ }
+ }
+
+ private int ifPresent(ConfigurationNode node, int or) {
+ if (node.virtual()) {
+ return or;
+ } else if (node.raw() instanceof Integer i) {
+ return i;
+ }
+ throw new RuntimeException(new SerializationException(node, Integer.class, "Expected an integer, got \"" + node.raw() + "\" instead"));
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/io/papermc/paper/configuration/serializer/EngineModeSerializer.java b/src/main/java/io/papermc/paper/configuration/serializer/EngineModeSerializer.java
new file mode 100644
index 0000000000000000000000000000000000000000..27c0679d376bb31ab52131dfea74b3b580ca92b5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,44 @@ Subject: [PATCH] Add configurable entity despawn distances


diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 0593d828c911c94c9833bf12b9c294e5dac1f4e8..5fd0e3d27f3c86f1ff767b45dfa6138c30f13e3e 100644
index 0593d828c911c94c9833bf12b9c294e5dac1f4e8..cd5281b61f833701131cc6a6bade7bff96515541 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -864,14 +864,14 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
@@ -863,20 +863,27 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
Player entityhuman = this.level().getNearestPlayer(this, -1.0D);

if (entityhuman != null) {
double d0 = entityhuman.distanceToSqr((Entity) this);
- double d0 = entityhuman.distanceToSqr((Entity) this);
- int i = this.getType().getCategory().getDespawnDistance();
+ int i = this.level().paperConfig().entities.spawning.despawnRanges.get(this.getType().getCategory()).hard(); // Paper - Configurable despawn distances
int j = i * i;
- int j = i * i;
+ // Paper start - Configurable despawn distances
+ io.papermc.paper.configuration.WorldConfiguration.Entities.Spawning.DespawnRange despawnRanges = this.level().paperConfig().entities.spawning.despawnRanges.get(this.getType().getCategory());

if (d0 > (double) j && this.removeWhenFarAway(d0)) {
this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
}
- if (d0 > (double) j && this.removeWhenFarAway(d0)) {
- this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
- }
+ double xzDistanceSquared = entityhuman.distanceToSqr(this.getX(), entityhuman.getY(), this.getZ());
+ double yDistance = Math.abs(entityhuman.getY() - this.getY());

- int k = this.getType().getCategory().getNoDespawnDistance();
+ int k = this.level().paperConfig().entities.spawning.despawnRanges.get(this.getType().getCategory()).soft(); // Paper - Configurable despawn distances
int l = k * k;
- int l = k * k;
+ int xzLimitSquared = despawnRanges.xzLimit() * despawnRanges.xzLimit();
+ int xzSoftLimitSquared = despawnRanges.xzSoftLimit() * despawnRanges.xzSoftLimit();
+ int yLimit = despawnRanges.yLimit();
+ int ySoftLimit = despawnRanges.ySoftLimit();

if (this.noActionTime > 600 && this.random.nextInt(800) == 0 && d0 > (double) l && this.removeWhenFarAway(d0)) {
- if (this.noActionTime > 600 && this.random.nextInt(800) == 0 && d0 > (double) l && this.removeWhenFarAway(d0)) {
+ if ((xzDistanceSquared > xzLimitSquared || yDistance > yLimit) && this.removeWhenFarAway(xzDistanceSquared)) {
this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
- } else if (d0 < (double) l) {
+ }
+
+ if (xzDistanceSquared > xzSoftLimitSquared || yDistance > ySoftLimit) {
+ if (this.noActionTime > 600 && this.random.nextInt(800) == 0 && this.removeWhenFarAway(xzDistanceSquared)) {
+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
+ }
+ } else {
+ // Paper end - Configurable despawn distances
this.noActionTime = 0;
}
}
4 changes: 2 additions & 2 deletions patches/server/0034-Player-affects-spawning-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ index 3126e8cab3c40e3af47f4c8925e1c6a9523309ba..3207166061bf9c4d7bf3f38e5a9f7aff
public static Predicate<Entity> withinDistance(double x, double y, double z, double max) {
double d4 = max * max;
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 5fd0e3d27f3c86f1ff767b45dfa6138c30f13e3e..a753fd0434f611d8c77270012e383e3210f1194b 100644
index 13f4c2f5aaa4cf107265b752e8157b1dee3fb524..b66bfbbebcd3217042771c47646a2b8e1f3da10d 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -860,7 +860,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
Expand All @@ -32,7 +32,7 @@ index 5fd0e3d27f3c86f1ff767b45dfa6138c30f13e3e..a753fd0434f611d8c77270012e383e32
+ Player entityhuman = this.level().findNearbyPlayer(this, -1.0D, EntitySelector.PLAYER_AFFECTS_SPAWNING); // Paper - Affects Spawning API

if (entityhuman != null) {
double d0 = entityhuman.distanceToSqr((Entity) this);
// Paper start - Configurable despawn distances
diff --git a/src/main/java/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java b/src/main/java/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java
index 3b7fc11b7832a72fb9b0806fe9847f4e30759e7b..3cb84856c10347162a8736ae1ef65165183ec8fe 100644
--- a/src/main/java/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java
Expand Down
6 changes: 3 additions & 3 deletions patches/server/0202-Add-entity-knockback-events.patch
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ index cccc60602360f25f0aeddbd16dad2bb63a1728a8..ada79af49d1cafe25ca6c1fb456e1c4c
}
}
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 55aecada617bd84676928a7818f1511b2d85e7bf..f56d431207323a80b7f566ac6e30eebf232ee695 100644
index e5da6a5317ad05d8213c7aff64adc26325157a57..b1ab34ebf213ec82467a854408130d3202cde192 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -1691,7 +1691,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
@@ -1698,7 +1698,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
if (f1 > 0.0F && target instanceof LivingEntity) {
LivingEntity entityliving = (LivingEntity) target;

Expand Down Expand Up @@ -273,7 +273,7 @@ index 6476c644d3da824c5ee4190cb45cde678ff1188f..b216140a8be65e210250358af8daf493
// CraftBukkit end
entity.setDeltaMovement(entity.getDeltaMovement().add(vec3d1));
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index cfdabb93c2d30845af9108552ed9bee9929250ce..e1b7bd5c23ba79b84ad257b7fb45e251da3978e5 100644
index cfdabb93c2d30845af9108552ed9bee9929250ce..9225746382bcecb0bab655a8232fecc09169225d 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -1922,19 +1922,33 @@ public class CraftEventFactory {
Expand Down
12 changes: 6 additions & 6 deletions patches/server/0243-Improve-death-events.patch
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ index a3a1450949703851625bbb257e92b3be4d79a06a..ff3f70b8c266dc3b2ab374ffd6905ecb
}
}
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index f7a77b31dc196823510f96bd3b2344058e20feac..279fa00fd9043e1995f22c79f47d0b41c27bd933 100644
index 39dff0a38b53624c935f27cc86ff036c831f407f..bdee5725029eda3a0e7bee407286480c0bb47db1 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -283,6 +283,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
Expand Down Expand Up @@ -229,10 +229,10 @@ index f7a77b31dc196823510f96bd3b2344058e20feac..279fa00fd9043e1995f22c79f47d0b41
public int getExpReward(@Nullable Entity entity) { // CraftBukkit
Level world = this.level();
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index f56d431207323a80b7f566ac6e30eebf232ee695..c2b10c3dba9d4d08e48f8e8836142b85f16b14cb 100644
index b1ab34ebf213ec82467a854408130d3202cde192..31beb61c8995bca632aeb83bf357f5b3a06868ba 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -1119,6 +1119,12 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
@@ -1126,6 +1126,12 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab

}

Expand All @@ -245,15 +245,15 @@ index f56d431207323a80b7f566ac6e30eebf232ee695..c2b10c3dba9d4d08e48f8e8836142b85
@Override
protected void dropCustomDeathLoot(ServerLevel world, DamageSource source, boolean causedByPlayer) {
super.dropCustomDeathLoot(world, source, causedByPlayer);
@@ -1127,6 +1133,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
@@ -1134,6 +1140,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab

for (int j = 0; j < i; ++j) {
EquipmentSlot enumitemslot = aenumitemslot[j];
+ if (this.shouldSkipLoot(enumitemslot)) continue; // Paper
ItemStack itemstack = this.getItemBySlot(enumitemslot);
float f = this.getEquipmentDropChance(enumitemslot);

@@ -1151,7 +1158,13 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
@@ -1158,7 +1165,13 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
}

this.spawnAtLocation(itemstack);
Expand Down Expand Up @@ -443,7 +443,7 @@ index 92f9502a2d5721ebb1757a069a0f138db66628d7..6c5bd88777ff79c7408cf5ffed0f099a

public void injectScaledMaxHealth(Collection<AttributeInstance> collection, boolean force) {
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index d1b473ef83df0ed4ae7cd9dd0525dac5e8a41223..a9a2b35378d6654ba00a48737f596553445214aa 100644
index d63cf5933fdcff6d71c7ddbfed3640acd1646b70..1f4c686e92e7449556ee5067553ed4473ba2f50e 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -901,9 +901,16 @@ public class CraftEventFactory {
Expand Down
Loading
Loading