mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-13 17:04:03 +00:00
141 lines
4.8 KiB
Java
141 lines
4.8 KiB
Java
package codechicken.nei.recipe;
|
|
|
|
import java.awt.Rectangle;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map.Entry;
|
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
import net.minecraft.client.gui.inventory.GuiFurnace;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.item.crafting.FurnaceRecipes;
|
|
|
|
import codechicken.nei.NEIClientUtils;
|
|
import codechicken.nei.NEIServerUtils;
|
|
import codechicken.nei.PositionedStack;
|
|
|
|
public class FurnaceRecipeHandler extends TemplateRecipeHandler {
|
|
|
|
public class SmeltingPair extends CachedRecipe {
|
|
|
|
public SmeltingPair(ItemStack ingred, ItemStack result) {
|
|
ingred.stackSize = 1;
|
|
this.ingred = new PositionedStack(ingred, 51, 6);
|
|
this.result = new PositionedStack(result, 111, 24);
|
|
}
|
|
|
|
public List<PositionedStack> getIngredients() {
|
|
return Collections.singletonList(ingred);
|
|
}
|
|
|
|
public PositionedStack getResult() {
|
|
return result;
|
|
}
|
|
|
|
public PositionedStack getOtherStack() {
|
|
return afuels.get((cycleticks / 48) % afuels.size()).stack;
|
|
}
|
|
|
|
final PositionedStack ingred;
|
|
final PositionedStack result;
|
|
}
|
|
|
|
public static class FuelPair {
|
|
|
|
public FuelPair(ItemStack ingred, int burnTime) {
|
|
this.stack = new PositionedStack(ingred, 51, 42, false);
|
|
this.burnTime = burnTime;
|
|
}
|
|
|
|
public final PositionedStack stack;
|
|
public final int burnTime;
|
|
}
|
|
|
|
public static ArrayList<FuelPair> afuels;
|
|
|
|
@Override
|
|
public void loadTransferRects() {
|
|
transferRects.add(new RecipeTransferRect(new Rectangle(50, 23, 18, 18), "fuel"));
|
|
transferRects.add(new RecipeTransferRect(new Rectangle(74, 23, 24, 18), "smelting"));
|
|
}
|
|
|
|
@Override
|
|
public Class<? extends GuiContainer> getGuiClass() {
|
|
return GuiFurnace.class;
|
|
}
|
|
|
|
@Override
|
|
public String getRecipeName() {
|
|
return NEIClientUtils.translate("recipe.furnace");
|
|
}
|
|
|
|
@Override
|
|
public TemplateRecipeHandler newInstance() {
|
|
// Use the non parallel version since we might already be using the forkJoinPool and might have no threads
|
|
// available
|
|
// This will ideally have been pre-cached elsewhere and will be a NOOP
|
|
findFuelsOnce();
|
|
return super.newInstance();
|
|
}
|
|
|
|
@Override
|
|
public void loadCraftingRecipes(String outputId, Object... results) {
|
|
if (outputId.equals("smelting") && getClass() == FurnaceRecipeHandler.class) { // don't want subclasses getting
|
|
// a hold of this
|
|
Map<ItemStack, ItemStack> recipes = FurnaceRecipes.smelting().getSmeltingList();
|
|
for (Entry<ItemStack, ItemStack> recipe : recipes.entrySet())
|
|
arecipes.add(new SmeltingPair(recipe.getKey(), recipe.getValue()));
|
|
} else super.loadCraftingRecipes(outputId, results);
|
|
}
|
|
|
|
@Override
|
|
public void loadCraftingRecipes(ItemStack result) {
|
|
Map<ItemStack, ItemStack> recipes = FurnaceRecipes.smelting().getSmeltingList();
|
|
for (Entry<ItemStack, ItemStack> recipe : recipes.entrySet())
|
|
if (NEIServerUtils.areStacksSameType(recipe.getValue(), result))
|
|
arecipes.add(new SmeltingPair(recipe.getKey(), recipe.getValue()));
|
|
}
|
|
|
|
@Override
|
|
public void loadUsageRecipes(String inputId, Object... ingredients) {
|
|
if (inputId.equals("fuel") && getClass() == FurnaceRecipeHandler.class) // don't want subclasses getting a hold
|
|
// of this
|
|
loadCraftingRecipes("smelting");
|
|
else super.loadUsageRecipes(inputId, ingredients);
|
|
}
|
|
|
|
@Override
|
|
public void loadUsageRecipes(ItemStack ingredient) {
|
|
Map<ItemStack, ItemStack> recipes = FurnaceRecipes.smelting().getSmeltingList();
|
|
for (Entry<ItemStack, ItemStack> recipe : recipes.entrySet())
|
|
if (NEIServerUtils.areStacksSameTypeCrafting(recipe.getKey(), ingredient)) {
|
|
SmeltingPair arecipe = new SmeltingPair(recipe.getKey(), recipe.getValue());
|
|
arecipe.setIngredientPermutation(Collections.singletonList(arecipe.ingred), ingredient);
|
|
arecipes.add(arecipe);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public String specifyTransferRect() {
|
|
return "smelting";
|
|
}
|
|
|
|
@Override
|
|
public String getGuiTexture() {
|
|
return "textures/gui/container/furnace.png";
|
|
}
|
|
|
|
@Override
|
|
public void drawExtras(int recipe) {
|
|
drawProgressBar(51, 25, 176, 0, 14, 14, 48, 7);
|
|
drawProgressBar(74, 23, 176, 14, 24, 16, 48, 0);
|
|
}
|
|
|
|
@Override
|
|
public String getOverlayIdentifier() {
|
|
return "smelting";
|
|
}
|
|
}
|