From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: William Blake Galbreath 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 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 itemImmuneToCactus = new ArrayList<>(); public List itemImmuneToExplosion = new ArrayList<>(); public List itemImmuneToFire = new ArrayList<>();