From 23e724232edbe235f259fb5f27f6c4d8566249d0 Mon Sep 17 00:00:00 2001 From: IPECTER Date: Thu, 18 May 2023 16:57:32 +0900 Subject: [PATCH] Implemented Let Me Despawn --- .../server/0036-Implement-FerriteCore.patch | 2 + .../0037-Let-Me-Despawn-Configuration.patch | 22 ++++++ .../0038-Implement-Let-Me-Despawn.patch | 74 +++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 patches/server/0037-Let-Me-Despawn-Configuration.patch create mode 100644 patches/server/0038-Implement-Let-Me-Despawn.patch diff --git a/patches/server/0036-Implement-FerriteCore.patch b/patches/server/0036-Implement-FerriteCore.patch index 1fe4aed..7317bd9 100644 --- a/patches/server/0036-Implement-FerriteCore.patch +++ b/patches/server/0036-Implement-FerriteCore.patch @@ -3,6 +3,8 @@ From: IPECTER Date: Wed, 10 May 2023 13:32:42 +0900 Subject: [PATCH] Implement FerriteCore +Original: malte0811/FerriteCore +Copyright (C) 2023 malte0811 diff --git a/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java b/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java index bee42ce7c1cb0f5ebd4890c02bc9c5dd727f7fd6..478802cedeef5166bf5662187038d1439be6c242 100644 diff --git a/patches/server/0037-Let-Me-Despawn-Configuration.patch b/patches/server/0037-Let-Me-Despawn-Configuration.patch new file mode 100644 index 0000000..74a0b89 --- /dev/null +++ b/patches/server/0037-Let-Me-Despawn-Configuration.patch @@ -0,0 +1,22 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: IPECTER +Date: Thu, 18 May 2023 16:21:37 +0900 +Subject: [PATCH] Let Me Despawn Configuration + + +diff --git a/src/main/java/org/plazmamc/plazma/configurations/LevelConfigurations.java b/src/main/java/org/plazmamc/plazma/configurations/LevelConfigurations.java +index a1b55bb5431d1712fc06da0cf06857a986efeea0..116384c1fe27a868bcbe1d21f0b2723c73b9170c 100644 +--- a/src/main/java/org/plazmamc/plazma/configurations/LevelConfigurations.java ++++ b/src/main/java/org/plazmamc/plazma/configurations/LevelConfigurations.java +@@ -131,4 +131,11 @@ public class LevelConfigurations extends ConfigurationPart { + } + + } ++ ++ public LetMeDespawn letMeDespawn; ++ public class LetMeDespawn extends ConfigurationPart { ++ ++ public boolean enabled = false; ++ ++ } + } diff --git a/patches/server/0038-Implement-Let-Me-Despawn.patch b/patches/server/0038-Implement-Let-Me-Despawn.patch new file mode 100644 index 0000000..395f61e --- /dev/null +++ b/patches/server/0038-Implement-Let-Me-Despawn.patch @@ -0,0 +1,74 @@ +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..e440cba3c4cd169e9771cc2f3c19b4c9861a640e 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; ++ } + + } + }