Files
NotEnoughItems/src/main/java/codechicken/nei/recipe/FurnaceRecipeHandler.java
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

140 lines
4.8 KiB
Java
Raw Normal View History

2014-04-29 10:54:20 +10:00
package codechicken.nei.recipe;
2023-09-25 00:34:42 +02:00
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;
2023-09-25 00:35:24 +02:00
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 {
2014-04-29 10:54:20 +10:00
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() {
2025-10-17 22:23:10 +03:00
return Collections.singletonList(ingred);
2014-04-29 10:54:20 +10:00
}
public PositionedStack getResult() {
return result;
}
public PositionedStack getOtherStack() {
return afuels.get((cycleticks / 48) % afuels.size()).stack;
}
2019-12-30 20:19:16 -08:00
final PositionedStack ingred;
final PositionedStack result;
2014-04-29 10:54:20 +10:00
}
2021-01-17 14:56:51 -08:00
public static class FuelPair {
2021-01-17 14:56:51 -08:00
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;
}
2021-03-28 12:01:40 -07:00
public static ArrayList<FuelPair> afuels;
2021-03-28 11:04:50 -07:00
2014-04-29 10:54:20 +10:00
@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
2021-01-17 12:03:33 -08:00
findFuelsOnce();
2014-04-29 10:54:20 +10:00
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
2026-08-10 06:55:40 -05:00
Map<ItemStack, ItemStack> recipes = FurnaceRecipes.smelting().getSmeltingList();
2014-04-29 10:54:20 +10:00
for (Entry<ItemStack, ItemStack> recipe : recipes.entrySet())
arecipes.add(new SmeltingPair(recipe.getKey(), recipe.getValue()));
} else super.loadCraftingRecipes(outputId, results);
2014-04-29 10:54:20 +10:00
}
@Override
public void loadCraftingRecipes(ItemStack result) {
2026-08-10 06:55:40 -05:00
Map<ItemStack, ItemStack> recipes = FurnaceRecipes.smelting().getSmeltingList();
2014-04-29 10:54:20 +10:00
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);
2014-04-29 10:54:20 +10:00
}
@Override
public void loadUsageRecipes(ItemStack ingredient) {
2026-08-10 06:55:40 -05:00
Map<ItemStack, ItemStack> recipes = FurnaceRecipes.smelting().getSmeltingList();
2014-04-29 10:54:20 +10:00
for (Entry<ItemStack, ItemStack> recipe : recipes.entrySet())
if (NEIServerUtils.areStacksSameTypeCrafting(recipe.getKey(), ingredient)) {
SmeltingPair arecipe = new SmeltingPair(recipe.getKey(), recipe.getValue());
2019-12-30 20:19:16 -08:00
arecipe.setIngredientPermutation(Collections.singletonList(arecipe.ingred), ingredient);
2014-04-29 10:54:20 +10:00
arecipes.add(arecipe);
}
}
2022-01-22 13:16:28 +09:00
@Override
public String specifyTransferRect() {
return "smelting";
}
2014-04-29 10:54:20 +10:00
@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";
}
}