From 48cc9b4bd5c65733c41e86e05bf4bdb5a4d80750 Mon Sep 17 00:00:00 2001 From: CrazyPants Date: Fri, 5 Sep 2014 01:07:04 +0800 Subject: [PATCH] Lots of refactoring and setup for the slice'n'dice. --- .../config/SliceAndSpliceRecipes_Core.xml | 21 ++ .../config/SliceAndSpliceRecipes_User.xml | 3 + resources/assets/enderio/lang/en_US.lang | 5 +- .../enderio/textures/gui/sliceAndSplice.png | Bin 0 -> 2452 bytes src/main/java/crazypants/enderio/EnderIO.java | 46 ++-- .../java/crazypants/enderio/GuiHandler.java | 1 + .../java/crazypants/enderio/ModObject.java | 1 + .../machine/AbstractPoweredTaskEntity.java | 13 +- .../machine/alloy/AlloyMachineRecipe.java | 42 ---- .../machine/alloy/AlloyRecipeManager.java | 139 ++--------- .../machine/alloy/BasicAlloyRecipe.java | 230 ------------------ .../enderio/machine/alloy/IAlloyRecipe.java | 12 - .../machine/alloy/TileAlloySmelter.java | 11 +- .../machine/crusher/CrusherRecipeManager.java | 11 +- .../crusher/GrindingBallTagHandler.java | 6 + .../enderio/machine/crusher/TileCrusher.java | 8 +- .../machine/recipe/AbstractMachineRecipe.java | 4 +- .../machine/recipe/BasicManyToOneRecipe.java | 120 +++++++++ .../machine/recipe/CustomTagHandler.java | 2 + .../machine/recipe/IManyToOneRecipe.java | 11 + .../recipe/ManyToOneMachineRecipe.java | 52 ++++ .../recipe/ManyToOneRecipeManager.java | 150 ++++++++++++ .../enderio/machine/recipe/Recipe.java | 2 +- .../machine/recipe/RecipeConfigParser.java | 3 +- .../slicensplice/BlockSliceAndSplice.java | 75 ++++++ .../slicensplice/ContainerSliceAndSplice.java | 52 ++++ .../slicensplice/GuiSliceAndSplice.java | 46 ++++ .../SliceAndSpliceRecipeManager.java | 29 +++ .../slicensplice/TileSliceAndSplice.java | 160 ++++++++++++ .../enderio/machine/soul/GuiSoulBinder.java | 9 - .../machine/spawner/TilePoweredSpawner.java | 2 +- .../enderio/machine/still/TileVat.java | 6 +- .../nei/AlloySmelterRecipeHandler.java | 2 +- 33 files changed, 798 insertions(+), 476 deletions(-) create mode 100644 resources/assets/enderio/config/SliceAndSpliceRecipes_Core.xml create mode 100644 resources/assets/enderio/config/SliceAndSpliceRecipes_User.xml create mode 100644 resources/assets/enderio/textures/gui/sliceAndSplice.png delete mode 100644 src/main/java/crazypants/enderio/machine/alloy/AlloyMachineRecipe.java delete mode 100644 src/main/java/crazypants/enderio/machine/alloy/BasicAlloyRecipe.java delete mode 100644 src/main/java/crazypants/enderio/machine/alloy/IAlloyRecipe.java create mode 100644 src/main/java/crazypants/enderio/machine/recipe/BasicManyToOneRecipe.java create mode 100644 src/main/java/crazypants/enderio/machine/recipe/IManyToOneRecipe.java create mode 100644 src/main/java/crazypants/enderio/machine/recipe/ManyToOneMachineRecipe.java create mode 100644 src/main/java/crazypants/enderio/machine/recipe/ManyToOneRecipeManager.java create mode 100644 src/main/java/crazypants/enderio/machine/slicensplice/BlockSliceAndSplice.java create mode 100644 src/main/java/crazypants/enderio/machine/slicensplice/ContainerSliceAndSplice.java create mode 100644 src/main/java/crazypants/enderio/machine/slicensplice/GuiSliceAndSplice.java create mode 100644 src/main/java/crazypants/enderio/machine/slicensplice/SliceAndSpliceRecipeManager.java create mode 100644 src/main/java/crazypants/enderio/machine/slicensplice/TileSliceAndSplice.java diff --git a/resources/assets/enderio/config/SliceAndSpliceRecipes_Core.xml b/resources/assets/enderio/config/SliceAndSpliceRecipes_Core.xml new file mode 100644 index 00000000..e52d5517 --- /dev/null +++ b/resources/assets/enderio/config/SliceAndSpliceRecipes_Core.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/resources/assets/enderio/config/SliceAndSpliceRecipes_User.xml b/resources/assets/enderio/config/SliceAndSpliceRecipes_User.xml new file mode 100644 index 00000000..2e1bd64d --- /dev/null +++ b/resources/assets/enderio/config/SliceAndSpliceRecipes_User.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/resources/assets/enderio/lang/en_US.lang b/resources/assets/enderio/lang/en_US.lang index fd7bb542..81ff83ad 100644 --- a/resources/assets/enderio/lang/en_US.lang +++ b/resources/assets/enderio/lang/en_US.lang @@ -269,7 +269,6 @@ tile.blockZombieGenerator.tooltip.detailed.line1=Consumes Nutrient Distillation tile.blockZombieGenerator.tooltip.detailed.line2=to generate power enderio.zombieGenerator.fuelTank=Nutrient Tank - tile.blockKillerJoe.name=Killer Joe tile.blockKillerJoe.tooltip.detailed.line1=Attacks nearby creatures when tile.blockKillerJoe.tooltip.detailed.line2=supplied with a sword and @@ -277,6 +276,10 @@ tile.blockKillerJoe.tooltip.detailed.line3=Nutrient Distillation enderio.killerJoe.fuelTank=Nutrient Tank enderio.killerJoe.giveXp.tooltip=Use XP +tile.blockSliceAndSplice.name=Slice'N'Splice +tile.blockSliceAndSplice.tooltip.detailed.line1=Slices heads and splices in +tile.blockSliceAndSplice.tooltip.detailed.line2=all sorts of useful things + tile.blockFarmStation.name=Farming Station tile.blockFarmStation.tooltip.detailed.line1=Plants and harvests crops tile.blockFarmStation.tooltip.detailed.line2=Requires power and diff --git a/resources/assets/enderio/textures/gui/sliceAndSplice.png b/resources/assets/enderio/textures/gui/sliceAndSplice.png new file mode 100644 index 0000000000000000000000000000000000000000..bc904bff0e47e8dd8e59a3159968575967fec575 GIT binary patch literal 2452 zcmeHIjW?887=PxSVa6aIwdAAF4DD{MMzYqiXHCqAmRTE<&*iNhHEfD8jE`a7MYYHh z*-j!#r#i?gyAnEP5lZ1i8BwuPQ(>|ZCEk7MtiPdiw&$FCp8LDM=id8#+>dlG-ZpKz zF&zN3-Q74l07yia1T-?CeyZ^EArxirR?n>fm$EhA?NS3EgO`U7ml(IVx99WuD2fV& zLWw9+5)&008=EMON{kW7VxyB1qT}P^6A}`nQmITPJ7sBd&dQ{A!`igun6^z8_ck*W z9^8yn30?y@ZkC#wnwgoIm6es3mzSTPUrUq`@kNtWS1xuymp1{ z7hChVKIXBu)^^r5EY_6hH1WdBx^uSr#08Jv&lH_x>8g3z-)@cwIPV$Iw<4=Yj>{N7 zxEpFz4gBSb9J?lI^9U*a*Lh7G!LE&GtOkea zko@wxjgmVJ^;~j}ZwJHIw_H@e>85Ctw|ubs`Y)@YAwk^+9LeZ8dGLPaZq7esg)f43 z;@g=7E1*_A_*NyF(mX*A%!2yxz+-{YQ`%~EtB;Psn2|X(Bsl|F0%hC3nTzFHoX2?J zI5)mU(QyN_c4azZmvf)Y+zsx8ezqYacldD08-#VcW2Y3;vDkdWz|fXVcbK2o5!RV^`U@?P;0EOS=D?oiFHc()*k6Wd~A!5lZkq)^(5%VGYi#vkf5$9i#S}IC?r)l zJyI+bdm}-TJ5x?N^7-EbrFsci(-i)hCEMN;uZH%?EBxK0efYr_vhC1=o5IC~KzLy? zfTuwXZUnd9&0K;I)#J~Hs*BWDBDD+WsX{Xu^<~hikh4jBxB!$g5!N{=0Ud5s-ycp! z>>m6v6pg4LgKF{e1WisQ;?Ofo8TZ3@J4n*Gh1rp(U1r&j8c(Mly{a`dD;jHYOW8<8 z&*@@7F$dBUvOGi9p5CZla)>iOCm)2`wx=zlU6Zs^rk0C5jSWZx8C$qcsx)$5h?;(x z3<=sR67SU`O1hAuq+Os0HI)>h#-|`Z@SwJy89-{lc7o)%zyZ_@raf7`^a)y+)8J?v zrE9z;COw4NL7F`fnQtJP%*ct*AF#R#s7l)Tm0F#R1nqHUKuyqZ2vMmni#LO(Y$ zf@&w|b_<7FTZ+^2-dxsu?+cMzZ2nh+Wx&S78yqgV>XRQY87Nf3FsOQMoEw>B_Di8R(in2;W~p_!&fjZ-SJRX_LI}9)b(uF5vU01(e;_1%3n#EBo>TqDxInDskl1#NB(L Sb~>*Y|2B6nk5lQ4ru+*ycXA~F literal 0 HcmV?d00001 diff --git a/src/main/java/crazypants/enderio/EnderIO.java b/src/main/java/crazypants/enderio/EnderIO.java index fd4e89aa..8c12cf0b 100644 --- a/src/main/java/crazypants/enderio/EnderIO.java +++ b/src/main/java/crazypants/enderio/EnderIO.java @@ -92,6 +92,8 @@ import crazypants.enderio.machine.painter.BlockPaintedWall; import crazypants.enderio.machine.painter.BlockPainter; import crazypants.enderio.machine.power.BlockCapacitorBank; import crazypants.enderio.machine.reservoir.BlockReservoir; +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.spawner.BlockPoweredSpawner; @@ -197,6 +199,7 @@ public class EnderIO { public static BlockCrafter blockCrafter; public static BlockPoweredSpawner blockPoweredSpawner; public static ItemBrokenSpawner itemBrokenSpawner; + public static BlockSliceAndSplice blockSliceAndSplice; public static BlockSoulBinder blockSoulFuser; public static BlockKillerJoe blockKillerJoe; @@ -252,23 +255,15 @@ public class EnderIO { ConduitGeometryUtil.setupBounds((float) Config.conduitScale); - blockEnderIo = BlockEnderIO.create(); - - blockTravelPlatform = BlockTravelAnchor.create(); - - blockSolarPanel = BlockSolarPanel.create(); blockStirlingGenerator = BlockStirlingGenerator.create(); blockCombustionGenerator = BlockCombustionGenerator.create(); blockZombieGenerator = BlockZombieGenerator.create(); + blockSolarPanel = BlockSolarPanel.create(); blockCrusher = BlockCrusher.create(); blockAlloySmelter = BlockAlloySmelter.create(); - blockVat = BlockVat.create(); - blockPowerMonitor = BlockPowerMonitor.create(); - blockFarmStation = BlockFarmStation.create(); blockCapacitorBank = BlockCapacitorBank.create(); - blockWirelessCharger = BlockWirelessCharger.create(); - + blockPainter = BlockPainter.create(); blockPaintedFence = BlockPaintedFence.create(); blockPaintedFenceGate = BlockPaintedFenceGate.create(); @@ -281,32 +276,40 @@ public class EnderIO { blockCrafter = BlockCrafter.create(); blockPaintedGlowstone = BlockPaintedGlowstone.create(); blockPaintedCarpet = BlockPaintedCarpet.create(); - + + blockVat = BlockVat.create(); + blockPowerMonitor = BlockPowerMonitor.create(); + blockFarmStation = BlockFarmStation.create(); + + blockWirelessCharger = BlockWirelessCharger.create(); blockHyperCube = BlockHyperCube.create(); - blockElectricLight = BlockElectricLight.create(); - blockLightNode = BlockLightNode.create(); blockTank = BlockTank.create(); blockReservoir = BlockReservoir.create(); blockVacuumChest = BlockVacuumChest.create(); + + blockEnderIo = BlockEnderIO.create(); + blockTravelPlatform = BlockTravelAnchor.create(); - blockEnchanter = BlockEnchanter.create(); - + blockSliceAndSplice = BlockSliceAndSplice.create(); + blockSoulFuser = BlockSoulBinder.create(); + blockPoweredSpawner = BlockPoweredSpawner.create(); blockKillerJoe = BlockKillerJoe.create(); - + blockEnchanter = BlockEnchanter.create(); + blockDarkSteelPressurePlate = BlockDarkSteelPressurePlate.create(); + blockElectricLight = BlockElectricLight.create(); + blockLightNode = BlockLightNode.create(); + blockReinforcedObsidian = BlockReinforcedObsidian.create(); - + blockFusedQuartz = BlockFusedQuartz.create(); itemFusedQuartzFrame = ItemFusedQuartzFrame.create(); blockConduitBundle = BlockConduitBundle.create(); blockConduitFacade = BlockConduitFacade.create(); itemConduitFacade = ItemConduitFacade.create(); - - blockPoweredSpawner = BlockPoweredSpawner.create(); - itemBrokenSpawner = ItemBrokenSpawner.create(); - blockSoulFuser = BlockSoulBinder.create(); + itemBrokenSpawner = ItemBrokenSpawner.create(); itemRedstoneConduit = ItemRedstoneConduit.create(); itemPowerConduit = ItemPowerConduit.create(); @@ -469,6 +472,7 @@ public class EnderIO { CrusherRecipeManager.getInstance().loadRecipesFromConfig(); AlloyRecipeManager.getInstance().loadRecipesFromConfig(); + SliceAndSpliceRecipeManager.getInstance().loadRecipesFromConfig(); VatRecipeManager.getInstance().loadRecipesFromConfig(); EnchanterRecipeManager.getInstance().loadRecipesFromConfig(); FarmersRegistry.addFarmers(); diff --git a/src/main/java/crazypants/enderio/GuiHandler.java b/src/main/java/crazypants/enderio/GuiHandler.java index 2d74f5c4..88bee8f1 100644 --- a/src/main/java/crazypants/enderio/GuiHandler.java +++ b/src/main/java/crazypants/enderio/GuiHandler.java @@ -44,6 +44,7 @@ public class GuiHandler implements IGuiHandler { public static final int GUI_ID_ENCHANTER = 91; public static final int GUI_ID_KILLER_JOE = 92; public static final int GUI_ID_SOUL_BINDER = 93; + public static final int GUI_ID_SLICE_N_SPLICE = 94; protected final Map guiHandlers = new HashMap(); diff --git a/src/main/java/crazypants/enderio/ModObject.java b/src/main/java/crazypants/enderio/ModObject.java index ec861db9..2ab79b9f 100644 --- a/src/main/java/crazypants/enderio/ModObject.java +++ b/src/main/java/crazypants/enderio/ModObject.java @@ -52,6 +52,7 @@ public enum ModObject { blockWirelessCharger, blockEnchanter, blockSoulBinder, + blockSliceAndSplice, blockPoweredSpawner, itemBrokenSpawner, diff --git a/src/main/java/crazypants/enderio/machine/AbstractPoweredTaskEntity.java b/src/main/java/crazypants/enderio/machine/AbstractPoweredTaskEntity.java index 9c481f47..8455b12e 100644 --- a/src/main/java/crazypants/enderio/machine/AbstractPoweredTaskEntity.java +++ b/src/main/java/crazypants/enderio/machine/AbstractPoweredTaskEntity.java @@ -237,19 +237,18 @@ public abstract class AbstractPoweredTaskEntity extends AbstractMachineEntity { return 0; } - protected MachineRecipeInput[] getInputs() { + protected MachineRecipeInput[] getRecipeInputs() { MachineRecipeInput[] res = new MachineRecipeInput[slotDefinition.getNumInputSlots()]; int fromSlot = slotDefinition.minInputSlot; for (int i = 0; i < res.length; i++) { res[i] = new MachineRecipeInput(fromSlot, inventory[fromSlot]); fromSlot++; } - return res; } protected IMachineRecipe canStartNextTask(float chance) { - IMachineRecipe nextRecipe = MachineRecipeRegistry.instance.getRecipeForInputs(getMachineName(), getInputs()); + IMachineRecipe nextRecipe = MachineRecipeRegistry.instance.getRecipeForInputs(getMachineName(), getRecipeInputs()); if(nextRecipe == null) { return null; // no template } @@ -259,7 +258,7 @@ public abstract class AbstractPoweredTaskEntity extends AbstractMachineEntity { protected boolean canInsertResult(float chance, IMachineRecipe nextRecipe) { - ResultStack[] nextResults = nextRecipe.getCompletedResult(chance, getInputs()); + ResultStack[] nextResults = nextRecipe.getCompletedResult(chance, getRecipeInputs()); List outputStacks = new ArrayList(slotDefinition.getNumOutputSlots()); if(slotDefinition.getNumOutputSlots() > 0) { boolean allFull = true; @@ -314,10 +313,10 @@ public abstract class AbstractPoweredTaskEntity extends AbstractMachineEntity { } protected boolean startNextTask(IMachineRecipe nextRecipe, float chance) { - if(hasPower() && nextRecipe.isRecipe(getInputs())) { + if(hasPower() && nextRecipe.isRecipe(getRecipeInputs())) { // then get our recipe and take away the source items currentTask = createTask(nextRecipe, chance); - List consumed = nextRecipe.getQuantitiesConsumed(getInputs()); + List consumed = nextRecipe.getQuantitiesConsumed(getRecipeInputs()); for (MachineRecipeInput item : consumed) { if(item != null) { if(item.item != null && item.item.stackSize > 0) { @@ -334,7 +333,7 @@ public abstract class AbstractPoweredTaskEntity extends AbstractMachineEntity { } protected IPoweredTask createTask(IMachineRecipe nextRecipe, float chance) { - return new PoweredTask(nextRecipe, chance, getInputs()); + return new PoweredTask(nextRecipe, chance, getRecipeInputs()); } @Override diff --git a/src/main/java/crazypants/enderio/machine/alloy/AlloyMachineRecipe.java b/src/main/java/crazypants/enderio/machine/alloy/AlloyMachineRecipe.java deleted file mode 100644 index dbf1ab3b..00000000 --- a/src/main/java/crazypants/enderio/machine/alloy/AlloyMachineRecipe.java +++ /dev/null @@ -1,42 +0,0 @@ -package crazypants.enderio.machine.alloy; - -import net.minecraft.item.ItemStack; -import crazypants.enderio.ModObject; -import crazypants.enderio.machine.MachineRecipeInput; -import crazypants.enderio.machine.recipe.AbstractMachineRecipe; -import crazypants.enderio.machine.recipe.IRecipe; - -public class AlloyMachineRecipe extends AbstractMachineRecipe { - - @Override - public String getUid() { - return "AlloySmelterRecipe"; - } - - @Override - public IRecipe getRecipeForInputs(MachineRecipeInput[] inputs) { - return AlloyRecipeManager.instance.getRecipeForInputs(inputs); - } - - @Override - public boolean isValidInput(MachineRecipeInput input) { - if(input == null) { - return false; - } - return AlloyRecipeManager.instance.isValidInput(input); - } - - @Override - public String getMachineName() { - return ModObject.blockAlloySmelter.unlocalisedName; - } - - @Override - public float getExperianceForOutput(ItemStack output) { - return AlloyRecipeManager.instance.getExperianceForOutput(output); - } - - public boolean isValidRecipeComponents(ItemStack[] resultInv) { - return AlloyRecipeManager.instance.isValidRecipeComponents(resultInv); - } -} \ No newline at end of file diff --git a/src/main/java/crazypants/enderio/machine/alloy/AlloyRecipeManager.java b/src/main/java/crazypants/enderio/machine/alloy/AlloyRecipeManager.java index c164a5c5..90eea154 100644 --- a/src/main/java/crazypants/enderio/machine/alloy/AlloyRecipeManager.java +++ b/src/main/java/crazypants/enderio/machine/alloy/AlloyRecipeManager.java @@ -14,15 +14,19 @@ import crazypants.enderio.ModObject; import crazypants.enderio.config.Config; import crazypants.enderio.machine.MachineRecipeInput; import crazypants.enderio.machine.MachineRecipeRegistry; +import crazypants.enderio.machine.recipe.BasicManyToOneRecipe; import crazypants.enderio.machine.recipe.CustomTagHandler; +import crazypants.enderio.machine.recipe.IManyToOneRecipe; import crazypants.enderio.machine.recipe.IRecipe; +import crazypants.enderio.machine.recipe.ManyToOneMachineRecipe; +import crazypants.enderio.machine.recipe.ManyToOneRecipeManager; import crazypants.enderio.machine.recipe.Recipe; import crazypants.enderio.machine.recipe.RecipeConfig; import crazypants.enderio.machine.recipe.RecipeConfigParser; import crazypants.enderio.machine.recipe.RecipeInput; import crazypants.util.Util; -public class AlloyRecipeManager { +public class AlloyRecipeManager extends ManyToOneRecipeManager { private static final String CORE_FILE_NAME = "AlloySmelterRecipes_Core.xml"; private static final String CUSTOM_FILE_NAME = "AlloySmelterRecipes_User.xml"; @@ -33,11 +37,10 @@ public class AlloyRecipeManager { return instance; } - private final List recipes = new ArrayList(); - VanillaSmeltingRecipe vanillaRecipe = new VanillaSmeltingRecipe(); public AlloyRecipeManager() { + super(CORE_FILE_NAME, CUSTOM_FILE_NAME, "Alloy Smelter"); } public VanillaSmeltingRecipe getVanillaRecipe() { @@ -47,136 +50,22 @@ public class AlloyRecipeManager { public void setVanillaRecipe(VanillaSmeltingRecipe vanillaRecipe) { this.vanillaRecipe = vanillaRecipe; } - - + + protected CustomTagHandler createCustomTagHandler() { + return new VanillaFurnaceTagHandler(); + } public void loadRecipesFromConfig() { - - VanillaFurnaceTagHandler tagHandler = new VanillaFurnaceTagHandler(); - RecipeConfig config = RecipeConfig.loadRecipeConfig(CORE_FILE_NAME, CUSTOM_FILE_NAME, tagHandler); - if(config != null) { - processConfig(config, tagHandler); - } else { - Log.error("Could not load recipes for Alloy Smelter."); - } - - MachineRecipeRegistry.instance.registerRecipe(ModObject.blockAlloySmelter.unlocalisedName, new AlloyMachineRecipe()); + super.loadRecipesFromConfig(); + MachineRecipeRegistry.instance.registerRecipe(ModObject.blockAlloySmelter.unlocalisedName, new ManyToOneMachineRecipe("AlloySmelterRecipe", ModObject.blockAlloySmelter.unlocalisedName, this)); //vanilla alloy furnace recipes MachineRecipeRegistry.instance.registerRecipe(ModObject.blockAlloySmelter.unlocalisedName, vanillaRecipe); } - public void addCustumRecipes(String xmlDef) { - RecipeConfig config; - VanillaFurnaceTagHandler tagHandler = new VanillaFurnaceTagHandler(); - try { - config = RecipeConfigParser.parse(xmlDef, tagHandler); - } catch (Exception e) { - Log.error("Error parsing custom xml"); - return; - } - - if(config == null) { - Log.error("Could process custom XML"); - return; - } - processConfig(config, tagHandler); - } - - public List getRecipes() { - return recipes; - } - - private void processConfig(RecipeConfig config, VanillaFurnaceTagHandler tagHandler) { - - if(config.isDumpItemRegistery()) { - Util.dumpModObjects(new File(Config.configDirectory, "modObjectsRegistery.txt")); - } - if(config.isDumpOreDictionary()) { - Util.dumpOreNames(new File(Config.configDirectory, "oreDictionaryRegistery.txt")); - } - - List newRecipes = config.getRecipes(false); - Log.info("Found " + newRecipes.size() + " valid Alloy Smelter recipes in config."); - for (Recipe rec : newRecipes) { - addRecipe(new BasicAlloyRecipe(rec)); - } - tagHandler.apply(); - Log.info("Finished processing Alloy Smelter recipes. " + recipes.size() + " recipes avaliable."); - - } - - public void addRecipe(IAlloyRecipe recipe) { - if(recipe == null) { - Log.debug("Could not add invalid recipe: " + recipe); - return; - } - IRecipe rec = getRecipeForInputs(recipe.getInputStacks()); - if(rec != null) { - Log.warn("Not adding supplied recipe as a recipe already exists for the input: " + recipe); - return; - } - recipes.add(recipe); - } - - private IRecipe getRecipeForInputs(List inputs) { - MachineRecipeInput[] ins = new MachineRecipeInput[inputs.size()]; - - for (int i = 0; i < inputs.size(); i++) { - ins[i] = new MachineRecipeInput(-1, inputs.get(i)); - } - return getRecipeForInputs(ins); - } - - IRecipe getRecipeForInputs(MachineRecipeInput[] inputs) { - - for (IAlloyRecipe rec : recipes) { - if(rec.isInputForRecipe(inputs)) { - return rec; - } - } - return null; - } - - public boolean isValidInput(MachineRecipeInput input) { - if(input == null || input.item == null) { - return false; - } - for (IAlloyRecipe recipe : recipes) { - for (RecipeInput ri : recipe.getInputs()) { - if(ri.isInput(input.item)) { - return true; - } - } - } - return false; - } - - public boolean isValidRecipeComponents(ItemStack[] inputs) { - if(inputs == null || inputs.length == 0) { - return false; - } - for (IAlloyRecipe recipe : recipes) { - if(recipe.isValidRecipeComponents(inputs)) { - return true; - } - } - return false; - } - - public float getExperianceForOutput(ItemStack output) { - for (IAlloyRecipe recipe : recipes) { - if(recipe.getOutput().getItem() == output.getItem() && recipe.getOutput().getItemDamage() == output.getItemDamage()) { - return recipe.getOutputs()[0].getExperiance(); - } - } - return 0; - } private static final String ELEMENT_ROOT = "vanillaFurnaceRecipes"; - private static final String ELEMENT_EXCLUDE = "exclude"; - //private static final String AT_EXCLUDE = "exclude"; private class VanillaFurnaceTagHandler implements CustomTagHandler { @@ -218,8 +107,8 @@ public class AlloyRecipeManager { return inTag; } - public void apply() { - + @Override + public void configProcessed() { if(enabled != null) { Log.info("AlloyRecipeManager: Vannila smelting in AlloySmelting enabled=" + enabled); vanillaRecipe.setEnabled(enabled.booleanValue()); diff --git a/src/main/java/crazypants/enderio/machine/alloy/BasicAlloyRecipe.java b/src/main/java/crazypants/enderio/machine/alloy/BasicAlloyRecipe.java deleted file mode 100644 index cc17939c..00000000 --- a/src/main/java/crazypants/enderio/machine/alloy/BasicAlloyRecipe.java +++ /dev/null @@ -1,230 +0,0 @@ -package crazypants.enderio.machine.alloy; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; -import crazypants.enderio.ModObject; -import crazypants.enderio.machine.MachineRecipeInput; -import crazypants.enderio.machine.recipe.Recipe; -import crazypants.enderio.machine.recipe.RecipeInput; -import crazypants.enderio.machine.recipe.RecipeOutput; - -public class BasicAlloyRecipe implements IAlloyRecipe { - - public static final int DEFAULT_ENERGY_USE = 1200; - - private int energyRequired = DEFAULT_ENERGY_USE; - private ItemStack output; - - private float expPerItem; - - private final Recipe recipe; - - public BasicAlloyRecipe(Recipe recipe) { - this.recipe = recipe; - this.output = recipe.getOutputs()[0].getOutput().copy(); - expPerItem = recipe.getOutputs()[0].getExperiance(); - energyRequired = recipe.getEnergyRequired(); - - } - - @Override - public boolean isValidRecipeComponents(ItemStack... items) { - - List inputs = new ArrayList(Arrays.asList(recipe.getInputs())); - for (ItemStack is : items) { - if(is != null) { - RecipeInput remove = null; - for (RecipeInput ri : inputs) { - if(ri.isInput(is)) { - remove = ri; - break; - } - } - if(remove != null) { - inputs.remove(remove); - } else { - return false; - } - } - } - return true; - } - - @Override - public ItemStack getOutput() { - return output; - } - - private ItemStack[] getNonNullInputStacks(ItemStack[] checking) { - if(checking == null) { - return new ItemStack[0]; - } - List result = new ArrayList(checking.length); - for (ItemStack st : checking) { - if(st != null) { - result.add(st); - } - } - return result.toArray(new ItemStack[result.size()]); - } - - private MachineRecipeInput[] getNonNullInputs(MachineRecipeInput[] checking) { - int numNonNulls = 0; - for (int i = 0; i < checking.length; i++) { - if(checking[i] != null && checking[i].item != null) { - numNonNulls++; - } - } - MachineRecipeInput[] result = new MachineRecipeInput[numNonNulls]; - int index = 0; - for (int i = 0; i < checking.length; i++) { - if(checking[i] != null && checking[i].item != null) { - result[index] = checking[i]; - index++; - } - } - return result; - } - - //@Override - public ItemStack[] getCompletedResult(float chance, MachineRecipeInput... inputs) { - return new ItemStack[] { output.copy() }; - } - - @Override - public boolean isValidInput(int slot, ItemStack input) { - if(input == null) { - return false; - } - return getRecipeComponentFromInput(input) != null; - } - - @Override - public boolean isValidInput(FluidStack fluid) { - return false; - } - - //@Override - public String getMachineName() { - return ModObject.blockAlloySmelter.unlocalisedName; - } - - public int getQuantityConsumed(MachineRecipeInput input) { - ItemStack ing = getRecipeComponentFromInput(input.item); - return ing == null ? 0 : ing.stackSize; - } - - private ItemStack getRecipeComponentFromInput(ItemStack input) { - if(input == null) { - return null; - } - for (RecipeInput ri : recipe.getInputs()) { - if(ri.isInput(input)) { - return ri.getInput(); - } - } - return null; - } - - //@Override - public MachineRecipeInput[] getQuantitiesConsumed(MachineRecipeInput[] inputs) { - List result = new ArrayList(); - for (MachineRecipeInput input : inputs) { - int numConsumed = getQuantityConsumed(input); - if(numConsumed > 0) { - ItemStack consumed = input.item.copy(); - consumed.stackSize = numConsumed; - result.add(new MachineRecipeInput(input.slotNumber, consumed)); - } - } - if(result.isEmpty()) { - return null; - } - return result.toArray(new MachineRecipeInput[result.size()]); - } - - static class InputKey { - - int itemID; - int damage; - - InputKey(int itemID, int damage) { - this.itemID = itemID; - this.damage = damage; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + damage; - result = prime * result + itemID; - return result; - } - - @Override - public boolean equals(Object obj) { - if(this == obj) { - return true; - } - if(obj == null) { - return false; - } - if(getClass() != obj.getClass()) { - return false; - } - InputKey other = (InputKey) obj; - if(damage != other.damage) { - return false; - } - if(itemID != other.itemID) { - return false; - } - return true; - } - - } - - @Override - public boolean isValid() { - return recipe != null && recipe.isValid(); - } - - @Override - public int getEnergyRequired() { - return energyRequired; - } - - @Override - public RecipeOutput[] getOutputs() { - return recipe.getOutputs(); - } - - @Override - public List getInputStacks() { - return recipe.getInputStacks(); - } - - @Override - public boolean isInputForRecipe(MachineRecipeInput... inputs) { - if(inputs == null) { - return false; - } - return recipe.isInputForRecipe(inputs); - } - - @Override - public RecipeInput[] getInputs() { - return recipe.getInputs(); - } - - @Override - public List getInputFluidStacks() { - return Collections.emptyList(); - } -} diff --git a/src/main/java/crazypants/enderio/machine/alloy/IAlloyRecipe.java b/src/main/java/crazypants/enderio/machine/alloy/IAlloyRecipe.java deleted file mode 100644 index 6e06ed10..00000000 --- a/src/main/java/crazypants/enderio/machine/alloy/IAlloyRecipe.java +++ /dev/null @@ -1,12 +0,0 @@ -package crazypants.enderio.machine.alloy; - -import net.minecraft.item.ItemStack; -import crazypants.enderio.machine.recipe.IRecipe; - -public interface IAlloyRecipe extends IRecipe { - - boolean isValidRecipeComponents(ItemStack... items); - - ItemStack getOutput(); - -} diff --git a/src/main/java/crazypants/enderio/machine/alloy/TileAlloySmelter.java b/src/main/java/crazypants/enderio/machine/alloy/TileAlloySmelter.java index 88f9644e..28bd2db6 100644 --- a/src/main/java/crazypants/enderio/machine/alloy/TileAlloySmelter.java +++ b/src/main/java/crazypants/enderio/machine/alloy/TileAlloySmelter.java @@ -12,6 +12,7 @@ import crazypants.enderio.machine.IMachineRecipe.ResultStack; import crazypants.enderio.machine.MachineRecipeInput; import crazypants.enderio.machine.MachineRecipeRegistry; import crazypants.enderio.machine.SlotDefinition; +import crazypants.enderio.machine.recipe.ManyToOneMachineRecipe; public class TileAlloySmelter extends AbstractPoweredTaskEntity { @@ -60,8 +61,8 @@ public class TileAlloySmelter extends AbstractPoweredTaskEntity { protected IMachineRecipe canStartNextTask(float chance) { if(mode == Mode.FURNACE) { VanillaSmeltingRecipe vr = AlloyRecipeManager.getInstance().vanillaRecipe; - if(vr.isRecipe(getInputs())) { - ResultStack[] res = vr.getCompletedResult(chance, getInputs()); + if(vr.isRecipe(getRecipeInputs())) { + ResultStack[] res = vr.getCompletedResult(chance, getRecipeInputs()); if(res == null || res.length == 0) { return null; } @@ -70,7 +71,7 @@ public class TileAlloySmelter extends AbstractPoweredTaskEntity { return null; } - IMachineRecipe nextRecipe = MachineRecipeRegistry.instance.getRecipeForInputs(getMachineName(), getInputs()); + IMachineRecipe nextRecipe = MachineRecipeRegistry.instance.getRecipeForInputs(getMachineName(), getRecipeInputs()); if(mode == Mode.ALLOY && nextRecipe instanceof VanillaSmeltingRecipe) { nextRecipe = null; } @@ -123,7 +124,7 @@ public class TileAlloySmelter extends AbstractPoweredTaskEntity { for (IMachineRecipe recipe : recipes) { if(!(recipe instanceof VanillaSmeltingRecipe)) { - if(recipe instanceof AlloyMachineRecipe) { + if(recipe instanceof ManyToOneMachineRecipe) { ItemStack[] resultInv = new ItemStack[slotDefinition.getNumInputSlots()]; for (int i = slotDefinition.getMinInputSlot(); i <= slotDefinition.getMaxInputSlot(); i++) { if(i >= 0 && i < inventory.length) { @@ -134,7 +135,7 @@ public class TileAlloySmelter extends AbstractPoweredTaskEntity { } } } - if(((AlloyMachineRecipe) recipe).isValidRecipeComponents(resultInv)) { + if(((ManyToOneMachineRecipe) recipe).isValidRecipeComponents(resultInv)) { return true; } diff --git a/src/main/java/crazypants/enderio/machine/crusher/CrusherRecipeManager.java b/src/main/java/crazypants/enderio/machine/crusher/CrusherRecipeManager.java index cfb6a72f..f1291528 100644 --- a/src/main/java/crazypants/enderio/machine/crusher/CrusherRecipeManager.java +++ b/src/main/java/crazypants/enderio/machine/crusher/CrusherRecipeManager.java @@ -33,8 +33,6 @@ public class CrusherRecipeManager { static final CrusherRecipeManager instance = new CrusherRecipeManager(); - - public static CrusherRecipeManager getInstance() { return instance; } @@ -47,14 +45,7 @@ public class CrusherRecipeManager { private Set excludedStacks = new HashSet(); - public CrusherRecipeManager() { - // GrindingBall gb = new GrindingBall(new ItemStack(Items.flint)); - // gb.setGrindingMultiplier(1.25f); - // gb.setChanceMultiplier(1.25f); - // gb.setPowerMultiplier(0.75f); - // gb.setDurationMJ(ORE_ENERGY_COST * 6); - // - // balls.add(gb); + public CrusherRecipeManager() { } public boolean isValidSagBall(ItemStack stack) { diff --git a/src/main/java/crazypants/enderio/machine/crusher/GrindingBallTagHandler.java b/src/main/java/crazypants/enderio/machine/crusher/GrindingBallTagHandler.java index 11b1cd79..d9cbaa50 100644 --- a/src/main/java/crazypants/enderio/machine/crusher/GrindingBallTagHandler.java +++ b/src/main/java/crazypants/enderio/machine/crusher/GrindingBallTagHandler.java @@ -78,4 +78,10 @@ public class GrindingBallTagHandler implements CustomTagHandler { return false; } + @Override + public void configProcessed() { + } + + + } diff --git a/src/main/java/crazypants/enderio/machine/crusher/TileCrusher.java b/src/main/java/crazypants/enderio/machine/crusher/TileCrusher.java index 89eed236..09c574b3 100644 --- a/src/main/java/crazypants/enderio/machine/crusher/TileCrusher.java +++ b/src/main/java/crazypants/enderio/machine/crusher/TileCrusher.java @@ -101,15 +101,15 @@ public class TileCrusher extends AbstractPoweredTaskEntity { PoweredTask res; useGrindingBall = false; if(gb != null) { - useGrindingBall = !CrusherRecipeManager.getInstance().isExcludedFromBallBonus(getInputs()); + useGrindingBall = !CrusherRecipeManager.getInstance().isExcludedFromBallBonus(getRecipeInputs()); if(useGrindingBall) { - res = new PoweredTask(nextRecipe, chance * gb.getChanceMultiplier(), getInputs()); + res = new PoweredTask(nextRecipe, chance * gb.getChanceMultiplier(), getRecipeInputs()); res.setRequiredEnergy(res.getRequiredEnergy() * gb.getPowerMultiplier()); } else { - res = new PoweredTask(nextRecipe, chance, getInputs()); + res = new PoweredTask(nextRecipe, chance, getRecipeInputs()); } } else { - res = new PoweredTask(nextRecipe, chance, getInputs()); + res = new PoweredTask(nextRecipe, chance, getRecipeInputs()); } return res; } diff --git a/src/main/java/crazypants/enderio/machine/recipe/AbstractMachineRecipe.java b/src/main/java/crazypants/enderio/machine/recipe/AbstractMachineRecipe.java index d6f6d391..f5eeac4e 100644 --- a/src/main/java/crazypants/enderio/machine/recipe/AbstractMachineRecipe.java +++ b/src/main/java/crazypants/enderio/machine/recipe/AbstractMachineRecipe.java @@ -23,11 +23,11 @@ public abstract class AbstractMachineRecipe implements IMachineRecipe { @Override public List getQuantitiesConsumed(MachineRecipeInput[] inputs) { IRecipe rec = getRecipeForInputs(inputs); - List result = new ArrayList(); + List result = new ArrayList(); for (RecipeInput ri : rec.getInputs()) { for (MachineRecipeInput input : inputs) { if(input != null && (input.item != null || input.fluid != null)) { - if(ri.isInput(input.item)) { + if(ri.isInput(input.item) && (ri.getSlotNumber() == -1 || ri.getSlotNumber() == input.slotNumber)) { result.add(new MachineRecipeInput(input.slotNumber, ri.getInput().copy())); break; } else if(ri.isInput(input.fluid)) { diff --git a/src/main/java/crazypants/enderio/machine/recipe/BasicManyToOneRecipe.java b/src/main/java/crazypants/enderio/machine/recipe/BasicManyToOneRecipe.java new file mode 100644 index 00000000..854f5e00 --- /dev/null +++ b/src/main/java/crazypants/enderio/machine/recipe/BasicManyToOneRecipe.java @@ -0,0 +1,120 @@ +package crazypants.enderio.machine.recipe; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import crazypants.enderio.ModObject; +import crazypants.enderio.machine.MachineRecipeInput; + +public class BasicManyToOneRecipe implements IManyToOneRecipe { + + private final int energyRequired; + private final ItemStack output; + + private final float expPerItem; + + private final Recipe recipe; + + public BasicManyToOneRecipe(Recipe recipe) { + this.recipe = recipe; + this.output = recipe.getOutputs()[0].getOutput().copy(); + expPerItem = recipe.getOutputs()[0].getExperiance(); + energyRequired = recipe.getEnergyRequired(); + } + + @Override + public boolean isValidRecipeComponents(ItemStack... items) { + + List inputs = new ArrayList(Arrays.asList(recipe.getInputs())); + for (ItemStack is : items) { + if(is != null) { + RecipeInput remove = null; + for (RecipeInput ri : inputs) { + if(ri.isInput(is)) { + remove = ri; + break; + } + } + if(remove != null) { + inputs.remove(remove); + } else { + return false; + } + } + } + return true; + } + + @Override + public ItemStack getOutput() { + return output; + } + + @Override + public boolean isValidInput(int slot, ItemStack input) { + if(input == null) { + return false; + } + return getRecipeComponentFromInput(input) != null; + } + + @Override + public boolean isValidInput(FluidStack fluid) { + return false; + } + + @Override + public boolean isValid() { + return recipe != null && recipe.isValid(); + } + + @Override + public int getEnergyRequired() { + return energyRequired; + } + + @Override + public RecipeOutput[] getOutputs() { + return recipe.getOutputs(); + } + + @Override + public List getInputStacks() { + return recipe.getInputStacks(); + } + + @Override + public boolean isInputForRecipe(MachineRecipeInput... inputs) { + if(inputs == null) { + return false; + } + return recipe.isInputForRecipe(inputs); + } + + @Override + public RecipeInput[] getInputs() { + return recipe.getInputs(); + } + + @Override + public List getInputFluidStacks() { + return Collections.emptyList(); + } + + private ItemStack getRecipeComponentFromInput(ItemStack input) { + if(input == null) { + return null; + } + for (RecipeInput ri : recipe.getInputs()) { + if(ri.isInput(input)) { + return ri.getInput(); + } + } + return null; + } + +} diff --git a/src/main/java/crazypants/enderio/machine/recipe/CustomTagHandler.java b/src/main/java/crazypants/enderio/machine/recipe/CustomTagHandler.java index d995c370..a0647b8f 100644 --- a/src/main/java/crazypants/enderio/machine/recipe/CustomTagHandler.java +++ b/src/main/java/crazypants/enderio/machine/recipe/CustomTagHandler.java @@ -8,5 +8,7 @@ public interface CustomTagHandler { boolean endElement(String uri, String localName, String qName) throws SAXException; boolean startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException; + + void configProcessed(); } diff --git a/src/main/java/crazypants/enderio/machine/recipe/IManyToOneRecipe.java b/src/main/java/crazypants/enderio/machine/recipe/IManyToOneRecipe.java new file mode 100644 index 00000000..d86a922f --- /dev/null +++ b/src/main/java/crazypants/enderio/machine/recipe/IManyToOneRecipe.java @@ -0,0 +1,11 @@ +package crazypants.enderio.machine.recipe; + +import net.minecraft.item.ItemStack; + +public interface IManyToOneRecipe extends IRecipe { + + boolean isValidRecipeComponents(ItemStack... items); + + ItemStack getOutput(); + +} diff --git a/src/main/java/crazypants/enderio/machine/recipe/ManyToOneMachineRecipe.java b/src/main/java/crazypants/enderio/machine/recipe/ManyToOneMachineRecipe.java new file mode 100644 index 00000000..3f6d6041 --- /dev/null +++ b/src/main/java/crazypants/enderio/machine/recipe/ManyToOneMachineRecipe.java @@ -0,0 +1,52 @@ +package crazypants.enderio.machine.recipe; + +import net.minecraft.item.ItemStack; +import crazypants.enderio.ModObject; +import crazypants.enderio.machine.MachineRecipeInput; +import crazypants.enderio.machine.alloy.AlloyRecipeManager; + +public class ManyToOneMachineRecipe extends AbstractMachineRecipe { + + private final String uid; + private final String machineName; + private final ManyToOneRecipeManager recipeManager; + + public ManyToOneMachineRecipe(String uid, String machineName, ManyToOneRecipeManager recipeManager) { + this.uid = uid; + this.machineName = machineName; + this.recipeManager = recipeManager; + } + + @Override + public String getUid() { + return uid; + } + + @Override + public IRecipe getRecipeForInputs(MachineRecipeInput[] inputs) { + return recipeManager.getRecipeForInputs(inputs); + } + + @Override + public boolean isValidInput(MachineRecipeInput input) { + if(input == null) { + return false; + } + return recipeManager.isValidInput(input); + } + + @Override + public String getMachineName() { + return machineName; + } + + @Override + public float getExperianceForOutput(ItemStack output) { + return recipeManager.getExperianceForOutput(output); + } + + public boolean isValidRecipeComponents(ItemStack[] resultInv) { + return recipeManager.isValidRecipeComponents(resultInv); + } + +} diff --git a/src/main/java/crazypants/enderio/machine/recipe/ManyToOneRecipeManager.java b/src/main/java/crazypants/enderio/machine/recipe/ManyToOneRecipeManager.java new file mode 100644 index 00000000..ad43a8c1 --- /dev/null +++ b/src/main/java/crazypants/enderio/machine/recipe/ManyToOneRecipeManager.java @@ -0,0 +1,150 @@ +package crazypants.enderio.machine.recipe; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.item.ItemStack; +import crazypants.enderio.Log; +import crazypants.enderio.config.Config; +import crazypants.enderio.machine.MachineRecipeInput; +import crazypants.util.Util; + +public class ManyToOneRecipeManager { + + private final List recipes = new ArrayList(); + + private final String coreFileName; + private final String customFileName; + private final String managerName; + + public ManyToOneRecipeManager(String coreFileName, String custonFileName, String managerName) { + this.coreFileName = coreFileName; + this.customFileName = custonFileName; + this.managerName = managerName; + } + + public void loadRecipesFromConfig() { + CustomTagHandler tagHandler = createCustomTagHandler(); + RecipeConfig config = RecipeConfig.loadRecipeConfig(coreFileName, customFileName, tagHandler); + if(config != null) { + processConfig(config); + if(tagHandler != null) { + tagHandler.configProcessed(); + } + } else { + Log.error("Could not load recipes for " + managerName + "."); + } + } + + protected CustomTagHandler createCustomTagHandler() { + return null; + } + + public void addCustumRecipes(String xmlDef) { + RecipeConfig config; + CustomTagHandler tagHandler = createCustomTagHandler(); + try { + config = RecipeConfigParser.parse(xmlDef, tagHandler); + } catch (Exception e) { + Log.error("Error parsing custom xml for " + managerName ); + return; + } + + if(config == null) { + Log.error("Could not process custom XML " + managerName); + return; + } + processConfig(config); + if(tagHandler != null) { + tagHandler.configProcessed(); + } + } + + public List getRecipes() { + return recipes; + } + + private void processConfig(RecipeConfig config) { + if(config.isDumpItemRegistery()) { + Util.dumpModObjects(new File(Config.configDirectory, "modObjectsRegistery.txt")); + } + if(config.isDumpOreDictionary()) { + Util.dumpOreNames(new File(Config.configDirectory, "oreDictionaryRegistery.txt")); + } + List newRecipes = config.getRecipes(false); + Log.info("Found " + newRecipes.size() + " valid " + managerName + " recipes in config."); + for (Recipe rec : newRecipes) { + addRecipe(new BasicManyToOneRecipe(rec)); + } + Log.info("Finished processing " + managerName + " recipes. " + recipes.size() + " recipes avaliable."); + } + + public void addRecipe(IManyToOneRecipe recipe) { + if(recipe == null) { + Log.debug("Could not add invalid recipe: " + recipe + " for " + managerName ); + return; + } + IRecipe rec = getRecipeForInputs(recipe.getInputStacks()); + if(rec != null) { + Log.warn("Not adding supplied recipe to " + managerName + " as a recipe already exists for the inputs: " + recipe); + return; + } + recipes.add(recipe); + } + + private IRecipe getRecipeForInputs(List inputs) { + MachineRecipeInput[] ins = new MachineRecipeInput[inputs.size()]; + + for (int i = 0; i < inputs.size(); i++) { + ins[i] = new MachineRecipeInput(-1, inputs.get(i)); + } + return getRecipeForInputs(ins); + } + + public IRecipe getRecipeForInputs(MachineRecipeInput[] inputs) { + + for (IManyToOneRecipe rec : recipes) { + if(rec.isInputForRecipe(inputs)) { + return rec; + } + } + return null; + } + + public boolean isValidInput(MachineRecipeInput input) { + if(input == null || input.item == null) { + return false; + } + for (IManyToOneRecipe recipe : recipes) { + for (RecipeInput ri : recipe.getInputs()) { + if(ri.isInput(input.item) && (ri.getSlotNumber() == -1 || input.slotNumber == ri.getSlotNumber())) { + return true; + } + } + } + return false; + } + + public boolean isValidRecipeComponents(ItemStack[] inputs) { + if(inputs == null || inputs.length == 0) { + return false; + } + for (IManyToOneRecipe recipe : recipes) { + if(recipe.isValidRecipeComponents(inputs)) { + return true; + } + } + return false; + } + + public float getExperianceForOutput(ItemStack output) { + for (IManyToOneRecipe recipe : recipes) { + if(recipe.getOutput().getItem() == output.getItem() && recipe.getOutput().getItemDamage() == output.getItemDamage()) { + return recipe.getOutputs()[0].getExperiance(); + } + } + return 0; + } + +} diff --git a/src/main/java/crazypants/enderio/machine/recipe/Recipe.java b/src/main/java/crazypants/enderio/machine/recipe/Recipe.java index 7831e000..5649009b 100644 --- a/src/main/java/crazypants/enderio/machine/recipe/Recipe.java +++ b/src/main/java/crazypants/enderio/machine/recipe/Recipe.java @@ -47,7 +47,7 @@ public class Recipe implements IRecipe { RecipeInput required = null; for(int i=0;i 0) || tst.isInput(input.fluid)) { required = tst; } } diff --git a/src/main/java/crazypants/enderio/machine/recipe/RecipeConfigParser.java b/src/main/java/crazypants/enderio/machine/recipe/RecipeConfigParser.java index 87eda5c7..6163ee17 100644 --- a/src/main/java/crazypants/enderio/machine/recipe/RecipeConfigParser.java +++ b/src/main/java/crazypants/enderio/machine/recipe/RecipeConfigParser.java @@ -34,7 +34,6 @@ import crazypants.enderio.machine.recipe.RecipeConfig.RecipeGroup; public class RecipeConfigParser extends DefaultHandler { - //public static final String ELEMENT_ROOT = "SAGMillRecipes"; public static final String ELEMENT_RECIPE_GROUP = "recipeGroup"; public static final String ELEMENT_RECIPE = "recipe"; public static final String ELEMENT_INPUT = "input"; @@ -322,7 +321,7 @@ public class RecipeConfigParser extends DefaultHandler { //TODO: What a hack! private boolean isElementRoot(String str) { - return "AlloySmelterRecipes".equals(str) || "SAGMillRecipes".equals(str) || "VatRecipes".equals(str); + return "AlloySmelterRecipes".equals(str) || "SAGMillRecipes".equals(str) || "VatRecipes".equals(str) || "SliceAndSpliceRecipes".equals(str); } private void addOutputStack(Attributes attributes) { diff --git a/src/main/java/crazypants/enderio/machine/slicensplice/BlockSliceAndSplice.java b/src/main/java/crazypants/enderio/machine/slicensplice/BlockSliceAndSplice.java new file mode 100644 index 00000000..1a58423e --- /dev/null +++ b/src/main/java/crazypants/enderio/machine/slicensplice/BlockSliceAndSplice.java @@ -0,0 +1,75 @@ +package crazypants.enderio.machine.slicensplice; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +import crazypants.enderio.GuiHandler; +import crazypants.enderio.ModObject; +import crazypants.enderio.machine.AbstractMachineBlock; +import crazypants.enderio.machine.AbstractMachineEntity; +import crazypants.enderio.machine.MachineRecipeRegistry; +import crazypants.enderio.machine.soul.BlockSoulBinder; +import crazypants.enderio.machine.soul.ContainerSoulBinder; +import crazypants.enderio.machine.soul.GuiSoulBinder; +import crazypants.enderio.machine.soul.SoulBinderSpawnerRecipe; +import crazypants.enderio.machine.soul.TileSoulBinder; + +public class BlockSliceAndSplice extends AbstractMachineBlock { + + public static int renderId; + + public static BlockSliceAndSplice create() { + BlockSliceAndSplice result = new BlockSliceAndSplice(); + result.init(); + return result; + } + + protected BlockSliceAndSplice() { + super(ModObject.blockSliceAndSplice, TileSliceAndSplice.class); + } + + @Override + public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + TileEntity te = world.getTileEntity(x, y, z); + if(te instanceof TileSliceAndSplice) { + return new ContainerSliceAndSplice(player.inventory, (AbstractMachineEntity) te); + } + return null; + } + + @Override + public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + TileEntity te = world.getTileEntity(x, y, z); + if(te instanceof TileSliceAndSplice) { + return new GuiSliceAndSplice(player.inventory, (AbstractMachineEntity) te); + } + return null; + } + + @Override + protected int getGuiId() { + return GuiHandler.GUI_ID_SLICE_N_SPLICE; + } + + @Override + protected String getMachineFrontIconKey(boolean active) { + return "enderio:blankMachinePanel"; + } + +// @Override +// public boolean renderAsNormalBlock() { +// return false; +// } +// +// @Override +// public boolean isOpaqueCube() { +// return false; +// } +// +// @Override +// public int getLightOpacity() { +// return 7; +// } + +} diff --git a/src/main/java/crazypants/enderio/machine/slicensplice/ContainerSliceAndSplice.java b/src/main/java/crazypants/enderio/machine/slicensplice/ContainerSliceAndSplice.java new file mode 100644 index 00000000..d8ad8ce6 --- /dev/null +++ b/src/main/java/crazypants/enderio/machine/slicensplice/ContainerSliceAndSplice.java @@ -0,0 +1,52 @@ +package crazypants.enderio.machine.slicensplice; + +import java.awt.Point; + +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import crazypants.enderio.machine.AbstractMachineContainer; +import crazypants.enderio.machine.AbstractMachineEntity; + +public class ContainerSliceAndSplice extends AbstractMachineContainer { + + private static final Point[] inputLocs = new Point[] { + new Point(44,40), + new Point(62,40), + new Point(80,40), + new Point(44,58), + new Point(62,58), + new Point(80,58), + new Point(54,16), + new Point(72,16) + }; + + public ContainerSliceAndSplice(InventoryPlayer playerInv, AbstractMachineEntity te) { + super(playerInv, te); + } + + @Override + protected void addMachineSlots(InventoryPlayer playerInv) { + + for(int i=0;i= tool.getMaxDamage()) { + inventory[toolIndex] = null; + } + } + } + + private EntityLivingBase getFakePlayer() { + if(fakePlayer == null) { + fakePlayer = FakePlayerFactory.getMinecraft(MinecraftServer.getServer().worldServerForDimension(worldObj.provider.dimensionId)); + } + return fakePlayer; + } + + protected MachineRecipeInput[] getRecipeInputs() { + MachineRecipeInput[] res = new MachineRecipeInput[slotDefinition.getNumInputSlots() - 2]; + int fromSlot = slotDefinition.minInputSlot; + for (int i = 0; i < res.length; i++) { + res[i] = new MachineRecipeInput(fromSlot, inventory[fromSlot]); + fromSlot++; + } + return res; + } + + @Override + protected boolean isMachineItemValidForSlot(int slot, ItemStack itemstack) { + if(itemstack == null || itemstack.getItem() == null) { + return false; + } + if(!slotDefinition.isInputSlot(slot)) { + return false; + } + if(slot == axeIndex) { + return itemstack.getItem() instanceof ItemAxe; + } + if(slot == shearsIndex) { + return itemstack.getItem() instanceof ItemShears; + } + + ItemStack currentStackInSlot = inventory[slot]; + if(currentStackInSlot != null) { + return currentStackInSlot.isItemEqual(itemstack); + } + + int numSlotsFilled = 0; + for (int i = slotDefinition.getMinInputSlot(); i <= slotDefinition.getMaxInputSlot(); i++) { + if(i >= 0 && i < inventory.length && i != axeIndex && i != shearsIndex) { + if(inventory[i] != null && inventory[i].stackSize > 0) { + numSlotsFilled++; + } + } + } + List recipes = MachineRecipeRegistry.instance.getRecipesForInput(getMachineName(), MachineRecipeInput.create(slot, itemstack)); + if(numSlotsFilled == 0 && !recipes.isEmpty()) { + return true; + } + return isValidInputForAlloyRecipe(slot, itemstack, numSlotsFilled, recipes); + } + + private boolean isValidInputForAlloyRecipe(int slot, ItemStack itemstack, int numSlotsFilled, List recipes) { + + ItemStack[] resultInv = new ItemStack[slotDefinition.getNumInputSlots()]; + for (int i = slotDefinition.getMinInputSlot(); i <= slotDefinition.getMaxInputSlot(); i++) { + if(i >= 0 && i < inventory.length && i != axeIndex && i != shearsIndex) { + if(i == slot) { + resultInv[i] = itemstack; + } else { + resultInv[i] = inventory[i]; + } + } + } + + for (IMachineRecipe recipe : recipes) { + if(recipe instanceof ManyToOneMachineRecipe) { + if(((ManyToOneMachineRecipe) recipe).isValidRecipeComponents(resultInv)) { + return true; + } + } + } + return false; + } + + private boolean isItemAlreadyInASlot(ItemStack itemstack) { + ItemStack currentStackType = null; + for (int i = slotDefinition.getMinInputSlot(); i <= slotDefinition.getMaxInputSlot() && currentStackType == null; i++) { + currentStackType = inventory[i]; + if(currentStackType != null && currentStackType.isItemEqual(itemstack)) { + return true; + } + } + return false; + } + +} diff --git a/src/main/java/crazypants/enderio/machine/soul/GuiSoulBinder.java b/src/main/java/crazypants/enderio/machine/soul/GuiSoulBinder.java index 342df3a5..464fa7fd 100644 --- a/src/main/java/crazypants/enderio/machine/soul/GuiSoulBinder.java +++ b/src/main/java/crazypants/enderio/machine/soul/GuiSoulBinder.java @@ -44,13 +44,4 @@ public class GuiSoulBinder extends GuiMachineBase { return false; } -// @Override -// protected void renderSlotHighlight(int slot, Vector4f col) { -// if(tileEntity.getSlotDefinition().isOutputSlot(slot)) { -// renderSlotHighlight(col, 117,31,24,24); -// } else if(slot != 1) { -// super.renderSlotHighlight(slot, col); -// } -// } - } diff --git a/src/main/java/crazypants/enderio/machine/spawner/TilePoweredSpawner.java b/src/main/java/crazypants/enderio/machine/spawner/TilePoweredSpawner.java index 5781161f..6fa2abe9 100644 --- a/src/main/java/crazypants/enderio/machine/spawner/TilePoweredSpawner.java +++ b/src/main/java/crazypants/enderio/machine/spawner/TilePoweredSpawner.java @@ -177,7 +177,7 @@ public class TilePoweredSpawner extends AbstractPoweredTaskEntity { @Override protected IPoweredTask createTask(IMachineRecipe nextRecipe, float chance) { - PoweredTask res = new PoweredTask(nextRecipe, chance, getInputs()); + PoweredTask res = new PoweredTask(nextRecipe, chance, getRecipeInputs()); int ticksDelay = TilePoweredSpawner.MIN_SPAWN_DELAY_BASE + (int) Math.round((TilePoweredSpawner.MAX_SPAWN_DELAY_BASE - TilePoweredSpawner.MIN_SPAWN_DELAY_BASE) * Math.random()); diff --git a/src/main/java/crazypants/enderio/machine/still/TileVat.java b/src/main/java/crazypants/enderio/machine/still/TileVat.java index 33102df0..f7ea0a73 100644 --- a/src/main/java/crazypants/enderio/machine/still/TileVat.java +++ b/src/main/java/crazypants/enderio/machine/still/TileVat.java @@ -50,7 +50,7 @@ public class TileVat extends AbstractPoweredTaskEntity implements IFluidHandler @Override protected boolean isMachineItemValidForSlot(int i, ItemStack itemstack) { - MachineRecipeInput[] inputs = getInputs(); + MachineRecipeInput[] inputs = getRecipeInputs(); inputs[i] = new MachineRecipeInput(i, itemstack); return VatRecipeManager.getInstance().isValidInput(inputs); } @@ -205,7 +205,7 @@ public class TileVat extends AbstractPoweredTaskEntity implements IFluidHandler } @Override - protected MachineRecipeInput[] getInputs() { + protected MachineRecipeInput[] getRecipeInputs() { MachineRecipeInput[] res = new MachineRecipeInput[slotDefinition.getNumInputSlots() + 1]; int fromSlot = slotDefinition.minInputSlot; for (int i = 0; i < res.length - 1; i++) { @@ -227,7 +227,7 @@ public class TileVat extends AbstractPoweredTaskEntity implements IFluidHandler return false; } - MachineRecipeInput[] inputs = getInputs(); + MachineRecipeInput[] inputs = getRecipeInputs(); if(inputTank.getFluidAmount() <= 0) { inputs[inputs.length - 1] = new MachineRecipeInput(0, new FluidStack(fluid, 1)); } diff --git a/src/main/java/crazypants/enderio/nei/AlloySmelterRecipeHandler.java b/src/main/java/crazypants/enderio/nei/AlloySmelterRecipeHandler.java index 90e66c73..0d4f5a23 100644 --- a/src/main/java/crazypants/enderio/nei/AlloySmelterRecipeHandler.java +++ b/src/main/java/crazypants/enderio/nei/AlloySmelterRecipeHandler.java @@ -12,9 +12,9 @@ import codechicken.nei.PositionedStack; import codechicken.nei.recipe.TemplateRecipeHandler; import crazypants.enderio.machine.alloy.AlloyRecipeManager; import crazypants.enderio.machine.alloy.GuiAlloySmelter; -import crazypants.enderio.machine.alloy.IAlloyRecipe; import crazypants.enderio.machine.alloy.VanillaSmeltingRecipe; import crazypants.enderio.machine.power.PowerDisplayUtil; +import crazypants.enderio.machine.recipe.IManyToOneRecipe; import crazypants.enderio.machine.recipe.IRecipe; import crazypants.enderio.machine.recipe.RecipeInput;