Files
Purpur/patches/server/0090-Entity-lifespan.patch
BillyGalbreath 391f9addfd Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
fb36f15d6 Let some more packets be send immediately, closes #4140 (#4896)
ede41fe16 Emancipate more features to PlayerHandshakeEvent
3fdeba1f5 [CI-SKIP] [Auto] Rebuild Patches
5fc07bd63 Maded Title-Objects directy sendable to targets
e7b9a478e Player Chunk Load/Unload Events
1d0cfc0cc MC-4 Fix item position desync
458db6206 Limit auto recipe packets
2020-12-16 18:05:35 -06:00

122 lines
5.4 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/EntityInsentient.java b/src/main/java/net/minecraft/server/EntityInsentient.java
index 7a40f0864677e54c3a0eca6dcb9a115864edfbbd..1d5d87e61946c674f61541455cf54018bfca1ecb 100644
--- a/src/main/java/net/minecraft/server/EntityInsentient.java
+++ b/src/main/java/net/minecraft/server/EntityInsentient.java
@@ -53,7 +53,7 @@ public abstract class EntityInsentient extends EntityLiving {
private NBTTagCompound by;
private BlockPosition bz;
private float bA;
-
+ public int ticksSinceLastInteraction; // Purpur
public boolean aware = true; // CraftBukkit
protected EntityInsentient(EntityTypes<? extends EntityInsentient> entitytypes, World world) {
@@ -205,6 +205,7 @@ public abstract class EntityInsentient extends EntityLiving {
entityliving = null;
}
}
+ if (entityliving instanceof EntityPlayer) this.ticksSinceLastInteraction = 0; // Purpur
this.goalTarget = entityliving;
return true;
// CraftBukkit end
@@ -248,10 +249,35 @@ public abstract class EntityInsentient extends EntityLiving {
this.m();
this.F();
}
-
+ incrementTicksSinceLastInteraction(); // Purpur
this.world.getMethodProfiler().exit();
}
+ // Purpur start
+ private void incrementTicksSinceLastInteraction() {
+ ++ticksSinceLastInteraction;
+ //if (hasRider()) {
+ // ticksSinceLastInteraction = 0;
+ // return;
+ //}
+ if (world.purpurConfig.entityLifeSpan <= 0) {
+ return; // feature disabled
+ }
+ if (!isTypeNotPersistent(0) || isPersistent() || isSpecialPersistence() || hasCustomName()) {
+ return; // mob persistent
+ }
+ if (ticksSinceLastInteraction > world.purpurConfig.entityLifeSpan) {
+ this.dead = true;
+ }
+ }
+
+ @Override
+ public boolean damageEntity(DamageSource damagesource, float f) {
+ if (damagesource.getEntity() instanceof EntityPlayer) this.ticksSinceLastInteraction = 0; // Purpur
+ return super.damageEntity(damagesource, f);
+ }
+ // Purpur end
+
@Override
protected void c(DamageSource damagesource) {
this.m();
@@ -425,6 +451,7 @@ public abstract class EntityInsentient extends EntityLiving {
}
nbttagcompound.setBoolean("Bukkit.Aware", this.aware); // CraftBukkit
+ nbttagcompound.setInt("Purpur.ticksSinceLastInteraction", ticksSinceLastInteraction); // Purpur
}
@Override
@@ -495,6 +522,11 @@ public abstract class EntityInsentient extends EntityLiving {
this.aware = nbttagcompound.getBoolean("Bukkit.Aware");
}
// CraftBukkit end
+ // Purpur start
+ if (nbttagcompound.hasKey("Purpur.ticksSinceLastInteraction")) {
+ ticksSinceLastInteraction = nbttagcompound.getInt("Purpur.ticksSinceLastInteraction");
+ }
+ // Purpur end
}
@Override
@@ -1544,7 +1576,7 @@ public abstract class EntityInsentient extends EntityLiving {
this.a((EntityLiving) this, entity);
this.z(entity);
}
-
+ if (entity instanceof EntityPlayer) this.ticksSinceLastInteraction = 0; // Purpur
return flag;
}
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index 7dab659663f0b9e115e3eee98ef71c072f52f061..54b77cab50fedb529998cb972cbe68b6f94f1dc4 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -2219,6 +2219,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
boolean triggerLeashUpdate = itemInHand != null && itemInHand.getItem() == Items.LEAD && entity instanceof EntityInsentient;
Item origItem = this.player.inventory.getItemInHand() == null ? null : this.player.inventory.getItemInHand().getItem();
PlayerInteractEntityEvent event;
+ if (entity instanceof EntityInsentient) ((EntityInsentient) entity).ticksSinceLastInteraction = 0; // Purpur
if (packetplayinuseentity.b() == PacketPlayInUseEntity.EnumEntityUseAction.INTERACT) {
event = new PlayerInteractEntityEvent((Player) this.getPlayer(), entity.getBukkitEntity(), (packetplayinuseentity.c() == EnumHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND);
} else {
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 91d7d123be1f5ffa12710bab56788b330dc3ba37..2f326f88257f5a45deee872865211d15fc67fac6 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -103,6 +103,11 @@ public class PurpurWorldConfig {
}
}
+ public int entityLifeSpan = 0;
+ private void entitySettings() {
+ entityLifeSpan = getInt("gameplay-mechanics.entity-lifespan", entityLifeSpan);
+ }
+
public List<Item> itemImmuneToExplosion = new ArrayList<>();
public List<Item> itemImmuneToFire = new ArrayList<>();
private void itemSettings() {