diff options
author | Raven Szewczyk <git@eigenraven.me> | 2024-05-24 19:50:35 +0100 |
---|---|---|
committer | Raven Szewczyk <git@eigenraven.me> | 2024-05-24 19:50:35 +0100 |
commit | 6d1b2216464d4dad449ac6fcfec476832224a55e (patch) | |
tree | 526a0c15f7056313c80e6c0386e025e9b3f61781 /src/main/java/gtPlusPlus/nei | |
parent | b5d35f40afa606ed1b07061dad82e0521a59c186 (diff) | |
download | GT5-Unofficial-6d1b2216464d4dad449ac6fcfec476832224a55e.tar.gz GT5-Unofficial-6d1b2216464d4dad449ac6fcfec476832224a55e.tar.bz2 GT5-Unofficial-6d1b2216464d4dad449ac6fcfec476832224a55e.zip |
Merge addon sources
Diffstat (limited to 'src/main/java/gtPlusPlus/nei')
-rw-r--r-- | src/main/java/gtPlusPlus/nei/DecayableRecipeHandler.java | 273 | ||||
-rw-r--r-- | src/main/java/gtPlusPlus/nei/GT_NEI_LFTR_Sparging.java | 502 | ||||
-rw-r--r-- | src/main/java/gtPlusPlus/nei/NEI_GTPP_Config.java | 102 | ||||
-rw-r--r-- | src/main/java/gtPlusPlus/nei/handlers/NeiTextureHandler.java | 126 |
4 files changed, 1003 insertions, 0 deletions
diff --git a/src/main/java/gtPlusPlus/nei/DecayableRecipeHandler.java b/src/main/java/gtPlusPlus/nei/DecayableRecipeHandler.java new file mode 100644 index 0000000000..499e53c317 --- /dev/null +++ b/src/main/java/gtPlusPlus/nei/DecayableRecipeHandler.java @@ -0,0 +1,273 @@ +package gtPlusPlus.nei; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.awt.Rectangle; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.resources.I18n; +import net.minecraft.item.ItemStack; +import net.minecraft.util.StatCollector; + +import codechicken.lib.gui.GuiDraw; +import codechicken.nei.PositionedStack; +import codechicken.nei.recipe.TemplateRecipeHandler; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.gui.machine.GUI_DecayablesChest; +import gtPlusPlus.core.handler.Recipes.DecayableRecipe; +import gtPlusPlus.core.item.base.dusts.BaseItemDustUnique; +import gtPlusPlus.core.item.materials.DustDecayable; +import gtPlusPlus.core.lib.VanillaColours; +import gtPlusPlus.nei.handlers.NeiTextureHandler; + +public class DecayableRecipeHandler extends TemplateRecipeHandler { + + public static final String mNEIName = "Decayables"; + + @Override + public String getRecipeName() { + return StatCollector.translateToLocal("GTPP.container.decaychest.name"); + } + + @Override + public String getGuiTexture() { + return GTPlusPlus.ID + ":textures/gui/nei/decayables.png"; + } + + @Override + public Class<? extends GuiContainer> getGuiClass() { + return GUI_DecayablesChest.class; + } + + @Override + public String getOverlayIdentifier() { + return "GTPP_Decayables"; + } + + @Override + public int recipiesPerPage() { + return 1; + } + + @Override + public void loadTransferRects() { + this.transferRects + .add(new RecipeTransferRect(new Rectangle(6, 3, 16, 16), getOverlayIdentifier(), new Object[0])); + } + + @Override + public void loadCraftingRecipes(ItemStack result) { + if (result == null || (!DustDecayable.class.isInstance(result.getItem()) + && !BaseItemDustUnique.class.isInstance(result.getItem()))) { + return; + } + if (result != null) { + // Logger.INFO("Looking up crafting recipes for "+ItemUtils.getItemName(result)); + } + final List<DecayableRecipe> recipes = DecayableRecipe.mRecipes; + for (final DecayableRecipe recipe : recipes) { + if (recipe.isValid()) { + final ItemStack input = recipe.mInput.copy(); + final ItemStack output = recipe.mOutput.copy(); + if (!GT_Utility.areStacksEqual(result, output, true)) { + continue; + } + // Logger.INFO("Showing Usage result for "+ItemUtils.getItemName(result)); + final DecayableRecipeNEI rec = new DecayableRecipeNEI(input, output, recipe.mTime); + this.arecipes.add(rec); + sort(); + } + } + } + + @Override + public void loadCraftingRecipes(String outputId, Object... results) { + if (outputId.equals(getOverlayIdentifier()) && this.getClass() == DecayableRecipeHandler.class) { + final List<DecayableRecipe> recipes = DecayableRecipe.mRecipes; + for (final DecayableRecipe recipe : recipes) { + if (recipe.isValid()) { + final ItemStack input = recipe.mInput.copy(); + final ItemStack output = recipe.mOutput.copy(); + final DecayableRecipeNEI rec = new DecayableRecipeNEI(input, output, recipe.mTime); + this.arecipes.add(rec); + sort(); + } + } + } else { + super.loadCraftingRecipes(outputId, results); + } + } + + @Override + public void loadUsageRecipes(ItemStack ingredient) { + final List<DecayableRecipe> recipes = DecayableRecipe.mRecipes; + if (ingredient != null) { + // Logger.INFO("Looking up Usage results for "+ItemUtils.getItemName(ingredient)); + } + for (final DecayableRecipe recipe : recipes) { + if (recipe.isValid()) { + final ItemStack input = recipe.mInput.copy(); + final ItemStack output = recipe.mOutput.copy(); + if (!GT_Utility.areStacksEqual(ingredient, input, true)) { + continue; + } + // Logger.INFO("Showing up Usage results for "+ItemUtils.getItemName(ingredient)); + final DecayableRecipeNEI rec = new DecayableRecipeNEI(input, output, recipe.mTime); + // rec.setIngredientPermutation((Collection) rec.input, ingredient); + this.arecipes.add(rec); + sort(); + } + } + } + + private void sort() { + List<DecayableRecipeNEI> g = new ArrayList<>(); + for (CachedRecipe u : arecipes) { + g.add((DecayableRecipeNEI) u); + } + if (g != null && !g.isEmpty()) { + Collections.sort(g); + } + } + + @Override + public void drawExtras(int recipeIndex) { + DecayableRecipeNEI recipe = (DecayableRecipeNEI) this.arecipes.get(recipeIndex); + + // GuiDraw.drawStringC(I18n.format("GTPP.container.decaychest.result", new Object[]{}), 43, 10, 8421504, false); + + int cost = recipe.time; + if (cost > 0) { + + // NEI Strings + String s = I18n.format("GTPP.nei.info", new Object[] { cost }); + String s0 = I18n.format("GTPP.nei.timetaken", new Object[] { cost }); + + // Time Strings + String s1 = I18n.format("GTPP.time.ticks", new Object[] { cost }); + String s2 = I18n.format("GTPP.time.seconds", new Object[] { cost }); + String s3 = I18n.format("GTPP.time.minutes", new Object[] { cost }); + String s4 = I18n.format("GTPP.time.hours", new Object[] { cost }); + String s5 = I18n.format("GTPP.time.days", new Object[] { cost }); + String s6 = I18n.format("GTPP.time.months", new Object[] { cost }); + int y = 20; + + int secs = cost / 20; + int mins = secs / 60; + int hours = mins / 60; + int days = hours / 24; + int months = days / 30; + + String suffix; + int formattedTime; + if (cost <= 20) { + suffix = s1; + formattedTime = cost; + } else if (cost <= (20 * 60)) { + suffix = s2; + formattedTime = secs; + } else if (cost <= (20 * 60 * 60)) { + suffix = s3; + formattedTime = mins; + } else if (cost <= (20 * 60 * 60 * 24)) { + suffix = s4; + formattedTime = hours; + } else if (cost < (20 * 60 * 60 * 24 * 30)) { + suffix = s5; + formattedTime = days; + } else if (cost <= (20 * 60 * 60 * 24 * 30)) { + suffix = s6; + formattedTime = months; + } else { + suffix = s1; + formattedTime = cost; + } + + int x = 5; + GuiDraw.drawString(s, x, 25, VanillaColours.DYE_BLACK.getAsInt(), false); + GuiDraw.drawString(s0, x, 40, VanillaColours.DYE_BLACK.getAsInt(), false); + + GuiDraw.drawString(suffix, x + 16, y + 30, VanillaColours.DYE_BLACK.getAsInt(), false); + + // Values + GuiDraw.drawString(("" + formattedTime), x, y + 30, VanillaColours.DYE_GREEN.getAsInt(), false); + + if (hours > 1) { + int aLeftoverMinutes = (cost - (hours * (20 * 60 * 60))); + if (aLeftoverMinutes > 0) { + int secs2 = aLeftoverMinutes / 20; + int mins2 = secs2 / 60; + GuiDraw.drawString(s3, x + 16, y + 42, VanillaColours.DYE_BLACK.getAsInt(), false); + GuiDraw.drawString(("" + mins2), x, y + 42, VanillaColours.DYE_GREEN.getAsInt(), false); + } + } + } + + NeiTextureHandler.RECIPE_BUTTON.renderIcon(6.0D, 3.0D, 16.0D, 16.0D, 0.0D, true); + } + + public class DecayableRecipeNEI extends TemplateRecipeHandler.CachedRecipe implements Comparable<CachedRecipe> { + + private PositionedStack input; + private PositionedStack output; + public int time; + + @Override + public PositionedStack getIngredient() { + return this.input; + } + + @Override + public PositionedStack getResult() { + return this.output; + } + + public DecayableRecipeNEI(final ItemStack input, final ItemStack result, final int time) { + super(); + this.input = new PositionedStack(input, 93, 24); + this.output = new PositionedStack(result, 142, 42); + this.time = time; + } + + @Override + public int compareTo(CachedRecipe o) { + boolean b = DecayableRecipeNEI.class.isInstance(o); + if (b) { + DecayableRecipeNEI p = (DecayableRecipeNEI) o; + if (p.time > this.time) { + return 1; + } else if (p.time == this.time) { + return 0; + } else { + return -1; + } + } + return 0; + } + + @Override + public boolean equals(Object obj) { + if (obj != null) { + if (DecayableRecipeNEI.class.isInstance(obj)) { + DecayableRecipeNEI p = (DecayableRecipeNEI) obj; + if (p != null) { + // Time check first to keep it simple and not unbox the Recipes. + if (p.time == this.time) { + ItemStack aInput = p.input.item; + ItemStack aOutput = p.output.item; + if (GT_Utility.areStacksEqual(aInput, this.input.item, true)) { + if (GT_Utility.areStacksEqual(aOutput, this.output.item, true)) { + return true; + } + } + } + } + } + } + return false; + } + } +} diff --git a/src/main/java/gtPlusPlus/nei/GT_NEI_LFTR_Sparging.java b/src/main/java/gtPlusPlus/nei/GT_NEI_LFTR_Sparging.java new file mode 100644 index 0000000000..c7c657f04a --- /dev/null +++ b/src/main/java/gtPlusPlus/nei/GT_NEI_LFTR_Sparging.java @@ -0,0 +1,502 @@ +package gtPlusPlus.nei; + +import java.awt.Rectangle; +import java.lang.ref.SoftReference; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.stream.Collectors; + +import net.minecraft.client.Minecraft; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import org.lwjgl.opengl.GL11; + +import codechicken.lib.gui.GuiDraw; +import codechicken.nei.PositionedStack; +import codechicken.nei.recipe.GuiCraftingRecipe; +import codechicken.nei.recipe.GuiRecipe; +import codechicken.nei.recipe.GuiUsageRecipe; +import codechicken.nei.recipe.TemplateRecipeHandler; +import cpw.mods.fml.common.event.FMLInterModComms; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.ItemList; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.objects.ItemData; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.GasSpargingRecipe; +import gregtech.api.util.GasSpargingRecipeMap; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; + +public class GT_NEI_LFTR_Sparging extends TemplateRecipeHandler { + + public static final String mNEIName = GasSpargingRecipeMap.mNEIDisplayName; + private SoftReference<List<GasSpargingRecipeNEI>> mCachedRecipes = null; + + public GT_NEI_LFTR_Sparging() { + this.transferRects.add( + new TemplateRecipeHandler.RecipeTransferRect( + new Rectangle(65, 13, 36, 18), + this.getOverlayIdentifier(), + new Object[0])); + if (!NEI_GTPP_Config.sIsAdded) { + FMLInterModComms.sendRuntimeMessage( + GT_Values.GT, + "NEIPlugins", + "register-crafting-handler", + "gregtechplusplus@" + this.getRecipeName() + "@" + this.getOverlayIdentifier()); + GuiCraftingRecipe.craftinghandlers.add(this); + GuiUsageRecipe.usagehandlers.add(this); + } + } + + @Override + public String getRecipeName() { + return mNEIName; + } + + @Override + public String getGuiTexture() { + return GasSpargingRecipeMap.mNEIGUIPath; + } + + @Override + public String getOverlayIdentifier() { + return gregtech.api.util.GasSpargingRecipeMap.mUnlocalizedName; + } + + @Override + public int recipiesPerPage() { + return 1; + } + + @Override + public void drawBackground(final int recipe) { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GuiDraw.changeTexture(this.getGuiTexture()); + GuiDraw.drawTexturedModalRect(-4, -8, 1, 3, 174, 68); + } + + @Override + public void loadTransferRects() { + this.transferRects + .add(new RecipeTransferRect(new Rectangle(72, 14, 22, 16), getOverlayIdentifier(), new Object[0])); + } + + public List<GasSpargingRecipeNEI> getCache() { + List<GasSpargingRecipeNEI> cache; + if (mCachedRecipes == null || (cache = mCachedRecipes.get()) == null) { + cache = GasSpargingRecipeMap.mRecipes.stream() // do not use parallel stream. This is already parallelized + // by NEI + .sorted() + .map(temp -> createCachedRecipe(temp)) + .collect(Collectors.toList()); + // while the NEI parallelize handlers, for each individual handler it still uses sequential execution model + // so we do not need any synchronization here + mCachedRecipes = new SoftReference<>(cache); + } + return cache; + } + + public GasSpargingRecipeNEI createCachedRecipe(GasSpargingRecipe aRecipe) { + return new GasSpargingRecipeNEI(aRecipe); + } + + @Override + public void loadCraftingRecipes(String outputId, Object... results) { + if (outputId.equals(getOverlayIdentifier())) { + arecipes.addAll(getCache()); + } else { + super.loadCraftingRecipes(outputId, results); + } + } + + @Override + public void loadCraftingRecipes(ItemStack aResult) { + ItemData tPrefixMaterial = GT_OreDictUnificator.getAssociation(aResult); + + ArrayList<ItemStack> tResults = new ArrayList<>(); + tResults.add(aResult); + tResults.add(GT_OreDictUnificator.get(true, aResult)); + if ((tPrefixMaterial != null) && (!tPrefixMaterial.mBlackListed) + && (!tPrefixMaterial.mPrefix.mFamiliarPrefixes.isEmpty())) { + for (OrePrefixes tPrefix : tPrefixMaterial.mPrefix.mFamiliarPrefixes) { + tResults.add(GT_OreDictUnificator.get(tPrefix, tPrefixMaterial.mMaterial.mMaterial, 1L)); + } + } + FluidStack tFluid = GT_Utility.getFluidForFilledItem(aResult, true); + FluidStack tFluidStack; + if (tFluid != null) { + tFluidStack = tFluid; + tResults.add(GT_Utility.getFluidDisplayStack(tFluid, false)); + } else tFluidStack = GT_Utility.getFluidFromDisplayStack(aResult); + if (tFluidStack != null) { + tResults.addAll(GT_Utility.getContainersFromFluid(tFluidStack)); + } + for (GasSpargingRecipeNEI recipe : getCache()) { + if (tResults.stream() + .anyMatch(stack -> recipe.contains(recipe.mOutputs, stack))) arecipes.add(recipe); + } + } + + @Override + public void loadUsageRecipes(ItemStack aInput) { + ItemData tPrefixMaterial = GT_OreDictUnificator.getAssociation(aInput); + + ArrayList<ItemStack> tInputs = new ArrayList<>(); + tInputs.add(aInput); + tInputs.add(GT_OreDictUnificator.get(false, aInput)); + if ((tPrefixMaterial != null) && (!tPrefixMaterial.mPrefix.mFamiliarPrefixes.isEmpty())) { + for (OrePrefixes tPrefix : tPrefixMaterial.mPrefix.mFamiliarPrefixes) { + tInputs.add(GT_OreDictUnificator.get(tPrefix, tPrefixMaterial.mMaterial.mMaterial, 1L)); + } + } + FluidStack tFluid = GT_Utility.getFluidForFilledItem(aInput, true); + FluidStack tFluidStack; + if (tFluid != null) { + tFluidStack = tFluid; + tInputs.add(GT_Utility.getFluidDisplayStack(tFluid, false)); + } else tFluidStack = GT_Utility.getFluidFromDisplayStack(aInput); + if (tFluidStack != null) { + tInputs.addAll(GT_Utility.getContainersFromFluid(tFluidStack)); + } + for (GasSpargingRecipeNEI recipe : getCache()) { + if (tInputs.stream() + .anyMatch(stack -> recipe.contains(recipe.mInputs, stack))) arecipes.add(recipe); + } + } + + protected static void drawText(int aX, int aY, String aString, int aColor) { + Minecraft.getMinecraft().fontRenderer.drawString(aString, aX, aY, aColor); + } + + @Override + public void drawExtras(int aRecipeIndex) { + final long tEUt = ((GasSpargingRecipeNEI) this.arecipes.get(aRecipeIndex)).mRecipe.mEUt; + final long tDuration = ((GasSpargingRecipeNEI) this.arecipes.get(aRecipeIndex)).mRecipe.mDuration; + drawText(10, 73, "Total: " + MathUtils.formatNumbers((long) (tDuration * tEUt)) + " EU", -16777216); + drawText(10, 83, "Usage: " + MathUtils.formatNumbers(tEUt) + " EU/t", -16777216); + drawText( + 10, + 93, + "Time: " + (tDuration < 20 ? "< 1" : MathUtils.formatNumbers(0.05d * tDuration)) + " secs", + -16777216); + drawText(10, 103, "Gas not used to sparge is", -16777216); + drawText(10, 113, "returned alongside outputs.", -16777216); + } + + @Override + public List<String> handleItemTooltip(final GuiRecipe<?> gui, final ItemStack aStack, final List<String> currenttip, + final int aRecipeIndex) { + final TemplateRecipeHandler.CachedRecipe tObject = this.arecipes.get(aRecipeIndex); + if ((tObject instanceof final GasSpargingRecipeNEI tRecipe)) { + ItemStack aSpargeInput = tRecipe.mOutputs.get(0).item; + ItemStack aSpentFuel = tRecipe.mOutputs.get(1).item; + for (final PositionedStack tStack : tRecipe.mOutputs) { + if (aStack == tStack.item) { + if (ItemList.Display_Fluid.isStackEqual(tStack.item, true, true)) { + if (GT_Utility.areStacksEqual(aStack, aSpentFuel, true)) { + break; + } + if (GT_Utility.areStacksEqual(aStack, aSpargeInput, true)) { + currenttip.add("The amount returned is the remainder after all other outputs."); + } + currenttip.add( + "Maximum Output: " + (((FixedPositionedStack) tStack).mChance / 100) + + "." + + ((((FixedPositionedStack) tStack).mChance % 100) < 10 + ? "0" + (((FixedPositionedStack) tStack).mChance % 100) + : Integer.valueOf(((FixedPositionedStack) tStack).mChance % 100)) + + "L"); + break; + } + break; + } + } + for (final PositionedStack tStack : tRecipe.mInputs) { + if (GT_Utility.areStacksEqual(aStack, tStack.item)) { + if ((gregtech.api.enums.ItemList.Display_Fluid.isStackEqual(tStack.item, true, true)) + || (tStack.item.stackSize != 0)) { + break; + } + if (ItemUtils.isControlCircuit(aStack)) { + currenttip.add("Does not get consumed in the process"); + } + break; + } + } + } + return currenttip; + } + + public class FixedPositionedStack extends PositionedStack { + + public final int mChance; + public boolean permutated = false; + + public FixedPositionedStack(final Object object, final int x, final int y) { + this(object, x, y, 0); + } + + public FixedPositionedStack(final Object object, final int x, final int y, final int aChance) { + super(object, x, y, true); + this.mChance = aChance; + } + + @Override + public void generatePermutations() { + if (this.permutated) { + return; + } + final ArrayList<ItemStack> tDisplayStacks = new ArrayList<>(); + for (final ItemStack tStack : this.items) { + if (GT_Utility.isStackValid(tStack)) { + if (tStack.getItemDamage() == 32767) { + final List<ItemStack> permutations = codechicken.nei.ItemList.itemMap.get(tStack.getItem()); + if (!permutations.isEmpty()) { + ItemStack stack; + for (final Iterator<ItemStack> i$ = permutations.iterator(); i$.hasNext(); tDisplayStacks + .add(GT_Utility.copyAmount(tStack.stackSize, new Object[] { stack }))) { + stack = i$.next(); + } + } else { + final ItemStack base = new ItemStack(tStack.getItem(), tStack.stackSize); + base.stackTagCompound = tStack.stackTagCompound; + tDisplayStacks.add(base); + } + } else { + tDisplayStacks.add(GT_Utility.copy(new Object[] { tStack })); + } + } + } + this.items = (tDisplayStacks.toArray(new ItemStack[0])); + if (this.items.length == 0) { + this.items = new ItemStack[] { new ItemStack(Blocks.fire) }; + } + this.permutated = true; + this.setPermutationToRender(0); + } + } + + public class GasSpargingRecipeNEI extends CachedRecipe implements Comparable<CachedRecipe> { + + public final GasSpargingRecipe mRecipe; + public final List<PositionedStack> mOutputs = new ArrayList<>(); + public final List<PositionedStack> mInputs = new ArrayList<>(); + + public GasSpargingRecipeNEI(GasSpargingRecipe tRecipe) { + super(); + this.mRecipe = tRecipe; + int tStartIndex = 0; + if (tRecipe.mFluidInputs.length > 0) { + if ((tRecipe.mFluidInputs[0] != null) && (tRecipe.mFluidInputs[0].getFluid() != null)) { + this.mInputs.add( + new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(tRecipe.mFluidInputs[0], true), + 30, + 5)); + } + if ((tRecipe.mFluidInputs.length > 1) && (tRecipe.mFluidInputs[1] != null) + && (tRecipe.mFluidInputs[1].getFluid() != null)) { + this.mInputs.add( + new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(tRecipe.mFluidInputs[1], true), + 12, + 5)); + } + if ((tRecipe.mFluidInputs.length > 2) && (tRecipe.mFluidInputs[2] != null) + && (tRecipe.mFluidInputs[2].getFluid() != null)) { + this.mInputs.add( + new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(tRecipe.mFluidInputs[2], true), + 48, + 5)); + } + if ((tRecipe.mFluidInputs.length > 3) && (tRecipe.mFluidInputs[3] != null) + && (tRecipe.mFluidInputs[3].getFluid() != null)) { + this.mInputs.add( + new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(tRecipe.mFluidInputs[3], true), + 12, + 23)); + } + if ((tRecipe.mFluidInputs.length > 4) && (tRecipe.mFluidInputs[4] != null) + && (tRecipe.mFluidInputs[4].getFluid() != null)) { + this.mInputs.add( + new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(tRecipe.mFluidInputs[4], true), + 30, + 23)); + } + if ((tRecipe.mFluidInputs.length > 5) && (tRecipe.mFluidInputs[5] != null) + && (tRecipe.mFluidInputs[5].getFluid() != null)) { + this.mInputs.add( + new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(tRecipe.mFluidInputs[5], true), + 48, + 23)); + } + if ((tRecipe.mFluidInputs.length > 6) && (tRecipe.mFluidInputs[6] != null) + && (tRecipe.mFluidInputs[6].getFluid() != null)) { + this.mInputs.add( + new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(tRecipe.mFluidInputs[6], true), + 12, + 41)); + } + if ((tRecipe.mFluidInputs.length > 7) && (tRecipe.mFluidInputs[7] != null) + && (tRecipe.mFluidInputs[7].getFluid() != null)) { + this.mInputs.add( + new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(tRecipe.mFluidInputs[7], true), + 30, + 41)); + } + if ((tRecipe.mFluidInputs.length > 8) && (tRecipe.mFluidInputs[8] != null) + && (tRecipe.mFluidInputs[8].getFluid() != null)) { + this.mInputs.add( + new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(tRecipe.mFluidInputs[8], true), + 48, + 41)); + } + } + + tStartIndex = 0; + if (tRecipe.mFluidOutputs.length > 0) { + if ((tRecipe.mFluidOutputs[0] != null) && (tRecipe.mFluidOutputs[0].getFluid() != null)) { + this.mOutputs.add( + new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(tRecipe.mFluidOutputs[0], false), + 120, + 5, + tRecipe.getMaxOutput(tStartIndex++))); + } + if ((tRecipe.mFluidOutputs.length > 1) && (tRecipe.mFluidOutputs[1] != null) + && (tRecipe.mFluidOutputs[1].getFluid() != null)) { + this.mOutputs.add( + new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(tRecipe.mFluidOutputs[1], true), + 102, + 5, + tRecipe.getMaxOutput(tStartIndex++))); + } + if ((tRecipe.mFluidOutputs.length > 2) && (tRecipe.mFluidOutputs[2] != null) + && (tRecipe.mFluidOutputs[2].getFluid() != null)) { + this.mOutputs.add( + new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(tRecipe.mFluidOutputs[2], false), + 138, + 5, + tRecipe.getMaxOutput(tStartIndex++))); + } + if ((tRecipe.mFluidOutputs.length > 3) && (tRecipe.mFluidOutputs[3] != null) + && (tRecipe.mFluidOutputs[3].getFluid() != null)) { + this.mOutputs.add( + new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(tRecipe.mFluidOutputs[3], false), + 102, + 23, + tRecipe.getMaxOutput(tStartIndex++))); + } + if ((tRecipe.mFluidOutputs.length > 4) && (tRecipe.mFluidOutputs[4] != null) + && (tRecipe.mFluidOutputs[4].getFluid() != null)) { + this.mOutputs.add( + new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(tRecipe.mFluidOutputs[4], false), + 120, + 23, + tRecipe.getMaxOutput(tStartIndex++))); + } + if ((tRecipe.mFluidOutputs.length > 5) && (tRecipe.mFluidOutputs[5] != null) + && (tRecipe.mFluidOutputs[5].getFluid() != null)) { + this.mOutputs.add( + new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(tRecipe.mFluidOutputs[5], false), + 138, + 23, + tRecipe.getMaxOutput(tStartIndex++))); + } + if ((tRecipe.mFluidOutputs.length > 6) && (tRecipe.mFluidOutputs[6] != null) + && (tRecipe.mFluidOutputs[6].getFluid() != null)) { + this.mOutputs.add( + new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(tRecipe.mFluidOutputs[6], false), + 102, + 41, + tRecipe.getMaxOutput(tStartIndex++))); + } + if ((tRecipe.mFluidOutputs.length > 7) && (tRecipe.mFluidOutputs[7] != null) + && (tRecipe.mFluidOutputs[7].getFluid() != null)) { + this.mOutputs.add( + new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(tRecipe.mFluidOutputs[7], false), + 120, + 41, + tRecipe.getMaxOutput(tStartIndex++))); + } + if ((tRecipe.mFluidOutputs.length > 8) && (tRecipe.mFluidOutputs[8] != null) + && (tRecipe.mFluidOutputs[8].getFluid() != null)) { + this.mOutputs.add( + new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(tRecipe.mFluidOutputs[8], false), + 138, + 41, + tRecipe.getMaxOutput(tStartIndex++))); + } + } + } + + @Override + public int compareTo(CachedRecipe o) { + boolean b = GasSpargingRecipeNEI.class.isInstance(o); + if (b) { + GasSpargingRecipeNEI p = (GasSpargingRecipeNEI) o; + if (p.mOutputs.size() > this.mOutputs.size()) { + return 1; + } else if (p.mOutputs.size() == this.mOutputs.size()) { + return 0; + } else { + return -1; + } + } + return 0; + } + + @Override + public boolean equals(Object obj) { + if (obj != null) { + if (GasSpargingRecipeNEI.class.isInstance(obj)) { + GasSpargingRecipeNEI p = (GasSpargingRecipeNEI) obj; + if (p != null) { + if (GT_Utility.areStacksEqual(p.mInputs.get(0).item, this.mInputs.get(0).item, true)) { + if (p.mOutputs.size() == this.mOutputs.size()) { + return true; + } + } + } + } + } + return false; + } + + @Override + public List<PositionedStack> getIngredients() { + return this.getCycledIngredients(GT_NEI_LFTR_Sparging.this.cycleticks / 10, this.mInputs); + } + + @Override + public PositionedStack getResult() { + return null; + } + + @Override + public List<PositionedStack> getOtherStacks() { + return this.mOutputs; + } + } +} diff --git a/src/main/java/gtPlusPlus/nei/NEI_GTPP_Config.java b/src/main/java/gtPlusPlus/nei/NEI_GTPP_Config.java new file mode 100644 index 0000000000..16cc1e8cbf --- /dev/null +++ b/src/main/java/gtPlusPlus/nei/NEI_GTPP_Config.java @@ -0,0 +1,102 @@ +package gtPlusPlus.nei; + +import java.util.Arrays; + +import net.minecraft.item.ItemStack; + +import codechicken.nei.api.API; +import codechicken.nei.api.IConfigureNEI; +import codechicken.nei.event.NEIRegisterHandlerInfosEvent; +import codechicken.nei.recipe.HandlerInfo; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import gregtech.api.enums.Mods; +import gregtech.api.recipe.RecipeMaps; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; + +public class NEI_GTPP_Config implements IConfigureNEI { + + public static boolean sIsAdded = true; + + @Override + public synchronized void loadConfig() { + sIsAdded = false; + + Logger.INFO("NEI Registration: Registering NEI handler for " + DecayableRecipeHandler.mNEIName); + API.registerRecipeHandler(new DecayableRecipeHandler()); + API.registerUsageHandler(new DecayableRecipeHandler()); + API.addRecipeCatalyst(new ItemStack(ModBlocks.blockDecayablesChest, 1), "GTPP_Decayables"); + + Logger.INFO("NEI Registration: Registering NEI handler for " + GT_NEI_LFTR_Sparging.mNEIName); + new GT_NEI_LFTR_Sparging(); + API.addRecipeCatalyst(GregtechItemList.Controller_Sparge_Tower.get(1), "gtpp.recipe.lftr.sparging"); + + for (GregtechItemList item : Arrays.asList( + GregtechItemList.GT4_Electric_Auto_Workbench_LV, + GregtechItemList.GT4_Electric_Auto_Workbench_MV, + GregtechItemList.GT4_Electric_Auto_Workbench_HV, + GregtechItemList.GT4_Electric_Auto_Workbench_EV, + GregtechItemList.GT4_Electric_Auto_Workbench_IV, + GregtechItemList.GT4_Electric_Auto_Workbench_LuV, + GregtechItemList.GT4_Electric_Auto_Workbench_ZPM, + GregtechItemList.GT4_Electric_Auto_Workbench_UV)) { + API.addRecipeCatalyst(item.get(1), "crafting", -10); + } + // Bronze workbench + API.removeRecipeCatalyst(ItemUtils.getItemStackFromFQRN("gregtech:gt.blockmachines:31081", 1), "crafting"); + API.removeRecipeCatalyst(ItemUtils.getItemStackFromFQRN("gregtech:gt.blockmachines:31082", 1), "crafting"); + + // Moved to its own handler + API.removeRecipeCatalyst( + GregtechItemList.Controller_Vacuum_Furnace.get(1), + GTPPRecipeMaps.chemicalDehydratorRecipes.unlocalizedName); + + // ULV simple washer + API.removeRecipeCatalyst( + ItemUtils.getItemStackFromFQRN("gregtech:gt.blockmachines:767", 1), + GTPPRecipeMaps.simpleWasherRecipes.unlocalizedName); + + // ULV combustion generator + API.removeRecipeCatalyst( + ItemUtils.getItemStackFromFQRN("gregtech:gt.blockmachines:960", 1), + RecipeMaps.dieselFuels.unlocalizedName); + + // ULV gas turbine + API.removeRecipeCatalyst( + ItemUtils.getItemStackFromFQRN("gregtech:gt.blockmachines:961", 1), + RecipeMaps.gasTurbineFuels.unlocalizedName); + + // Hide Flasks + if (Utils.isClient()) { + API.addItemListEntry(GregtechItemList.VOLUMETRIC_FLASK_8k.get(1)); + API.addItemListEntry(GregtechItemList.VOLUMETRIC_FLASK_32k.get(1)); + } + sIsAdded = true; + } + + @SubscribeEvent + public void registerHandlerInfo(NEIRegisterHandlerInfosEvent event) { + event.registerHandlerInfo( + new HandlerInfo.Builder("gtpp.recipe.lftr.sparging", CORE.name, Mods.GTPlusPlus.ID) + .setDisplayStack(GregtechItemList.Controller_Sparge_Tower.get(1)) + .setShiftY(6) + .setHeight(135) + .setMaxRecipesPerPage(1) + .build()); + } + + @Override + public String getName() { + return "GT++ NEI Plugin"; + } + + @Override + public String getVersion() { + return "(1.12)"; + } +} diff --git a/src/main/java/gtPlusPlus/nei/handlers/NeiTextureHandler.java b/src/main/java/gtPlusPlus/nei/handlers/NeiTextureHandler.java new file mode 100644 index 0000000000..2644ffb4ff --- /dev/null +++ b/src/main/java/gtPlusPlus/nei/handlers/NeiTextureHandler.java @@ -0,0 +1,126 @@ +package gtPlusPlus.nei.handlers; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; + +/** + * Based on crazypants.enderio.gui.IconEIO + * + * @author Original EIO Author + * + * This is free and unencumbered software released into the public domain. + * + * Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source + * code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. + * + * In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all + * copyright interest in the software to the public domain. We make this dedication for the benefit of the + * public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt + * act of relinquishment in perpetuity of all present and future rights to this software under copyright law. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED + * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * For more information, please refer to <http://unlicense.org/> + * + * https://github.com/SleepyTrousers/EnderIO/blob/release/1.7.10/2.2/src/main/java/crazypants/render/RenderUtil.java + * + */ +public final class NeiTextureHandler { + + public static final NeiTextureHandler RECIPE_BUTTON = new NeiTextureHandler(128, 116, 24, 24); + + public final double minU; + public final double maxU; + public final double minV; + public final double maxV; + public final double width; + public final double height; + + public static final ResourceLocation TEXTURE = new ResourceLocation( + GTPlusPlus.ID + ":textures/gui/nei/widgets.png"); + + public NeiTextureHandler(int x, int y, int width, int height) { + this( + width, + height, + (float) (0.00390625D * (double) x), + (float) (0.00390625D * (double) (x + width)), + (float) (0.00390625D * (double) y), + (float) (0.00390625D * (double) (y + height))); + } + + public NeiTextureHandler(double width, double height, double minU, double maxU, double minV, double maxV) { + this.width = width; + this.height = height; + this.minU = minU; + this.maxU = maxU; + this.minV = minV; + this.maxV = maxV; + } + + public void renderIcon(double x, double y, double width, double height, double zLevel, boolean doDraw) { + this.renderIcon(x, y, width, height, zLevel, doDraw, false); + } + + public void renderIcon(double x, double y, double width, double height, double zLevel, boolean doDraw, + boolean flipY) { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + Tessellator tessellator = Tessellator.instance; + if (doDraw) { + bindTexture(TEXTURE); + tessellator.startDrawingQuads(); + } + + if (flipY) { + tessellator.addVertexWithUV(x, y + height, zLevel, this.minU, this.minV); + tessellator.addVertexWithUV(x + width, y + height, zLevel, this.maxU, this.minV); + tessellator.addVertexWithUV(x + width, y + 0.0D, zLevel, this.maxU, this.maxV); + tessellator.addVertexWithUV(x, y + 0.0D, zLevel, this.minU, this.maxV); + } else { + tessellator.addVertexWithUV(x, y + height, zLevel, this.minU, this.maxV); + tessellator.addVertexWithUV(x + width, y + height, zLevel, this.maxU, this.maxV); + tessellator.addVertexWithUV(x + width, y + 0.0D, zLevel, this.maxU, this.minV); + tessellator.addVertexWithUV(x, y + 0.0D, zLevel, this.minU, this.minV); + } + + if (doDraw) { + tessellator.draw(); + } + } + + public static final ResourceLocation BLOCK_TEX; + public static final ResourceLocation ITEM_TEX; + public static final ResourceLocation GLINT_TEX; + public static int BRIGHTNESS_MAX; + + static { + BLOCK_TEX = TextureMap.locationBlocksTexture; + ITEM_TEX = TextureMap.locationItemsTexture; + GLINT_TEX = new ResourceLocation("textures/misc/enchanted_item_glint.png"); + BRIGHTNESS_MAX = 15728880; + } + + public static TextureManager engine() { + return Minecraft.getMinecraft().renderEngine; + } + + public static void bindTexture(String string) { + engine().bindTexture(new ResourceLocation(string)); + } + + public static void bindTexture(ResourceLocation tex) { + engine().bindTexture(tex); + } + +} |