Files
Purpur/patches/server/0087-Entity-lifespan.patch
BillyGalbreath 643d9681ff Updated Upstream (Paper & Tuinity)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
8fa15382b [Auto] Updated Upstream (CraftBukkit)
732b2f6b5 [CI-SKIP] [Auto] Rebuild Patches
c5a39ffa2 Add BlockPreDispenseEvent (#5075)
8aeb4c9c3 Correctly skip pathfinder ticks for inactive entities (#5085)
0e420049c Fix console spam when removing chests in water
56b7935bb Add PlayerChangeBeaconEffectEvent
2eda45c34 added Wither API
97d0c571b Added Vanilla Entity Tags
fccac282a fix NPE in getDisplayNameComponent
24e140372 Configurable max leash distance

Tuinity Changes:
d3ee22224 Merge dev/lighting
2021-01-20 23:52:16 -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 c9791be9385c83c8ab626ff3661b0c6cb45822ad..c2144f78c24f015775a00b1c82de645e0e2c153a 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
@@ -249,10 +250,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();
@@ -426,6 +452,7 @@ public abstract class EntityInsentient extends EntityLiving {
}
nbttagcompound.setBoolean("Bukkit.Aware", this.aware); // CraftBukkit
+ nbttagcompound.setInt("Purpur.ticksSinceLastInteraction", ticksSinceLastInteraction); // Purpur
}
@Override
@@ -496,6 +523,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
@@ -1543,7 +1575,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 ffccdc3bf1d28836f4fc2772ebfde843415ea232..8932f4854d9fc52fb2ec66a748e640dfd8806461 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -2271,6 +2271,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 3d6f4de01409c70c5f4d2fcd7a52d158aa0fdf80..d7635a3b2abb15407f55119bc29a5ee583ea714a 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> itemImmuneToCactus = new ArrayList<>();
public List<Item> itemImmuneToExplosion = new ArrayList<>();
public List<Item> itemImmuneToFire = new ArrayList<>();