From 6d8b0a0e72d1a5c5bae2c1c940dcd04945fc01ac Mon Sep 17 00:00:00 2001 From: Super <26164930+EmperorSuper@users.noreply.github.com> Date: Mon, 13 Oct 2025 12:46:14 +0300 Subject: [PATCH 1/3] Add block blacklist for magnets --- .../common/handler/ConfigHandler.java | 19 +++++++++++++- .../common/items/tools/Magnet.java | 25 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/brandon3055/draconicevolution/common/handler/ConfigHandler.java b/src/main/java/com/brandon3055/draconicevolution/common/handler/ConfigHandler.java index 9f961c22..ca2d0d6d 100644 --- a/src/main/java/com/brandon3055/draconicevolution/common/handler/ConfigHandler.java +++ b/src/main/java/com/brandon3055/draconicevolution/common/handler/ConfigHandler.java @@ -55,6 +55,8 @@ public class ConfigHandler { public static boolean enableFlight; private static String[] itemDislocatorBlacklist; public static Map itemDislocatorBlacklistMap = new HashMap(); + private static String[] itemDislocatorBlockBlacklist; + public static Map itemDislocatorBlockBlacklistMap = new HashMap(); public static boolean itemDislocatorDisableSound; // spawner @@ -303,7 +305,12 @@ public class ConfigHandler { "Item Dislocator Blacklist", Configuration.CATEGORY_GENERAL, new String[] { "appliedenergistics2:item.ItemCrystalSeed" }, - "A list of items of items that should be ignored by the item dislocator. Use the items registry name e.g. minecraft:apple you can also add a meta value like so minecraft:wool|4"); + "A list of items that should be ignored by the item dislocator. Use the items registry name e.g. minecraft:apple you can also add a meta value like so minecraft:wool|4"); + itemDislocatorBlockBlacklist = config.getStringList( + "Item Dislocator Block Blacklist", + Configuration.CATEGORY_GENERAL, + new String[] { "Thaumcraft:blockAlchemyFurnace|0", "Botania:pool" }, + "A list of blocks that will cause items above or inside of them to be ignored by the item dislocator. Use the items registry name e.g. minecraft:apple you can also add a meta value like so minecraft:wool|4"); itemDislocatorDisableSound = config.get( Configuration.CATEGORY_GENERAL, "Item Dislocator Disable Sound", @@ -428,6 +435,16 @@ public class ConfigHandler { } } + itemDislocatorBlockBlacklistMap.clear(); + for (String s : itemDislocatorBlockBlacklist) { + if (s.contains("|")) { + itemDislocatorBlockBlacklistMap + .put(s.substring(0, s.indexOf("|")), Integer.parseInt(s.substring(s.indexOf("|") + 1))); + } else { + itemDislocatorBlockBlacklistMap.put(s, -1); + } + } + if (disableLog) { disableLog = false; LogHelper.warn("###########################################"); 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 f0cff832..91ddf6e4 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 @@ -3,6 +3,7 @@ package com.brandon3055.draconicevolution.common.items.tools; import java.util.ArrayList; import java.util.List; +import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityClientPlayerMP; import net.minecraft.client.renderer.texture.IIconRegister; @@ -147,6 +148,30 @@ public class Magnet extends ItemDE implements IBauble, IConfigurableItem { continue; } + int x = (int) Math.floor(item.posX); + int y = (int) Math.floor(item.posY); + int z = (int) Math.floor(item.posZ); + + Block block = world.getBlock(x, y, z); + String blockName = Item.itemRegistry.getNameForObject(Item.getItemFromBlock(block)); + int meta = world.getBlockMetadata(x, y, z); + if (ConfigHandler.itemDislocatorBlockBlacklistMap.containsKey(blockName) + && (ConfigHandler.itemDislocatorBlockBlacklistMap.get(blockName) == -1 + || ConfigHandler.itemDislocatorBlockBlacklistMap.get(blockName) == meta)) { + continue; + } + + y--; + + block = world.getBlock(x, y, z); + blockName = Item.itemRegistry.getNameForObject(Item.getItemFromBlock(block)); + meta = world.getBlockMetadata(x, y, z); + if (ConfigHandler.itemDislocatorBlockBlacklistMap.containsKey(blockName) + && (ConfigHandler.itemDislocatorBlockBlacklistMap.get(blockName) == -1 + || ConfigHandler.itemDislocatorBlockBlacklistMap.get(blockName) == meta)) { + continue; + } + if (!skipPlayerCheck) { EntityPlayer closestPlayer = world.getClosestPlayerToEntity(item, range); if (closestPlayer == null || closestPlayer != player) continue; From 26a65a6345b3742c8d9c85de8e72e755e3ddde5c Mon Sep 17 00:00:00 2001 From: SuperSoupr <26164930+SuperSoupr@users.noreply.github.com> Date: Tue, 16 Dec 2025 23:25:51 +0200 Subject: [PATCH 2/3] Catch NumberFormatException --- .../common/handler/ConfigHandler.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/brandon3055/draconicevolution/common/handler/ConfigHandler.java b/src/main/java/com/brandon3055/draconicevolution/common/handler/ConfigHandler.java index ca2d0d6d..0468fff0 100644 --- a/src/main/java/com/brandon3055/draconicevolution/common/handler/ConfigHandler.java +++ b/src/main/java/com/brandon3055/draconicevolution/common/handler/ConfigHandler.java @@ -428,8 +428,14 @@ public class ConfigHandler { itemDislocatorBlacklistMap.clear(); for (String s : itemDislocatorBlacklist) { if (s.contains("|")) { - itemDislocatorBlacklistMap - .put(s.substring(0, s.indexOf("|")), Integer.parseInt(s.substring(s.indexOf("|") + 1))); + try { + itemDislocatorBlacklistMap + .put(s.substring(0, s.indexOf("|")), Integer.parseInt(s.substring(s.indexOf("|") + 1))); + } catch (NumberFormatException e) { + LogHelper.error("Error while loading dislocator blacklist."); + LogHelper.error("Could not parse meta (damage) for \"" + s + "\""); + e.printStackTrace(); + } } else { itemDislocatorBlacklistMap.put(s, -1); } @@ -438,8 +444,14 @@ public class ConfigHandler { itemDislocatorBlockBlacklistMap.clear(); for (String s : itemDislocatorBlockBlacklist) { if (s.contains("|")) { - itemDislocatorBlockBlacklistMap - .put(s.substring(0, s.indexOf("|")), Integer.parseInt(s.substring(s.indexOf("|") + 1))); + try { + itemDislocatorBlockBlacklistMap + .put(s.substring(0, s.indexOf("|")), Integer.parseInt(s.substring(s.indexOf("|") + 1))); + } catch (NumberFormatException e) { + LogHelper.error("Error while loading dislocator block blacklist."); + LogHelper.error("Could not parse meta (damage) for \"" + s + "\""); + e.printStackTrace(); + } } else { itemDislocatorBlockBlacklistMap.put(s, -1); } From 5c1711dccace4b559b7fd8073e2d618b4d188348 Mon Sep 17 00:00:00 2001 From: SuperSoupr <26164930+SuperSoupr@users.noreply.github.com> Date: Tue, 16 Dec 2025 23:56:58 +0200 Subject: [PATCH 3/3] Don't duplicate code --- .../common/items/tools/Magnet.java | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 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 91ddf6e4..bee82b61 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 @@ -152,25 +152,19 @@ public class Magnet extends ItemDE implements IBauble, IConfigurableItem { int y = (int) Math.floor(item.posY); int z = (int) Math.floor(item.posZ); - Block block = world.getBlock(x, y, z); - String blockName = Item.itemRegistry.getNameForObject(Item.getItemFromBlock(block)); - int meta = world.getBlockMetadata(x, y, z); - if (ConfigHandler.itemDislocatorBlockBlacklistMap.containsKey(blockName) - && (ConfigHandler.itemDislocatorBlockBlacklistMap.get(blockName) == -1 - || ConfigHandler.itemDislocatorBlockBlacklistMap.get(blockName) == meta)) { - continue; + boolean skip = false; + for (int i = 0; i < 2; i++) { + Block block = world.getBlock(x, y - i, z); + String blockName = Item.itemRegistry.getNameForObject(Item.getItemFromBlock(block)); + int meta = world.getBlockMetadata(x, y - i, z); + if (ConfigHandler.itemDislocatorBlockBlacklistMap.containsKey(blockName) + && (ConfigHandler.itemDislocatorBlockBlacklistMap.get(blockName) == -1 + || ConfigHandler.itemDislocatorBlockBlacklistMap.get(blockName) == meta)) { + skip = true; + } } - y--; - - block = world.getBlock(x, y, z); - blockName = Item.itemRegistry.getNameForObject(Item.getItemFromBlock(block)); - meta = world.getBlockMetadata(x, y, z); - if (ConfigHandler.itemDislocatorBlockBlacklistMap.containsKey(blockName) - && (ConfigHandler.itemDislocatorBlockBlacklistMap.get(blockName) == -1 - || ConfigHandler.itemDislocatorBlockBlacklistMap.get(blockName) == meta)) { - continue; - } + if (skip) continue; if (!skipPlayerCheck) { EntityPlayer closestPlayer = world.getClosestPlayerToEntity(item, range);