Files
Purpur/patches/server/0084-Entity-lifespan.patch
jmp 274c7b2ccc Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
d5cb9308f fix #5224
d23f8b62e fix? #5222
0f2575de2 fix? #5222
7c3499702 fix? #5218
c8eec830b fix #5217
a235c77ce Adventure 4.5.0
2021-02-22 14:41:41 -08: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 9807441d53fcf4ef7aaffe3801542f5a371eb7af..43cdeaae22bf020d0b3c1e1c56e65e73fc8106b0 100644
--- a/src/main/java/net/minecraft/server/EntityInsentient.java
+++ b/src/main/java/net/minecraft/server/EntityInsentient.java
@@ -54,7 +54,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) {
@@ -206,6 +206,7 @@ public abstract class EntityInsentient extends EntityLiving {
entityliving = null;
}
}
+ if (entityliving instanceof EntityPlayer) this.ticksSinceLastInteraction = 0; // Purpur
this.goalTarget = entityliving;
return true;
// CraftBukkit end
@@ -250,10 +251,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();
@@ -427,6 +453,7 @@ public abstract class EntityInsentient extends EntityLiving {
}
nbttagcompound.setBoolean("Bukkit.Aware", this.aware); // CraftBukkit
+ nbttagcompound.setInt("Purpur.ticksSinceLastInteraction", ticksSinceLastInteraction); // Purpur
}
@Override
@@ -497,6 +524,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
@@ -1553,7 +1585,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 fd3c9904afa5eb6175d308ab046801cee7a21297..cdcf02a73d3dffecac3605f0c7438075e5bceac3 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -2303,6 +2303,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 07e60861c99db1ee1ba7a01c7a666a83e644aa2a..2e3fee6bc4f3af7ad07a0db5657ffb3238e77e96 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<>();