Re-add and update NEI plugin to work again

This commit is contained in:
Ben Spiers 2013-08-10 20:52:59 +01:00
parent 9fae571278
commit 2389d3d864
10 changed files with 969 additions and 0 deletions

View file

@ -0,0 +1,139 @@
package mekanism.nei;
import java.awt.Rectangle;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import net.minecraft.item.ItemStack;
import org.lwjgl.opengl.GL11;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.TemplateRecipeHandler;
import static codechicken.core.gui.GuiDraw.*;
public abstract class AdvancedMachineRecipeHandler extends TemplateRecipeHandler
{
int ticksPassed;
public abstract String getRecipeId();
public abstract ItemStack getFuelStack();
public abstract Set<Entry<ItemStack, ItemStack>> getRecipes();
@Override
public void drawBackground(int i)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
changeTexture(getGuiTexture());
drawTexturedModalRect(12, 0, 28, 5, 144, 68);
}
@Override
public void drawExtras(int i)
{
float f = ticksPassed >= 40 ? (ticksPassed - 40) % 20 / 20.0F : 0.0F;
drawProgressBar(63, 34, 176 + 26, 0, 24, 7, f, 0);
f = ticksPassed >= 20 && ticksPassed < 40 ? (ticksPassed - 20) % 20 / 20.0F : 1.0F;
if(ticksPassed < 20) f = 0.0F;
drawProgressBar(45, 32, 176 + 26, 7, 5, 12, f, 3);
f = ticksPassed <= 20 ? ticksPassed / 20.0F : 1.0F;
drawProgressBar(149, 12, 176 + 26, 19, 4, 52, f, 3);
}
@Override
public void onUpdate()
{
super.onUpdate();
ticksPassed++;
}
@Override
public void loadTransferRects()
{
transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(63, 34, 24, 7), getRecipeId(), new Object[0]));
}
@Override
public void loadCraftingRecipes(String outputId, Object... results)
{
if(outputId.equals(getRecipeId()))
{
for(Map.Entry irecipe : getRecipes())
{
arecipes.add(new CachedIORecipe(irecipe, getFuelStack()));
}
}
else {
super.loadCraftingRecipes(outputId, results);
}
}
@Override
public void loadCraftingRecipes(ItemStack result)
{
for(Map.Entry irecipe : getRecipes())
{
if(NEIServerUtils.areStacksSameTypeCrafting((ItemStack)irecipe.getValue(), result))
{
arecipes.add(new CachedIORecipe(irecipe, getFuelStack()));
}
}
}
@Override
public void loadUsageRecipes(ItemStack ingredient)
{
for(Map.Entry irecipe : getRecipes())
{
if(NEIServerUtils.areStacksSameTypeCrafting((ItemStack)irecipe.getKey(), ingredient))
{
arecipes.add(new CachedIORecipe(irecipe, getFuelStack()));
}
}
}
public class CachedIORecipe extends TemplateRecipeHandler.CachedRecipe
{
public PositionedStack inputStack;
public PositionedStack outputStack;
public PositionedStack fuelStack;
@Override
public PositionedStack getIngredient()
{
return inputStack;
}
@Override
public PositionedStack getResult()
{
return outputStack;
}
@Override
public PositionedStack getOtherStack()
{
return fuelStack;
}
public CachedIORecipe(ItemStack input, ItemStack output, ItemStack fuel)
{
super();
inputStack = new PositionedStack(input, 40, 12);
outputStack = new PositionedStack(output, 100, 30);
fuelStack = new PositionedStack(fuel, 40, 48);
}
public CachedIORecipe(Map.Entry recipe, ItemStack fuel)
{
this((ItemStack)recipe.getKey(), (ItemStack)recipe.getValue(), fuel);
}
}
}

View file

