geforkt von Mirrors/Paper
Add Configuration for vertical Despawn Ranges (#10440)
Dieser Commit ist enthalten in:
Ursprung
c1b2a34de3
Commit
258b830f5e
@ -9,19 +9,40 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
--- a/src/main/java/net/minecraft/world/entity/Mob.java
|
--- a/src/main/java/net/minecraft/world/entity/Mob.java
|
||||||
+++ b/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
|
@@ -0,0 +0,0 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
||||||
|
Player entityhuman = this.level().getNearestPlayer(this, -1.0D);
|
||||||
|
|
||||||
if (entityhuman != null) {
|
if (entityhuman != null) {
|
||||||
double d0 = entityhuman.distanceToSqr((Entity) this);
|
- double d0 = entityhuman.distanceToSqr((Entity) this);
|
||||||
- int i = this.getType().getCategory().getDespawnDistance();
|
- 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)) {
|
- if (d0 > (double) j && this.removeWhenFarAway(d0)) {
|
||||||
this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
|
- 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.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -866,11 +866,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+import io.leangen.geantyref.TypeToken;
|
+import io.leangen.geantyref.TypeToken;
|
||||||
+import io.papermc.paper.configuration.legacy.RequiresSpigotInitialization;
|
+import io.papermc.paper.configuration.legacy.RequiresSpigotInitialization;
|
||||||
+import io.papermc.paper.configuration.mapping.InnerClassFieldDiscoverer;
|
+import io.papermc.paper.configuration.mapping.InnerClassFieldDiscoverer;
|
||||||
+import io.papermc.paper.configuration.serializer.ComponentSerializer;
|
+import io.papermc.paper.configuration.serializer.*;
|
||||||
+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.FastutilMapSerializer;
|
||||||
+import io.papermc.paper.configuration.serializer.collections.MapSerializer;
|
+import io.papermc.paper.configuration.serializer.collections.MapSerializer;
|
||||||
+import io.papermc.paper.configuration.serializer.collections.TableSerializer;
|
+import io.papermc.paper.configuration.serializer.collections.TableSerializer;
|
||||||
@ -1095,6 +1091,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ .register(new TypeToken<Reference2IntMap<?>>() {}, new FastutilMapSerializer.SomethingToPrimitive<Reference2IntMap<?>>(Reference2IntOpenHashMap::new, Integer.TYPE))
|
+ .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<Reference2LongMap<?>>() {}, new FastutilMapSerializer.SomethingToPrimitive<Reference2LongMap<?>>(Reference2LongOpenHashMap::new, Long.TYPE))
|
||||||
+ .register(new TypeToken<Table<?, ?, ?>>() {}, new TableSerializer())
|
+ .register(new TypeToken<Table<?, ?, ?>>() {}, new TableSerializer())
|
||||||
|
+ .register(new TypeToken<WorldConfiguration.Entities.Spawning.DespawnRange>() {}, new DespawnRangeSerializer())
|
||||||
+ .register(StringRepresentableSerializer::isValidFor, new StringRepresentableSerializer())
|
+ .register(StringRepresentableSerializer::isValidFor, new StringRepresentableSerializer())
|
||||||
+ .register(IntOr.Default.SERIALIZER)
|
+ .register(IntOr.Default.SERIALIZER)
|
||||||
+ .register(IntOr.Disabled.SERIALIZER)
|
+ .register(IntOr.Disabled.SERIALIZER)
|
||||||
@ -1603,12 +1600,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ @MergeMap
|
+ @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)));
|
+ 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
|
+ @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
|
+ @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)));
|
+ 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 xzLimit, @Required int yLimit, @Required int xzSoftLimit, @Required int ySoftLimit, @Required boolean longSyntax, @Required boolean softLongSyntax) {
|
||||||
+ public record DespawnRange(@Required int soft, @Required int hard) {
|
+ public DespawnRange(int hard, int soft) {
|
||||||
|
+ this(hard, hard, soft, soft, false, false);
|
||||||
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ public WaterAnimalSpawnHeight wateranimalSpawnHeight;
|
+ public WaterAnimalSpawnHeight wateranimalSpawnHeight;
|
||||||
@ -2461,6 +2460,99 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ return MiniMessage.miniMessage().serialize(component);
|
+ 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<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
|
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
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
||||||
|
@ -32,7 +32,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ Player entityhuman = this.level().findNearbyPlayer(this, -1.0D, EntitySelector.PLAYER_AFFECTS_SPAWNING); // Paper - Affects Spawning API
|
+ Player entityhuman = this.level().findNearbyPlayer(this, -1.0D, EntitySelector.PLAYER_AFFECTS_SPAWNING); // Paper - Affects Spawning API
|
||||||
|
|
||||||
if (entityhuman != null) {
|
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
|
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
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java
|
--- a/src/main/java/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren