diff --git a/src/main/java/mekanism/api/PressurizedProducts.java b/src/main/java/mekanism/api/PressurizedProducts.java index e4e32fd23..830fc55a6 100644 --- a/src/main/java/mekanism/api/PressurizedProducts.java +++ b/src/main/java/mekanism/api/PressurizedProducts.java @@ -7,9 +7,7 @@ import net.minecraft.item.ItemStack; public class PressurizedProducts { - private ItemStack itemOutput; - private GasStack gasOutput; public PressurizedProducts(ItemStack item, GasStack gas) @@ -49,5 +47,4 @@ public class PressurizedProducts { return new PressurizedProducts(itemOutput.copy(), gasOutput.copy()); } - } diff --git a/src/main/java/mekanism/api/PressurizedReactants.java b/src/main/java/mekanism/api/PressurizedReactants.java index 8846f0d9e..07e588235 100644 --- a/src/main/java/mekanism/api/PressurizedReactants.java +++ b/src/main/java/mekanism/api/PressurizedReactants.java @@ -3,7 +3,6 @@ package mekanism.api; import mekanism.api.gas.GasStack; import mekanism.api.gas.GasTank; import mekanism.common.util.StackUtils; - import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTank; @@ -122,5 +121,19 @@ public class PressurizedReactants { return new PressurizedReactants(theSolid.copy(), theFluid.copy(), theGas.copy()); } - + + public ItemStack getSolid() + { + return theSolid; + } + + public FluidStack getFluid() + { + return theFluid; + } + + public GasStack getGas() + { + return theGas; + } } diff --git a/src/main/java/mekanism/api/gas/Gas.java b/src/main/java/mekanism/api/gas/Gas.java index b2d6e3b44..f05be52c6 100644 --- a/src/main/java/mekanism/api/gas/Gas.java +++ b/src/main/java/mekanism/api/gas/Gas.java @@ -115,6 +115,7 @@ public class Gas { return this.getFluid().getIcon(); } + return icon; } @@ -131,7 +132,9 @@ public class Gas { fluid.setIcons(getIcon()); } + from_fluid = false; + return this; } @@ -202,8 +205,7 @@ public class Gas fluid = new Fluid(getName()).setGaseous(true); FluidRegistry.registerFluid(fluid); } - else - { + else { fluid = FluidRegistry.getFluid(getName()); } } diff --git a/src/main/java/mekanism/client/nei/MachineRecipeHandler.java b/src/main/java/mekanism/client/nei/MachineRecipeHandler.java index b44731316..0551646d6 100644 --- a/src/main/java/mekanism/client/nei/MachineRecipeHandler.java +++ b/src/main/java/mekanism/client/nei/MachineRecipeHandler.java @@ -153,6 +153,7 @@ public abstract class MachineRecipeHandler extends BaseRecipeHandler public CachedIORecipe(ItemStack itemstack, ItemStack itemstack1) { super(); + input = new PositionedStack(itemstack, 40, 12); output = new PositionedStack(itemstack1, 100, 30); } diff --git a/src/main/java/mekanism/client/nei/NEIMekanismConfig.java b/src/main/java/mekanism/client/nei/NEIMekanismConfig.java index ca95d0843..0246c439c 100644 --- a/src/main/java/mekanism/client/nei/NEIMekanismConfig.java +++ b/src/main/java/mekanism/client/nei/NEIMekanismConfig.java @@ -12,6 +12,7 @@ import mekanism.client.gui.GuiElectrolyticSeparator; import mekanism.client.gui.GuiEnrichmentChamber; import mekanism.client.gui.GuiMetallurgicInfuser; import mekanism.client.gui.GuiOsmiumCompressor; +import mekanism.client.gui.GuiPRC; import mekanism.client.gui.GuiPrecisionSawmill; import mekanism.client.gui.GuiPurificationChamber; import mekanism.client.gui.GuiRotaryCondensentrator; @@ -76,6 +77,9 @@ public class NEIMekanismConfig implements IConfigureNEI API.registerRecipeHandler(new ChemicalCrystallizerRecipeHandler()); API.registerUsageHandler(new ChemicalCrystallizerRecipeHandler()); + + API.registerRecipeHandler(new PRCRecipeHandler()); + API.registerUsageHandler(new PRCRecipeHandler()); API.setGuiOffset(GuiEnrichmentChamber.class, 16, 6); API.setGuiOffset(GuiOsmiumCompressor.class, 16, 6); @@ -93,6 +97,7 @@ public class NEIMekanismConfig implements IConfigureNEI API.setGuiOffset(GuiChemicalDissolutionChamber.class, ChemicalDissolutionChamberRecipeHandler.xOffset, ChemicalDissolutionChamberRecipeHandler.yOffset); API.setGuiOffset(GuiChemicalWasher.class, ChemicalWasherRecipeHandler.xOffset, ChemicalWasherRecipeHandler.yOffset); API.setGuiOffset(GuiChemicalCrystallizer.class, ChemicalCrystallizerRecipeHandler.xOffset, ChemicalCrystallizerRecipeHandler.yOffset); + API.setGuiOffset(GuiPRC.class, PRCRecipeHandler.xOffset, PRCRecipeHandler.yOffset); API.hideItem(new ItemStack(Mekanism.BoundingBlock)); API.hideItem(new ItemStack(Mekanism.ItemProxy)); diff --git a/src/main/java/mekanism/client/nei/PRCRecipeHandler.java b/src/main/java/mekanism/client/nei/PRCRecipeHandler.java new file mode 100644 index 000000000..18f929c09 --- /dev/null +++ b/src/main/java/mekanism/client/nei/PRCRecipeHandler.java @@ -0,0 +1,429 @@ +package mekanism.client.nei; + +import static codechicken.lib.gui.GuiDraw.changeTexture; +import static codechicken.lib.gui.GuiDraw.drawTexturedModalRect; + +import java.awt.Point; +import java.awt.Rectangle; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import mekanism.api.PressurizedReactants; +import mekanism.api.PressurizedRecipe; +import mekanism.api.gas.GasStack; +import mekanism.client.gui.GuiElement; +import mekanism.client.gui.GuiPRC; +import mekanism.client.gui.GuiPowerBar; +import mekanism.client.gui.GuiPowerBar.IPowerInfoHandler; +import mekanism.client.gui.GuiProgress; +import mekanism.client.gui.GuiProgress.IProgressInfoHandler; +import mekanism.client.gui.GuiProgress.ProgressBar; +import mekanism.client.gui.GuiSlot; +import mekanism.client.gui.GuiSlot.SlotOverlay; +import mekanism.client.gui.GuiSlot.SlotType; +import mekanism.client.nei.RotaryCondensentratorRecipeHandler.CachedIORecipe; +import mekanism.common.ObfuscatedNames; +import mekanism.common.recipe.RecipeHandler.Recipe; +import mekanism.common.util.MekanismUtils; +import mekanism.common.util.MekanismUtils.ResourceType; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import org.lwjgl.opengl.GL11; + +import codechicken.lib.gui.GuiDraw; +import codechicken.nei.NEIClientConfig; +import codechicken.nei.NEIServerUtils; +import codechicken.nei.PositionedStack; +import codechicken.nei.recipe.GuiRecipe; +import codechicken.nei.recipe.TemplateRecipeHandler; + +public class PRCRecipeHandler extends BaseRecipeHandler +{ + private int ticksPassed; + + public static int xOffset = 5; + public static int yOffset = 3; + + @Override + public void addGuiElements() + { + guiElements.add(new GuiSlot(SlotType.INPUT, this, MekanismUtils.getResource(ResourceType.GUI, getGuiTexture()), 53, 34)); + guiElements.add(new GuiSlot(SlotType.POWER, this, MekanismUtils.getResource(ResourceType.GUI, getGuiTexture()), 140, 18).with(SlotOverlay.POWER)); + guiElements.add(new GuiSlot(SlotType.OUTPUT, this, MekanismUtils.getResource(ResourceType.GUI, getGuiTexture()), 115, 34)); + + guiElements.add(new GuiPowerBar(this, new IPowerInfoHandler() { + @Override + public double getLevel() + { + return ticksPassed <= 20 ? ticksPassed / 20.0F : 1.0F; + } + }, MekanismUtils.getResource(ResourceType.GUI, getGuiTexture()), 164, 15)); + guiElements.add(new GuiProgress(new IProgressInfoHandler() + { + @Override + public double getProgress() + { + return ticksPassed >= 20 ? (ticksPassed - 20) % 20 / 20.0F : 0.0F; + } + }, getProgressType(), this, MekanismUtils.getResource(ResourceType.GUI, getGuiTexture()), 75, 37)); + } + + public ProgressBar getProgressType() + { + return ProgressBar.MEDIUM; + } + + public Set> getRecipes() + { + return Recipe.PRESSURIZED_REACTION_CHAMBER.get().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, 80); + + for(GuiElement e : guiElements) + { + e.renderBackground(0, 0, xOffset, yOffset); + } + } + + @Override + public void loadTransferRects() + { + transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(70, 34, 36, 10), getRecipeId(), new Object[0])); + } + + @Override + public void onUpdate() + { + super.onUpdate(); + ticksPassed++; + } + + @Override + public String getRecipeName() + { + return MekanismUtils.localize("tile.MachineBlock2.PressurizedReactionChamber.name"); + } + + @Override + public Class getGuiClass() + { + return GuiPRC.class; + } + + @Override + public String getOverlayIdentifier() + { + return "prc"; + } + + @Override + public int recipiesPerPage() + { + return 1; + } + + public String getRecipeId() + { + return "mekanism.prc"; + } + + @Override + public String getGuiTexture() + { + return "nei/GuiPRC.png"; + } + + @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.pressurizedRecipe.reactants.getFluid() != null) + { + displayGauge(58, 26-xOffset, 14-yOffset, 176, 4, 58, recipe.pressurizedRecipe.reactants.getFluid(), null); + } + + if(recipe.pressurizedRecipe.reactants.getGas() != null) + { + displayGauge(58, 26-xOffset, 14-yOffset, 176, 4, 58, null, recipe.pressurizedRecipe.reactants.getGas()); + } + + if(recipe.pressurizedRecipe.products.getGasOutput() != null) + { + displayGauge(58, 80-xOffset, 5-yOffset, 176, 4, 58, null, recipe.pressurizedRecipe.products.getGasOutput()); + } + } + + @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("gas") && results.length == 1 && results[0] instanceof GasStack) + { + for(Map.Entry irecipe : getRecipes()) + { + if(irecipe.getValue().reactants.containsType((GasStack)results[0])) + { + arecipes.add(new CachedIORecipe(irecipe)); + } + } + } + else { + super.loadCraftingRecipes(outputId, results); + } + } + + @Override + public void loadCraftingRecipes(ItemStack result) + { + for(Map.Entry irecipe : getRecipes()) + { + if(NEIServerUtils.areStacksSameTypeCrafting(irecipe.getValue().products.getItemOutput(), result)) + { + arecipes.add(new CachedIORecipe(irecipe)); + } + } + } + + @Override + public void loadUsageRecipes(String inputId, Object... ingredients) + { + if(inputId.equals("gas") && ingredients.length == 1 && ingredients[0] instanceof GasStack) + { + for(Map.Entry irecipe : getRecipes()) + { + if(irecipe.getKey().containsType((GasStack)ingredients[0])) + { + arecipes.add(new CachedIORecipe(irecipe)); + } + } + } + else if(inputId.equals("fluid") && ingredients.length == 1 && ingredients[0] instanceof FluidStack) + { + for(Map.Entry irecipe : getRecipes()) + { + if(irecipe.getKey().containsType((FluidStack)ingredients[0])) + { + arecipes.add(new CachedIORecipe(irecipe)); + } + } + } + else { + super.loadUsageRecipes(inputId, ingredients); + } + } + + @Override + public void loadUsageRecipes(ItemStack ingredient) + { + for(Map.Entry irecipe : getRecipes()) + { + if(NEIServerUtils.areStacksSameTypeCrafting(irecipe.getKey().getSolid(), ingredient)) + { + arecipes.add(new CachedIORecipe(irecipe)); + } + } + } + + @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 >= 80 && xAxis <= 96 && yAxis >= 5+13 && yAxis <= 63+13) + { + currenttip.add(((CachedIORecipe)arecipes.get(recipe)).pressurizedRecipe.reactants.getFluid().getFluid().getLocalizedName()); + } + else if(xAxis >= 26 && xAxis <= 42 && yAxis >= 14+13 && yAxis <= 72+13) + { + currenttip.add(((CachedIORecipe)arecipes.get(recipe)).pressurizedRecipe.reactants.getGas().getGas().getLocalizedName()); + } + else if(xAxis >= 134 && xAxis <= 150 && yAxis >= 14+13 && yAxis <= 72+13) + { + currenttip.add(((CachedIORecipe)arecipes.get(recipe)).pressurizedRecipe.products.getGasOutput().getGas().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 >= 80 && xAxis <= 96 && yAxis >= 5+13 && yAxis <= 63+13) + { + fluid = ((CachedIORecipe)arecipes.get(recipe)).pressurizedRecipe.reactants.getFluid(); + } + else if(xAxis >= 26 && xAxis <= 42 && yAxis >= 14+13 && yAxis <= 72+13) + { + gas = ((CachedIORecipe)arecipes.get(recipe)).pressurizedRecipe.reactants.getGas(); + } + else if(xAxis >= 134 && xAxis <= 150 && yAxis >= 14+13 && yAxis <= 72+13) + { + gas = ((CachedIORecipe)arecipes.get(recipe)).pressurizedRecipe.products.getGasOutput(); + } + + 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 >= 80 && xAxis <= 96 && yAxis >= 5+13 && yAxis <= 63+13) + { + fluid = ((CachedIORecipe)arecipes.get(recipe)).pressurizedRecipe.reactants.getFluid(); + } + else if(xAxis >= 26 && xAxis <= 42 && yAxis >= 14+13 && yAxis <= 72+13) + { + gas = ((CachedIORecipe)arecipes.get(recipe)).pressurizedRecipe.reactants.getGas(); + } + else if(xAxis >= 134 && xAxis <= 150 && yAxis >= 14+13 && yAxis <= 72+13) + { + gas = ((CachedIORecipe)arecipes.get(recipe)).pressurizedRecipe.products.getGasOutput(); + } + + 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); + } + + public class CachedIORecipe extends TemplateRecipeHandler.CachedRecipe + { + public PressurizedRecipe pressurizedRecipe; + + public PositionedStack input; + public PositionedStack output; + + @Override + public PositionedStack getIngredient() + { + return input; + } + + @Override + public PositionedStack getResult() + { + return output; + } + + public CachedIORecipe(PressurizedRecipe recipe) + { + super(); + + pressurizedRecipe = recipe; + + input = new PositionedStack(recipe.reactants.getSolid(), 54, 35); + output = new PositionedStack(recipe.products.getItemOutput(), 116, 35); + } + + public CachedIORecipe(Map.Entry recipe) + { + this((PressurizedRecipe)recipe.getValue()); + } + } +} diff --git a/src/main/java/mekanism/client/render/RenderPartTransmitter.java b/src/main/java/mekanism/client/render/RenderPartTransmitter.java index 000550ead..79e06dd04 100644 --- a/src/main/java/mekanism/client/render/RenderPartTransmitter.java +++ b/src/main/java/mekanism/client/render/RenderPartTransmitter.java @@ -492,6 +492,7 @@ public class RenderPartTransmitter implements IIconSelfRegister public void renderStatic(PartSidedPipe transmitter) { CCRenderState.reset(); + CCRenderState.hasColour = true; CCRenderState.setBrightness(transmitter.world(), transmitter.x(), transmitter.y(), transmitter.z()); for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) diff --git a/src/main/java/mekanism/common/multipart/PartMechanicalPipe.java b/src/main/java/mekanism/common/multipart/PartMechanicalPipe.java index d5631a1ca..4d019c870 100644 --- a/src/main/java/mekanism/common/multipart/PartMechanicalPipe.java +++ b/src/main/java/mekanism/common/multipart/PartMechanicalPipe.java @@ -245,7 +245,7 @@ public class PartMechanicalPipe extends PartTransmitter implements @SideOnly(Side.CLIENT) public void renderDynamic(Vector3 pos, float f, int pass) { - if(pass == 1) + if(pass == 0) { RenderPartTransmitter.getInstance().renderContents(this, pos); } diff --git a/src/main/java/mekanism/common/multipart/PartPressurizedTube.java b/src/main/java/mekanism/common/multipart/PartPressurizedTube.java index 0178dbc5a..c69434be2 100644 --- a/src/main/java/mekanism/common/multipart/PartPressurizedTube.java +++ b/src/main/java/mekanism/common/multipart/PartPressurizedTube.java @@ -245,7 +245,7 @@ public class PartPressurizedTube extends PartTransmitter implements @SideOnly(Side.CLIENT) public void renderDynamic(Vector3 pos, float f, int pass) { - if(pass == 1) + if(pass == 0) { RenderPartTransmitter.getInstance().renderContents(this, pos); } diff --git a/src/main/java/mekanism/common/multipart/PartUniversalCable.java b/src/main/java/mekanism/common/multipart/PartUniversalCable.java index b36443242..f4aec49d0 100644 --- a/src/main/java/mekanism/common/multipart/PartUniversalCable.java +++ b/src/main/java/mekanism/common/multipart/PartUniversalCable.java @@ -210,7 +210,7 @@ public class PartUniversalCable extends PartTransmitter implement @SideOnly(Side.CLIENT) public void renderDynamic(Vector3 pos, float frame, int pass) { - if(pass == 1 && MekanismClient.fancyUniversalCableRender) + if(pass == 0 && MekanismClient.fancyUniversalCableRender) { RenderPartTransmitter.getInstance().renderContents(this, pos); } diff --git a/src/main/resources/assets/mekanism/gui/nei/GuiPRC.png b/src/main/resources/assets/mekanism/gui/nei/GuiPRC.png new file mode 100644 index 000000000..c03129db1 Binary files /dev/null and b/src/main/resources/assets/mekanism/gui/nei/GuiPRC.png differ