aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/goodgenerator/blocks/tileEntity/MTECoolantTower.java
blob: be0fe5b4ce650a5107c2fb823e7fab5ffaca15ed (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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package goodgenerator.blocks.tileEntity;

import static com.gtnewhorizon.structurelib.structure.StructureUtility.*;
import static goodgenerator.util.DescTextLocalization.BLUE_PRINT_INFO;
import static gregtech.api.enums.Textures.BlockIcons.*;
import static gregtech.api.util.GTStructureUtility.*;
import static gregtech.api.util.GTUtility.filterValidMTEs;

import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;

import org.jetbrains.annotations.NotNull;

import com.gtnewhorizon.structurelib.alignment.constructable.IConstructable;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment;
import com.gtnewhorizon.structurelib.structure.StructureDefinition;

import goodgenerator.blocks.tileEntity.base.MTETooltipMultiBlockBaseEM;
import goodgenerator.util.DescTextLocalization;
import gregtech.api.GregTechAPI;
import gregtech.api.enums.Materials;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.MTEHatchInput;
import gregtech.api.metatileentity.implementations.MTEHatchMultiInput;
import gregtech.api.recipe.check.CheckRecipeResult;
import gregtech.api.recipe.check.CheckRecipeResultRegistry;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GTModHandler;
import gregtech.api.util.GTUtility;
import gregtech.api.util.MultiblockTooltipBuilder;
import tectech.thing.metaTileEntity.multi.base.TTMultiblockBase;

public class MTECoolantTower extends MTETooltipMultiBlockBaseEM implements IConstructable, ISurvivalConstructable {

    protected IStructureDefinition<MTECoolantTower> multiDefinition = null;
    private static final int CASING_INDEX = 1539;

    public MTECoolantTower(int aID, String aName, String aNameRegional) {
        super(aID, aName, aNameRegional);
    }

    public MTECoolantTower(String name) {
        super(name);
    }

    @Override
    public IStructureDefinition<? extends TTMultiblockBase> getStructure_EM() {
        if (multiDefinition == null) {
            multiDefinition = StructureDefinition.<MTECoolantTower>builder()
                .addShape(
                    mName,
                    transpose(
                        new String[][] {
                            { "           ", "           ", "    BBB    ", "   B   B   ", "  B     B  ", "  B     B  ",
                                "  B     B  ", "   B   B   ", "    BBB    ", "           ", "           " },
                            { "           ", "           ", "    BBB    ", "   BBBBB   ", "  BB   BB  ", "  BB   BB  ",
                                "  BB   BB  ", "   BBBBB   ", "    BBB    ", "           ", "           " },
                            { "           ", "           ", "           ", "    BBB    ", "   B   B   ", "   B   B   ",
                                "   B   B   ", "    BBB    ", "           ", "           ", "           " },
                            { "           ", "           ", "           ", "    BBB    ", "   B   B   ", "   B   B   ",
                                "   B   B   ", "    BBB    ", "           ", "           ", "           " },
                            { "           ", "           ", "           ", "    BBB    ", "   B   B   ", "   B   B   ",
                                "   B   B   ", "    BBB    ", "           ", "           ", "           " },
                            { "           ", "           ", "    BBB    ", "   BBBBB   ", "  BB   BB  ", "  BB   BB  ",
                                "  BB   BB  ", "   BBBBB   ", "    BBB    ", "           ", "           " },
                            { "           ", "           ", "    BBB    ", "   B   B   ", "  B     B  ", "  B     B  ",
                                "  B     B  ", "   B   B   ", "    BBB    ", "           ", "           " },
                            { "           ", "           ", "    BBB    ", "   B   B   ", "  B     B  ", "  B     B  ",
                                "  B     B  ", "   B   B   ", "    BBB    ", "           ", "           " },
                            { "           ", "    BBB    ", "   BBBBB   ", "  BB   BB  ", " BB     BB ", " BB     BB ",
                                " BB     BB ", "  BB   BB  ", "   BBBBB   ", "    BBB    ", "           " },
                            { "           ", "    BBB    ", "   B   B   ", "  B     B  ", " B       B ", " B       B ",
                                " B       B ", "  B     B  ", "   B   B   ", "    BBB    ", "           " },
                            { "           ", "   BBBBB   ", "  BB   BB  ", " BB     BB ", " B       B ", " B       B ",
                                " B       B ", " BB     BB ", "  BB   BB  ", "   BBBBB   ", "           " },
                            { "   HH~HH   ", "  HBBBBBH  ", " HB     BH ", "HB       BH", "HB       BH", "HB       BH",
                                "HB       BH", "HB       BH", " HB     BH ", "  HBBBBBH  ", "   HHHHH   " },
                            { "   CCCCC   ", "  C     C  ", " C       C ", "C         C", "C         C", "C         C",
                                "C         C", "C         C", " C       C ", "  C     C  ", "   CCCCC   " }, }))
                .addElement('B', ofBlockAnyMeta(GregTechAPI.sBlockConcretes, 8))
                .addElement('C', ofFrame(Materials.TungstenCarbide))
                .addElement(
                    'H',
                    buildHatchAdder(MTECoolantTower.class)
                        .atLeast(
                            gregtech.api.enums.HatchElement.InputHatch,
                            gregtech.api.enums.HatchElement.OutputHatch)
                        .casingIndex(CASING_INDEX)
                        .dot(1)
                        .buildAndChain(ofBlockAnyMeta(GregTechAPI.sBlockConcretes, 8)))
                .build();
        }
        return multiDefinition;
    }

    @Override
    public boolean checkMachine_EM(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) {
        return structureCheck_EM(mName, 5, 11, 0);
    }

    @Override
    protected MultiblockTooltipBuilder createTooltip() {
        final MultiblockTooltipBuilder tt = new MultiblockTooltipBuilder();
        tt.addMachineType("Coolant Tower")
            .addInfo("Controller block for the Coolant Tower.")
            .addInfo("Turn Steam back to Distilled Water.")
            .addInfo(BLUE_PRINT_INFO)
            .addSeparator()
            .addController("Mid of the second layer.")
            .addInputHatch("Input Hatch", 1)
            .addOutputHatch("Output Hatch", 1)
            .toolTipFinisher("Good Generator");
        return tt;
    }

    @Override
    public void construct(ItemStack stackSize, boolean hintsOnly) {
        structureBuild_EM(mName, 5, 11, 0, stackSize, hintsOnly);
    }

    @Override
    public String[] getStructureDescription(ItemStack stackSize) {
        return DescTextLocalization.addText("CoolantTower.hint", 3);
    }

    @Override
    public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
        return new MTECoolantTower(mName);
    }

    @Override
    public int getMaxEfficiency(ItemStack aStack) {
        return 10000;
    }

    @Override
    public boolean onRunningTick(ItemStack aStack) {
        return true;
    }

    @Override
    protected @NotNull CheckRecipeResult checkProcessing_EM() {
        this.mMaxProgresstime = 20;
        int steam = 0;

        for (MTEHatchInput tHatch : filterValidMTEs(mInputHatches)) {
            steam += maybeDrainHatch(tHatch);
        }
        addOutput(GTModHandler.getDistilledWater(steam / 160));
        return CheckRecipeResultRegistry.SUCCESSFUL;
    }

    private int maybeDrainHatch(MTEHatchInput tHatch) {
        if (tHatch instanceof MTEHatchMultiInput) {
            int drained = 0;
            for (FluidStack maybeSteam : ((MTEHatchMultiInput) tHatch).getStoredFluid()) {
                drained += maybeDrainSteam(tHatch, maybeSteam);
            }
            return drained;
        }
        return maybeDrainSteam(tHatch, tHatch.getFillableStack());
    }

    private int maybeDrainSteam(MTEHatchInput tHatch, FluidStack maybeSteam) {
        if (maybeSteam == null) return 0;
        if (!GTUtility.areFluidsEqual(maybeSteam, GTModHandler.getSteam(1))) return 0;
        FluidStack defoSteam = tHatch.drain(ForgeDirection.UNKNOWN, maybeSteam, true);
        return defoSteam.amount;
    }

    @Override
    public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, ForgeDirection side, ForgeDirection facing,
        int colorIndex, boolean aActive, boolean aRedstone) {
        if (side == facing) {
            if (aActive) return new ITexture[] { casingTexturePages[12][3], TextureFactory.builder()
                .addIcon(OVERLAY_FRONT_HEAT_EXCHANGER_ACTIVE)
                .extFacing()
                .build(),
                TextureFactory.builder()
                    .addIcon(OVERLAY_FRONT_HEAT_EXCHANGER_ACTIVE_GLOW)
                    .extFacing()
                    .glow()
                    .build() };
            return new ITexture[] { casingTexturePages[12][3], TextureFactory.builder()
                .addIcon(OVERLAY_FRONT_HEAT_EXCHANGER)
                .extFacing()
                .build(),
                TextureFactory.builder()
                    .addIcon(OVERLAY_FRONT_HEAT_EXCHANGER_GLOW)
                    .extFacing()
                    .glow()
                    .build() };
        }
        return new ITexture[] { casingTexturePages[12][3] };
    }

    @Override
    public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) {
        if (mMachine) return -1;
        return survivialBuildPiece(mName, stackSize, 5, 11, 0, elementBudget, env, false, true);
    }

    @Override
    public boolean getDefaultHasMaintenanceChecks() {
        return false;
    }
}