diff --git a/common/mekanism/client/nei/NEIMekanismConfig.java b/common/mekanism/client/nei/NEIMekanismConfig.java index 861b756cf..b7c09e959 100644 --- a/common/mekanism/client/nei/NEIMekanismConfig.java +++ b/common/mekanism/client/nei/NEIMekanismConfig.java @@ -12,6 +12,7 @@ import mekanism.client.gui.GuiOsmiumCompressor; import mekanism.client.gui.GuiPrecisionSawmill; import mekanism.client.gui.GuiPurificationChamber; import mekanism.client.gui.GuiRotaryCondensentrator; +import mekanism.client.gui.GuiSalinationController; import mekanism.common.Mekanism; import codechicken.nei.api.API; import codechicken.nei.api.IConfigureNEI; @@ -60,6 +61,9 @@ public class NEIMekanismConfig implements IConfigureNEI API.registerRecipeHandler(new PrecisionSawmillRecipeHandler()); API.registerUsageHandler(new PrecisionSawmillRecipeHandler()); + API.registerRecipeHandler(new SalinationControllerRecipeHandler()); + API.registerUsageHandler(new SalinationControllerRecipeHandler()); + API.setGuiOffset(GuiEnrichmentChamber.class, 16, 6); API.setGuiOffset(GuiOsmiumCompressor.class, 16, 6); API.setGuiOffset(GuiCrusher.class, 16, 6); @@ -72,6 +76,7 @@ public class NEIMekanismConfig implements IConfigureNEI API.setGuiOffset(GuiRotaryCondensentrator.class, RotaryCondensentratorRecipeHandler.xOffset, RotaryCondensentratorRecipeHandler.yOffset); API.setGuiOffset(GuiElectrolyticSeparator.class, ElectrolyticSeparatorRecipeHandler.xOffset, ElectrolyticSeparatorRecipeHandler.yOffset); API.setGuiOffset(GuiPrecisionSawmill.class, 16, 6); + API.setGuiOffset(GuiSalinationController.class, SalinationControllerRecipeHandler.xOffset, SalinationControllerRecipeHandler.yOffset); API.hideItem(Mekanism.boundingBlockID); API.hideItem(Mekanism.ItemProxy.itemID); @@ -86,6 +91,6 @@ public class NEIMekanismConfig implements IConfigureNEI @Override public String getVersion() { - return "1.1"; + return "1.2"; } } diff --git a/common/mekanism/client/nei/SalinationControllerRecipeHandler.java b/common/mekanism/client/nei/SalinationControllerRecipeHandler.java new file mode 100644 index 000000000..1bf1328d6 --- /dev/null +++ b/common/mekanism/client/nei/SalinationControllerRecipeHandler.java @@ -0,0 +1,284 @@ +package mekanism.client.nei; + +import static codechicken.core.gui.GuiDraw.changeTexture; +import static codechicken.core.gui.GuiDraw.drawTexturedModalRect; + +import java.awt.Point; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import mekanism.client.gui.GuiSalinationController; +import mekanism.common.ObfuscatedNames; +import mekanism.common.recipe.RecipeHandler.Recipe; +import mekanism.common.util.MekanismUtils; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +import org.lwjgl.opengl.GL11; + +import codechicken.core.gui.GuiDraw; +import codechicken.nei.NEIClientConfig; +import codechicken.nei.PositionedStack; +import codechicken.nei.recipe.GuiRecipe; +import codechicken.nei.recipe.TemplateRecipeHandler; + +public class SalinationControllerRecipeHandler extends BaseRecipeHandler +{ + private int ticksPassed; + + private static Map recipes = new HashMap(); + + public static int xOffset = 5; + public static int yOffset = 12; + + static { + if(recipes.isEmpty()) + { + recipes.put(new FluidStack(FluidRegistry.WATER, 1), new FluidStack(FluidRegistry.getFluid("brine"), 1)); + } + } + + @Override + public String getRecipeName() + { + return "Salination Controller"; + } + + @Override + public String getOverlayIdentifier() + { + return "salinationcontroller"; + } + + @Override + public String getGuiTexture() + { + return "mekanism:gui/nei/GuiSalinationController.png"; + } + + @Override + public Class getGuiClass() + { + return GuiSalinationController.class; + } + + public String getRecipeId() + { + return "mekanism.salinationcontroller"; + } + + public Set> getRecipes() + { + return recipes.entrySet(); + } + + @Override + public void drawBackground(int i) + { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + changeTexture(getGuiTexture()); + drawTexturedModalRect(-2, 0, 3, yOffset, 170, 62); + } + + @Override + public void drawExtras(int i) + { + CachedIORecipe recipe = (CachedIORecipe)arecipes.get(i); + + drawProgressBar(49-xOffset, 64-yOffset, 176, 59, 78, 8, ticksPassed < 20 ? ticksPassed % 20 / 20.0F : 1.0F, 0); + + if(recipe.fluidInput != null) + { + displayGauge(58, 7-xOffset, 14-yOffset, 176, 0, 58, recipe.fluidInput, null); + } + + if(recipe.fluidOutput != null) + { + displayGauge(58, 153-xOffset, 14-yOffset, 176, 0, 58, recipe.fluidOutput, null); + } + } + + @Override + public void onUpdate() + { + super.onUpdate(); + + ticksPassed++; + } + + @Override + public void loadCraftingRecipes(String outputId, Object... results) + { + if(outputId.equals(getRecipeId())) + { + for(Map.Entry irecipe : getRecipes()) + { + arecipes.add(new CachedIORecipe(irecipe)); + } + } + else if(outputId.equals("fluid") && results.length == 1 && results[0] instanceof FluidStack) + { + for(Map.Entry irecipe : getRecipes()) + { + if(((FluidStack)results[0]).isFluidEqual(irecipe.getValue())) + { + arecipes.add(new CachedIORecipe(irecipe)); + } + } + } + else { + super.loadCraftingRecipes(outputId, results); + } + } + + @Override + public void loadUsageRecipes(String inputId, Object... ingredients) + { + if(inputId.equals("fluid") && ingredients.length == 1 && ingredients[0] instanceof FluidStack) + { + for(Map.Entry irecipe : getRecipes()) + { + if(irecipe.getKey().isFluidEqual((FluidStack)ingredients[0])) + { + arecipes.add(new CachedIORecipe(irecipe)); + } + } + } + else { + super.loadUsageRecipes(inputId, ingredients); + } + } + + @Override + public List handleTooltip(GuiRecipe gui, List currenttip, int recipe) + { + Point point = GuiDraw.getMousePosition(); + + int xAxis = point.x-(Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiLeft); + int yAxis = point.y-(Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiTop); + + if(xAxis >= 7 && xAxis <= 23 && yAxis >= 14+4 && yAxis <= 72+4) + { + currenttip.add(((CachedIORecipe)arecipes.get(recipe)).fluidInput.getFluid().getLocalizedName()); + } + else if(xAxis >= 153 && xAxis <= 169 && yAxis >= 14+4 && yAxis <= 72+4) + { + currenttip.add(((CachedIORecipe)arecipes.get(recipe)).fluidOutput.getFluid().getLocalizedName()); + } + + return super.handleTooltip(gui, currenttip, recipe); + } + + @Override + public boolean keyTyped(GuiRecipe gui, char keyChar, int keyCode, int recipe) + { + Point point = GuiDraw.getMousePosition(); + + int xAxis = point.x-(Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiLeft); + int yAxis = point.y-(Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiTop); + + FluidStack stack = null; + + if(xAxis >= 7 && xAxis <= 23 && yAxis >= 14+4 && yAxis <= 72+4) + { + stack = ((CachedIORecipe)arecipes.get(recipe)).fluidInput; + } + else if(xAxis >= 153 && xAxis <= 169 && yAxis >= 14+4 && yAxis <= 72+4) + { + stack = ((CachedIORecipe)arecipes.get(recipe)).fluidOutput; + } + + if(stack != null) + { + if(keyCode == NEIClientConfig.getKeyBinding("gui.recipe")) + { + if(doFluidLookup(stack, false)) + { + return true; + } + } + else if(keyCode == NEIClientConfig.getKeyBinding("gui.usage")) + { + if(doFluidLookup(stack, true)) + { + return true; + } + } + } + + return super.keyTyped(gui, keyChar, keyCode, recipe); + } + + @Override + public boolean mouseClicked(GuiRecipe gui, int button, int recipe) + { + Point point = GuiDraw.getMousePosition(); + + int xAxis = point.x - (Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiLeft); + int yAxis = point.y - (Integer)MekanismUtils.getPrivateValue(gui, GuiContainer.class, ObfuscatedNames.GuiContainer_guiTop); + + FluidStack stack = null; + + if(xAxis >= 7 && xAxis <= 23 && yAxis >= 14+4 && yAxis <= 72+4) + { + stack = ((CachedIORecipe)arecipes.get(recipe)).fluidInput; + } + else if(xAxis >= 153 && xAxis <= 169 && yAxis >= 14+4 && yAxis <= 72+4) + { + stack = ((CachedIORecipe)arecipes.get(recipe)).fluidOutput; + } + + if(stack != null) + { + if(button == 0) + { + if(doFluidLookup(stack, false)) + { + return true; + } + } + else if(button == 1) + { + if(doFluidLookup(stack, true)) + { + return true; + } + } + } + + return super.mouseClicked(gui, button, recipe); + } + + @Override + public int recipiesPerPage() + { + return 1; + } + + public class CachedIORecipe extends TemplateRecipeHandler.CachedRecipe + { + public FluidStack fluidInput; + public FluidStack fluidOutput; + + @Override + public PositionedStack getResult() + { + return null; + } + + public CachedIORecipe(FluidStack input, FluidStack output) + { + fluidInput = input; + fluidOutput = output; + } + + public CachedIORecipe(Map.Entry recipe) + { + this((FluidStack)recipe.getKey(), (FluidStack)recipe.getValue()); + } + } +} diff --git a/resources/assets/mekanism/gui/nei/GuiSalinationController.png b/resources/assets/mekanism/gui/nei/GuiSalinationController.png new file mode 100644 index 000000000..ad9ddd463 Binary files /dev/null and b/resources/assets/mekanism/gui/nei/GuiSalinationController.png differ