Files
Purpur/patches/server/0075-Entity-lifespan.patch
granny 0090323edb Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@7569191 Send disguised chat for vanished players
PaperMC/Paper@96fd31b Fix chunk sending when the computed time overflows (#8833)
PaperMC/Paper@39aef52 Fix `Tick::addTo`/`::between` causing SOE (#8824)
PaperMC/Paper@0c3311c Add Entity Body Yaw API (#8822)
PaperMC/Paper@0c9ace8 Add AntiXray layered obfuscation mode (#8799)
PaperMC/Paper@5eca964 [ci skip] Rebuild patches
2023-02-09 17:55:16 -08:00

113 lines
5.0 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/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 952b1bf1a1b4da6c6b691099d20c9a3fbe7f0a2e..2018a1b24f3cb50aafc0593506d27e6bde248993 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -2829,6 +2829,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
}
if (entity.distanceToSqr(this.player.getEyePosition()) < ServerGamePacketListenerImpl.MAX_INTERACTION_DISTANCE) {
+ if (entity instanceof Mob mob) mob.ticksSinceLastInteraction = 0; // Purpur
packet.dispatch(new ServerboundInteractPacket.Handler() {
private void performInteraction(InteractionHand enumhand, ServerGamePacketListenerImpl.EntityInteraction playerconnection_a, PlayerInteractEntityEvent event) { // CraftBukkit
ItemStack itemstack = ServerGamePacketListenerImpl.this.player.getItemInHand(enumhand);
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 4d093e8f158b40c3ff99328aa107459910e85a8d..e69aef21170be18f1582ff5e9f7e62bb1e788078 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -134,6 +134,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) {
@@ -290,6 +291,7 @@ public abstract class Mob extends LivingEntity {
entityliving = null;
}
}
+ if (entityliving instanceof ServerPlayer) this.ticksSinceLastInteraction = 0; // Purpur
this.target = entityliving;
return true;
// CraftBukkit end
@@ -336,9 +338,29 @@ public abstract class Mob extends LivingEntity {
this.playAmbientSound();
}
+ incrementTicksSinceLastInteraction(); // Purpur
this.level.getProfiler().pop();
}
+ // Purpur start
+ 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();
+ }
+ }
+ // Purpur end
+
@Override
protected void playHurtSound(DamageSource source) {
this.resetAmbientSoundTime();
@@ -528,6 +550,7 @@ public abstract class Mob extends LivingEntity {
}
nbt.putBoolean("Bukkit.Aware", this.aware); // CraftBukkit
+ nbt.putInt("Purpur.ticksSinceLastInteraction", this.ticksSinceLastInteraction); // Purpur
}
@Override
@@ -598,6 +621,11 @@ public abstract class Mob extends LivingEntity {
this.aware = nbt.getBoolean("Bukkit.Aware");
}
// CraftBukkit end
+ // Purpur start
+ if (nbt.contains("Purpur.ticksSinceLastInteraction")) {
+ this.ticksSinceLastInteraction = nbt.getInt("Purpur.ticksSinceLastInteraction");
+ }
+ // Purpur end
}
@Override
@@ -1666,6 +1694,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 6c30a046a7f3c8f8222f0e75b9d9aa18f5ddb9f3..4ed217b503320b1272e79b0fa7c964e6038e4cdf 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
@@ -128,6 +128,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<>();