Skip to content

Commit aa41e13

Browse files
BillyGalbreathgranny
authored andcommitted
Entity lifespan
1 parent b7601d9 commit aa41e13

5 files changed

Lines changed: 98 additions & 121 deletions

File tree

patches/server/0070-Entity-lifespan.patch

Lines changed: 0 additions & 111 deletions
This file was deleted.

purpur-server/minecraft-patches/features/0001-Ridables.patch

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ index 8be848d3aaa34be2fa9a9de8f9f2908f0903b60f..a1ebdd491e79fff8e224095ee6058cd5
6262

6363
private void updatePlayerAttributes() {
6464
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
65-
index 8e3359e0d2b3ff0ecb5f736eed8e22133819fd36..413e47a0257a6d275fe389e5c249be34685e38cc 100644
65+
index 2a8e90005efe88cbff727e64687df69d0c9ac4e6..ab651a0612320bbccce396652c1cf6db7ee2ae03 100644
6666
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
6767
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
68-
@@ -2794,6 +2794,8 @@ public class ServerGamePacketListenerImpl
68+
@@ -2795,6 +2795,8 @@ public class ServerGamePacketListenerImpl
6969

7070
ServerGamePacketListenerImpl.this.cserver.getPluginManager().callEvent(event);
7171

@@ -246,10 +246,10 @@ index fd518913a12651a6df719628dfedc88b70806567..3e85aa9f530bef69a678c9349f366d9c
246246
// Paper end - Add EntityMoveEvent
247247
if (this.level() instanceof ServerLevel serverLevel && this.isSensitiveToWater() && this.isInWaterRainOrBubble()) {
248248
diff --git a/net/minecraft/world/entity/Mob.java b/net/minecraft/world/entity/Mob.java
249-
index 1ed07fd23985a6bf8cf8300f74c92b7531a79fc6..e8f86c69f122d94d707eebd41b1e1c26edb3700a 100644
249+
index 44f896e5a6d2a42aac9806c747e6e044cc34f795..84d49e82c82ea7cbd05b6c53df3e8ac6c966b292 100644
250250
--- a/net/minecraft/world/entity/Mob.java
251251
+++ b/net/minecraft/world/entity/Mob.java
252-
@@ -150,8 +150,8 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
252+
@@ -151,8 +151,8 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
253253
super(entityType, level);
254254
this.goalSelector = new GoalSelector();
255255
this.targetSelector = new GoalSelector();
@@ -260,7 +260,7 @@ index 1ed07fd23985a6bf8cf8300f74c92b7531a79fc6..e8f86c69f122d94d707eebd41b1e1c26
260260
this.jumpControl = new JumpControl(this);
261261
this.bodyRotationControl = this.createBodyControl();
262262
this.navigation = this.createNavigation(level);
263-
@@ -1377,7 +1377,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
263+
@@ -1405,7 +1405,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
264264
}
265265

266266
protected InteractionResult mobInteract(Player player, InteractionHand hand) {
@@ -269,7 +269,7 @@ index 1ed07fd23985a6bf8cf8300f74c92b7531a79fc6..e8f86c69f122d94d707eebd41b1e1c26
269269
}
270270

271271
public boolean isWithinRestriction() {
272-
@@ -1694,4 +1694,58 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
272+
@@ -1723,4 +1723,58 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
273273
public float[] getArmorDropChances() {
274274
return this.armorDropChances;
275275
}

purpur-server/minecraft-patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,20 @@
119119
} // Paper
120120
}
121121

122-
@@ -1525,6 +_,8 @@
123-
this.lastPosZ = to.getZ();
122+
@@ -1526,6 +_,8 @@
124123
this.lastYaw = to.getYaw();
125124
this.lastPitch = to.getPitch();
126-
+
127-
+ if (!to.getWorld().getUID().equals(from.getWorld().getUID()) || to.getBlockX() != from.getBlockX() || to.getBlockY() != from.getBlockY() || to.getBlockZ() != from.getBlockZ() || to.getYaw() != from.getYaw() || to.getPitch() != from.getPitch()) this.player.resetLastActionTime(); // Purpur - AFK API
128125

126+
+ if (!to.getWorld().getUID().equals(from.getWorld().getUID()) || to.getBlockX() != from.getBlockX() || to.getBlockY() != from.getBlockY() || to.getBlockZ() != from.getBlockZ() || to.getYaw() != from.getYaw() || to.getPitch() != from.getPitch()) this.player.resetLastActionTime(); // Purpur - AFK API
127+
+
129128
Location oldTo = to.clone();
130129
PlayerMoveEvent event = new PlayerMoveEvent(player, from, to);
130+
this.cserver.getPluginManager().callEvent(event);
131+
@@ -2734,6 +_,7 @@
132+
133+
AABB boundingBox = target.getBoundingBox();
134+
if (this.player.canInteractWithEntity(boundingBox, io.papermc.paper.configuration.GlobalConfiguration.get().misc.clientInteractionLeniencyDistance.or(3.0))) { // Paper - configurable lenience value for interact range
135+
+ if (target instanceof net.minecraft.world.entity.Mob mob) mob.ticksSinceLastInteraction = 0; // Purpur - Entity lifespan
136+
packet.dispatch(
137+
new ServerboundInteractPacket.Handler() {
138+
private void performInteraction(InteractionHand hand, ServerGamePacketListenerImpl.EntityInteraction entityInteraction, PlayerInteractEntityEvent event) { // CraftBukkit
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
--- a/net/minecraft/world/entity/Mob.java
2+
+++ b/net/minecraft/world/entity/Mob.java
3+
@@ -145,6 +_,7 @@
4+
private BlockPos restrictCenter = BlockPos.ZERO;
5+
private float restrictRadius = -1.0F;
6+
public boolean aware = true; // CraftBukkit
7+
+ public int ticksSinceLastInteraction; // Purpur - Entity lifespan
8+
9+
protected Mob(EntityType<? extends Mob> entityType, Level level) {
10+
super(entityType, level);
11+
@@ -294,6 +_,7 @@
12+
target = null;
13+
}
14+
}
15+
+ if (target instanceof net.minecraft.server.level.ServerPlayer) this.ticksSinceLastInteraction = 0; // Purpur - Entity lifespan
16+
this.target = target;
17+
return true;
18+
// CraftBukkit end
19+
@@ -337,7 +_,27 @@
20+
}
21+
22+
profilerFiller.pop();
23+
- }
24+
+ incrementTicksSinceLastInteraction(); // Purpur - Entity lifespan
25+
+ }
26+
+
27+
+ // Purpur start - Entity lifespan
28+
+ private void incrementTicksSinceLastInteraction() {
29+
+ ++this.ticksSinceLastInteraction;
30+
+ if (getRider() != null) {
31+
+ this.ticksSinceLastInteraction = 0;
32+
+ return;
33+
+ }
34+
+ if (this.level().purpurConfig.entityLifeSpan <= 0) {
35+
+ return; // feature disabled
36+
+ }
37+
+ if (!this.removeWhenFarAway(0) || isPersistenceRequired() || requiresCustomPersistence() || hasCustomName()) {
38+
+ return; // mob persistent
39+
+ }
40+
+ if (this.ticksSinceLastInteraction > this.level().purpurConfig.entityLifeSpan) {
41+
+ this.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DISCARD);
42+
+ }
43+
+ }
44+
+ // Purpur end - Entity lifespan
45+
46+
@Override
47+
protected void playHurtSound(DamageSource source) {
48+
@@ -486,6 +_,7 @@
49+
compound.putBoolean("NoAI", this.isNoAi());
50+
}
51+
compound.putBoolean("Bukkit.Aware", this.aware); // CraftBukkit
52+
+ compound.putInt("Purpur.ticksSinceLastInteraction", this.ticksSinceLastInteraction); // Purpur - Entity lifespan
53+
}
54+
55+
@Override
56+
@@ -568,6 +_,11 @@
57+
this.aware = compound.getBoolean("Bukkit.Aware");
58+
}
59+
// CraftBukkit end
60+
+ // Purpur start - Entity lifespan
61+
+ if (compound.contains("Purpur.ticksSinceLastInteraction")) {
62+
+ this.ticksSinceLastInteraction = compound.getInt("Purpur.ticksSinceLastInteraction");
63+
+ }
64+
+ // Purpur end - Entity lifespan
65+
}
66+
67+
@Override
68+
@@ -1619,6 +_,7 @@
69+
this.playAttackSound();
70+
}
71+
72+
+ if (target instanceof net.minecraft.server.level.ServerPlayer) this.ticksSinceLastInteraction = 0; // Purpur - Entity lifespan
73+
return flag;
74+
}
75+

purpur-server/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ private void elytraSettings() {
109109
elytraDamagePerTridentBoost = getInt("gameplay-mechanics.elytra.damage-per-boost.trident", elytraDamagePerTridentBoost);
110110
}
111111

112+
public int entityLifeSpan = 0;
113+
private void entitySettings() {
114+
entityLifeSpan = getInt("gameplay-mechanics.entity-lifespan", entityLifeSpan);
115+
}
116+
112117
public List<Item> itemImmuneToCactus = new ArrayList<>();
113118
public List<Item> itemImmuneToExplosion = new ArrayList<>();
114119
public List<Item> itemImmuneToFire = new ArrayList<>();

0 commit comments

Comments
 (0)