From dac7fd44f93f890b03c1ce1dfab5b7f22f2b4d29 Mon Sep 17 00:00:00 2001 From: Aidan Brady Date: Thu, 9 Jan 2014 22:09:48 -0500 Subject: [PATCH] Work on Rotary Condensentrator recipe handler --- .../client/nei/NEIMekanismConfig.java | 2 + .../RotaryCondensentratorRecipeHandler.java | 328 +++++++++++++++++- 2 files changed, 328 insertions(+), 2 deletions(-) diff --git a/common/mekanism/client/nei/NEIMekanismConfig.java b/common/mekanism/client/nei/NEIMekanismConfig.java index f0818de69..632f3a71a 100644 --- a/common/mekanism/client/nei/NEIMekanismConfig.java +++ b/common/mekanism/client/nei/NEIMekanismConfig.java @@ -9,6 +9,7 @@ import mekanism.client.gui.GuiEnrichmentChamber; import mekanism.client.gui.GuiMetallurgicInfuser; import mekanism.client.gui.GuiOsmiumCompressor; import mekanism.client.gui.GuiPurificationChamber; +import mekanism.client.gui.GuiRotaryCondensentrator; import mekanism.common.Mekanism; import codechicken.nei.api.API; import codechicken.nei.api.IConfigureNEI; @@ -57,6 +58,7 @@ public class NEIMekanismConfig implements IConfigureNEI API.setGuiOffset(GuiMetallurgicInfuser.class, 5, 15); API.setGuiOffset(GuiChemicalOxidizer.class, ChemicalOxidizerRecipeHandler.xOffset, ChemicalOxidizerRecipeHandler.yOffset); API.setGuiOffset(GuiChemicalInfuser.class, ChemicalInfuserRecipeHandler.xOffset, ChemicalInfuserRecipeHandler.yOffset); + API.setGuiOffset(GuiRotaryCondensentrator.class, RotaryCondensentratorRecipeHandler.xOffset, RotaryCondensentratorRecipeHandler.yOffset); API.hideItem(Mekanism.boundingBlockID); API.hideItem(Mekanism.ItemProxy.itemID); diff --git a/common/mekanism/client/nei/RotaryCondensentratorRecipeHandler.java b/common/mekanism/client/nei/RotaryCondensentratorRecipeHandler.java index eff76147d..9cc2adc26 100644 --- a/common/mekanism/client/nei/RotaryCondensentratorRecipeHandler.java +++ b/common/mekanism/client/nei/RotaryCondensentratorRecipeHandler.java @@ -1,6 +1,330 @@ package mekanism.client.nei; -public class RotaryCondensentratorRecipeHandler -{ +import static codechicken.core.gui.GuiDraw.changeTexture; +import static codechicken.core.gui.GuiDraw.drawTexturedModalRect; +import java.awt.Point; +import java.awt.Rectangle; +import java.util.List; +import java.util.Map; + +import mekanism.api.ChemicalInput; +import mekanism.api.gas.Gas; +import mekanism.api.gas.GasRegistry; +import mekanism.api.gas.GasStack; +import mekanism.client.gui.GuiChemicalInfuser; +import mekanism.common.ObfuscatedNames; +import mekanism.common.util.MekanismUtils; +import net.minecraft.client.gui.inventory.GuiContainer; +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 RotaryCondensentratorRecipeHandler extends BaseRecipeHandler +{ + private int ticksPassed; + + public static int xOffset = 5; + public static int yOffset = 3; + + @Override + public String getRecipeName() + { + return "Rotary Condensentrator"; + } + + @Override + public String getOverlayIdentifier() + { + return "rotarycondensentrator"; + } + + @Override + public String getGuiTexture() + { + return "mekanism:gui/nei/GuiRotaryCondensentrator.png"; + } + + @Override + public Class getGuiClass() + { + return GuiChemicalInfuser.class; + } + + public String getRecipeId() + { + return "mekanism.rotarycondensentrator"; + } + + @Override + public void drawBackground(int i) + { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + changeTexture(getGuiTexture()); + drawTexturedModalRect(-2, 0, 3, yOffset, 170, 71); + } + + @Override + public void drawExtras(int i) + { + CachedIORecipe recipe = (CachedIORecipe)arecipes.get(i); + + drawTexturedModalRect(47-xOffset, 39-yOffset, 176, 71, 28, 8); + drawTexturedModalRect(101-xOffset, 39-yOffset, 176, 63, 28, 8); + + if(recipe.gasStack != null) + { + displayGauge(58, 26-xOffset, 14-yOffset, 176, 4, 58, null, recipe.gasStack); + } + + if(recipe.fluidStack != null) + { + displayGauge(58, 134-xOffset, 14-yOffset, 176, 4, 58, recipe.fluidStack, null); + } + } + + @Override + public void onUpdate() + { + super.onUpdate(); + + ticksPassed++; + } + + @Override + public void loadTransferRects() + { + transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(47-xOffset, 39-yOffset, 28, 8), getRecipeId(), new Object[0])); + transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(101-xOffset, 39-yOffset, 28, 8), getRecipeId(), new Object[0])); + } + + @Override + public void loadCraftingRecipes(String outputId, Object... results) + { + if(outputId.equals(getRecipeId())) + { + for(Gas gas : GasRegistry.getRegisteredGasses()) + { + if(gas.hasFluid()) + { + arecipes.add(new CachedIORecipe(new GasStack(gas, 1), new FluidStack(gas.getFluid(), 1))); + } + } + } + else if(outputId.equals("gas") && results.length == 1 && results[0] instanceof GasStack) + { + GasStack gas = (GasStack)results[0]; + + if(gas.getGas().hasFluid()) + { + arecipes.add(new CachedIORecipe(new GasStack(gas.getGas(), 1), new FluidStack(gas.getGas().getFluid(), 1))); + } + } + else if(outputId.equals("fluid") && results.length == 1 && results[0] instanceof FluidStack) + { + FluidStack fluid = (FluidStack)results[0]; + Gas gas = GasRegistry.getGas(fluid.getFluid()); + + if(gas != null) + { + arecipes.add(new CachedIORecipe(new GasStack(gas, 1), new FluidStack(fluid.getFluid(), 1))); + } + } + else { + super.loadCraftingRecipes(outputId, results); + } + } + + @Override + public void loadUsageRecipes(String inputId, Object... ingredients) + { + if(inputId.equals("gas") && ingredients.length == 1 && ingredients[0] instanceof GasStack) + { + GasStack gas = (GasStack)ingredients[0]; + + if(gas.getGas().hasFluid()) + { + arecipes.add(new CachedIORecipe(new GasStack(gas.getGas(), 1), new FluidStack(gas.getGas().getFluid(), 1))); + } + } + else if(inputId.equals("fluid") && ingredients.length == 1 && ingredients[0] instanceof FluidStack) + { + FluidStack fluid = (FluidStack)ingredients[0]; + Gas gas = GasRegistry.getGas(fluid.getFluid()); + + if(gas != null) + { + arecipes.add(new CachedIORecipe(new GasStack(gas, 1), new FluidStack(fluid.getFluid(), 1))); + } + } + 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 >= 26 && xAxis <= 42 && yAxis >= 14+13 && yAxis <= 72+13) + { + currenttip.add(((CachedIORecipe)arecipes.get(recipe)).gasStack.getGas().getLocalizedName()); + } + else if(xAxis >= 134 && xAxis <= 150 && yAxis >= 14+13 && yAxis <= 72+13) + { + currenttip.add(((CachedIORecipe)arecipes.get(recipe)).fluidStack.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); + + GasStack gas = null; + FluidStack fluid = null; + + if(xAxis >= 26 && xAxis <= 42 && yAxis >= 14+13 && yAxis <= 72+13) + { + gas = ((CachedIORecipe)arecipes.get(recipe)).gasStack; + } + else if(xAxis >= 134 && xAxis <= 150 && yAxis >= 14+13 && yAxis <= 72+13) + { + fluid = ((CachedIORecipe)arecipes.get(recipe)).fluidStack; + } + + if(gas != null) + { + if(keyCode == NEIClientConfig.getKeyBinding("gui.recipe")) + { + if(doGasLookup(gas, false)) + { + return true; + } + } + else if(keyCode == NEIClientConfig.getKeyBinding("gui.usage")) + { + if(doGasLookup(gas, true)) + { + return true; + } + } + } + else if(fluid != null) + { + if(keyCode == NEIClientConfig.getKeyBinding("gui.recipe")) + { + if(doFluidLookup(fluid, false)) + { + return true; + } + } + else if(keyCode == NEIClientConfig.getKeyBinding("gui.usage")) + { + if(doFluidLookup(fluid, 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); + + GasStack gas = null; + FluidStack fluid = null; + + if(xAxis >= 26 && xAxis <= 42 && yAxis >= 14+13 && yAxis <= 72+13) + { + gas = ((CachedIORecipe)arecipes.get(recipe)).gasStack; + } + else if(xAxis >= 134 && xAxis <= 150 && yAxis >= 14+13 && yAxis <= 72+13) + { + fluid = ((CachedIORecipe)arecipes.get(recipe)).fluidStack; + } + + if(gas != null) + { + if(button == 0) + { + if(doGasLookup(gas, false)) + { + return true; + } + } + else if(button == 1) + { + if(doGasLookup(gas, true)) + { + return true; + } + } + } + else if(fluid != null) + { + if(button == 0) + { + if(doFluidLookup(fluid, false)) + { + return true; + } + } + else if(button == 1) + { + if(doFluidLookup(fluid, true)) + { + return true; + } + } + } + + return super.mouseClicked(gui, button, recipe); + } + + @Override + public int recipiesPerPage() + { + return 1; + } + + public class CachedIORecipe extends TemplateRecipeHandler.CachedRecipe + { + public GasStack gasStack; + public FluidStack fluidStack; + + @Override + public PositionedStack getResult() + { + return null; + } + + public CachedIORecipe(GasStack gas, FluidStack fluid) + { + gasStack = gas; + fluidStack = fluid; + } + } }