Entity lifespan

This commit is contained in:
William Blake Galbreath
2025-01-07 16:47:40 -08:00
committed by granny
parent fae83be586
commit d2a0414806
5 changed files with 98 additions and 121 deletions

View File

@@ -0,0 +1,75 @@
--- a/net/minecraft/world/entity/Mob.java
+++ b/net/minecraft/world/entity/Mob.java
@@ -145,6 +_,7 @@
private BlockPos restrictCenter = BlockPos.ZERO;
private float restrictRadius = -1.0F;
public boolean aware = true; // CraftBukkit
+ public int ticksSinceLastInteraction; // Purpur - Entity lifespan
protected Mob(EntityType<? extends Mob> entityType, Level level) {
super(entityType, level);
@@ -294,6 +_,7 @@
target = null;
}
}
+ if (target instanceof net.minecraft.server.level.ServerPlayer) this.ticksSinceLastInteraction = 0; // Purpur - Entity lifespan
this.target = target;
return true;
// CraftBukkit end
@@ -337,7 +_,27 @@
}
profilerFiller.pop();
- }
+ incrementTicksSinceLastInteraction(); // Purpur - Entity lifespan
+ }
+
+ // Purpur start - Entity lifespan
+ private void incrementTicksSinceLastInteraction() {
+ ++this.ticksSinceLastInteraction;
+ if (getRider() != null) {
+ this.ticksSinceLastInteraction = 0;
+ return;
+ }
+ if (this.level().purpurConfig.entityLifeSpan <= 0) {
+ return; // feature disabled
+ }
+ if (!this.removeWhenFarAway(0) || isPersistenceRequired() || requiresCustomPersistence() || hasCustomName()) {
+ return; // mob persistent
+ }
+ if (this.ticksSinceLastInteraction > this.level().purpurConfig.entityLifeSpan) {
+ this.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DISCARD);
+ }
+ }
+ // Purpur end - Entity lifespan
@Override
protected void playHurtSound(DamageSource source) {
@@ -486,6 +_,7 @@
compound.putBoolean("NoAI", this.isNoAi());
}
compound.putBoolean("Bukkit.Aware", this.aware); // CraftBukkit
+ compound.putInt("Purpur.ticksSinceLastInteraction", this.ticksSinceLastInteraction); // Purpur - Entity lifespan
}
@Override
@@ -568,6 +_,11 @@
this.aware = compound.getBoolean("Bukkit.Aware");
}
// CraftBukkit end
+ // Purpur start - Entity lifespan
+ if (compound.contains("Purpur.ticksSinceLastInteraction")) {
+ this.ticksSinceLastInteraction = compound.getInt("Purpur.ticksSinceLastInteraction");
+ }
+ // Purpur end - Entity lifespan
}
@Override
@@ -1619,6 +_,7 @@
this.playAttackSound();
}
+ if (target instanceof net.minecraft.server.level.ServerPlayer) this.ticksSinceLastInteraction = 0; // Purpur - Entity lifespan
return flag;
}