@ -0,0 +1,54 @@
package mekanism.nei;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import mekanism.client.GuiCombiner;
import mekanism.common.RecipeHandler.Recipe;
public class CombinerRecipeHandler extends AdvancedMachineRecipeHandler
{
@Override
public String getRecipeName()
{
return "Combiner";
}
@Override
public String getRecipeId()
{
return "mekanism.combiner";
}
@Override
public String getOverlayIdentifier()
{
return "combiner";
}
@Override
public Set getRecipes()
{
return Recipe.COMBINER.get().entrySet();
}
@Override
public String getGuiTexture()
{
return "mekanism:gui/GuiCombiner.png";
}
@Override
public ItemStack getFuelStack()
{
return new ItemStack(Block.cobblestone);
}
@Override
public Class getGuiClass()
{
return GuiCombiner.class;
}
}

View file

@ -0,0 +1,45 @@
package mekanism.nei;
import java.util.Set;
import mekanism.client.GuiCrusher;
import mekanism.common.RecipeHandler.Recipe;
public class CrusherRecipeHandler extends MachineRecipeHandler
{
@Override
public String getRecipeName()
{
return "Crusher";
}
@Override
public String getRecipeId()
{
return "mekanism.crusher";
}
@Override
public String getOverlayIdentifier()
{
return "crusher";
}
@Override
public Set getRecipes()
{
return Recipe.CRUSHER.get().entrySet();
}
@Override
public String getGuiTexture()
{
return "mekanism:gui/GuiCrusher.png";
}
@Override
public Class getGuiClass()
{
return GuiCrusher.class;
}
}

View file

@ -0,0 +1,45 @@
package mekanism.nei;
import java.util.Set;
import mekanism.client.GuiEnrichmentChamber;
import mekanism.common.RecipeHandler.Recipe;
public class EnrichmentChamberRecipeHandler extends MachineRecipeHandler
{
@Override
public String getRecipeName()
{
return "Enrichment Chamber";
}
@Override
public String getRecipeId()
{
return "mekanism.chamber";
}
@Override
public String getOverlayIdentifier()
{
return "chamber";
}
@Override
public Set getRecipes()
{
return Recipe.ENRICHMENT_CHAMBER.get().entrySet();
}
@Override
public String getGuiTexture()
{
return "mekanism:gui/GuiChamber.png";
}
@Override
public Class getGuiClass()
{
return GuiEnrichmentChamber.class;
}
}

View file

@ -0,0 +1,125 @@
package mekanism.nei;
import java.awt.Rectangle;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import net.minecraft.item.ItemStack;
import org.lwjgl.opengl.GL11;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.forge.GuiContainerManager;
import codechicken.nei.recipe.TemplateRecipeHandler;
import static codechicken.core.gui.GuiDraw.*;
public abstract class MachineRecipeHandler extends TemplateRecipeHandler
{
int ticksPassed;
public abstract String getRecipeId();
public abstract Set<Entry<ItemStack, ItemStack>> getRecipes();
@Override
public void drawBackground(int i)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
changeTexture(getGuiTexture());
drawTexturedModalRect(12, 0, 28, 5, 144, 68);
}
@Override
public void drawExtras(int i)
{
float f = ticksPassed >= 20 ? (ticksPassed - 20) % 20 / 20.0F : 0.0F;
drawProgressBar(63, 34, 176 + 26, 0, 24, 7, f, 0);
f = ticksPassed <= 20 ? ticksPassed / 20.0F : 1.0F;
drawProgressBar(149, 12, 176 + 26, 7, 4, 52, f, 3);
}
@Override
public void onUpdate()
{
super.onUpdate();
ticksPassed++;
}
@Override
public void loadTransferRects()
{
transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(63, 34, 24, 7), getRecipeId(), new Object[0]));
}
@Override
public void loadCraftingRecipes(String outputId, Object... results)
{
if(outputId.equals(getRecipeId()))
{
for(Map.Entry irecipe : getRecipes())
{
arecipes.add(new CachedIORecipe(irecipe));
}
}
else {
super.loadCraftingRecipes(outputId, results);
}
}
@Override
public void loadCraftingRecipes(ItemStack result)
{
for(Map.Entry irecipe : getRecipes())
{
if(NEIServerUtils.areStacksSameTypeCrafting((ItemStack)irecipe.getValue(), result))
{
arecipes.add(new CachedIORecipe(irecipe));
}
}
}
@Override
public void loadUsageRecipes(ItemStack ingredient)
{
for(Map.Entry irecipe : getRecipes())
{
if(NEIServerUtils.areStacksSameTypeCrafting((ItemStack)irecipe.getKey(), ingredient))
{
arecipes.add(new CachedIORecipe(irecipe));
}
}
}
public class CachedIORecipe extends TemplateRecipeHandler.CachedRecipe
{
public PositionedStack input;
public PositionedStack output;
@Override
public PositionedStack getIngredient()
{
return input;
}
@Override
public PositionedStack getResult()
{
return output;
}
public CachedIORecipe(ItemStack itemstack, ItemStack itemstack1)
{
super();
input = new PositionedStack(itemstack, 40, 12);
output = new PositionedStack(itemstack1, 100, 30);
}
public CachedIORecipe(Map.Entry recipe)
{
this((ItemStack)recipe.getKey(), (ItemStack)recipe.getValue());
}
}
}

View file

@ -0,0 +1,193 @@
package mekanism.nei;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import mekanism.api.IEnergizedItem;
import mekanism.common.IEnergyCube;
import mekanism.common.IFactory;
import mekanism.common.MekanismRecipe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.ShapedRecipeHandler;
public class MekanismRecipeHandler extends ShapedRecipeHandler
{
@Override
public String getRecipeName()
{
return "Shaped Mekanism Crafting";
}
@Override
public void loadCraftingRecipes(String outputId, Object... results)
{
if(outputId.equals("crafting") && getClass() == MekanismRecipeHandler.class)
{
List<IRecipe> allrecipes = CraftingManager.getInstance().getRecipeList();
for(IRecipe irecipe : allrecipes)
{
if(irecipe instanceof MekanismRecipe)
{
MekanismRecipe energyRecipe = (MekanismRecipe)irecipe;
CachedEnergyRecipe recipe = new CachedEnergyRecipe(energyRecipe.width, energyRecipe.height, energyRecipe.getInput(), energyRecipe.getRecipeOutput());
arecipes.add(recipe);
}
}
}
else {
super.loadCraftingRecipes(outputId, results);
}
}
@Override
public void loadCraftingRecipes(ItemStack result)
{
List<IRecipe> allrecipes = CraftingManager.getInstance().getRecipeList();
for(IRecipe irecipe : allrecipes)
{
if(irecipe instanceof MekanismRecipe && areItemsEqual(irecipe.getRecipeOutput(), result))
{
MekanismRecipe energyRecipe = (MekanismRecipe)irecipe;
CachedEnergyRecipe recipe = new CachedEnergyRecipe(energyRecipe.width, energyRecipe.height, energyRecipe.getInput(), energyRecipe.getRecipeOutput());
arecipes.add(recipe);
}
}
}
@Override
public void loadUsageRecipes(ItemStack ingredient)
{
List<IRecipe> allrecipes = CraftingManager.getInstance().getRecipeList();
for(IRecipe irecipe : allrecipes)
{
if(irecipe instanceof MekanismRecipe)
{
MekanismRecipe energyRecipe = (MekanismRecipe)irecipe;
CachedEnergyRecipe recipe = new CachedEnergyRecipe(energyRecipe.width, energyRecipe.height, energyRecipe.getInput(), energyRecipe.getRecipeOutput());
if(recipe.contains(recipe.ingredients, ingredient))
{
recipe.setIngredientPermutation(recipe.ingredients, ingredient);
arecipes.add(recipe);
}
}
}
}
public static boolean areItemsEqual(ItemStack stack1, ItemStack stack2)
{
if(stack1 == null && stack2 != null || stack1 != null && stack2 == null)
{
return false;
}
else if(stack1 == null && stack2 == null)
{
return true;
}
if(stack1.itemID != stack2.itemID)
{
return false;
}
if(!(stack1.getItem() instanceof IEnergizedItem) && !(stack2.getItem() instanceof IEnergizedItem))
{
if(stack1.getItemDamage() != stack2.getItemDamage())
{
return false;
}
}
else {
if(((IEnergizedItem)stack1.getItem()).isMetadataSpecific() && ((IEnergizedItem)stack2.getItem()).isMetadataSpecific())
{
if(stack1.getItemDamage() != stack2.getItemDamage())
{
return false;
}
}
if(stack1.getItem() instanceof IEnergyCube && stack2.getItem() instanceof IEnergyCube)
{
if(((IEnergyCube)stack1.getItem()).getEnergyCubeTier(stack1) != ((IEnergyCube)stack2.getItem()).getEnergyCubeTier(stack2))
{
return false;
}
}
else if(stack1.getItem() instanceof IFactory && stack2.getItem() instanceof IFactory)
{
if(((IFactory)stack1.getItem()).isFactory(stack1) && ((IFactory)stack2.getItem()).isFactory(stack2))
{
if(((IFactory)stack1.getItem()).getRecipeType(stack1) != ((IFactory)stack2.getItem()).getRecipeType(stack2))
{
return false;
}
}
}
}
return true;
}
public class CachedEnergyRecipe extends CachedRecipe
{
public ArrayList<PositionedStack> ingredients;
public PositionedStack result;
public CachedEnergyRecipe(int width, int height, Object[] items, ItemStack out)
{
result = new PositionedStack(out, 119, 24);
ingredients = new ArrayList<PositionedStack>();
setIngredients(width, height, items);
}
public void setIngredients(int width, int height, Object[] items)
{
for(int x = 0; x < width; x++)
{
for(int y = 0; y < height; y++)
{
if(items[y*width+x] == null)
{
continue;
}
PositionedStack stack = new PositionedStack(items[y*width+x], 25+x*18, 6+y*18);
stack.setMaxSize(1);
ingredients.add(stack);
}
}
}
@Override
public ArrayList<PositionedStack> getIngredients()
{
return (ArrayList<PositionedStack>)getCycledIngredients(MekanismRecipeHandler.this.cycleticks / 20, ingredients);
}
@Override
public PositionedStack getResult()
{
return result;
}
@Override
public boolean contains(Collection<PositionedStack> ingredients, ItemStack ingredient)
{
for(PositionedStack stack : ingredients)
{
for(ItemStack item : stack.items)
{
if(areItemsEqual(item, ingredient))
{
return true;
}
}
}
return false;
}
}
}

