Added ability to add Soul Binder recipes via IMC.

This commit is contained in:
CrazyPants committed 2014-10-18 20:24:58 +08:00
1 parent b33caa57eb
commit 6cb0b6e011
5 files changed
+147 -11

No files matched your search

@@ -114,6 +114,7 @@ import crazypants.enderio.machine.slicensplice.BlockSliceAndSplice;
import crazypants.enderio.machine.slicensplice.SliceAndSpliceRecipeManager;
import crazypants.enderio.machine.solar.BlockSolarPanel;
import crazypants.enderio.machine.soul.BlockSoulBinder;
import crazypants.enderio.machine.soul.SoulBinderRecipeManager;
import crazypants.enderio.machine.spawner.BlockPoweredSpawner;
import crazypants.enderio.machine.spawner.ItemBrokenSpawner;
import crazypants.enderio.machine.spawnguard.BlockSpawnGuard;
@@ -610,6 +611,7 @@ public class EnderIO {
VatRecipeManager.getInstance().loadRecipesFromConfig();
EnchanterRecipeManager.getInstance().loadRecipesFromConfig();
FarmersRegistry.addFarmers();
SoulBinderRecipeManager.getInstance().addDefaultRecipes();
if(fluidXpJuice == null) { //should have been registered by open blocks
fluidXpJuice = FluidRegistry.getFluid("xpjuice");
@@ -651,6 +653,10 @@ public class EnderIO {
} else if(AlloyRecipeManager.IMC_KEY.equals(key)) {
AlloyRecipeManager.getInstance().addCustumRecipes(value);
}
} else if(msg.isNBTMessage()) {
if(SoulBinderRecipeManager.IMC_KEY.equals(msg.key)) {
SoulBinderRecipeManager.getInstance().addRecipeFromNBT(msg.getNBTValue());
}
}
}
}
@@ -0,0 +1,29 @@
package crazypants.enderio.machine.soul;
import net.minecraft.item.ItemStack;
import crazypants.enderio.EnderIO;
import crazypants.enderio.config.Config;
import crazypants.enderio.material.Material;
public class BasicSoulBinderRecipe extends AbstractSoulBinderRecipe {
private ItemStack inputStack;
private ItemStack outputStack;
public BasicSoulBinderRecipe(ItemStack inputStack, ItemStack outputStack, int energyRequired, int xpRequired, String uid, String... entityNames) {
super(energyRequired, xpRequired, uid, entityNames);
this.inputStack = inputStack.copy();
this.outputStack = outputStack.copy();
}
@Override
public ItemStack getInputStack() {
return inputStack.copy();
}
@Override
public ItemStack getOutputStack() {
return outputStack.copy();
}
}
@@ -47,16 +47,7 @@ public class BlockSoulBinder extends AbstractMachineBlock<TileSoulBinder> {
protected BlockSoulBinder() {
super(ModObject.blockSoulBinder, TileSoulBinder.class);
}
@Override
protected void init() {
super.init();
MachineRecipeRegistry.instance.registerRecipe(ModObject.blockSoulBinder.unlocalisedName, SoulBinderSpawnerRecipe.instance);
MachineRecipeRegistry.instance.registerRecipe(ModObject.blockSoulBinder.unlocalisedName, SoulBinderReanimationRecipe.instance);
MachineRecipeRegistry.instance.registerRecipe(ModObject.blockSoulBinder.unlocalisedName, SoulBinderEnderCystalRecipe.instance);
MachineRecipeRegistry.instance.registerRecipe(ModObject.blockSoulBinder.unlocalisedName, SoulBinderAttractorCystalRecipe.instance);
}
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
@@ -0,0 +1,110 @@
package crazypants.enderio.machine.soul;
import cpw.mods.fml.common.event.FMLInterModComms;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import crazypants.enderio.Log;
import crazypants.enderio.ModObject;
import crazypants.enderio.machine.MachineRecipeRegistry;
public class SoulBinderRecipeManager {
private static final SoulBinderRecipeManager instance = new SoulBinderRecipeManager();
public static final String IMC_KEY = "recipe:soulbinder";
public static final String KEY_RECIPE_UID = "recipeUID";
public static final String KEY_INPUT_STACK = "inputStack";
public static final String KEY_OUTPUT_STACK = "outputStack";
public static final String KEY_REQUIRED_ENERGY = "requiredEnergyRF";
public static final String KEY_REQUIRED_XP = "requiredXP";
public static final String KEY_SOUL_TYPES = "entityTypes";
public static SoulBinderRecipeManager getInstance() {
return instance;
}
public void addDefaultRecipes() {
MachineRecipeRegistry.instance.registerRecipe(ModObject.blockSoulBinder.unlocalisedName, SoulBinderSpawnerRecipe.instance);
MachineRecipeRegistry.instance.registerRecipe(ModObject.blockSoulBinder.unlocalisedName, SoulBinderReanimationRecipe.instance);
MachineRecipeRegistry.instance.registerRecipe(ModObject.blockSoulBinder.unlocalisedName, SoulBinderEnderCystalRecipe.instance);
MachineRecipeRegistry.instance.registerRecipe(ModObject.blockSoulBinder.unlocalisedName, SoulBinderAttractorCystalRecipe.instance);
}
// Example of how to add a recipe:
//
// NBTTagCompound root = new NBTTagCompound();
// root.setString(SoulBinderRecipeManager.KEY_RECIPE_UID, "diamondToWood");
// root.setInteger(SoulBinderRecipeManager.KEY_REQUIRED_ENERGY, 50000);
// root.setInteger(SoulBinderRecipeManager.KEY_REQUIRED_XP, 7);
// root.setString(SoulBinderRecipeManager.KEY_SOUL_TYPES, "Zombie|SpecialMobs.SpecialZombie|Villager");
// ItemStack is = new ItemStack(Items.diamond);
// NBTTagCompound stackRoot = new NBTTagCompound();
// is.writeToNBT(stackRoot);
// root.setTag(SoulBinderRecipeManager.KEY_INPUT_STACK, stackRoot);
// is = new ItemStack(Blocks.planks);
// stackRoot = new NBTTagCompound();
// is.writeToNBT(stackRoot);
// root.setTag(SoulBinderRecipeManager.KEY_OUTPUT_STACK, stackRoot);
//
// SoulBinderRecipeManager.getInstance().addRecipeFromNBT(root);
// FMLInterModComms.sendMessage("EnderIO", "recipe:soulbinder", root);
public boolean addRecipeFromNBT(NBTTagCompound root) {
try {
String recipeUid = root.getString(KEY_RECIPE_UID);
if(recipeUid == null || recipeUid.trim().length() == 0) {
Log.error("SoulBinderRecipeManager: Could not add custom soul binder recipe from IMC as recipe UID not set: " + root);
return false;
}
ItemStack inputStack = getStackFromRoot(root, KEY_INPUT_STACK);
if(inputStack == null) {
Log.error("SoulBinderRecipeManager: Could not add custom soul binder recipe from IMC as no input stack defined: " + root);
return false;
}
ItemStack outputStack = getStackFromRoot(root, KEY_OUTPUT_STACK);
if(outputStack == null) {
Log.error("SoulBinderRecipeManager: Could not add custom soul binder recipe from IMC as no output stack defined: " + root);
return false;
}
int energyRequired = root.getInteger(KEY_REQUIRED_ENERGY);
if(energyRequired <= 0) {
Log.error("SoulBinderRecipeManager: Could not add custom soul binder recipe from IMC as energy required was <= 0: " + root);
return false;
}
int xpLevelsRequired = root.getInteger(KEY_REQUIRED_XP);
if(xpLevelsRequired <= 0) {
Log.error("SoulBinderRecipeManager: Could not add custom soul binder recipe from IMC as energy required was <= 0: " + root);
return false;
}
String str = root.getString(KEY_SOUL_TYPES);
if(str == null || str.trim().length() == 0) {
Log.error("SoulBinderRecipeManager: Could not add custom soul binder recipe from IMC as no soul types defined: " + root);
return false;
}
String[] entityNames = str.split("\\|");
BasicSoulBinderRecipe recipe = new BasicSoulBinderRecipe(inputStack, outputStack, energyRequired, xpLevelsRequired, recipeUid, entityNames);
MachineRecipeRegistry.instance.registerRecipe(ModObject.blockSoulBinder.unlocalisedName, recipe);
return true;
} catch (Exception e) {
Log.error("SoulBinderRecipeManager: Could not add custom soul binder exception thrown when parsing message: " + e);
return false;
}
}
private ItemStack getStackFromRoot(NBTTagCompound root, String string) {
NBTTagCompound stackRoot = root.getCompoundTag(string);
if(stackRoot == null) {
return null;
}
return ItemStack.loadItemStackFromNBT(stackRoot);
}
}