diff --git a/patches/server/Add-configurable-entity-despawn-distances.patch b/patches/server/Add-configurable-entity-despawn-distances.patch index ae1208d177..15311ad1e8 100644 --- a/patches/server/Add-configurable-entity-despawn-distances.patch +++ b/patches/server/Add-configurable-entity-despawn-distances.patch @@ -9,40 +9,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 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 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()); ++ int i = this.level().paperConfig().entities.spawning.despawnRanges.get(this.getType().getCategory()).hard(); // Paper - Configurable despawn distances + int j = i * i; -- 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()); + if (d0 > (double) j && this.removeWhenFarAway(d0)) { + this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause + } - int k = this.getType().getCategory().getNoDespawnDistance(); -- int l = k * k; -+ int xzLimitSquared = despawnRanges.xzLimit() * despawnRanges.xzLimit(); -+ int xzSoftLimitSquared = despawnRanges.xzSoftLimit() * despawnRanges.xzSoftLimit(); -+ int yLimit = despawnRanges.yLimit(); -+ int ySoftLimit = despawnRanges.ySoftLimit(); ++ int k = this.level().paperConfig().entities.spawning.despawnRanges.get(this.getType().getCategory()).soft(); // Paper - Configurable despawn distances + int l = k * k; -- 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; - } - } + if (this.noActionTime > 600 && this.random.nextInt(800) == 0 && d0 > (double) l && this.removeWhenFarAway(d0)) { diff --git a/patches/server/Paper-config-files.patch b/patches/server/Paper-config-files.patch index 6fe19e16de..5aa0d8ff70 100644 --- a/patches/server/Paper-config-files.patch +++ b/patches/server/Paper-config-files.patch @@ -866,7 +866,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +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.*; ++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.collections.FastutilMapSerializer; +import io.papermc.paper.configuration.serializer.collections.MapSerializer; +import io.papermc.paper.configuration.serializer.collections.TableSerializer; @@ -1091,7 +1095,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + .register(new TypeToken>() {}, new FastutilMapSerializer.SomethingToPrimitive>(Reference2IntOpenHashMap::new, Integer.TYPE)) + .register(new TypeToken>() {}, new FastutilMapSerializer.SomethingToPrimitive>(Reference2LongOpenHashMap::new, Long.TYPE)) + .register(new TypeToken>() {}, new TableSerializer()) -+ .register(new TypeToken() {}, new DespawnRangeSerializer()) + .register(StringRepresentableSerializer::isValidFor, new StringRepresentableSerializer()) + .register(IntOr.Default.SERIALIZER) + .register(IntOr.Disabled.SERIALIZER) @@ -1600,14 +1603,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + @MergeMap + public Reference2IntMap spawnLimits = Util.make(new Reference2IntOpenHashMap<>(NaturalSpawner.SPAWNING_CATEGORIES.length), map -> Arrays.stream(NaturalSpawner.SPAWNING_CATEGORIES).forEach(mobCategory -> map.put(mobCategory, -1))); + @MergeMap -+ public Map despawnRanges = Arrays.stream(MobCategory.values()).collect(Collectors.toMap(Function.identity(), category -> new DespawnRange(category.getDespawnDistance(), category.getNoDespawnDistance()))); ++ public Map despawnRanges = Arrays.stream(MobCategory.values()).collect(Collectors.toMap(Function.identity(), category -> new DespawnRange(category.getNoDespawnDistance(), category.getDespawnDistance()))); + @MergeMap + public Reference2IntMap ticksPerSpawn = Util.make(new Reference2IntOpenHashMap<>(NaturalSpawner.SPAWNING_CATEGORIES.length), map -> Arrays.stream(NaturalSpawner.SPAWNING_CATEGORIES).forEach(mobCategory -> map.put(mobCategory, -1))); + -+ 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); -+ } ++ @ConfigSerializable ++ public record DespawnRange(@Required int soft, @Required int hard) { + } + + public WaterAnimalSpawnHeight wateranimalSpawnHeight; @@ -2460,99 +2461,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + 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..0000000000000000000000000000000000000000 ---- /dev/null -+++ b/src/main/java/io/papermc/paper/configuration/serializer/DespawnRangeSerializer.java -@@ -0,0 +0,0 @@ -+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 { -+ -+ @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..0000000000000000000000000000000000000000 diff --git a/patches/server/Player-affects-spawning-API.patch b/patches/server/Player-affects-spawning-API.patch index aeb0c6b613..7f70948768 100644 --- a/patches/server/Player-affects-spawning-API.patch +++ b/patches/server/Player-affects-spawning-API.patch @@ -32,7 +32,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + Player entityhuman = this.level().findNearbyPlayer(this, -1.0D, EntitySelector.PLAYER_AFFECTS_SPAWNING); // Paper - Affects Spawning API if (entityhuman != null) { - // Paper start - Configurable despawn distances + double d0 = entityhuman.distanceToSqr((Entity) this); 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java