Kiln has NEI support.
parent
28bc989fc8
commit
a83cbdbe2b
|
@ -0,0 +1,315 @@
|
|||
package net.einsteinsci.betterbeginnings.nei;
|
||||
|
||||
import codechicken.nei.ItemList;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.api.IRecipeOverlayRenderer;
|
||||
import codechicken.nei.recipe.GuiRecipe;
|
||||
import codechicken.nei.recipe.ICraftingHandler;
|
||||
import codechicken.nei.recipe.IUsageHandler;
|
||||
import codechicken.nei.recipe.TemplateRecipeHandler;
|
||||
import net.einsteinsci.betterbeginnings.ModMain;
|
||||
import net.einsteinsci.betterbeginnings.gui.GuiKiln;
|
||||
import net.einsteinsci.betterbeginnings.register.RegisterBlocks;
|
||||
import net.einsteinsci.betterbeginnings.register.recipe.KilnRecipes;
|
||||
import net.einsteinsci.betterbeginnings.tileentity.TileEntityKiln;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDoor;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntityFurnace;
|
||||
import net.minecraftforge.fml.common.Optional;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
// region interface-only
|
||||
/*
|
||||
// Can't use TemplateRecipeHandler as it's not an interface :`(
|
||||
@Optional.InterfaceList( {
|
||||
@Optional.Interface(iface = "codechicken.nei.recipe.ICraftingHandler", modid = "NotEnoughItems"),
|
||||
@Optional.Interface(iface = "codechicken.nei.recipe.IUsageHandler", modid = "NotEnoughItems") }
|
||||
)
|
||||
public class KilnRecipeHandler implements ICraftingHandler, IUsageHandler
|
||||
{
|
||||
@Override
|
||||
public ICraftingHandler getRecipeHandler(String outputId, Object... results)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IUsageHandler getUsageHandler(String inputId, Object... ingredients)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numRecipes()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground(int recipe)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawForeground(int recipe)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PositionedStack> getIngredientStacks(int recipe)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PositionedStack> getOtherStacks(int recipetype)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PositionedStack getResultStack(int recipe)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasOverlay(GuiContainer gui, Container container, int recipe)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRecipeOverlayRenderer getOverlayRenderer(GuiContainer gui, int recipe)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IOverlayHandler getOverlayHandler(GuiContainer gui, int recipe)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int recipiesPerPage()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> handleTooltip(GuiRecipe gui, List<String> currenttip, int recipe)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> handleItemTooltip(GuiRecipe gui, ItemStack stack, List<String> currenttip, int recipe)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyTyped(GuiRecipe gui, char keyChar, int keyCode, int recipe)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(GuiRecipe gui, int button, int recipe)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} */
|
||||
// endregion
|
||||
|
||||
public class KilnRecipeHandler extends TemplateRecipeHandler
|
||||
{
|
||||
public class KilnCachedRecipe extends CachedRecipe
|
||||
{
|
||||
PositionedStack input;
|
||||
PositionedStack output;
|
||||
|
||||
public KilnCachedRecipe(ItemStack _input, ItemStack _output)
|
||||
{
|
||||
input = new PositionedStack(_input, 51, 6);
|
||||
output = new PositionedStack(_output, 111, 24);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PositionedStack> getIngredients()
|
||||
{
|
||||
return getCycledIngredients(cycleticks / 48, Collections.singletonList(input));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PositionedStack getOtherStack() {
|
||||
return afuels.get((cycleticks / 48) % afuels.size()).stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PositionedStack getResult()
|
||||
{
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
public static class FuelPair
|
||||
{
|
||||
public FuelPair(ItemStack ingred, int burnTime) {
|
||||
this.stack = new PositionedStack(ingred, 51, 42, false);
|
||||
this.burnTime = burnTime;
|
||||
}
|
||||
|
||||
public PositionedStack stack;
|
||||
public int burnTime;
|
||||
}
|
||||
|
||||
public static ArrayList<FuelPair> afuels;
|
||||
public static HashSet<Block> efuels;
|
||||
|
||||
@Override
|
||||
public TemplateRecipeHandler newInstance()
|
||||
{
|
||||
if (afuels == null || afuels.isEmpty())
|
||||
{
|
||||
findFuels();
|
||||
}
|
||||
return super.newInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends GuiContainer> getGuiClass()
|
||||
{
|
||||
return GuiKiln.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGuiTexture()
|
||||
{
|
||||
// vanilla
|
||||
return "minecraft:textures/gui/container/furnace.png";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeName()
|
||||
{
|
||||
return I18n.format("container.kiln");
|
||||
}
|
||||
|
||||
public String getRecipeID()
|
||||
{
|
||||
return ModMain.MODID + ":" + RegisterBlocks.kiln.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadCraftingRecipes(String outputId, Object... results)
|
||||
{
|
||||
if (outputId.equals(getRecipeID()))
|
||||
{
|
||||
for (Object obj : KilnRecipes.smelting().getSmeltingList().entrySet())
|
||||
{
|
||||
Map.Entry entry = (Map.Entry)obj;
|
||||
|
||||
ItemStack inp = (ItemStack)entry.getKey();
|
||||
ItemStack outp = (ItemStack)entry.getValue();
|
||||
|
||||
arecipes.add(new KilnCachedRecipe(inp, outp));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
super.loadCraftingRecipes(outputId, results);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadCraftingRecipes(ItemStack result)
|
||||
{
|
||||
for (Object obj : KilnRecipes.smelting().getSmeltingList().entrySet())
|
||||
{
|
||||
Map.Entry entry = (Map.Entry)obj;
|
||||
|
||||
ItemStack inp = (ItemStack)entry.getKey();
|
||||
ItemStack outp = (ItemStack)entry.getValue();
|
||||
|
||||
if (outp.getIsItemStackEqual(result))
|
||||
{
|
||||
arecipes.add(new KilnCachedRecipe(inp, outp));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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 "kiln";
|
||||
}
|
||||
|
||||
private static Set<Item> excludedFuels()
|
||||
{
|
||||
Set<Item> efuels = new HashSet<>();
|
||||
efuels.add(Item.getItemFromBlock(Blocks.brown_mushroom));
|
||||
efuels.add(Item.getItemFromBlock(Blocks.red_mushroom));
|
||||
efuels.add(Item.getItemFromBlock(Blocks.standing_sign));
|
||||
efuels.add(Item.getItemFromBlock(Blocks.wall_sign));
|
||||
efuels.add(Item.getItemFromBlock(Blocks.trapped_chest));
|
||||
return efuels;
|
||||
}
|
||||
|
||||
private static void findFuels()
|
||||
{
|
||||
afuels = new ArrayList<>();
|
||||
Set<Item> efuels = excludedFuels();
|
||||
|
||||
for (ItemStack item : ItemList.items)
|
||||
{
|
||||
Block block = Block.getBlockFromItem(item.getItem());
|
||||
if (block instanceof BlockDoor)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (efuels.contains(item.getItem()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int burnTime = TileEntityKiln.getItemBurnTime(item);
|
||||
if (burnTime > 0)
|
||||
{
|
||||
afuels.add(new FuelPair(item.copy(), burnTime));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,6 +14,10 @@ public class NEIConfig implements IConfigureNEI
|
|||
@Override
|
||||
public void loadConfig()
|
||||
{
|
||||
KilnRecipeHandler kilnRecipeHandler = new KilnRecipeHandler();
|
||||
|
||||
API.registerRecipeHandler(kilnRecipeHandler);
|
||||
|
||||
API.hideItem(new ItemStack(RegisterBlocks.kilnLit));
|
||||
API.hideItem(new ItemStack(RegisterBlocks.brickOvenLit));
|
||||
API.hideItem(new ItemStack(RegisterBlocks.smelterLit));
|
||||
|
|
|
@ -12,8 +12,8 @@ public class KilnRecipes
|
|||
{
|
||||
private static final KilnRecipes SMELTINGBASE = new KilnRecipes();
|
||||
|
||||
private Map smeltingList = new HashMap();
|
||||
private Map experienceList = new HashMap();
|
||||
private Map<ItemStack, ItemStack> smeltingList = new HashMap<>();
|
||||
private Map<ItemStack, Float> experienceList = new HashMap<>();
|
||||
|
||||
private KilnRecipes()
|
||||
{
|
||||
|
@ -61,8 +61,8 @@ public class KilnRecipes
|
|||
|
||||
public ItemStack getSmeltingResult(ItemStack stack)
|
||||
{
|
||||
Iterator iterator = smeltingList.entrySet().iterator();
|
||||
Entry entry;
|
||||
Iterator<Entry<ItemStack, ItemStack> > iterator = smeltingList.entrySet().iterator();
|
||||
Entry<ItemStack, ItemStack> entry;
|
||||
|
||||
do
|
||||
{
|
||||
|
@ -71,10 +71,15 @@ public class KilnRecipes
|
|||
return null;
|
||||
}
|
||||
|
||||
entry = (Entry)iterator.next();
|
||||
} while (!canBeSmelted(stack, (ItemStack)entry.getKey()));
|
||||
entry = iterator.next();
|
||||
} while (!canBeSmelted(stack, entry.getKey()));
|
||||
|
||||
return (ItemStack)entry.getValue();
|
||||
return entry.getValue();
|
||||
}
|
||||
|
||||
public Map getSmeltingList()
|
||||
{
|
||||
return smeltingList;
|
||||
}
|
||||
|
||||
private boolean canBeSmelted(ItemStack stack, ItemStack stack2)
|
||||
|
@ -86,8 +91,8 @@ public class KilnRecipes
|
|||
|
||||
public float giveExperience(ItemStack stack)
|
||||
{
|
||||
Iterator iterator = experienceList.entrySet().iterator();
|
||||
Entry entry;
|
||||
Iterator<Entry<ItemStack, Float> > iterator = experienceList.entrySet().iterator();
|
||||
Entry<ItemStack, Float> entry;
|
||||
|
||||
do
|
||||
{
|
||||
|
@ -96,14 +101,14 @@ public class KilnRecipes
|
|||
return 0.0f;
|
||||
}
|
||||
|
||||
entry = (Entry)iterator.next();
|
||||
} while (!canBeSmelted(stack, (ItemStack)entry.getKey()));
|
||||
entry = iterator.next();
|
||||
} while (!canBeSmelted(stack, entry.getKey()));
|
||||
|
||||
if (stack.getItem().getSmeltingExperience(stack) != -1)
|
||||
{
|
||||
return stack.getItem().getSmeltingExperience(stack);
|
||||
}
|
||||
|
||||
return ((Float)entry.getValue()).floatValue();
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue