mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 08:27:43 +01:00
Entity lifespan
This commit is contained in:
committed by
granny
parent
fae83be586
commit
d2a0414806
@@ -1,111 +0,0 @@
|
||||
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/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
index 0654c2753a44b4cda55fd92513fabc45ff4ab6c9..6b460227a12ba275c02243a1fbafb87e3845cb14 100644
|
||||
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
@@ -2922,6 +2922,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
||||
AABB axisalignedbb = entity.getBoundingBox();
|
||||
|
||||
if (this.player.canInteractWithEntity(axisalignedbb, io.papermc.paper.configuration.GlobalConfiguration.get().misc.clientInteractionLeniencyDistance.or(3.0D))) { // Paper - configurable lenience value for interact range
|
||||
+ 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/net/minecraft/world/entity/Mob.java b/net/minecraft/world/entity/Mob.java
|
||||
index 261288f51ed47b0eac80cc965c76683f3e13687f..1f253d5ace885423aa25ebdd986e1909a15ba018 100644
|
||||
--- a/net/minecraft/world/entity/Mob.java
|
||||
+++ b/net/minecraft/world/entity/Mob.java
|
||||
@@ -144,6 +144,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
||||
private BlockPos restrictCenter;
|
||||
private float restrictRadius;
|
||||
|
||||
+ public int ticksSinceLastInteraction; // Purpur
|
||||
public boolean aware = true; // CraftBukkit
|
||||
|
||||
protected Mob(EntityType<? extends Mob> type, Level world) {
|
||||
@@ -330,6 +331,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
||||
entityliving = null;
|
||||
}
|
||||
}
|
||||
+ if (entityliving instanceof net.minecraft.server.level.ServerPlayer) this.ticksSinceLastInteraction = 0; // Purpur
|
||||
this.target = entityliving;
|
||||
return true;
|
||||
// CraftBukkit end
|
||||
@@ -374,8 +376,28 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
||||
}
|
||||
|
||||
gameprofilerfiller.pop();
|
||||
+ incrementTicksSinceLastInteraction(); // Purpur
|
||||
}
|
||||
|
||||
+ // 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(org.bukkit.event.entity.EntityRemoveEvent.Cause.DISCARD);
|
||||
+ }
|
||||
+ }
|
||||
+ // Purpur end
|
||||
+
|
||||
@Override
|
||||
protected void playHurtSound(DamageSource damageSource) {
|
||||
this.resetAmbientSoundTime();
|
||||
@@ -544,6 +566,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
||||
}
|
||||
|
||||
nbt.putBoolean("Bukkit.Aware", this.aware); // CraftBukkit
|
||||
+ nbt.putInt("Purpur.ticksSinceLastInteraction", this.ticksSinceLastInteraction); // Purpur
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -634,6 +657,11 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
||||
this.aware = nbt.getBoolean("Bukkit.Aware");
|
||||
}
|
||||
// CraftBukkit end
|
||||
+ // Purpur start
|
||||
+ if (nbt.contains("Purpur.ticksSinceLastInteraction")) {
|
||||
+ this.ticksSinceLastInteraction = nbt.getInt("Purpur.ticksSinceLastInteraction");
|
||||
+ }
|
||||
+ // Purpur end
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1738,6 +1766,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
||||
this.playAttackSound();
|
||||
}
|
||||
|
||||
+ if (target instanceof net.minecraft.server.level.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 6e68accdf6d4067f69cf7b29381ee2eab7a2b20c..bfd03c3cdc2b80415730aa1a18fad5afe838df25 100644
|
||||
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
@@ -120,6 +120,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<>();
|
||||
@@ -62,10 +62,10 @@ index 8be848d3aaa34be2fa9a9de8f9f2908f0903b60f..a1ebdd491e79fff8e224095ee6058cd5
|
||||
|
||||
private void updatePlayerAttributes() {
|
||||
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
index 8e3359e0d2b3ff0ecb5f736eed8e22133819fd36..413e47a0257a6d275fe389e5c249be34685e38cc 100644
|
||||
index 2a8e90005efe88cbff727e64687df69d0c9ac4e6..ab651a0612320bbccce396652c1cf6db7ee2ae03 100644
|
||||
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
@@ -2794,6 +2794,8 @@ public class ServerGamePacketListenerImpl
|
||||
@@ -2795,6 +2795,8 @@ public class ServerGamePacketListenerImpl
|
||||
|
||||
ServerGamePacketListenerImpl.this.cserver.getPluginManager().callEvent(event);
|
||||
|
||||
@@ -246,10 +246,10 @@ index fd518913a12651a6df719628dfedc88b70806567..3e85aa9f530bef69a678c9349f366d9c
|
||||
// Paper end - Add EntityMoveEvent
|
||||
if (this.level() instanceof ServerLevel serverLevel && this.isSensitiveToWater() && this.isInWaterRainOrBubble()) {
|
||||
diff --git a/net/minecraft/world/entity/Mob.java b/net/minecraft/world/entity/Mob.java
|
||||
index 1ed07fd23985a6bf8cf8300f74c92b7531a79fc6..e8f86c69f122d94d707eebd41b1e1c26edb3700a 100644
|
||||
index 44f896e5a6d2a42aac9806c747e6e044cc34f795..84d49e82c82ea7cbd05b6c53df3e8ac6c966b292 100644
|
||||
--- a/net/minecraft/world/entity/Mob.java
|
||||
+++ b/net/minecraft/world/entity/Mob.java
|
||||
@@ -150,8 +150,8 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
||||
@@ -151,8 +151,8 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
||||
super(entityType, level);
|
||||
this.goalSelector = new GoalSelector();
|
||||
this.targetSelector = new GoalSelector();
|
||||
@@ -260,7 +260,7 @@ index 1ed07fd23985a6bf8cf8300f74c92b7531a79fc6..e8f86c69f122d94d707eebd41b1e1c26
|
||||
this.jumpControl = new JumpControl(this);
|
||||
this.bodyRotationControl = this.createBodyControl();
|
||||
this.navigation = this.createNavigation(level);
|
||||
@@ -1377,7 +1377,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
||||
@@ -1405,7 +1405,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
||||
}
|
||||
|
||||
protected InteractionResult mobInteract(Player player, InteractionHand hand) {
|
||||
@@ -269,7 +269,7 @@ index 1ed07fd23985a6bf8cf8300f74c92b7531a79fc6..e8f86c69f122d94d707eebd41b1e1c26
|
||||
}
|
||||
|
||||
public boolean isWithinRestriction() {
|
||||
@@ -1694,4 +1694,58 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
||||
@@ -1723,4 +1723,58 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
||||
public float[] getArmorDropChances() {
|
||||
return this.armorDropChances;
|
||||
}
|
||||
|
||||
@@ -119,12 +119,20 @@
|
||||
} // Paper
|
||||
}
|
||||
|
||||
@@ -1525,6 +_,8 @@
|
||||
this.lastPosZ = to.getZ();
|
||||
@@ -1526,6 +_,8 @@
|
||||
this.lastYaw = to.getYaw();
|
||||
this.lastPitch = to.getPitch();
|
||||
+
|
||||
+ 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
|
||||
|
||||
+ 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
|
||||
+
|
||||
Location oldTo = to.clone();
|
||||
PlayerMoveEvent event = new PlayerMoveEvent(player, from, to);
|
||||
this.cserver.getPluginManager().callEvent(event);
|
||||
@@ -2734,6 +_,7 @@
|
||||
|
||||
AABB boundingBox = target.getBoundingBox();
|
||||
if (this.player.canInteractWithEntity(boundingBox, io.papermc.paper.configuration.GlobalConfiguration.get().misc.clientInteractionLeniencyDistance.or(3.0))) { // Paper - configurable lenience value for interact range
|
||||
+ if (target instanceof net.minecraft.world.entity.Mob mob) mob.ticksSinceLastInteraction = 0; // Purpur - Entity lifespan
|
||||
packet.dispatch(
|
||||
new ServerboundInteractPacket.Handler() {
|
||||
private void performInteraction(InteractionHand hand, ServerGamePacketListenerImpl.EntityInteraction entityInteraction, PlayerInteractEntityEvent event) { // CraftBukkit
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
--- a/net/minecraft/world/entity/Mob.java
|
||||
+++ b/net/minecraft/world/entity/Mob.java
|
||||
@@ -145,6 +_,7 @@
|
||||
private BlockPos restrictCenter = BlockPos.ZERO;
|
||||
private float restrictRadius = -1.0F;
|
||||
public boolean aware = true; // CraftBukkit
|
||||
+ public int ticksSinceLastInteraction; // Purpur - Entity lifespan
|
||||
|
||||
protected Mob(EntityType<? extends Mob> entityType, Level level) {
|
||||
super(entityType, level);
|
||||
@@ -294,6 +_,7 @@
|
||||
target = null;
|
||||
}
|
||||
}
|
||||
+ if (target instanceof net.minecraft.server.level.ServerPlayer) this.ticksSinceLastInteraction = 0; // Purpur - Entity lifespan
|
||||
this.target = target;
|
||||
return true;
|
||||
// CraftBukkit end
|
||||
@@ -337,7 +_,27 @@
|
||||
}
|
||||
|
||||
profilerFiller.pop();
|
||||
- }
|
||||
+ incrementTicksSinceLastInteraction(); // Purpur - Entity lifespan
|
||||
+ }
|
||||
+
|
||||
+ // Purpur start - Entity lifespan
|
||||
+ 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(org.bukkit.event.entity.EntityRemoveEvent.Cause.DISCARD);
|
||||
+ }
|
||||
+ }
|
||||
+ // Purpur end - Entity lifespan
|
||||
|
||||
@Override
|
||||
protected void playHurtSound(DamageSource source) {
|
||||
@@ -486,6 +_,7 @@
|
||||
compound.putBoolean("NoAI", this.isNoAi());
|
||||
}
|
||||
compound.putBoolean("Bukkit.Aware", this.aware); // CraftBukkit
|
||||
+ compound.putInt("Purpur.ticksSinceLastInteraction", this.ticksSinceLastInteraction); // Purpur - Entity lifespan
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -568,6 +_,11 @@
|
||||
this.aware = compound.getBoolean("Bukkit.Aware");
|
||||
}
|
||||
// CraftBukkit end
|
||||
+ // Purpur start - Entity lifespan
|
||||
+ if (compound.contains("Purpur.ticksSinceLastInteraction")) {
|
||||
+ this.ticksSinceLastInteraction = compound.getInt("Purpur.ticksSinceLastInteraction");
|
||||
+ }
|
||||
+ // Purpur end - Entity lifespan
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1619,6 +_,7 @@
|
||||
this.playAttackSound();
|
||||
}
|
||||
|
||||
+ if (target instanceof net.minecraft.server.level.ServerPlayer) this.ticksSinceLastInteraction = 0; // Purpur - Entity lifespan
|
||||
return flag;
|
||||
}
|
||||
|
||||
@@ -109,6 +109,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<>();
|
||||
|
||||
Reference in New Issue
Block a user