View file

@ -0,0 +1,207 @@
package mekanism.nei;
import java.awt.Rectangle;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import mekanism.api.InfuseObject;
import mekanism.api.InfuseRegistry;
import mekanism.api.InfuseType;
import mekanism.api.InfusionInput;
import mekanism.api.InfusionOutput;
import mekanism.client.GuiMetallurgicInfuser;
import mekanism.common.RecipeHandler.Recipe;
import net.minecraft.item.ItemStack;
import org.lwjgl.opengl.GL11;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.forge.GuiContainerManager;
import codechicken.nei.recipe.TemplateRecipeHandler;
import static codechicken.core.gui.GuiDraw.*;
public class MetallurgicInfuserRecipeHandler extends TemplateRecipeHandler
{
private int ticksPassed;
@Override
public String getRecipeName()
{
return "Metallurgic Infuser";
}
@Override
public String getOverlayIdentifier()
{
return "infuser";
}
@Override
public String getGuiTexture()
{
return "mekanism:gui/GuiMetallurgicInfuser.png";
}
@Override
public Class getGuiClass()
{
return GuiMetallurgicInfuser.class;
}
public String getRecipeId()
{
return "mekanism.infuser";
}
public ItemStack getInfuseStack(InfuseType type)
{
for(Map.Entry<ItemStack, InfuseObject> obj : InfuseRegistry.getObjectMap().entrySet())
{
if(obj.getValue().type == type)
{
return obj.getKey();
}
}
return null;
}
public Set<Entry<InfusionInput, InfusionOutput>> getRecipes()
{
return Recipe.METALLURGIC_INFUSER.get().entrySet();
}
@Override
public void drawBackground(int i)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
changeTexture(getGuiTexture());
drawTexturedModalRect(0, 0, 5, 15, 166, 56);
}
@Override
public void drawExtras(int i)
{
InfuseType type = ((CachedIORecipe)arecipes.get(i)).infusionType;
float f = ticksPassed >= 40 ? (ticksPassed - 40) % 20 / 20.0F : 0.0F;
drawProgressBar(67, 32, 176 + 26, 52, 32, 8, f, 0);
f = ticksPassed >= 20 && ticksPassed < 40 ? (ticksPassed - 20) % 20 / 20.0F : 1.0F;
if(ticksPassed < 20) f = 0.0F;
f = ticksPassed <= 20 ? ticksPassed / 20.0F : 1.0F;
drawProgressBar(160, 2, 176 + 26, 0, 4, 52, f, 3);
changeTexture(type.texture);
drawProgressBar(2, 2, type.texX, type.texY, 4, 52, f, 3);
}
@Override
public void onUpdate()
{
super.onUpdate();
ticksPassed++;
}
@Override
public void loadTransferRects()
{
transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(67, 32, 32, 8), getRecipeId(), new Object[0]));
}
@Override
public void loadCraftingRecipes(String outputId, Object... results)
{
if(outputId.equals(getRecipeId()))
{
for(Map.Entry irecipe : getRecipes())
{
arecipes.add(new CachedIORecipe(irecipe, getInfuseStack(((InfusionInput)irecipe.getKey()).infusionType), ((InfusionInput)irecipe.getKey()).infusionType));
}
}
else {
super.loadCraftingRecipes(outputId, results);
}
}
@Override
public int recipiesPerPage()
{
return 2;
}
@Override
public void loadCraftingRecipes(ItemStack result)
{
for(Map.Entry irecipe : getRecipes())
{
if(NEIServerUtils.areStacksSameTypeCrafting(((InfusionOutput)irecipe.getValue()).resource, result))
{
arecipes.add(new CachedIORecipe(irecipe, getInfuseStack(((InfusionInput)irecipe.getKey()).infusionType), ((InfusionInput)irecipe.getKey()).infusionType));
}
}
}
@Override
public void loadUsageRecipes(ItemStack ingredient)
{
for(Map.Entry irecipe : getRecipes())
{
if(NEIServerUtils.areStacksSameTypeCrafting(((InfusionInput)irecipe.getKey()).inputStack, ingredient))
{
arecipes.add(new CachedIORecipe(irecipe, getInfuseStack(((InfusionInput)irecipe.getKey()).infusionType), ((InfusionInput)irecipe.getKey()).infusionType));
}
}
}
public class CachedIORecipe extends TemplateRecipeHandler.CachedRecipe
{
public PositionedStack inputStack;
public PositionedStack outputStack;
public PositionedStack infuseStack;
public InfuseType infusionType;
@Override
public PositionedStack getIngredient()
{
return inputStack;
}
@Override
public PositionedStack getResult()
{
return outputStack;
}
@Override
public PositionedStack getOtherStack()
{
return infuseStack;
}
public CachedIORecipe(ItemStack input, ItemStack output, ItemStack infuse, InfuseType type)
{
super();
inputStack = new PositionedStack(input, 46, 28);
outputStack = new PositionedStack(output, 104, 28);
if(infuse != null)
{
infuseStack = new PositionedStack(infuse, 12, 20);
}
infusionType = type;
}
public CachedIORecipe(Map.Entry recipe, ItemStack infuse, InfuseType type)
{
this(((InfusionInput)recipe.getKey()).inputStack, ((InfusionOutput)recipe.getValue()).resource, infuse, type);
}
}
}

