Files
Purpur/patches/server/0079-Entity-lifespan.patch
Encode42 eda086ea50 Updated Upstream (Pufferfish)
Upstream has released updates that appear to apply and compile correctly

Pufferfish Changes:
pufferfish-gg/Pufferfish@e535b1b Change goal selector from a disable to a throttle to improve vanilla parity
2022-01-05 14:22:32 -05:00

107 lines
4.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Sat, 11 Jul 2020 19:41:34 -0500
Subject: [PATCH] Entity lifespan
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 9d43556ecdafed0605bfd6f65c4f5795a41261a9..6f4396ab99bf87560544e3eb7f4e8711595af2ae 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -129,6 +129,7 @@ public abstract class Mob extends LivingEntity {
private BlockPos restrictCenter;
private float restrictRadius;
+ public int ticksSinceLastInteraction; // Purpur
public boolean aware = true; // CraftBukkit
protected Mob(EntityType<? extends Mob> type, Level world) {
@@ -288,6 +289,7 @@ public abstract class Mob extends LivingEntity {
entityliving = null;
}
}
+ if (entityliving instanceof ServerPlayer) this.ticksSinceLastInteraction = 0; // Purpur
this.target = entityliving;
return true;
// CraftBukkit end
@@ -332,9 +334,35 @@ public abstract class Mob extends LivingEntity {
this.playAmbientSound();
}
+ incrementTicksSinceLastInteraction();
this.level.getProfiler().pop();
}
+ // Purpur start
+ private void incrementTicksSinceLastInteraction() {
+ ++ticksSinceLastInteraction;
+ //if (hasRider()) {
+ // ticksSinceLastInteraction = 0;
+ // return;
+ //}
+ if (level.purpurConfig.entityLifeSpan <= 0) {
+ return; // feature disabled
+ }
+ if (!this.removeWhenFarAway(0) || isPersistenceRequired() || requiresCustomPersistence() || hasCustomName()) {
+ return; // mob persistent
+ }
+ if (ticksSinceLastInteraction > level.purpurConfig.entityLifeSpan) {
+ this.discard();
+ }
+ }
+
+ @Override
+ public boolean hurt(DamageSource source, float amount) {
+ if (source.getEntity() instanceof ServerPlayer) this.ticksSinceLastInteraction = 0; // Purpur
+ return super.hurt(source, amount);
+ }
+ // Purpur end
+
@Override
protected void playHurtSound(DamageSource source) {
this.resetAmbientSoundTime();
@@ -518,6 +546,7 @@ public abstract class Mob extends LivingEntity {
}
nbt.putBoolean("Bukkit.Aware", this.aware); // CraftBukkit
+ nbt.putInt("Purpur.ticksSinceLastInteraction", ticksSinceLastInteraction); // Purpur
}
@Override
@@ -588,6 +617,11 @@ public abstract class Mob extends LivingEntity {
this.aware = nbt.getBoolean("Bukkit.Aware");
}
// CraftBukkit end
+ // Purpur start
+ if (nbt.contains("Purpur.ticksSinceLastInteraction")) {
+ ticksSinceLastInteraction = nbt.getInt("Purpur.ticksSinceLastInteraction");
+ }
+ // Purpur end
}
@Override
@@ -1613,6 +1647,7 @@ public abstract class Mob extends LivingEntity {
this.setLastHurtMob(target);
}
+ if (target instanceof ServerPlayer) this.ticksSinceLastInteraction = 0; // Purpur
return flag;
}
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
index 96fd3a8735eacd42ec983b4f91ad88bec2a9a3a5..29609a60af03e8334f847aeb90c57a9e352b1893 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
@@ -123,6 +123,11 @@ public class PurpurWorldConfig {
elytraDamagePerTridentBoost = getInt("gameplay-mechanics.elytra.damage-per-boost.trident", elytraDamagePerTridentBoost);
}
+ public int entityLifeSpan = 0;
+ private void entitySettings() {
+ entityLifeSpan = getInt("gameplay-mechanics.entity-lifespan", entityLifeSpan);
+ }
+
public List<Item> itemImmuneToCactus = new ArrayList<>();
public List<Item> itemImmuneToExplosion = new ArrayList<>();
public List<Item> itemImmuneToFire = new ArrayList<>();