From 6cb0b6e011ca35ce86b0733e6dfa129323530b81 Mon Sep 17 00:00:00 2001 From: CrazyPants Date: Sat, 18 Oct 2014 20:24:58 +0800 Subject: [PATCH] Added ability to add Soul Binder recipes via IMC. --- ReleaseNotes.txt | 2 +- src/main/java/crazypants/enderio/EnderIO.java | 6 + .../machine/soul/BasicSoulBinderRecipe.java | 29 +++++ .../enderio/machine/soul/BlockSoulBinder.java | 11 +- .../machine/soul/SoulBinderRecipeManager.java | 110 ++++++++++++++++++ 5 files changed, 147 insertions(+), 11 deletions(-) create mode 100644 src/main/java/crazypants/enderio/machine/soul/BasicSoulBinderRecipe.java create mode 100644 src/main/java/crazypants/enderio/machine/soul/SoulBinderRecipeManager.java diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index e1ffced5..1a631601 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -12,7 +12,7 @@ Changes - Fix WAILA tooltip for dim.trans., was showing channel types even with no channels assigned to them (tterrag) - Dimensional Transceiver send/receive item buffers will only accept one stack per item type - #1127 Implemented IEnergyContainerItem on the Capacitor Bank item so it can be charged in item form (Tonius) - +- Added ability to add Soul Binder recipes via IMC Bugs - Fix tormented enderman head (and future head variants) dropping damage 0 always (tterrag) diff --git a/src/main/java/crazypants/enderio/EnderIO.java b/src/main/java/crazypants/enderio/EnderIO.java index d379531c..2e115069 100644 --- a/src/main/java/crazypants/enderio/EnderIO.java +++ b/src/main/java/crazypants/enderio/EnderIO.java @@ -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()); + } } } } diff --git a/src/main/java/crazypants/enderio/machine/soul/BasicSoulBinderRecipe.java b/src/main/java/crazypants/enderio/machine/soul/BasicSoulBinderRecipe.java new file mode 100644 index 00000000..21b66edc --- /dev/null +++ b/src/main/java/crazypants/enderio/machine/soul/BasicSoulBinderRecipe.java @@ -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(); + } + +} diff --git a/src/main/java/crazypants/enderio/machine/soul/BlockSoulBinder.java b/src/main/java/crazypants/enderio/machine/soul/BlockSoulBinder.java index 83f36991..afef0941 100644 --- a/src/main/java/crazypants/enderio/machine/soul/BlockSoulBinder.java +++ b/src/main/java/crazypants/enderio/machine/soul/BlockSoulBinder.java @@ -47,16 +47,7 @@ public class BlockSoulBinder extends AbstractMachineBlock { 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) { diff --git a/src/main/java/crazypants/enderio/machine/soul/SoulBinderRecipeManager.java b/src/main/java/crazypants/enderio/machine/soul/SoulBinderRecipeManager.java new file mode 100644 index 00000000..b5b50da0 --- /dev/null +++ b/src/main/java/crazypants/enderio/machine/soul/SoulBinderRecipeManager.java @@ -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); + } + +}