Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
notTamion committed Apr 21, 2024
1 parent da89d7e commit d6f0c44
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 36 deletions.
94 changes: 87 additions & 7 deletions patches/server/0005-Paper-config-files.patch
Original file line number Diff line number Diff line change
Expand Up @@ -839,10 +839,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..fa1c0aee8c3a4d0868482cf5c703bbfd08e09874
index 0000000000000000000000000000000000000000..30e45c81e6ec6bfb7d246cdbc51c75861f875280
--- /dev/null
+++ b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java
@@ -0,0 +1,465 @@
@@ -0,0 +1,467 @@
+package io.papermc.paper.configuration;
+
+import com.google.common.base.Suppliers;
Expand All @@ -852,6 +852,7 @@ index 0000000000000000000000000000000000000000..fa1c0aee8c3a4d0868482cf5c703bbfd
+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.DespawnRangeSerializer;
+import io.papermc.paper.configuration.serializer.EnumValueSerializer;
+import io.papermc.paper.configuration.serializer.NbtPathSerializer;
+import io.papermc.paper.configuration.serializer.PacketClassSerializer;
Expand Down Expand Up @@ -1011,6 +1012,7 @@ index 0000000000000000000000000000000000000000..fa1c0aee8c3a4d0868482cf5c703bbfd
+ .register(MapSerializer.TYPE, new MapSerializer(false))
+ .register(new EnumValueSerializer())
+ .register(new ComponentSerializer())
+ .register(WorldConfiguration.Entities.Spawning.DespawnRange.class, new DespawnRangeSerializer())
+ );
+ }
+
Expand Down Expand Up @@ -1394,10 +1396,10 @@ index 0000000000000000000000000000000000000000..351fbbc577556ebbd62222615801a96b
+}
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..4392bbba7df3de91c93f1d6801d43a8291f48cae
index 0000000000000000000000000000000000000000..c144a8eab511378936072d55dc4533e35272123d
--- /dev/null
+++ b/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java
@@ -0,0 +1,553 @@
@@ -0,0 +1,556 @@
+package io.papermc.paper.configuration;
+
+import com.google.common.collect.HashBasedTable;
Expand Down Expand Up @@ -1582,12 +1584,15 @@ index 0000000000000000000000000000000000000000..4392bbba7df3de91c93f1d6801d43a82
+ @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(), -1, -1)));
+ 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, @Required int softY, @Required int hardY) {
+ public record DespawnRange(@Required int xzLimit, @Required int yLimit, @Required int xzSoftLimit, @Required int ySoftLimit) {
+
+ public DespawnRange(int hard, int soft) {
+ this(hard, hard, soft, soft);
+ }
+ }
+
+ public WaterAnimalSpawnHeight wateranimalSpawnHeight;
Expand Down Expand Up @@ -2440,6 +2445,81 @@ 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..c10f02d17e1312786903a3f3f1b46ee8388fbefd
--- /dev/null
+++ b/src/main/java/io/papermc/paper/configuration/serializer/DespawnRangeSerializer.java
@@ -0,0 +1,69 @@
+package io.papermc.paper.configuration.serializer;
+
+import io.papermc.paper.configuration.WorldConfiguration.Entities.Spawning.DespawnRange;
+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> {
+ public DespawnRangeSerializer() {
+ }
+
+ @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;
+ if (hard.hasChild("horizontal") && hard.hasChild("vertical")) {
+ xzLimit = hard.node("horizontal").getInt();
+ yLimit = hard.node("vertical").getInt();
+ } else {
+ xzLimit = hard.getInt();
+ yLimit = hard.getInt();
+ }
+
+ if (soft.hasChild("horizontal") && soft.hasChild("vertical")) {
+ xzSoftLimit = soft.node("horizontal").getInt();
+ ySoftLimit = soft.node("vertical").getInt();
+ } else {
+ xzSoftLimit = soft.getInt();
+ ySoftLimit = soft.getInt();
+ }
+
+ return new DespawnRange(xzLimit, yLimit, xzSoftLimit, ySoftLimit);
+ }
+
+ @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 (xzLimit == yLimit) {
+ hard.set(xzLimit);
+ } else {
+ hard.node("horizontal").set(despawnRange.xzLimit());
+ hard.node("vertical").set(despawnRange.yLimit());
+ }
+ if (xzSoftLimit == ySoftLimit) {
+ soft.set(xzSoftLimit);
+ } else {
+ soft.node("horizontal").set(xzSoftLimit);
+ soft.node("vertical").set(ySoftLimit);
+ }
+ }
+}
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
35 changes: 23 additions & 12 deletions patches/server/0023-Add-configurable-entity-despawn-distances.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,46 @@ Subject: [PATCH] Add configurable entity despawn distances
Co-authored-by: Tamion <70228790+notTamion@users.noreply.github.com>

diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 8395130fcc148ed1500342ead78b20a1387f23e9..23275334821d4eb0c3c746494357ffb921b3d4fa 100644
index 8395130fcc148ed1500342ead78b20a1387f23e9..7472d8db30762d29941c9fd48618e9f2095b08a0 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -854,19 +854,21 @@ public abstract class Mob extends LivingEntity implements Targeting {
@@ -853,22 +853,29 @@ public abstract class Mob extends LivingEntity implements Targeting {
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
+ double d1 = Math.abs(entityhuman.getY() - this.getY());
+ io.papermc.paper.configuration.WorldConfiguration.Entities.Spawning.DespawnRange despawnRanges = this.level().paperConfig().entities.spawning.despawnRanges.get(this.getType().getCategory());
+ int j = despawnRanges.hard() * despawnRanges.hard();

- if (d0 > (double) j && this.removeWhenFarAway(d0)) {
+ if ((d0 > (double) j || d1 > despawnRanges.hardY() && despawnRanges.hardY() != -1) && this.removeWhenFarAway(d0)) {
+ // Paper end - Configurable despawn distances
this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
}
- this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
- }
+ double xzDistance = entityhuman.distanceToSqr(this.getX(), entityhuman.getY(), this.getZ());
+ double yDistance = Math.abs(entityhuman.getY() - this.getY());

- int k = this.getType().getCategory().getNoDespawnDistance();
- int l = k * k;
+ int l = despawnRanges.soft() * despawnRanges.soft(); // Paper - Configurable despawn distances
+ int xzLimit = despawnRanges.xzLimit() * despawnRanges.xzLimit();
+ int xzSoftLimit = 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 || d1 > despawnRanges.softY() && despawnRanges.softY() != -1) && this.removeWhenFarAway(d0)) { // Paper - Configurable despawn distances
+ if ((xzDistance > xzLimit || yDistance > yLimit) && this.removeWhenFarAway(xzDistance)) {
this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
- } else if (d0 < (double) l) {
+ } else if (d0 < (double) l && (d1 < despawnRanges.softY() || despawnRanges.softY() == -1)) { // Paper - Configurable despawn distances
+ }
+
+ if (xzDistance > xzSoftLimit || yDistance > ySoftLimit) {
+ if (this.noActionTime > 600 && this.random.nextInt(800) == 0 && this.removeWhenFarAway(xzDistance)) {
+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
+ }
+ } else {
this.noActionTime = 0;
}
+ // Paper end - Configurable despawn distances
}

} else {
4 changes: 2 additions & 2 deletions patches/server/0029-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 1ab169b362cc18d2467e5ed6a4af325d7f6dd247..2de1ad28d42d4beec69901bf985ac0be582f00b9 100644
index 7472d8db30762d29941c9fd48618e9f2095b08a0..a753334c07c1082fdb314ca7dd1d7ede9ca32fb4 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -850,7 +850,7 @@ public abstract class Mob extends LivingEntity implements Targeting {
Expand All @@ -32,7 +32,7 @@ index 1ab169b362cc18d2467e5ed6a4af325d7f6dd247..2de1ad28d42d4beec69901bf985ac0be
+ 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 c7ab59aa0e2fd0f3e7252647ddb25b82ac604830..8f20239f3ef7ebe41fac8ee6e024c36dafec33c4 100644
--- a/src/main/java/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java
Expand Down
8 changes: 4 additions & 4 deletions patches/server/0245-Improve-death-events.patch
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ index c6c6fb195476e0d37b0007510044928ebe6e4572..4b3d1c8452bd759db6fc8d3d9fcf98e2
// CraftBukkit start
public int getExpReward() {
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index b40c89e1a1d18fba59925bf6c3a8084a19311b67..4d66ad4f3b857f45940483efad01393d5ba13605 100644
index 501f25376f045d0bec56037fa759216f33e01085..5efd69c8119f4fb7ef857f518b798876497266b3 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -1060,6 +1060,12 @@ public abstract class Mob extends LivingEntity implements Targeting {
@@ -1065,6 +1065,12 @@ public abstract class Mob extends LivingEntity implements Targeting {

}

Expand All @@ -250,15 +250,15 @@ index b40c89e1a1d18fba59925bf6c3a8084a19311b67..4d66ad4f3b857f45940483efad01393d
@Override
protected void dropCustomDeathLoot(DamageSource source, int lootingMultiplier, boolean allowDrops) {
super.dropCustomDeathLoot(source, lootingMultiplier, allowDrops);
@@ -1068,6 +1074,7 @@ public abstract class Mob extends LivingEntity implements Targeting {
@@ -1073,6 +1079,7 @@ public abstract class Mob extends LivingEntity implements Targeting {

for (int k = 0; k < j; ++k) {
EquipmentSlot enumitemslot = aenumitemslot[k];
+ if (this.shouldSkipLoot(enumitemslot)) continue; // Paper
ItemStack itemstack = this.getItemBySlot(enumitemslot);
float f = this.getEquipmentDropChance(enumitemslot);
boolean flag1 = f > 1.0F;
@@ -1078,7 +1085,13 @@ public abstract class Mob extends LivingEntity implements Targeting {
@@ -1083,7 +1090,13 @@ public abstract class Mob extends LivingEntity implements Targeting {
}

this.spawnAtLocation(itemstack);
Expand Down
10 changes: 5 additions & 5 deletions patches/server/0505-Expand-EntityUnleashEvent.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Expand EntityUnleashEvent


diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 4d66ad4f3b857f45940483efad01393d5ba13605..6c825ae9ca40c1302931260fe67c9ee9b4a38c01 100644
index 5efd69c8119f4fb7ef857f518b798876497266b3..b3804f5daca3a673392de5f711af0631bf0ebd19 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -1302,12 +1302,15 @@ public abstract class Mob extends LivingEntity implements Targeting {
@@ -1307,12 +1307,15 @@ public abstract class Mob extends LivingEntity implements Targeting {
return InteractionResult.PASS;
} else if (this.getLeashHolder() == player) {
// CraftBukkit start - fire PlayerUnleashEntityEvent
Expand All @@ -26,7 +26,7 @@ index 4d66ad4f3b857f45940483efad01393d5ba13605..6c825ae9ca40c1302931260fe67c9ee9
this.gameEvent(GameEvent.ENTITY_INTERACT, player);
return InteractionResult.sidedSuccess(this.level().isClientSide);
} else {
@@ -1475,8 +1478,11 @@ public abstract class Mob extends LivingEntity implements Targeting {
@@ -1480,8 +1483,11 @@ public abstract class Mob extends LivingEntity implements Targeting {

if (this.leashHolder != null) {
if (!this.isAlive() || !this.leashHolder.isAlive()) {
Expand All @@ -40,7 +40,7 @@ index 4d66ad4f3b857f45940483efad01393d5ba13605..6c825ae9ca40c1302931260fe67c9ee9
}

}
@@ -1539,8 +1545,11 @@ public abstract class Mob extends LivingEntity implements Targeting {
@@ -1544,8 +1550,11 @@ public abstract class Mob extends LivingEntity implements Targeting {
boolean flag1 = super.startRiding(entity, force);

if (flag1 && this.isLeashed()) {
Expand All @@ -54,7 +54,7 @@ index 4d66ad4f3b857f45940483efad01393d5ba13605..6c825ae9ca40c1302931260fe67c9ee9
}

return flag1;
@@ -1730,8 +1739,11 @@ public abstract class Mob extends LivingEntity implements Targeting {
@@ -1735,8 +1744,11 @@ public abstract class Mob extends LivingEntity implements Targeting {
@Override
protected void removeAfterChangingDimensions() {
super.removeAfterChangingDimensions();
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0926-Fix-inventory-desync.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Fix inventory desync


diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 6c825ae9ca40c1302931260fe67c9ee9b4a38c01..39f4210febe58c06347047ae66c813e9dcdfe43c 100644
index b3804f5daca3a673392de5f711af0631bf0ebd19..ffbc033a3251499b1eb4c8f60995e706c58c9a31 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -1338,6 +1338,7 @@ public abstract class Mob extends LivingEntity implements Targeting {
@@ -1343,6 +1343,7 @@ public abstract class Mob extends LivingEntity implements Targeting {
// CraftBukkit start - fire PlayerLeashEntityEvent
if (CraftEventFactory.callPlayerLeashEntityEvent(this, player, player, hand).isCancelled()) {
((ServerPlayer) player).connection.send(new ClientboundSetEntityLinkPacket(this, this.getLeashHolder()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Fix silent equipment change for mobs


diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 39f4210febe58c06347047ae66c813e9dcdfe43c..8f5848da6decd828ad0c1632fa281ee052578d62 100644
index ffbc033a3251499b1eb4c8f60995e706c58c9a31..a3edab4104bf0053a09d69c9c10c31a468287fe8 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -1049,13 +1049,20 @@ public abstract class Mob extends LivingEntity implements Targeting {
@@ -1054,13 +1054,20 @@ public abstract class Mob extends LivingEntity implements Targeting {

@Override
public void setItemSlot(EquipmentSlot slot, ItemStack stack) {
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0972-Add-PlayerShieldDisableEvent.patch
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ sideeffects, meaning the disable event cannot share a handlerlist with
the cooldown event

diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 8f5848da6decd828ad0c1632fa281ee052578d62..7690a4632c84084ffc9605ef9a8f113b5e79f0aa 100644
index a3edab4104bf0053a09d69c9c10c31a468287fe8..2f9dc65fc7f8a537edd459985e6e7d00a591258d 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -1701,7 +1701,11 @@ public abstract class Mob extends LivingEntity implements Targeting {
@@ -1706,7 +1706,11 @@ public abstract class Mob extends LivingEntity implements Targeting {
float f = 0.25F + (float) EnchantmentHelper.getBlockEfficiency(this) * 0.05F;

if (this.random.nextFloat() < f) {
Expand Down

0 comments on commit d6f0c44

Please sign in to comment.