Доброго времени суток. Попытался добавить поддержку Майнтвикера для мода, на клиенте запускается все хорошо, скрипты работают, на сервере вылетает npe
Данный метод(regMineTweakerCrafing()) вызывается в FMLPostInitializationEvent
лог:
java.lang.NullPointerException: Exception in server tick loop
at stanhebben.zenscript.type.ZenTypeNative.complete(ZenTypeNative.java:113)
at minetweaker.runtime.GlobalRegistry.registerNativeClass(GlobalRegistry.java:95)
at minetweaker.MineTweakerAPI.registerClass(MineTweakerAPI.java:340)
at me.Sa1ZeR_.UfiThings.compat.Tweak.regMineTweakerCrafing(Tweak.java:8)
at me.Sa1ZeR_.UfiThings.proxy.CommonProxy.postInitServer(CommonProxy.java:39)
at me.Sa1ZeR_.UfiThings.UfiThings.postInit(UfiThings.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:532)
at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:212)
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:190)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:119)
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:742)
at cpw.mods.fml.server.FMLServerHandler.finishServerLoading(FMLServerHandler.java:97)
at cpw.mods.fml.common.FMLCommonHandler.onServerStarted(FMLCommonHandler.java:325)
at net.minecraft.server.dedicated.DedicatedServer.func_71197_b(DedicatedServer.java:288)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:643)
at java.lang.Thread.run(Unknown Source)
Tweak.class:
public class Tweak {
public static void regMineTweakerCrafing() {
MineTweakerAPI.registerClass(AdvWorkBench.class);
}
}
Данный метод(regMineTweakerCrafing()) вызывается в FMLPostInitializationEvent
AdvWorkBench:
@ZenClass("mods.ufithings.AdvWB")
public class AdvWorkBench {
@ZenMethod
public static void addShapeless(IItemStack output, IIngredient[] ingredients){
MineTweakerAPI.apply(new Add(new ShapelessOreRecipe(toStack(output), toObjects(ingredients))));
}
@ZenMethod
public static void addShaped(IItemStack output, IIngredient[][] ingredients){
int height = ingredients.length;
int width = 0;
for(IIngredient[] row : ingredients){
if(width < row.length)
width = row.length;
}
Object[] input = new Object[width * height];
int x = 0;
for(IIngredient[] row : ingredients){
for(IIngredient ingredient : row){
input[x++] = toActualObject(ingredient);
}
}
MineTweakerAPI.apply(new Add(new WBAShapedRecipes(width, height, toStackArray(input), toStack(output))));
}
@ZenMethod
public static void remove(IItemStack target){
MineTweakerAPI.apply(new Remove(toStack(target)));
}
private static ItemStack toStack(IItemStack item){
if (item == null) return null;
else {
Object internal = item.getInternal();
if (internal == null || !(internal instanceof ItemStack)) {
//MineTweakerAPI.getLogger().logError("Not a valid item stack: " + item);
}
return (ItemStack) internal;
}
}
private static ItemStack[] toStackArray(Object[] obj) {
ItemStack[] itemstacks = new ItemStack[obj.length];
for(int i = 0; i < obj.length; i++) {
itemstacks[i] = (ItemStack) obj[i];
}
return itemstacks;
}
private static Object toObject(IIngredient ingredient){
if (ingredient == null) return null;
else {
if (ingredient instanceof IOreDictEntry) {
return toString((IOreDictEntry)ingredient);
} else if (ingredient instanceof IItemStack) {
return toStack((IItemStack) ingredient);
} else return null;
}
}
private static Object[] toObjects(IIngredient[] list){
if(list == null)
return null;
Object[] ingredients = new Object[list.length];
for(int x = 0;x < list.length;x++){
ingredients[x] = toObject(list[x]);
}
return ingredients;
}
private static Object toActualObject(IIngredient ingredient){
if (ingredient == null) return null;
else {
if (ingredient instanceof IOreDictEntry) {
return OreDictionary.getOres(toString((IOreDictEntry) ingredient));
} else if (ingredient instanceof IItemStack) {
return toStack((IItemStack) ingredient);
} else return null;
}
}
private static String toString(IOreDictEntry entry) {
return (entry).getName();
}
private static class Add implements IUndoableAction {
IRecipe recipe;
public Add(IRecipe add){
recipe = add;
}
@Override
public void apply() {
WorkBenchAdvCraftingManager.getInstance().getRecipeList().add(recipe);
}
@Override
public boolean canUndo() {
return true;
}
@Override
public void undo() {
WorkBenchAdvCraftingManager.getInstance().getRecipeList().remove(recipe);
}
@Override
public String describe() {
return "Adding Advanced Crafting Table Recipe for " + recipe.getRecipeOutput().getDisplayName();
}
@Override
public String describeUndo() {
return "Un-adding Advanced Crafting Table Recipe for " + recipe.getRecipeOutput().getDisplayName();
}
@Override
public Object getOverrideKey() {
return null;
}
}
private static class Remove implements IUndoableAction {
IRecipe recipe = null;
ItemStack remove;
public Remove(ItemStack rem){
remove = rem;
}
@Override
public void apply() {
for(Object object : WorkBenchAdvCraftingManager.getInstance().getRecipeList()) {
if(object instanceof IRecipe) {
IRecipe craft = (IRecipe)object;
if(craft.getRecipeOutput().isItemEqual(remove)) {
recipe = craft;
WorkBenchAdvCraftingManager.getInstance().getRecipeList().remove(object);
break;
}
}
}
}
@Override
public boolean canUndo() {
return recipe != null;
}
@Override
public void undo() {
WorkBenchAdvCraftingManager.getInstance().getRecipeList().add(recipe);
}
@Override
public String describe() {
return "Removing Advanced Crafting Table Recipe for " + remove.getDisplayName();
}
@Override
public String describeUndo() {
return "Un-remove Advanced Crafting Table Recipe for " + remove.getDisplayName();
}
@Override
public Object getOverrideKey() {
return null;
}
}
}