mirror of
https://github.com/GTNewHorizons/ModTweaker.git
synced 2026-11-24 22:24:30 +00:00
ModTweaker2 Rework
- Revised base classes for IUndoableAction - Reordered lots of code, so stuck actions should be less frequent - Added wildcard support to many "remove" methods - Started working on exist & duplicate checks
This commit is contained in:
1 parent
f5034b04d8
commit
da33cc6fab
112 files changed
+4596
-3522
No files matched your search
@@ -1,10 +1,21 @@
|
||||
package modtweaker2.mods.fsp.handlers;
|
||||
|
||||
import static modtweaker2.helpers.InputHelper.toIItemStack;
|
||||
import static modtweaker2.helpers.InputHelper.toStack;
|
||||
import static modtweaker2.helpers.StackHelper.matches;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import modtweaker2.helpers.InputHelper;
|
||||
import modtweaker2.helpers.LogHelper;
|
||||
import modtweaker2.utils.BaseMapAddition;
|
||||
import modtweaker2.utils.BaseMapRemoval;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import org.apache.commons.lang3.tuple.MutablePair;
|
||||
@@ -15,41 +26,51 @@ import flaxbeard.steamcraft.api.SteamcraftRegistry;
|
||||
|
||||
@ZenClass("mods.fsp.Furnace")
|
||||
public class Furnace {
|
||||
|
||||
public static final String name = "FSP Furnace (Steamed Foods)";
|
||||
|
||||
@ZenMethod
|
||||
public static void addSteamFood(IItemStack input, IItemStack output) {
|
||||
MineTweakerAPI.apply(new AddSteamFood(toStack(input), MutablePair.of(toStack(input).getItem(), toStack(input).getItemDamage()), MutablePair.of(toStack(output).getItem(), toStack(output).getItemDamage())));
|
||||
}
|
||||
|
||||
private static class AddSteamFood extends BaseMapAddition {
|
||||
private final ItemStack stack;
|
||||
|
||||
public AddSteamFood(ItemStack stack, MutablePair key, MutablePair recipe) {
|
||||
super("FSP Furnace - Steam Food", SteamcraftRegistry.steamedFoods, key, recipe);
|
||||
this.stack = stack;
|
||||
private static class AddSteamFood extends BaseMapAddition<MutablePair<Item, Integer>, MutablePair<Item, Integer>> {
|
||||
public AddSteamFood(ItemStack stack, MutablePair<Item, Integer> key, MutablePair<Item, Integer> recipe) {
|
||||
super(Furnace.name, SteamcraftRegistry.steamedFoods);
|
||||
recipes.put(key, recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo() {
|
||||
return stack.getDisplayName();
|
||||
public String getRecipeInfo(Entry<MutablePair<Item, Integer>, MutablePair<Item, Integer>> recipe) {
|
||||
return InputHelper.getStackDescription(new ItemStack(recipe.getKey().left, 1, recipe.getKey().right));
|
||||
}
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeSteamFood(IItemStack input) {
|
||||
MineTweakerAPI.apply(new RemoveSteamFood(toStack(input), MutablePair.of(toStack(input).getItem(), toStack(input).getItemDamage())));
|
||||
public static void removeSteamFood(IIngredient input) {
|
||||
Map<MutablePair<Item, Integer>, MutablePair<Item, Integer>> recipes = new HashMap<MutablePair<Item, Integer>, MutablePair<Item, Integer>>();
|
||||
|
||||
for(Entry<MutablePair<Item, Integer>, MutablePair<Item, Integer>> recipe : SteamcraftRegistry.steamedFoods.entrySet()) {
|
||||
if(matches(input, toIItemStack(new ItemStack(recipe.getKey().left, 1, recipe.getKey().right)))) {
|
||||
recipes.put(recipe.getKey(), recipe.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
if(!recipes.isEmpty()) {
|
||||
MineTweakerAPI.apply(new RemoveSteamFood(recipes));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", Furnace.name, input.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveSteamFood extends BaseMapRemoval {
|
||||
private final ItemStack stack;
|
||||
|
||||
public RemoveSteamFood(ItemStack stack, MutablePair key) {
|
||||
super("FSP Furnace - Steam Food", SteamcraftRegistry.steamedFoods, key);
|
||||
this.stack = stack;
|
||||
private static class RemoveSteamFood extends BaseMapRemoval<MutablePair<Item, Integer>, MutablePair<Item, Integer>> {
|
||||
public RemoveSteamFood(Map<MutablePair<Item, Integer>, MutablePair<Item, Integer>> recipes) {
|
||||
super(Furnace.name, SteamcraftRegistry.steamedFoods, recipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo() {
|
||||
return stack.getDisplayName();
|
||||
public String getRecipeInfo(Entry<MutablePair<Item, Integer>, MutablePair<Item, Integer>> recipe) {
|
||||
return InputHelper.getStackDescription(new ItemStack(recipe.getKey().left, 1, recipe.getKey().right));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user