View file

@ -0,0 +1,54 @@
package mekanism.nei;
import mekanism.client.GuiCombiner;
import mekanism.client.GuiCrusher;
import mekanism.client.GuiEnrichmentChamber;
import mekanism.client.GuiMetallurgicInfuser;
import mekanism.client.GuiOsmiumCompressor;
import mekanism.client.GuiPurificationChamber;
import mekanism.common.Mekanism;
import codechicken.nei.api.API;
import codechicken.nei.api.IConfigureNEI;
public class NEIMekanismConfig implements IConfigureNEI
{
@Override
public void loadConfig()
{
API.registerRecipeHandler(new EnrichmentChamberRecipeHandler());
API.registerUsageHandler(new EnrichmentChamberRecipeHandler());
API.registerRecipeHandler(new OsmiumCompressorRecipeHandler());
API.registerUsageHandler(new OsmiumCompressorRecipeHandler());
API.registerRecipeHandler(new CrusherRecipeHandler());
API.registerUsageHandler(new CrusherRecipeHandler());
API.registerRecipeHandler(new CombinerRecipeHandler());
API.registerUsageHandler(new CombinerRecipeHandler());
API.registerRecipeHandler(new MetallurgicInfuserRecipeHandler());
API.registerUsageHandler(new MetallurgicInfuserRecipeHandler());
API.registerRecipeHandler(new PurificationChamberRecipeHandler());
API.registerUsageHandler(new PurificationChamberRecipeHandler());
API.registerRecipeHandler(new MekanismRecipeHandler());
API.registerUsageHandler(new MekanismRecipeHandler());
API.setGuiOffset(GuiEnrichmentChamber.class, 16, 5);
API.setGuiOffset(GuiOsmiumCompressor.class, 16, 5);
API.setGuiOffset(GuiCrusher.class, 16, 5);
API.setGuiOffset(GuiCombiner.class, 16, 5);
API.setGuiOffset(GuiPurificationChamber.class, 16, 5);
API.setGuiOffset(GuiMetallurgicInfuser.class, 5, 15);
API.hideItem(Mekanism.boundingBlockID);
}
@Override
public String getName()
{
return "Mekanism NEI Plugin";
}
@Override
public String getVersion()
{
return "1.0.3";
}
}

