mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
107 lines
4.1 KiB
Diff
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 de3f7b0798d803e6d13a3c95aaaef3045ea22fed..9b8b82bf5bb276be51b8ba5c023879b3a45212cb 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Mob.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
|
|
@@ -125,6 +125,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) {
|
|
@@ -278,6 +279,7 @@ public abstract class Mob extends LivingEntity {
|
|
entityliving = null;
|
|
}
|
|
}
|
|
+ if (entityliving instanceof ServerPlayer) this.ticksSinceLastInteraction = 0; // Purpur
|
|
this.target = entityliving;
|
|
return true;
|
|
// CraftBukkit end
|
|
@@ -322,9 +324,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.dead = true;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @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();
|
|
@@ -508,6 +536,7 @@ public abstract class Mob extends LivingEntity {
|
|
}
|
|
|
|
nbt.putBoolean("Bukkit.Aware", this.aware); // CraftBukkit
|
|
+ nbt.putInt("Purpur.ticksSinceLastInteraction", ticksSinceLastInteraction); // Purpur
|
|
}
|
|
|
|
@Override
|
|
@@ -578,6 +607,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
|
|
@@ -1583,6 +1617,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/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
index af064d4ea1c64a5cd99b784a04599b650cd83d5d..8ba4f1abcb6832878339bd6bd3e12f5e7f046774 100644
|
|
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
@@ -101,6 +101,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<>();
|