From 7ada07b5ac30e3206dc5ec5fc4e740bf270febc5 Mon Sep 17 00:00:00 2001 From: SuperSoupr <26164930+SuperSoupr@users.noreply.github.com> Date: Sat, 24 Jan 2026 21:15:24 +0200 Subject: [PATCH] Add block blacklist for magnets (#80) Co-authored-by: Super <26164930+EmperorSuper@users.noreply.github.com> --- .../common/handler/ConfigHandler.java | 35 +++++++++++++++++-- .../common/items/tools/Magnet.java | 19 ++++++++++ 2 files changed, 51 insertions(+), 3 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 dd472f3..1ef634a 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", @@ -422,13 +429,35 @@ 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); } } + itemDislocatorBlockBlacklistMap.clear(); + for (String s : itemDislocatorBlockBlacklist) { + if (s.contains("|")) { + 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); + } + } + 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 f0cff83..bee82b6 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,24 @@ 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); + + 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; + } + } + + if (skip) continue; + if (!skipPlayerCheck) { EntityPlayer closestPlayer = world.getClosestPlayerToEntity(item, range); if (closestPlayer == null || closestPlayer != player) continue;