View file

@ -0,0 +1,54 @@
package mekanism.nei;
import java.util.Set;
import net.minecraft.item.ItemStack;
import mekanism.client.GuiOsmiumCompressor;
import mekanism.common.Mekanism;
import mekanism.common.RecipeHandler.Recipe;
public class OsmiumCompressorRecipeHandler extends AdvancedMachineRecipeHandler
{
@Override
public String getRecipeName()
{
return "Osmium Compressor";
}
@Override
public String getRecipeId()
{
return "mekanism.compressor";
}
@Override
public String getOverlayIdentifier()
{
return "compressor";
}
@Override
public Set getRecipes()
{
return Recipe.OSMIUM_COMPRESSOR.get().entrySet();
}
@Override
public String getGuiTexture()
{
return "mekanism:gui/GuiCompressor.png";
}
@Override
public ItemStack getFuelStack()
{
return new ItemStack(Mekanism.Ingot, 1, 1);
}
@Override
public Class getGuiClass()
{
return GuiOsmiumCompressor.class;
}
}

View file

@ -0,0 +1,53 @@
package mekanism.nei;
import java.util.Set;
import mekanism.client.GuiPurificationChamber;
import mekanism.common.RecipeHandler.Recipe;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class PurificationChamberRecipeHandler extends AdvancedMachineRecipeHandler
{
@Override
public String getRecipeName()
{
return "Purification Chamber";
}
@Override
public String getRecipeId()
{
return "mekanism.purificationchamber";
}
@Override
public String getOverlayIdentifier()
{
return "purificationchamber";
}
@Override
public Set getRecipes()
{
return Recipe.PURIFICATION_CHAMBER.get().entrySet();
}
@Override
public String getGuiTexture()
{
return "mekanism:gui/GuiPurificationChamber.png";
}
@Override
public ItemStack getFuelStack()
{
return new ItemStack(Item.flint);
}
@Override
public Class getGuiClass()
{
return GuiPurificationChamber.class;
}
}