aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtneioreplugin/plugin/gregtech5/PluginGT5UndergroundFluid.java
blob: bd1bbf0a007c9ea21a8dceaeeb609d3776829182 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package gtneioreplugin.plugin.gregtech5;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;

import codechicken.lib.gui.GuiDraw;
import codechicken.nei.PositionedStack;
import gregtech.api.util.GTUtility;
import gtneioreplugin.plugin.PluginBase;
import gtneioreplugin.plugin.item.ItemDimensionDisplay;
import gtneioreplugin.util.GT5UndergroundFluidHelper;
import gtneioreplugin.util.GT5UndergroundFluidHelper.UndergroundFluidWrapper;

public class PluginGT5UndergroundFluid extends PluginBase {

    private static final int lineSpace = 20;
    private static final int xDimensionDisplay = 30;
    private static final int halfItemLength = 16 / 2;
    private static final DecimalFormat format = new DecimalFormat("0.#");

    @Override
    public void loadCraftingRecipes(String outputId, Object... results) {
        if (outputId.equals(getOutputId())) {
            for (Map.Entry<String, List<UndergroundFluidWrapper>> entry : GT5UndergroundFluidHelper.getAllEntries()
                .entrySet()) {
                Fluid fluid = FluidRegistry.getFluid(entry.getKey());
                if (fluid != null) {
                    this.arecipes.add(new CachedUndergroundFluidRecipe(fluid, entry.getValue()));
                }
            }
        } else {
            super.loadCraftingRecipes(outputId, results);
        }
    }

    @Override
    public void loadCraftingRecipes(ItemStack result) {
        Fluid fluid = null;
        FluidStack containerFluid = GTUtility.getFluidForFilledItem(result, true);
        if (containerFluid != null) {
            fluid = containerFluid.getFluid();
        }
        if (fluid == null) {
            FluidStack displayFluid = GTUtility.getFluidFromDisplayStack(result);
            if (displayFluid != null) {
                fluid = displayFluid.getFluid();
            }
        }
        if (fluid == null) return;

        List<UndergroundFluidWrapper> wrappers = GT5UndergroundFluidHelper.getEntry(fluid.getName());
        if (wrappers != null) {
            this.arecipes.add(new CachedUndergroundFluidRecipe(fluid, wrappers));
        }
    }

    @Override
    public void loadUsageRecipes(ItemStack ingredient) {
        String dimension = ItemDimensionDisplay.getDimension(ingredient);
        if (dimension != null) {
            for (Map.Entry<String, List<UndergroundFluidWrapper>> entry : GT5UndergroundFluidHelper.getAllEntries()
                .entrySet()) {
                boolean found = false;
                for (UndergroundFluidWrapper wrapper : entry.getValue()) {
                    if (wrapper.dimension.equals(dimension)) {
                        found = true;
                        break;
                    }
                }
                if (found) {
                    Fluid fluid = FluidRegistry.getFluid(entry.getKey());
                    if (fluid != null) {
                        this.arecipes.add(new CachedUndergroundFluidRecipe(fluid, entry.getValue()));
                    }
                }
            }
        }
    }

    @Override
    public void drawExtras(int recipeIndex) {
        drawSeeAllRecipesLabel();

        int xChance = 85;
        int xAmount = 140;
        int yHeader = 30;
        int black = 0x404040;

        GuiDraw.drawStringC(I18n.format("gtnop.gui.nei.dimension") + ":", xDimensionDisplay, yHeader, black, false);
        GuiDraw.drawStringC(I18n.format("gtnop.gui.nei.chance") + ":", xChance, yHeader, black, false);
        GuiDraw.drawStringC(I18n.format("gtnop.gui.nei.fluidAmount") + ":", xAmount, yHeader, black, false);

        int y = 50;
        CachedUndergroundFluidRecipe recipe = (CachedUndergroundFluidRecipe) this.arecipes.get(recipeIndex);
        for (int i = 0; i < recipe.dimensionDisplayItems.size(); i++) {
            GuiDraw.drawStringC(format.format((double) recipe.chances.get(i) / 100) + "%", xChance, y, black, false);
            GuiDraw.drawStringC(
                recipe.minAmounts.get(i)
                    .toString() + "-"
                    + recipe.maxAmounts.get(i)
                        .toString(),
                xAmount,
                y,
                black,
                false);
            y += lineSpace;
        }
    }

    @Override
    public String getOutputId() {
        return "GTOrePluginUndergroundFluid";
    }

    @Override
    public String getRecipeName() {
        return I18n.format("gtnop.gui.undergroundFluid.name");
    }

    private class CachedUndergroundFluidRecipe extends CachedRecipe {

        private final PositionedStack targetFluidDisplay;
        private final List<PositionedStack> dimensionDisplayItems = new ArrayList<>();
        private final List<Integer> chances = new ArrayList<>();
        private final List<Integer> maxAmounts = new ArrayList<>();
        private final List<Integer> minAmounts = new ArrayList<>();

        private CachedUndergroundFluidRecipe(Fluid fluid, List<UndergroundFluidWrapper> wrappers) {
            targetFluidDisplay = new PositionedStack(
                GTUtility.getFluidDisplayStack(fluid),
                getGuiWidth() / 2 - halfItemLength,
                3);
            int y = 50 - halfItemLength;
            for (UndergroundFluidWrapper wrapper : wrappers) {
                ItemStack dimensionDisplay = ItemDimensionDisplay.getItem(wrapper.dimension);
                if (dimensionDisplay != null) {
                    dimensionDisplayItems.add(
                        new PositionedStack(
                            dimensionDisplay,
                            xDimensionDisplay - halfItemLength,
                            y + GuiDraw.fontRenderer.FONT_HEIGHT / 2));
                    y += lineSpace;
                    chances.add(wrapper.chance);
                    maxAmounts.add(wrapper.maxAmount);
                    minAmounts.add(wrapper.minAmount);
                }
            }
        }

        @Override
        public PositionedStack getResult() {
            return targetFluidDisplay;
        }

        @Override
        public List<PositionedStack> getIngredients() {
            return dimensionDisplayItems;
        }
    }
}