mirror of
https://github.com/GTNewHorizons/WailaHarvestability.git
synced 2026-10-26 14:34:05 +00:00
Change block name compare to GTUtility.isOre (#8)
This commit is contained in:
1 parent
2fce774946
commit
bdf88a1262
2 files changed
+34
-5
No files matched your search
@@ -61,7 +61,7 @@ public class WailaHandler implements IWailaDataProvider {
|
||||
EntityPlayer player = accessor.getPlayer();
|
||||
|
||||
// for disguised blocks
|
||||
if (itemStack.getItem() instanceof ItemBlock && !ProxyGregTech.isOreBlock(block)
|
||||
if (itemStack.getItem() instanceof ItemBlock && !ProxyGregTech.isOreBlock(block, meta)
|
||||
&& !ProxyGregTech.isCasing(block)
|
||||
&& !ProxyGregTech.isMachine(block)) {
|
||||
block = Block.getBlockFromItem(itemStack.getItem());
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package squeek.wailaharvestability.proxy;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@@ -9,16 +13,41 @@ import cpw.mods.fml.common.registry.GameRegistry;
|
||||
public class ProxyGregTech {
|
||||
|
||||
public static final String modID = "gregtech";
|
||||
public static final String oreBlockID = "gt.blockores";
|
||||
public static final String oreBlockUniqueIdentifier = modID + ":" + oreBlockID;
|
||||
public static final String casingID = "gt.blockcasings";
|
||||
public static final String casingUniqueIdentifier = modID + ":" + casingID;
|
||||
public static final String machineID = "gt.blockmachines";
|
||||
public static final String machineUniqueIdentifier = modID + ":" + machineID;
|
||||
public static boolean isModLoaded = Loader.isModLoaded(modID);
|
||||
|
||||
public static boolean isOreBlock(Block block) {
|
||||
return isModLoaded && GameRegistry.findUniqueIdentifierFor(block).toString().equals(oreBlockUniqueIdentifier);
|
||||
/**
|
||||
* Use a nested class so that ProxyGregTech can load without loading GTMethods. This allows us to keep GTUTIL_IS_ORE
|
||||
* static final without hacky code (MethodHandles have zero runtime cost if they're stored in a static final field).
|
||||
*/
|
||||
private static class GTMethods {
|
||||
|
||||
public static final MethodHandle GTUTIL_IS_ORE;
|
||||
|
||||
static {
|
||||
try {
|
||||
GTUTIL_IS_ORE = MethodHandles.lookup().findStatic(
|
||||
Class.forName("gregtech.api.util.GTUtility"),
|
||||
"isOre",
|
||||
MethodType.methodType(boolean.class, Block.class, int.class));
|
||||
} catch (NoSuchMethodException | IllegalAccessException | ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isOreBlock(Block block, int meta) {
|
||||
if (!isModLoaded) return false;
|
||||
|
||||
try {
|
||||
// loads GTMethods
|
||||
return (boolean) GTMethods.GTUTIL_IS_ORE.invokeExact(block, meta);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isCasing(Block block) {
|
||||
|
||||
Reference in new issue
Block a user