From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: IPECTER Date: Thu, 18 May 2023 16:42:40 +0900 Subject: [PATCH] Implement Let Me Despawn Original: frikinjay/let-me-despawn Copyright (C) 2023 frikinjay diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java index 3a365d7efd439cb8ddb99381bd714fb48896f4d2..b6d27332eb151bdf408909b241c493da54841c8e 100644 --- a/src/main/java/net/minecraft/world/entity/Mob.java +++ b/src/main/java/net/minecraft/world/entity/Mob.java @@ -885,7 +885,7 @@ public abstract class Mob extends LivingEntity implements Targeting { public void checkDespawn() { if (this.level.getDifficulty() == Difficulty.PEACEFUL && this.shouldDespawnInPeaceful()) { this.discard(); - } else if (!this.isPersistenceRequired() && !this.requiresCustomPersistence()) { + } else if ((this.level.plazmaLevelConfiguration().letMeDespawn.enabled || !this.isPersistenceRequired()) && !this.requiresCustomPersistence()) { // Paper start - optimise checkDespawn Player entityhuman = this.level.findNearbyPlayer(this, level.paperConfig().entities.spawning.despawnRanges.get(this.getType().getCategory()).hard() + 1, EntitySelector.PLAYER_AFFECTS_SPAWNING); // Paper if (entityhuman == null) { @@ -899,14 +899,14 @@ public abstract class Mob extends LivingEntity implements Targeting { int j = i * i; if (d0 > (double) j && this.removeWhenFarAway(d0)) { - this.discard(); + this.dropEquipmentOnDespawn(); this.discard(); // Plazma - Let Me Despawn } int k = this.level.paperConfig().entities.spawning.despawnRanges.get(this.getType().getCategory()).soft(); // Paper - custom despawn distances int l = k * k; if (this.noActionTime > 600 && this.random.nextInt(800) == 0 && d0 > (double) l && this.removeWhenFarAway(d0)) { - this.discard(); + this.dropEquipmentOnDespawn(); this.discard(); // Plazma - Let Me Despawn } else if (d0 < (double) l) { this.noActionTime = 0; } @@ -917,6 +917,19 @@ public abstract class Mob extends LivingEntity implements Targeting { } } + // Plazma start - Let Me Despawn + private void dropEquipmentOnDespawn() { + if (!this.level.plazmaLevelConfiguration().letMeDespawn.dropPickedUpItem()) return; + for (EquipmentSlot equipmentSlot : EquipmentSlot.values()) { + ItemStack itemStack = this.getItemBySlot(equipmentSlot); + if (!itemStack.isEmpty() && !EnchantmentHelper.hasVanishingCurse(itemStack)) { + this.spawnAtLocation(itemStack); + this.setItemSlot(equipmentSlot, ItemStack.EMPTY); + } + } + } + // Plazma end + @Override protected final void serverAiStep() { ++this.noActionTime; diff --git a/src/main/java/org/plazmamc/plazma/configurations/LevelConfigurations.java b/src/main/java/org/plazmamc/plazma/configurations/LevelConfigurations.java index 116384c1fe27a868bcbe1d21f0b2723c73b9170c..97ffcd1c0e50ab21756404a483fa8d1f4b6579b1 100644 --- a/src/main/java/org/plazmamc/plazma/configurations/LevelConfigurations.java +++ b/src/main/java/org/plazmamc/plazma/configurations/LevelConfigurations.java @@ -136,6 +136,11 @@ public class LevelConfigurations extends ConfigurationPart { public class LetMeDespawn extends ConfigurationPart { public boolean enabled = false; + boolean dropPickedUpItem = true; + + public boolean dropPickedUpItem() { + return enabled && dropPickedUpItem; + } } }