mirror of
https://github.com/PaperMC/Paper.git
synced 2025-02-12 10:31:37 +01:00
Add configurable entity despawn distances
This commit is contained in:
parent
92ffacc419
commit
a24a98199a
@ -48,7 +48,7 @@
|
|||||||
protected void registerGoals() {}
|
protected void registerGoals() {}
|
||||||
|
|
||||||
public static AttributeSupplier.Builder createMobAttributes() {
|
public static AttributeSupplier.Builder createMobAttributes() {
|
||||||
@@ -264,13 +284,44 @@
|
@@ -264,11 +284,42 @@
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
protected final LivingEntity getTargetFromBrain() {
|
protected final LivingEntity getTargetFromBrain() {
|
||||||
@ -60,8 +60,8 @@
|
|||||||
- this.target = target;
|
- this.target = target;
|
||||||
+ // CraftBukkit start - fire event
|
+ // CraftBukkit start - fire event
|
||||||
+ this.setTarget(target, EntityTargetEvent.TargetReason.UNKNOWN, true);
|
+ this.setTarget(target, EntityTargetEvent.TargetReason.UNKNOWN, true);
|
||||||
}
|
+ }
|
||||||
|
+
|
||||||
+ public boolean setTarget(LivingEntity entityliving, EntityTargetEvent.TargetReason reason, boolean fireEvent) {
|
+ public boolean setTarget(LivingEntity entityliving, EntityTargetEvent.TargetReason reason, boolean fireEvent) {
|
||||||
+ if (this.getTarget() == entityliving) return false;
|
+ if (this.getTarget() == entityliving) return false;
|
||||||
+ if (fireEvent) {
|
+ if (fireEvent) {
|
||||||
@ -90,11 +90,9 @@
|
|||||||
+ this.target = entityliving;
|
+ this.target = entityliving;
|
||||||
+ return true;
|
+ return true;
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
+ }
|
}
|
||||||
+
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canAttackType(EntityType<?> type) {
|
|
||||||
return type != EntityType.GHAST;
|
|
||||||
@@ -399,6 +450,12 @@
|
@@ -399,6 +450,12 @@
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -208,7 +206,7 @@
|
|||||||
|
|
||||||
this.setItemSlotAndDropWhenKilled(enumitemslot, itemstack2);
|
this.setItemSlotAndDropWhenKilled(enumitemslot, itemstack2);
|
||||||
return itemstack2;
|
return itemstack2;
|
||||||
@@ -768,7 +856,7 @@
|
@@ -768,25 +856,29 @@
|
||||||
@Override
|
@Override
|
||||||
public void checkDespawn() {
|
public void checkDespawn() {
|
||||||
if (this.level().getDifficulty() == Difficulty.PEACEFUL && this.shouldDespawnInPeaceful()) {
|
if (this.level().getDifficulty() == Difficulty.PEACEFUL && this.shouldDespawnInPeaceful()) {
|
||||||
@ -217,24 +215,42 @@
|
|||||||
} else if (!this.isPersistenceRequired() && !this.requiresCustomPersistence()) {
|
} else if (!this.isPersistenceRequired() && !this.requiresCustomPersistence()) {
|
||||||
Player entityhuman = this.level().getNearestPlayer(this, -1.0D);
|
Player entityhuman = this.level().getNearestPlayer(this, -1.0D);
|
||||||
|
|
||||||
@@ -778,14 +866,14 @@
|
if (entityhuman != null) {
|
||||||
int j = i * i;
|
- double d0 = entityhuman.distanceToSqr((Entity) this);
|
||||||
|
- int i = this.getType().getCategory().getDespawnDistance();
|
||||||
if (d0 > (double) j && this.removeWhenFarAway(d0)) {
|
- int j = i * i;
|
||||||
|
-
|
||||||
|
- if (d0 > (double) j && this.removeWhenFarAway(d0)) {
|
||||||
- this.discard();
|
- this.discard();
|
||||||
|
+ // Paper start - Configurable despawn distances
|
||||||
|
+ final io.papermc.paper.configuration.WorldConfiguration.Entities.Spawning.DespawnRangePair despawnRangePair = this.level().paperConfig().entities.spawning.despawnRanges.get(this.getType().getCategory());
|
||||||
|
+ final io.papermc.paper.configuration.type.DespawnRange.Shape shape = this.level().paperConfig().entities.spawning.despawnRangeShape;
|
||||||
|
+ final double dy = Math.abs(entityhuman.getY() - this.getY());
|
||||||
|
+ final double dySqr = Math.pow(dy, 2);
|
||||||
|
+ final double dxSqr = Math.pow(entityhuman.getX() - this.getX(), 2);
|
||||||
|
+ final double dzSqr = Math.pow(entityhuman.getZ() - this.getZ(), 2);
|
||||||
|
+ final double distanceSquared = dxSqr + dzSqr + dySqr;
|
||||||
|
+ // Despawn if hard/soft limit is exceeded
|
||||||
|
+ if (despawnRangePair.hard().shouldDespawn(shape, dxSqr, dySqr, dzSqr, dy) && this.removeWhenFarAway(distanceSquared)) {
|
||||||
+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
|
+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
|
||||||
}
|
}
|
||||||
|
-
|
||||||
int k = this.getType().getCategory().getNoDespawnDistance();
|
- int k = this.getType().getCategory().getNoDespawnDistance();
|
||||||
int l = k * k;
|
- int l = k * k;
|
||||||
|
-
|
||||||
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)) {
|
||||||
- this.discard();
|
- this.discard();
|
||||||
+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
|
- } else if (d0 < (double) l) {
|
||||||
} else if (d0 < (double) l) {
|
+ if (despawnRangePair.soft().shouldDespawn(shape, dxSqr, dySqr, dzSqr, dy)) {
|
||||||
|
+ if (this.noActionTime > 600 && this.random.nextInt(800) == 0 && this.removeWhenFarAway(distanceSquared)) {
|
||||||
|
+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
|
||||||
|
+ }
|
||||||
|
+ } else {
|
||||||
|
+ // Paper end - Configurable despawn distances
|
||||||
this.noActionTime = 0;
|
this.noActionTime = 0;
|
||||||
}
|
}
|
||||||
@@ -799,6 +887,15 @@
|
}
|
||||||
|
@@ -799,6 +891,15 @@
|
||||||
@Override
|
@Override
|
||||||
protected final void serverAiStep() {
|
protected final void serverAiStep() {
|
||||||
++this.noActionTime;
|
++this.noActionTime;
|
||||||
@ -250,7 +266,7 @@
|
|||||||
ProfilerFiller gameprofilerfiller = Profiler.get();
|
ProfilerFiller gameprofilerfiller = Profiler.get();
|
||||||
|
|
||||||
gameprofilerfiller.push("sensing");
|
gameprofilerfiller.push("sensing");
|
||||||
@@ -1338,7 +1435,7 @@
|
@@ -1338,7 +1439,7 @@
|
||||||
if (itemstack.getItem() instanceof SpawnEggItem) {
|
if (itemstack.getItem() instanceof SpawnEggItem) {
|
||||||
if (this.level() instanceof ServerLevel) {
|
if (this.level() instanceof ServerLevel) {
|
||||||
SpawnEggItem itemmonsteregg = (SpawnEggItem) itemstack.getItem();
|
SpawnEggItem itemmonsteregg = (SpawnEggItem) itemstack.getItem();
|
||||||
@ -259,7 +275,7 @@
|
|||||||
|
|
||||||
optional.ifPresent((entityinsentient) -> {
|
optional.ifPresent((entityinsentient) -> {
|
||||||
this.onOffspringSpawnedFromEgg(player, entityinsentient);
|
this.onOffspringSpawnedFromEgg(player, entityinsentient);
|
||||||
@@ -1389,28 +1486,45 @@
|
@@ -1389,28 +1490,45 @@
|
||||||
return this.restrictRadius != -1.0F;
|
return this.restrictRadius != -1.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,7 +327,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
return t0;
|
return t0;
|
||||||
@@ -1420,10 +1534,17 @@
|
@@ -1420,10 +1538,17 @@
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public <T extends Mob> T convertTo(EntityType<T> entityType, ConversionParams context, ConversionParams.AfterConversion<T> finalizer) {
|
public <T extends Mob> T convertTo(EntityType<T> entityType, ConversionParams context, ConversionParams.AfterConversion<T> finalizer) {
|
||||||
@ -330,7 +346,7 @@
|
|||||||
@Override
|
@Override
|
||||||
public Leashable.LeashData getLeashData() {
|
public Leashable.LeashData getLeashData() {
|
||||||
return this.leashData;
|
return this.leashData;
|
||||||
@@ -1458,6 +1579,7 @@
|
@@ -1458,6 +1583,7 @@
|
||||||
boolean flag1 = super.startRiding(entity, force);
|
boolean flag1 = super.startRiding(entity, force);
|
||||||
|
|
||||||
if (flag1 && this.isLeashed()) {
|
if (flag1 && this.isLeashed()) {
|
||||||
@ -338,7 +354,7 @@
|
|||||||
this.dropLeash();
|
this.dropLeash();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1542,7 +1664,7 @@
|
@@ -1542,7 +1668,7 @@
|
||||||
|
|
||||||
if (f1 > 0.0F && target instanceof LivingEntity) {
|
if (f1 > 0.0F && target instanceof LivingEntity) {
|
||||||
entityliving = (LivingEntity) target;
|
entityliving = (LivingEntity) target;
|
||||||
|
Loading…
Reference in New Issue
Block a user