Sort of Revert "why was this done twice"

This reverts commit 363adeb681.

Fixes #209
This commit is contained in:
modmuss50 2015-11-01 16:24:35 +00:00
parent 4ab88e0aae
commit bffbd31cab
11 changed files with 637 additions and 6 deletions

View file

@ -0,0 +1,129 @@
package techreborn.compat.minetweaker;
import minetweaker.IUndoableAction;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack;
import net.minecraft.item.ItemStack;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import techreborn.api.recipe.IBaseRecipeType;
import techreborn.api.recipe.RecipeHandler;
import techreborn.api.recipe.machines.AssemblingMachineRecipe;
import techreborn.lib.Reference;
import techreborn.util.ItemUtils;
import java.util.ArrayList;
import java.util.List;
@ZenClass("mods.techreborn.assemblingMachine")
public class MTAssemblingMachine {
@ZenMethod
public static void addRecipe(IItemStack output, IIngredient input1, IIngredient input2, int ticktime, int euTick) {
ItemStack oInput1 = (ItemStack) MinetweakerCompat.toObject(input1);
ItemStack oInput2 = (ItemStack) MinetweakerCompat.toObject(input2);
AssemblingMachineRecipe r = new AssemblingMachineRecipe(oInput1, oInput2, MinetweakerCompat.toStack(output), ticktime, euTick);
MineTweakerAPI.apply(new Add(r));
}
private static class Add implements IUndoableAction {
private final AssemblingMachineRecipe recipe;
public Add(AssemblingMachineRecipe recipe) {
this.recipe = recipe;
}
@Override
public void apply() {
RecipeHandler.addRecipe(recipe);
}
@Override
public boolean canUndo() {
return true;
}
@Override
public void undo() {
RecipeHandler.recipeList.remove(recipe);
}
@Override
public String describe() {
return "Adding Assembling Machine Recipe for " + recipe.getOutput(0).getDisplayName();
}
@Override
public String describeUndo() {
return "Removing Assembling Machine Recipe for " + recipe.getOutput(0).getDisplayName();
}
@Override
public Object getOverrideKey() {
return null;
}
}
@ZenMethod
public static void removeRecipe(IItemStack output)
{
MineTweakerAPI.apply(new Remove(MinetweakerCompat.toStack(output)));
}
private static class Remove implements IUndoableAction
{
private final ItemStack output;
List<AssemblingMachineRecipe> removedRecipes = new ArrayList<AssemblingMachineRecipe>();
public Remove(ItemStack output)
{
this.output = output;
}
@Override
public void apply()
{
for(IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.assemblingMachineRecipe)){
for(ItemStack stack : recipeType.getOutputs()){
if(ItemUtils.isItemEqual(stack, output, true, false)){
removedRecipes.add((AssemblingMachineRecipe) recipeType);
RecipeHandler.recipeList.remove(recipeType);
break;
}
}
}
}
@Override
public void undo()
{
if(removedRecipes!=null){
for(AssemblingMachineRecipe recipe : removedRecipes){
if(recipe!=null){
RecipeHandler.addRecipe(recipe);
}
}
}
}
@Override
public String describe()
{
return "Removing Assembling Machine Recipe for " + output.getDisplayName();
}
@Override
public String describeUndo()
{
return "Re-Adding Assembling Machine Recipe for " + output.getDisplayName();
}
@Override
public Object getOverrideKey()
{
return null;
}
@Override
public boolean canUndo()
{
return true;
}
}
}

View file

@ -33,6 +33,7 @@ public class MinetweakerCompat implements ICompatModule {
@Override
public void postInit(FMLPostInitializationEvent event) {
MineTweakerAPI.registerClass(MTAlloySmelter.class);
MineTweakerAPI.registerClass(MTAssemblingMachine.class);
MineTweakerAPI.registerClass(MTBlastFurnace.class);
MineTweakerAPI.registerClass(MTCentrifuge.class);
MineTweakerAPI.registerClass(MTChemicalReactor.class);

View file

@ -0,0 +1,59 @@
package techreborn.compat.nei.recipes;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.TemplateRecipeHandler;
import net.minecraft.client.gui.inventory.GuiContainer;
import techreborn.api.recipe.IBaseRecipeType;
import techreborn.client.gui.GuiAssemblingMachine;
import techreborn.lib.Reference;
import techreborn.util.ItemUtils;
import java.awt.*;
import java.util.List;
public class AssemblingMachineRecipeHandler extends GenericRecipeHander implements INeiBaseRecipe {
@Override
public void addPositionedStacks(List<PositionedStack> input, List<PositionedStack> outputs, IBaseRecipeType recipeType) {
int offset = 4;
if (recipeType.getInputs().size() > 0) {
PositionedStack pStack = new PositionedStack(ItemUtils.getStackWithAllOre(recipeType.getInputs().get(0)), 47 - offset, 17 - offset, false);
input.add(pStack);
}
if (recipeType.getInputs().size() > 1) {
PositionedStack pStack2 = new PositionedStack(ItemUtils.getStackWithAllOre(recipeType.getInputs().get(1)), 65 - offset, 17 - offset, false);
input.add(pStack2);
}
if (recipeType.getOutputsSize() > 0) {
PositionedStack pStack3 = new PositionedStack(recipeType.getOutput(0), 116 - offset, 35 - offset, false);
outputs.add(pStack3);
}
}
@Override
public String getRecipeName() {
return Reference.assemblingMachineRecipe;
}
@Override
public String getGuiTexture() {
return "techreborn:textures/gui/assembling_machine.png";
}
@Override
public Class<? extends GuiContainer> getGuiClass() {
return GuiAssemblingMachine.class;
}
@Override
public INeiBaseRecipe getNeiBaseRecipe() {
return this;
}
@Override
public void loadTransferRects() {
this.transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(
new Rectangle(80, 20, 20, 20), getNeiBaseRecipe().getRecipeName(), new Object[0]));
}
}