Bugfixing in TConstruct Smeltery

This commit is contained in:
Zixxl 2015-07-08 15:03:58 +02:00
parent 003a5dc92c
commit d153adc91b
2 changed files with 116 additions and 93 deletions

View file

@ -81,7 +81,7 @@ public class Grind {
@ZenMethod @ZenMethod
public static void removeRecipe(IIngredient output) { public static void removeRecipe(IIngredient output) {
if(output == null) { if(output == null) {
LogHelper.logError(String.format("Required parameters missing for %s Recipe.", Grind.name)); LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name));
return; return;
} }
@ -98,7 +98,7 @@ public class Grind {
if(!result.isEmpty()) { if(!result.isEmpty()) {
MineTweakerAPI.apply(new Remove(result)); MineTweakerAPI.apply(new Remove(result));
} else { } else {
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", Grind.name, output.toString())); LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", name, output.toString()));
} }
} }

View file

@ -3,6 +3,7 @@ package modtweaker2.mods.tconstruct.handlers;
import static modtweaker2.helpers.InputHelper.isABlock; import static modtweaker2.helpers.InputHelper.isABlock;
import static modtweaker2.helpers.InputHelper.toFluid; import static modtweaker2.helpers.InputHelper.toFluid;
import static modtweaker2.helpers.InputHelper.toFluids; import static modtweaker2.helpers.InputHelper.toFluids;
import static modtweaker2.helpers.InputHelper.toIItemStack;
import static modtweaker2.helpers.InputHelper.toILiquidStack; import static modtweaker2.helpers.InputHelper.toILiquidStack;
import static modtweaker2.helpers.InputHelper.toStack; import static modtweaker2.helpers.InputHelper.toStack;
import static modtweaker2.helpers.StackHelper.matches; import static modtweaker2.helpers.StackHelper.matches;
@ -10,6 +11,8 @@ import static modtweaker2.helpers.StackHelper.matches;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -18,8 +21,6 @@ import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IIngredient; import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack; import minetweaker.api.item.IItemStack;
import minetweaker.api.liquid.ILiquidStack; import minetweaker.api.liquid.ILiquidStack;
import minetweaker.api.minecraft.MineTweakerMC;
import minetweaker.api.oredict.IOreDictEntry;
import modtweaker2.helpers.InputHelper; import modtweaker2.helpers.InputHelper;
import modtweaker2.helpers.LogHelper; import modtweaker2.helpers.LogHelper;
import modtweaker2.mods.tconstruct.TConstructHelper; import modtweaker2.mods.tconstruct.TConstructHelper;
@ -27,12 +28,10 @@ import modtweaker2.utils.BaseListAddition;
import modtweaker2.utils.BaseListRemoval; import modtweaker2.utils.BaseListRemoval;
import modtweaker2.utils.BaseMapAddition; import modtweaker2.utils.BaseMapAddition;
import modtweaker2.utils.BaseMapRemoval; import modtweaker2.utils.BaseMapRemoval;
import modtweaker2.utils.BaseUndoable;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
import stanhebben.zenscript.annotations.Optional; import stanhebben.zenscript.annotations.Optional;
import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod; import stanhebben.zenscript.annotations.ZenMethod;
@ -42,6 +41,8 @@ import tconstruct.library.crafting.AlloyMix;
public class Smeltery { public class Smeltery {
public static final String nameFuel = "TConstruct Smeltery - Fuel"; public static final String nameFuel = "TConstruct Smeltery - Fuel";
public static final String nameMelting = "TConstruct Smeltery - Melting";
public static final String nameAlloy = "TConstruct Smeltery - Alloy";
/********************************************** TConstruct Alloy Recipes **********************************************/ /********************************************** TConstruct Alloy Recipes **********************************************/
@ -68,21 +69,28 @@ public class Smeltery {
// Removing a TConstruct Alloy recipe // Removing a TConstruct Alloy recipe
@ZenMethod @ZenMethod
public static void removeAlloy(ILiquidStack output) { public static void removeAlloy(IIngredient output) {
MineTweakerAPI.apply(new RemoveAlloy((toFluid(output)))); List<AlloyMix> recipes = new LinkedList<AlloyMix>();
for(AlloyMix r : TConstructHelper.alloys) {
if(r != null && matches(output, toILiquidStack(r.result))) {
recipes.add(r);
}
}
if(!recipes.isEmpty()) {
MineTweakerAPI.apply(new RemoveAlloy(recipes));
} else {
LogHelper.logError(String.format("No %s recipes found for %s. Command ignored!", nameAlloy, output.toString()));
}
} }
// Removes a recipe, apply is never the same for anything, so will always // Removes a recipe, apply is never the same for anything, so will always
// need to override it // need to override it
private static class RemoveAlloy extends BaseListRemoval<AlloyMix> { private static class RemoveAlloy extends BaseListRemoval<AlloyMix> {
public RemoveAlloy(FluidStack output) { public RemoveAlloy(List<AlloyMix> recipes) {
super("Smeltery - Alloy", TConstructHelper.alloys); super(nameAlloy, TConstructHelper.alloys, recipes);
for (AlloyMix r : TConstructHelper.alloys) {
if (r.result != null && output != null && r.result.getFluid() == output.getFluid()) {
recipes.add(r);
}
}
} }
@Override @Override
@ -95,117 +103,132 @@ public class Smeltery {
// Adding a TConstruct Melting recipe // Adding a TConstruct Melting recipe
@ZenMethod @ZenMethod
public static void addMelting(IItemStack input, ILiquidStack output, int temp, @Optional IItemStack block) { public static void addMelting(IIngredient input, ILiquidStack output, int temp, @Optional IItemStack block) {
if (block == null) List<MeltingRecipe> recipes = new LinkedList<MeltingRecipe>();
block = input;
if (isABlock(block)) { for(IItemStack in : input.getItems()) {
Block theBlock = Block.getBlockFromItem(toStack(block).getItem()); if(block == null && !isABlock(toStack(in))) {
int theMeta = toStack(block).getItemDamage(); LogHelper.logWarning(String.format("Item %s is not a block and no block renderer is provided for %s recipe. Input ignored!", in.toString(), nameMelting));
MineTweakerAPI.apply(new AddMelting(toStack(input), theBlock, theMeta, temp, toFluid(output))); } else {
} recipes.add(new MeltingRecipe(toStack(in), toFluid(output), temp, block == null ? toStack(in) : toStack(block)));
}
}
if(!recipes.isEmpty()) {
MineTweakerAPI.apply(new AddMelting(recipes));
} else {
LogHelper.logError(String.format("No %s recipes could be added for input %s.", nameMelting, input.toString()));
}
} }
@ZenMethod private static class AddMelting extends BaseListAddition<MeltingRecipe> {
public static void addMelting(IOreDictEntry input, ILiquidStack output, int temp, @Optional IItemStack block) {
for (ItemStack stack : OreDictionary.getOres(input.getName())) {
addMelting(MineTweakerMC.getIItemStack(stack), output, temp, block);
}
}
// Takes all the variables and saves them in place public AddMelting(List<MeltingRecipe> recipes) {
private static class AddMelting extends BaseUndoable { super(nameMelting, null, recipes);
private final ItemStack input;
private final Block block;
private final int meta;
private final int temp;
private final FluidStack output;
public AddMelting(ItemStack input, Block block, int meta, int temp, FluidStack output) {
super("Smeltery - Melting");
this.input = input;
this.block = block;
this.meta = meta;
this.temp = temp;
this.output = output;
} }
// Adds the Melting recipe
@Override @Override
public void apply() { public void apply() {
tconstruct.library.crafting.Smeltery.instance.addMelting(input, block, meta, temp, output); for(MeltingRecipe recipe : recipes) {
tconstruct.library.crafting.Smeltery.addMelting(recipe.input, recipe.getRendererBlock(), recipe.getRendererMeta(), recipe.temperature, recipe.fluid);
successful.add(recipe);
}
} }
// Removes the Melting recipe from the hashmaps
@Override @Override
public void undo() { public void undo() {
ItemMetaWrapper in = new ItemMetaWrapper(input); for(MeltingRecipe recipe : successful) {
TConstructHelper.smeltingList.remove(in); TConstructHelper.smeltingList.remove(recipe.meta);
TConstructHelper.temperatureList.remove(in); TConstructHelper.temperatureList.remove(recipe.meta);
TConstructHelper.renderIndex.remove(in); TConstructHelper.renderIndex.remove(recipe.meta);
} }
@Override
public String getRecipeInfo() {
return input.getDisplayName();
} }
@Override
public String getRecipeInfo(MeltingRecipe recipe) {
return InputHelper.getStackDescription(recipe.input);
}
} }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Removing a TConstruct Melting recipe // Removing a TConstruct Melting recipe
@ZenMethod @ZenMethod
public static void removeMelting(IItemStack input) { public static void removeMelting(IIngredient input) {
MineTweakerAPI.apply(new RemoveMelting((toStack(input)))); List<MeltingRecipe> recipes = new LinkedList<MeltingRecipe>();
for(ItemMetaWrapper meta : TConstructHelper.smeltingList.keySet()) {
ItemStack in = new ItemStack(meta.item, 1, meta.meta);
if(matches(input, toIItemStack(in))) {
recipes.add(new MeltingRecipe(
in,
TConstructHelper.smeltingList.get(meta),
TConstructHelper.temperatureList.get(meta),
TConstructHelper.renderIndex.get(meta)));
}
}
if(!recipes.isEmpty()) {
MineTweakerAPI.apply(new RemoveMelting(recipes));
} else {
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", nameMelting, input.toString()));
}
} }
@ZenMethod private static class RemoveMelting extends BaseListRemoval<MeltingRecipe> {
public static void removeMelting(IOreDictEntry input) {
for (ItemStack stack : OreDictionary.getOres(input.getName())) { public RemoveMelting(List<MeltingRecipe> recipes) {
removeMelting(MineTweakerMC.getIItemStack(stack)); super(nameMelting, null, recipes);
}
}
// Removes a recipe, apply is never the same for anything, so will always
// need to override it
private static class RemoveMelting extends BaseUndoable {
private final ItemStack input;
private FluidStack fluid;
private Integer temp;
private ItemStack renderer;
public RemoveMelting(ItemStack input) {
super("Smeltery - Melting");
this.input = input;
} }
// Gets the current values, and saves, them removes them from the
// hashmaps
@Override @Override
public void apply() { public void apply() {
ItemMetaWrapper in = new ItemMetaWrapper(input); for(MeltingRecipe recipe : recipes) {
fluid = TConstructHelper.smeltingList.get(in); TConstructHelper.smeltingList.remove(recipe.meta);
temp = TConstructHelper.temperatureList.get(in); TConstructHelper.temperatureList.remove(recipe.meta);
renderer = TConstructHelper.renderIndex.get(in); TConstructHelper.renderIndex.remove(recipe.meta);
TConstructHelper.smeltingList.remove(in);
TConstructHelper.temperatureList.remove(in); successful.add(recipe);
TConstructHelper.renderIndex.remove(in); }
} }
// Reads the Melting recipe @Override
@Override
public void undo() { public void undo() {
// tconstruct.library.crafting.Smeltery.instance.addMelting(input, for(MeltingRecipe recipe : successful) {
// Block.getBlockFromItem(renderer.getItem()), tconstruct.library.crafting.Smeltery.addMelting(recipe.input, recipe.getRendererBlock(), recipe.getRendererMeta(), recipe.temperature, recipe.fluid);
// renderer.getItemDamage(), temp, fluid); }
} }
@Override @Override
public String getRecipeInfo() { public String getRecipeInfo(MeltingRecipe recipe) {
return input.getDisplayName(); return InputHelper.getStackDescription(recipe.input);
} }
} }
protected static class MeltingRecipe {
public final ItemMetaWrapper meta;
public final ItemStack input;
public final FluidStack fluid;
public final Integer temperature;
public final ItemStack renderer;
protected MeltingRecipe(ItemStack input, FluidStack fluid, int temperature, ItemStack renderer) {
this.input = input;
this.fluid = fluid;
this.temperature = temperature;
this.renderer = renderer;
this.meta = new ItemMetaWrapper(input);
}
public Block getRendererBlock() {
return Block.getBlockFromItem(renderer.getItem());
}
public int getRendererMeta() {
return renderer.getItemDamage();
}
}
/********************************************** TConstruct Fuel Recipes **********************************************/ /********************************************** TConstruct Fuel Recipes **********************************************/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////