13
0
geforkt von Mirrors/Paper

Re-implement maxLeashDistance world conf and call missing event (#11301)

* Re-implement maxLeashDistance world config and call missing event

* migrate config setting to double or default

* fixes

---------

Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
Dieser Commit ist enthalten in:
Lulu13022002 2024-08-25 23:32:32 +02:00
Ursprung 4a97c636b7
Commit e24e14e58d
4 geänderte Dateien mit 60 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -13,7 +13,20 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
- if ((double) f > 10.0D) {
+ if ((double) f > entity.level().paperConfig().misc.maxLeashDistance) { // Paper - Configurable max leash distance
+ if ((double) f > entity.level().paperConfig().misc.maxLeashDistance.or(LEASH_TOO_FAR_DIST)) { // Paper - Configurable max leash distance
((Leashable) entity).leashTooFarBehaviour();
} else if ((double) f > 6.0D) {
((Leashable) entity).elasticRangeLeashBehaviour(entity1, f);
diff --git a/src/main/java/net/minecraft/world/entity/TamableAnimal.java b/src/main/java/net/minecraft/world/entity/TamableAnimal.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/TamableAnimal.java
+++ b/src/main/java/net/minecraft/world/entity/TamableAnimal.java
@@ -0,0 +0,0 @@ public abstract class TamableAnimal extends Animal implements OwnableEntity {
@Override
public boolean handleLeashAtDistance(Entity leashHolder, float distance) {
if (this.isInSittingPose()) {
- if (distance > 10.0F) {
+ if (distance > (float) this.level().paperConfig().misc.maxLeashDistance.or(Leashable.LEASH_TOO_FAR_DIST)) { // Paper - Configurable max leash distance
this.dropLeash(true, true);
}

Datei anzeigen

@ -27,11 +27,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
@@ -0,0 +0,0 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
protected void removeAfterChangingDimensions() {
this.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION, null); // CraftBukkit - add Bukkit remove cause
if (this instanceof Leashable leashable) {
- if (this instanceof Leashable leashable) {
- this.level().getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN)); // CraftBukkit
- leashable.dropLeash(true, false);
+ if (this instanceof Leashable leashable && leashable.isLeashed()) { // Paper - only call if it is leashed
+ // Paper start - Expand EntityUnleashEvent
+ final EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN, false); // CraftBukkit
+ event.callEvent();
@ -95,6 +97,23 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
return flag1;
diff --git a/src/main/java/net/minecraft/world/entity/TamableAnimal.java b/src/main/java/net/minecraft/world/entity/TamableAnimal.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/TamableAnimal.java
+++ b/src/main/java/net/minecraft/world/entity/TamableAnimal.java
@@ -0,0 +0,0 @@ public abstract class TamableAnimal extends Animal implements OwnableEntity {
public boolean handleLeashAtDistance(Entity leashHolder, float distance) {
if (this.isInSittingPose()) {
if (distance > (float) this.level().paperConfig().misc.maxLeashDistance.or(Leashable.LEASH_TOO_FAR_DIST)) { // Paper - Configurable max leash distance
- this.dropLeash(true, true);
+ // Paper start - Expand EntityUnleashEvent
+ org.bukkit.event.entity.EntityUnleashEvent event = new org.bukkit.event.entity.EntityUnleashEvent(this.getBukkitEntity(), org.bukkit.event.entity.EntityUnleashEvent.UnleashReason.DISTANCE, true);
+ if (!event.callEvent()) return false;
+ this.dropLeash(true, event.isDropLeash());
+ // Paper end - Expand EntityUnleashEvent
}
return false;
diff --git a/src/main/java/net/minecraft/world/entity/decoration/LeashFenceKnotEntity.java b/src/main/java/net/minecraft/world/entity/decoration/LeashFenceKnotEntity.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/decoration/LeashFenceKnotEntity.java

Datei anzeigen

@ -52,8 +52,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
if (entity2 != null) {
if (this != entity2) {
+ // Paper start - Fix item duplication and teleport issues
+ if (this instanceof Mob) {
+ ((Mob) this).dropLeash(true, true); // Paper drop lead
+ if (this instanceof Leashable leashable) {
+ leashable.dropLeash(true, true); // Paper drop lead
+ }
+ // Paper end - Fix item duplication and teleport issues
entity2.restoreFrom(this);

Datei anzeigen

@ -1031,6 +1031,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ .register(MapSerializer.TYPE, new MapSerializer(false))
+ .register(new EnumValueSerializer())
+ .register(new ComponentSerializer())
+ .register(IntOr.Default.SERIALIZER)
+ .register(IntOr.Disabled.SERIALIZER)
+ .register(DoubleOr.Default.SERIALIZER)
+ .register(DoubleOr.Disabled.SERIALIZER)
+ .register(BooleanOrDefault.SERIALIZER)
+ .register(Duration.SERIALIZER)
+ .register(DurationOrDisabled.SERIALIZER)
+ .register(NbtPathSerializer.SERIALIZER)
+ );
+ }
+
@ -1054,9 +1062,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ .header(GLOBAL_HEADER)
+ .serializers(builder -> builder
+ .register(new PacketClassSerializer())
+ .register(IntOr.Disabled.SERIALIZER)
+ .register(IntOr.Default.SERIALIZER)
+ .register(DoubleOr.Default.SERIALIZER)
+ );
+ }
+
@ -1100,14 +1105,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ .register(new TypeToken<Table<?, ?, ?>>() {}, new TableSerializer())
+ .register(DespawnRange.class, DespawnRange.SERIALIZER)
+ .register(StringRepresentableSerializer::isValidFor, new StringRepresentableSerializer())
+ .register(IntOr.Default.SERIALIZER)
+ .register(IntOr.Disabled.SERIALIZER)
+ .register(DoubleOr.Default.SERIALIZER)
+ .register(BooleanOrDefault.SERIALIZER)
+ .register(Duration.SERIALIZER)
+ .register(DurationOrDisabled.SERIALIZER)
+ .register(EngineMode.SERIALIZER)
+ .register(NbtPathSerializer.SERIALIZER)
+ .register(FallbackValueSerializer.create(contextMap.require(SPIGOT_WORLD_CONFIG_CONTEXT_KEY).get(), MinecraftServer::getServer))
+ .register(new RegistryValueSerializer<>(new TypeToken<EntityType<?>>() {}, access, Registries.ENTITY_TYPE, true))
+ .register(new RegistryValueSerializer<>(Item.class, access, Registries.ITEM, true))
@ -1985,7 +1983,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ public boolean showSignClickCommandFailureMsgsToPlayer = false;
+ public RedstoneImplementation redstoneImplementation = RedstoneImplementation.VANILLA;
+ public boolean disableEndCredits = false;
+ public double maxLeashDistance = Leashable.LEASH_TOO_FAR_DIST;
+ public DoubleOr.Default maxLeashDistance = DoubleOr.Default.USE_DEFAULT;
+ public boolean disableSprintInterruptionOnAttack = false;
+ public int shieldBlockingDelay = 5;
+ public boolean disableRelativeProjectileVelocity = false;
@ -4835,6 +4833,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+
+import com.google.common.base.Preconditions;
+import java.util.OptionalDouble;
+import java.util.function.DoublePredicate;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import org.spongepowered.configurate.serialize.ScalarSerializer;
@ -4857,6 +4856,20 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ public static final ScalarSerializer<Default> SERIALIZER = new Serializer<>(Default.class, Default::new, DEFAULT_VALUE, USE_DEFAULT);
+ }
+
+ record Disabled(OptionalDouble value) implements DoubleOr {
+ private static final String DISABLED_VALUE = "disabled";
+ public static final Disabled DISABLED = new Disabled(OptionalDouble.empty());
+ public static final ScalarSerializer<Disabled> SERIALIZER = new Serializer<>(Disabled.class, Disabled::new, DISABLED_VALUE, DISABLED);
+
+ public boolean test(DoublePredicate predicate) {
+ return this.value.isPresent() && predicate.test(this.value.getAsDouble());
+ }
+
+ public boolean enabled() {
+ return this.value.isPresent();
+ }
+ }
+
+ final class Serializer<T extends DoubleOr> extends OptionalNumSerializer<T, OptionalDouble> {
+ Serializer(final Class<T> classOfT, final Function<OptionalDouble, T> factory, String emptySerializedValue, T emptyValue) {
+ super(classOfT, emptySerializedValue, emptyValue, OptionalDouble::empty, OptionalDouble::isEmpty, factory, double.class);