Add variation removal support to API, add ICarvingRegistry

This commit is contained in:
tterrag1098 committed 2015-01-22 21:33:43 -05:00
1 parent 760c0c8864
commit bfabad129f
10 files changed
+85 -12

No files matched your search

@@ -1,5 +1,7 @@
package com.cricketcraft.chisel.api.carving;
import java.lang.reflect.Field;
import net.minecraft.item.ItemStack;
public class CarvingUtils {
@@ -27,4 +29,30 @@ public class CarvingUtils {
public static ItemStack getStack(ICarvingVariation variation) {
return new ItemStack(variation.getBlock(), 1, variation.getItemMeta());
}
private static Field _chisel;
private static boolean errored = false;
private static final String CARVING_CLASS = "com.cricketcraft.chisel.carving.Carving";
/**
* @return The instance of the chisel carving registry from the chisel mod.
* <p>
* If chisel is not installed or some other error occurs this will return null.
*/
public static ICarvingRegistry getChiselRegistry() {
if (errored) {
return null;
}
try {
if (_chisel == null) {
_chisel = Class.forName(CARVING_CLASS).getDeclaredField("chisel");
}
return (ICarvingRegistry) _chisel.get(null);
} catch (Exception e) {
e.printStackTrace();
errored = true;
return getChiselRegistry();
}
}
}