mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-24 05:54:27 +00:00
Solegnolia support for Magnet
This commit is contained in:
1 parent
1096ca7f1d
commit
df6b32455e
2 files changed
+55
-6
No files matched your search
@@ -21,8 +21,8 @@ import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.item.PacketMagnetState.SlotType;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.util.BaublesUtil;
|
||||
|
||||
import static crazypants.enderio.item.darksteel.DarkSteelItems.itemMagnet;
|
||||
import static crazypants.util.BotaniaUtil.hasSolegnoliaAround;
|
||||
|
||||
public class MagnetController implements IEntitySelector {
|
||||
|
||||
@@ -112,13 +112,19 @@ public class MagnetController implements IEntitySelector {
|
||||
|
||||
@Override
|
||||
public boolean isEntityApplicable(Entity var1) {
|
||||
if (!blacklist.isEmpty() && var1 instanceof EntityItem) {
|
||||
Item item = ((EntityItem) var1).getEntityItem().getItem();
|
||||
for (Item blacklisted : blacklist) {
|
||||
if (blacklisted == item) {
|
||||
return false;
|
||||
if (var1.isDead) {
|
||||
return false;
|
||||
}
|
||||
if (var1 instanceof EntityItem) {
|
||||
if (!blacklist.isEmpty()) {
|
||||
Item item = ((EntityItem) var1).getEntityItem().getItem();
|
||||
for (Item blacklisted : blacklist) {
|
||||
if (blacklisted == item) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return !hasSolegnoliaAround(var1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package crazypants.util;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import crazypants.enderio.Log;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
public class BotaniaUtil {
|
||||
|
||||
private static final String SOLEGNOLIA = "vazkii.botania.common.block.subtile.functional.SubTileSolegnolia";
|
||||
private static final String HAS_SOLEGNOLIA_AROUND = "hasSolegnoliaAround";
|
||||
private static Method hasSolegnoliaAround = null;
|
||||
private static int errorCount = -1;
|
||||
|
||||
public static boolean hasSolegnoliaAround(Entity entity) {
|
||||
if (errorCount < 0) {
|
||||
errorCount = 0;
|
||||
try {
|
||||
Class<?> solegnolia = Class.forName(SOLEGNOLIA);
|
||||
hasSolegnoliaAround = solegnolia.getMethod(HAS_SOLEGNOLIA_AROUND, Entity.class);
|
||||
} catch (Throwable t) {
|
||||
Log.debug("Didn't find Botania's Solegnolia class. Magnet will be greedy.");
|
||||
}
|
||||
}
|
||||
if (hasSolegnoliaAround != null) {
|
||||
try {
|
||||
Boolean result = (Boolean) hasSolegnoliaAround.invoke(null, entity);
|
||||
if (errorCount > 0) {
|
||||
errorCount--;
|
||||
}
|
||||
return result;
|
||||
} catch (Throwable t) {
|
||||
if (errorCount++ > 10) {
|
||||
Log.warn("Failed to interact with Botania too often. Magnet will ignore Solegnolias from now on. Last error was: " + t);
|
||||
hasSolegnoliaAround = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user