Bugfixing in TConstruct Smeltery
This commit is contained in:
parent
003a5dc92c
commit
d153adc91b
2 changed files with 116 additions and 93 deletions
|
@ -81,7 +81,7 @@ public class Grind {
|
|||
@ZenMethod
|
||||
public static void removeRecipe(IIngredient output) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ public class Grind {
|
|||
if(!result.isEmpty()) {
|
||||
MineTweakerAPI.apply(new Remove(result));
|
||||
} 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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package modtweaker2.mods.tconstruct.handlers;
|
|||
import static modtweaker2.helpers.InputHelper.isABlock;
|
||||
import static modtweaker2.helpers.InputHelper.toFluid;
|
||||
import static modtweaker2.helpers.InputHelper.toFluids;
|
||||
import static modtweaker2.helpers.InputHelper.toIItemStack;
|
||||
import static modtweaker2.helpers.InputHelper.toILiquidStack;
|
||||
import static modtweaker2.helpers.InputHelper.toStack;
|
||||
import static modtweaker2.helpers.StackHelper.matches;
|
||||
|
@ -10,6 +11,8 @@ import static modtweaker2.helpers.StackHelper.matches;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
|
@ -18,8 +21,6 @@ import minetweaker.MineTweakerAPI;
|
|||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import modtweaker2.helpers.InputHelper;
|
||||
import modtweaker2.helpers.LogHelper;
|
||||
import modtweaker2.mods.tconstruct.TConstructHelper;
|
||||
|
@ -27,12 +28,10 @@ import modtweaker2.utils.BaseListAddition;
|
|||
import modtweaker2.utils.BaseListRemoval;
|
||||
import modtweaker2.utils.BaseMapAddition;
|
||||
import modtweaker2.utils.BaseMapRemoval;
|
||||
import modtweaker2.utils.BaseUndoable;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
@ -42,6 +41,8 @@ import tconstruct.library.crafting.AlloyMix;
|
|||
public class Smeltery {
|
||||
|
||||
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 **********************************************/
|
||||
|
||||
|
@ -68,21 +69,28 @@ public class Smeltery {
|
|||
|
||||
// Removing a TConstruct Alloy recipe
|
||||
@ZenMethod
|
||||
public static void removeAlloy(ILiquidStack output) {
|
||||
MineTweakerAPI.apply(new RemoveAlloy((toFluid(output))));
|
||||
public static void removeAlloy(IIngredient 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
|
||||
// need to override it
|
||||
private static class RemoveAlloy extends BaseListRemoval<AlloyMix> {
|
||||
public RemoveAlloy(FluidStack output) {
|
||||
super("Smeltery - Alloy", TConstructHelper.alloys);
|
||||
|
||||
for (AlloyMix r : TConstructHelper.alloys) {
|
||||
if (r.result != null && output != null && r.result.getFluid() == output.getFluid()) {
|
||||
recipes.add(r);
|
||||
}
|
||||
}
|
||||
public RemoveAlloy(List<AlloyMix> recipes) {
|
||||
super(nameAlloy, TConstructHelper.alloys, recipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -95,117 +103,132 @@ public class Smeltery {
|
|||
|
||||
// Adding a TConstruct Melting recipe
|
||||
@ZenMethod
|
||||
public static void addMelting(IItemStack input, ILiquidStack output, int temp, @Optional IItemStack block) {
|
||||
if (block == null)
|
||||
block = input;
|
||||
if (isABlock(block)) {
|
||||
Block theBlock = Block.getBlockFromItem(toStack(block).getItem());
|
||||
int theMeta = toStack(block).getItemDamage();
|
||||
MineTweakerAPI.apply(new AddMelting(toStack(input), theBlock, theMeta, temp, toFluid(output)));
|
||||
}
|
||||
public static void addMelting(IIngredient input, ILiquidStack output, int temp, @Optional IItemStack block) {
|
||||
List<MeltingRecipe> recipes = new LinkedList<MeltingRecipe>();
|
||||
|
||||
for(IItemStack in : input.getItems()) {
|
||||
if(block == null && !isABlock(toStack(in))) {
|
||||
LogHelper.logWarning(String.format("Item %s is not a block and no block renderer is provided for %s recipe. Input ignored!", in.toString(), nameMelting));
|
||||
} 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
|
||||
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);
|
||||
}
|
||||
}
|
||||
private static class AddMelting extends BaseListAddition<MeltingRecipe> {
|
||||
|
||||
// Takes all the variables and saves them in place
|
||||
private static class AddMelting extends BaseUndoable {
|
||||
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;
|
||||
public AddMelting(List<MeltingRecipe> recipes) {
|
||||
super(nameMelting, null, recipes);
|
||||
}
|
||||
|
||||
// Adds the Melting recipe
|
||||
@Override
|
||||
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
|
||||
public void undo() {
|
||||
ItemMetaWrapper in = new ItemMetaWrapper(input);
|
||||
TConstructHelper.smeltingList.remove(in);
|
||||
TConstructHelper.temperatureList.remove(in);
|
||||
TConstructHelper.renderIndex.remove(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo() {
|
||||
return input.getDisplayName();
|
||||
for(MeltingRecipe recipe : successful) {
|
||||
TConstructHelper.smeltingList.remove(recipe.meta);
|
||||
TConstructHelper.temperatureList.remove(recipe.meta);
|
||||
TConstructHelper.renderIndex.remove(recipe.meta);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo(MeltingRecipe recipe) {
|
||||
return InputHelper.getStackDescription(recipe.input);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Removing a TConstruct Melting recipe
|
||||
@ZenMethod
|
||||
public static void removeMelting(IItemStack input) {
|
||||
MineTweakerAPI.apply(new RemoveMelting((toStack(input))));
|
||||
public static void removeMelting(IIngredient 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
|
||||
public static void removeMelting(IOreDictEntry input) {
|
||||
for (ItemStack stack : OreDictionary.getOres(input.getName())) {
|
||||
removeMelting(MineTweakerMC.getIItemStack(stack));
|
||||
}
|
||||
}
|
||||
private static class RemoveMelting extends BaseListRemoval<MeltingRecipe> {
|
||||
|
||||
// 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;
|
||||
public RemoveMelting(List<MeltingRecipe> recipes) {
|
||||
super(nameMelting, null, recipes);
|
||||
}
|
||||
|
||||
// Gets the current values, and saves, them removes them from the
|
||||
// hashmaps
|
||||
@Override
|
||||
public void apply() {
|
||||
ItemMetaWrapper in = new ItemMetaWrapper(input);
|
||||
fluid = TConstructHelper.smeltingList.get(in);
|
||||
temp = TConstructHelper.temperatureList.get(in);
|
||||
renderer = TConstructHelper.renderIndex.get(in);
|
||||
TConstructHelper.smeltingList.remove(in);
|
||||
TConstructHelper.temperatureList.remove(in);
|
||||
TConstructHelper.renderIndex.remove(in);
|
||||
for(MeltingRecipe recipe : recipes) {
|
||||
TConstructHelper.smeltingList.remove(recipe.meta);
|
||||
TConstructHelper.temperatureList.remove(recipe.meta);
|
||||
TConstructHelper.renderIndex.remove(recipe.meta);
|
||||
|
||||
successful.add(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
// Reads the Melting recipe
|
||||
@Override
|
||||
@Override
|
||||
public void undo() {
|
||||
// tconstruct.library.crafting.Smeltery.instance.addMelting(input,
|
||||
// Block.getBlockFromItem(renderer.getItem()),
|
||||
// renderer.getItemDamage(), temp, fluid);
|
||||
for(MeltingRecipe recipe : successful) {
|
||||
tconstruct.library.crafting.Smeltery.addMelting(recipe.input, recipe.getRendererBlock(), recipe.getRendererMeta(), recipe.temperature, recipe.fluid);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo() {
|
||||
return input.getDisplayName();
|
||||
public String getRecipeInfo(MeltingRecipe recipe) {
|
||||
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 **********************************************/
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in a new issue