From 358c55b82d5300f4f661e279d903045562410437 Mon Sep 17 00:00:00 2001 From: Ruling-0 <47913168+Ruling-0@users.noreply.github.com> Date: Mon, 19 May 2025 00:12:31 -0500 Subject: [PATCH 1/2] Magnet attracts only if closest player, and delay self-drop --- .../common/items/tools/Magnet.java | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/brandon3055/draconicevolution/common/items/tools/Magnet.java b/src/main/java/com/brandon3055/draconicevolution/common/items/tools/Magnet.java index f6bfca86..7d5fb50a 100644 --- a/src/main/java/com/brandon3055/draconicevolution/common/items/tools/Magnet.java +++ b/src/main/java/com/brandon3055/draconicevolution/common/items/tools/Magnet.java @@ -112,6 +112,8 @@ public class Magnet extends ItemDE implements IBauble, IConfigurableItem { entity.posZ).expand(range, range, range)); boolean playSound = false; + boolean didPlayerDrop; + NBTTagCompound itemNBT = new NBTTagCompound(); for (EntityItem item : items) { if (item.getEntityItem() == null || ModHelper.isAE2EntityFloatingItem(item) @@ -126,19 +128,37 @@ public class Magnet extends ItemDE implements IBauble, IConfigurableItem { == item.getEntityItem().getItemDamage())) { continue; } - playSound = true; - if (item.delayBeforeCanPickup > 0) { - item.delayBeforeCanPickup = 0; + EntityPlayer closestPlayer = world.getClosestPlayerToEntity(item, range); + + if (closestPlayer != null && closestPlayer != player) { + continue; + } + + didPlayerDrop = item.func_145800_j() != null + && item.func_145800_j().equals(player.getCommandSenderName()); + item.writeEntityToNBT(itemNBT); + + if (!world.isRemote) { + if (!didPlayerDrop) item.delayBeforeCanPickup = 0; + if (item.delayBeforeCanPickup <= 0) { + itemNBT.setBoolean("attractable", true); + item.readEntityFromNBT(itemNBT); + } + } + + if (itemNBT.getBoolean("attractable")) { + playSound = true; + item.motionX = 0; + item.motionY = 0; + item.motionZ = 0; + item.setPosition( + entity.posX - 0.2 + (world.rand.nextDouble() * 0.4), + entity.posY - 0.6, + entity.posZ - 0.2 + (world.rand.nextDouble() * 0.4)); } - item.motionX = 0; - item.motionY = 0; - item.motionZ = 0; - item.setPosition( - entity.posX - 0.2 + (world.rand.nextDouble() * 0.4), - entity.posY - 0.6, - entity.posZ - 0.2 + (world.rand.nextDouble() * 0.4)); } + if (playSound && !ConfigHandler.itemDislocatorDisableSound) { world.playSoundAtEntity( entity, From 33e048a295d458eababdb4131e8fb0b55daac17b Mon Sep 17 00:00:00 2001 From: Ruling-0 <47913168+Ruling-0@users.noreply.github.com> Date: Mon, 19 May 2025 00:21:05 -0500 Subject: [PATCH 2/2] Move player drop check to server-only --- .../draconicevolution/common/items/tools/Magnet.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/brandon3055/draconicevolution/common/items/tools/Magnet.java b/src/main/java/com/brandon3055/draconicevolution/common/items/tools/Magnet.java index 7d5fb50a..aa638868 100644 --- a/src/main/java/com/brandon3055/draconicevolution/common/items/tools/Magnet.java +++ b/src/main/java/com/brandon3055/draconicevolution/common/items/tools/Magnet.java @@ -130,16 +130,15 @@ public class Magnet extends ItemDE implements IBauble, IConfigurableItem { } EntityPlayer closestPlayer = world.getClosestPlayerToEntity(item, range); - if (closestPlayer != null && closestPlayer != player) { continue; } - didPlayerDrop = item.func_145800_j() != null - && item.func_145800_j().equals(player.getCommandSenderName()); item.writeEntityToNBT(itemNBT); if (!world.isRemote) { + didPlayerDrop = item.func_145800_j() != null + && item.func_145800_j().equals(player.getCommandSenderName()); if (!didPlayerDrop) item.delayBeforeCanPickup = 0; if (item.delayBeforeCanPickup <= 0) { itemNBT.setBoolean("attractable", true);