aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/tileentities/machines/multiblock/LaserEngraver.java
blob: 36a1271e0daf6e01f9a70a05f2de3f58a07f87c0 (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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
package gregtech.common.tileentities.machines.multiblock;

import static com.gtnewhorizon.structurelib.structure.StructureUtility.*;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlockUnlocalizedName;
import static gregtech.api.enums.Mods.*;
import static gregtech.api.multitileentity.multiblock.base.MultiBlockPart.*;
import static gregtech.api.multitileentity.multiblock.base.MultiBlockPart.ENERGY_IN;
import static gregtech.api.multitileentity.multiblock.base.MultiBlockPart.FLUID_OUT;
import static gregtech.api.util.GT_StructureUtilityMuTE.*;

import java.util.UUID;

import javax.annotation.Nonnull;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
import com.gtnewhorizon.structurelib.structure.StructureDefinition;
import com.gtnewhorizon.structurelib.util.Vec3Impl;
import com.gtnewhorizons.modularui.api.math.Alignment;
import com.gtnewhorizons.modularui.api.math.Color;
import com.gtnewhorizons.modularui.api.widget.IWidgetBuilder;
import com.gtnewhorizons.modularui.common.widget.ButtonWidget;
import com.gtnewhorizons.modularui.common.widget.MultiChildWidget;
import com.gtnewhorizons.modularui.common.widget.textfield.NumericWidget;

import gregtech.api.GregTechAPI;
import gregtech.api.enums.GTValues;
import gregtech.api.enums.Materials;
import gregtech.api.gui.modularui.GTUITextures;
import gregtech.api.multitileentity.enums.GT_MultiTileCasing;
import gregtech.api.multitileentity.multiblock.base.ComplexParallelController;
import gregtech.api.recipe.RecipeMap;
import gregtech.api.util.GTStructureUtility;
import gregtech.api.util.MultiblockTooltipBuilder;
import gregtech.common.tileentities.machines.multiblock.logic.LaserEngraverProcessingLogic;

public class LaserEngraver extends ComplexParallelController<LaserEngraver, LaserEngraverProcessingLogic> {

    private static IStructureDefinition<LaserEngraver> STRUCTURE_DEFINITION = null;
    protected static final String STRUCTURE_MAIN = "Main";
    protected static final String STRUCTURE_PIECE_T1 = "T1";
    protected static final String STRUCTURE_PIECE_T2 = "T2";
    protected static final String STRUCTURE_PIECE_T3 = "T3";
    protected static final String STRUCTURE_PIECE_T4 = "T4";
    protected static final String STRUCTURE_PIECE_T5 = "T5";
    protected static final String STRUCTURE_PIECE_T6 = "T6";
    protected static final int PROCESS_WINDOW_BASE_ID = 100;
    protected static final Vec3Impl STRUCTURE_OFFSET_T1 = new Vec3Impl(3, 1, 0);
    protected static final Vec3Impl STRUCTURE_OFFSET_T2 = new Vec3Impl(1, 3, 0);
    protected static final Vec3Impl STRUCTURE_OFFSET_T3 = new Vec3Impl(-6, 0, -5);
    protected static final Vec3Impl STRUCTURE_OFFSET_T4 = new Vec3Impl(18, 0, 0);
    protected static final Vec3Impl STRUCTURE_OFFSET_T5 = new Vec3Impl(-18, 0, 9);
    protected static final Vec3Impl STRUCTURE_OFFSET_T6 = new Vec3Impl(18, 0, 0);
    protected static final int MAX_PROCESSES = 6;
    protected RecipeMap<?> recipeMap;
    private UUID LaserEngraver;

    @Override
    public String getTileEntityName() {
        return "gt.multitileentity.multiblock.laserengraver";
    }

    @Override
    public Vec3Impl getStartingStructureOffset() {
        return STRUCTURE_OFFSET_T1;
    }

    @Override
    public boolean checkMachine() {
        buildState.startBuilding(getStartingStructureOffset());
        if (!checkPiece(STRUCTURE_PIECE_T1, buildState.getCurrentOffset())) return buildState.failBuilding();
        if (maxComplexParallels > 1) {
            buildState.addOffset(STRUCTURE_OFFSET_T2);
            if (!checkPiece(STRUCTURE_PIECE_T2, buildState.getCurrentOffset())) return buildState.failBuilding();
        }
        if (maxComplexParallels > 2) {
            buildState.addOffset(STRUCTURE_OFFSET_T3);
            if (!checkPiece(STRUCTURE_PIECE_T3, buildState.getCurrentOffset())) return buildState.failBuilding();
        }
        if (maxComplexParallels > 3) {
            buildState.addOffset(STRUCTURE_OFFSET_T4);
            if (!checkPiece(STRUCTURE_PIECE_T4, buildState.getCurrentOffset())) return buildState.failBuilding();
        }
        if (maxComplexParallels > 4) {
            buildState.addOffset(STRUCTURE_OFFSET_T5);
            if (!checkPiece(STRUCTURE_PIECE_T5, buildState.getCurrentOffset())) return buildState.failBuilding();
        }
        if (maxComplexParallels > 5) {
            buildState.addOffset(STRUCTURE_OFFSET_T6);
            if (!checkPiece(STRUCTURE_PIECE_T6, buildState.getCurrentOffset())) return buildState.failBuilding();
        }
        buildState.stopBuilding();
        return super.checkMachine();
    }

    @Override
    public void construct(ItemStack trigger, boolean hintsOnly) {
        buildState.startBuilding(getStartingStructureOffset());
        buildPiece(STRUCTURE_PIECE_T1, trigger, hintsOnly, buildState.getCurrentOffset());
        if (maxComplexParallels > 1) {
            buildState.addOffset(STRUCTURE_OFFSET_T2);
            buildPiece(STRUCTURE_PIECE_T2, trigger, hintsOnly, buildState.getCurrentOffset());
        }
        if (maxComplexParallels > 2) {
            buildState.addOffset(STRUCTURE_OFFSET_T3);
            buildPiece(STRUCTURE_PIECE_T3, trigger, hintsOnly, buildState.getCurrentOffset());
        }
        if (maxComplexParallels > 3) {
            buildState.addOffset(STRUCTURE_OFFSET_T4);
            buildPiece(STRUCTURE_PIECE_T4, trigger, hintsOnly, buildState.getCurrentOffset());
        }
        if (maxComplexParallels > 4) {
            buildState.addOffset(STRUCTURE_OFFSET_T5);
            buildPiece(STRUCTURE_PIECE_T5, trigger, hintsOnly, buildState.getCurrentOffset());
        }
        if (maxComplexParallels > 5) {
            buildState.addOffset(STRUCTURE_OFFSET_T6);
            buildPiece(STRUCTURE_PIECE_T6, trigger, hintsOnly, buildState.getCurrentOffset());
        }
        buildState.stopBuilding();
    }

    @Override
    public IStructureDefinition<LaserEngraver> getStructureDefinition() {
        if (STRUCTURE_DEFINITION == null) {
            STRUCTURE_DEFINITION = StructureDefinition.<LaserEngraver>builder()
                .addShape(
                    STRUCTURE_PIECE_T1,
                    transpose(
                        // spotless:off
                        new String[][]{{"ACADA", "AAAAA", "AAAAA"}, {"GGA~A", "H   I", "GGAAA"},
                            {"AAAAA", "ABBBA", "AAAAA"}}))
                .addShape(
                    STRUCTURE_PIECE_T2,
                    new String[][]{{"       ", "       ", "       ", "       ", "       ", "       "},
                        {"  K    ", "  K    ", "  K    ", "       ", "       ", "       "},
                        {"  K    ", "       ", "       ", "       ", "       ", "       "},
                        {"  K    ", "       ", "       ", "       ", "       ", "       "},
                        {"  K    ", "       ", "       ", "       ", "       ", "       "},
                        {"  K    ", "FBF FBF", " G   G ", " G   G ", " G   G ", "FBF FBF"},
                        {" KKKKK ", "BIB BIB", "G G G G", "G G G G", "G G G G", "BHB BHB"},
                        {" K   K ", "FBF FBF", " G   G ", " G   G ", " G   G ", "FBF FBF"},
                        {" K   K ", "       ", "       ", "       ", "       ", "       "},
                        {" K   K ", "FBF FBF", " G   G ", " G   G ", " G   G ", "FBF FBF"},
                        {" KKKKK ", "BIB BIB", "G G G G", "G G G G", "G G G G", "BHB BHB"},
                        {"       ", "FBF FBF", " G   G ", " G   G ", " G   G ", "FBF FBF",}})
                .addShape(
                    STRUCTURE_PIECE_T3,
                    new String[][]{
                        {"              ", "   BBBBB  FBF ", "   BGGGB   G  ", "   BGGGB   G  ", "   BMLMB   G  ", "   BBBBB  FBF "},
                        {"     KKKKKKK  ", "  BBAAABB BIB ", "  B     B G G ", "  B     B G G ", "  B     B G G ", "  BBBBBBB BHB "},
                        {"     K        ", "  BABBBAB FBF ", "  G     G  G  ", "  G     G  G  ", "  M HHH M  G  ", "  BBBBBBB FBF "},
                        {"KKKKKK        ", "  BABIBAB     ", "  G     G     ", "  G     G     ", "  L HHH L     ", "  BBBBBBB     "},
                        {"     K        ", "  BABBBAB FBF ", "  G     G  G  ", "  G     G  G  ", "  M HHH M  G  ", "  BBBBBBB FBF "},
                        {"     KKKKKKK  ", "  BBAAABB BIB ", "  B     B G G ", "  B     B G G ", "  B     B G G ", "  BBBBBBB BHB "},
                        {"              ", "   BBBBB  FBF ", "   BGGGB   G  ", "   BGGGB   G  ", "   BMLMB   G  ", "   BBBBB  FBF "}})
                .addShape(
                    STRUCTURE_PIECE_T4,
                    new String[][]{
                        {"             ", "FBF  BBBBB   ", " G   BGGGB   ", " G   BGGGB   ", " G   BNLNB   ", "FBF  BBBBB   "},
                        {" KKKKKKK     ", "BIB BBAAABB  ", "G G B     B  ", "G G B     B  ", "G G B     B  ", "BHB BBBBBBB  "},
                        {"       K     ", "FBF BABBBAB  ", " G  G     G  ", " G  G     G  ", " G  N HHH N  ", "FBF BBBBBBB  "},
                        {"       KKKKKK", "    BABIBAB  ", "    G     G  ", "    G     G  ", "    L HHH L  ", "    BBBBBBB  "},
                        {"       K     ", "FBF BABBBAB  ", " G  G     G  ", " G  G     G  ", " G  N HHH N  ", "FBF BBBBBBB  "},
                        {" KKKKKKK     ", "BIB BBAAABB  ", "G G B     B  ", "G G B     B  ", "G G B     B  ", "BHB BBBBBBB  "},
                        {"             ", "FBF  BBBBB   ", " G   BGGGB   ", " G   BGGGB   ", " G   BNLNB   ", "FBF  BBBBB   "}})
                .addShape(
                    STRUCTURE_PIECE_T5,
                    new String[][]{
                        {"              ", "   BBBBB  FBF ", "   BGGGB   G  ", "   BGGGB   G  ", "   BOLOB   G  ", "   BBBBB  FBF "},
                        {"     KKKKKKK  ", "  BBAAABB BIB ", "  B     B G G ", "  B     B G G ", "  B     B G G ", "  BBBBBBB BHB "},
                        {"     K        ", "  BABBBAB FBF ", "  G     G  G  ", "  G     G  G  ", "  O HHH O  G  ", "  BBBBBBB FBF "},
                        {"     K        ", "  BABIBAB     ", "  G     G     ", "  G     G     ", "  L HHH L     ", "  BBBBBBB     "},
                        {"     K        ", "  BABBBAB FBF ", "  G     G  G  ", "  G     G  G  ", "  O HHH O  G  ", "  BBBBBBB FBF "},
                        {"     KKKKKKK  ", "  BBAAABB BIB ", "  B     B G G ", "  B     B G G ", "  B     B G G ", "  BBBBBBB BHB "},
                        {"     K        ", "   BBBBB  FBF ", "   BGGGB   G  ", "   BGGGB   G  ", "   BOLOB   G  ", "   BBBBB  FBF "},
                        {"     K  ", "       ", "       ", "       ", "       "},
                        {"     K  ", "       ", "       ", "       ", "       "},
                        {"     K  ", "       ", "       ", "       ", "       "}})
                .addShape(
                    STRUCTURE_PIECE_T6,
                    new String[][]{
                        {"             ", "FBF  BBBBB   ", " G   BGGGB   ", " G   BGGGB   ", " G   BPLPB   ", "FBF  BBBBB   "},
                        {" KKKKKKK     ", "BIB BBAAABB  ", "G G B     B  ", "G G B     B  ", "G G B     B  ", "BHB BBBBBBB  "},
                        {"       K     ", "FBF BABBBAB  ", " G  G     G  ", " G  G     G  ", " G  P HHH P  ", "FBF BBBBBBB  "},
                        {"       K     ", "    BABIBAB  ", "    G     G  ", "    G     G  ", "    L HHH L  ", "    BBBBBBB  "},
                        {"       K     ", "FBF BABBBAB  ", " G  G     G  ", " G  G     G  ", " G  P HHH P  ", "FBF BBBBBBB  "},
                        {" KKKKKKK     ", "BIB BBAAABB  ", "G G B     B  ", "G G B     B  ", "G G B     B  ", "BHB BBBBBBB  "},
                        {"       K     ", "FBF  BBBBB   ", " G   BGGGB   ", " G   BGGGB   ", " G   BPLPB   ", "FBF  BBBBB   "},
                        {"       K  ", "       ", "       ", "       ", "       "},
                        {"       K  ", "       ", "       ", "       ", "       "},
                        {"       K  ", "       ", "       ", "       ", "       "}})
                // spotless:on
                .addElement(
                    'A',
                    ofMuTECasings(
                        FLUID_IN | ITEM_IN | FLUID_OUT | ITEM_OUT | ENERGY_IN,
                        GT_MultiTileCasing.LaserEngraver.getCasing()))
                .addElement(
                    'B',
                    ofMuTECasings(
                        FLUID_IN | ITEM_IN | FLUID_OUT | ITEM_OUT | ENERGY_IN,
                        GT_MultiTileCasing.BlackLaserEngraverCasing.getCasing()))
                .addElement(
                    'C',
                    ofMuTECasings(NOTHING, CLEANROOM_CASINGS, GT_MultiTileCasing.LaserEngraver.getCasing()))
                .addElement('D', ofMuTECasings(NOTHING, WIRELESS_CASINGS, GT_MultiTileCasing.LaserEngraver.getCasing()))
                .addElement('E', ofMuTECasings(NOTHING, MOTOR_CASINGS))
                .addElement('F', GTStructureUtility.ofFrame(Materials.Naquadah)

                )
                .addElement('H', ofMuTECasings(NOTHING, GT_MultiTileCasing.Mirror.getCasing()))

                .addElement(
                    'G',
                    ofChain(
                        ofBlockUnlocalizedName(IndustrialCraft2.ID, "blockAlloyGlass", 0, true),
                        ofBlockUnlocalizedName(BartWorks.ID, "BW_GlasBlocks", 0, true),
                        ofBlockUnlocalizedName(BartWorks.ID, "BW_GlasBlocks2", 0, true),
                        ofBlockUnlocalizedName(Thaumcraft.ID, "blockCosmeticOpaque", 2, false)))
                .addElement('I', ofMuTECasings(NOTHING, EMITTER_CASINGS))
                .addElement('K', ofBlock(GregTechAPI.sBlockCasings3, 11))
                .addElement('L', ofMuTECasings(NOTHING, ROBOT_ARM_CASINGS))
                .addElement('M', ofMuTECasings(NOTHING, GT_MultiTileCasing.LaserEngraverUpgrade1.getCasing()))
                .addElement('N', ofMuTECasings(NOTHING, GT_MultiTileCasing.LaserEngraverUpgrade2.getCasing()))
                .addElement('O', ofMuTECasings(NOTHING, GT_MultiTileCasing.LaserEngraverUpgrade3.getCasing()))
                .addElement('P', ofMuTECasings(NOTHING, GT_MultiTileCasing.LaserEngraverUpgrade4.getCasing()))
                .build();
            buildState.stopBuilding();
        }
        return STRUCTURE_DEFINITION;
    }

    protected MultiChildWidget createMainPage(IWidgetBuilder<?> builder) {
        MultiChildWidget child = new MultiChildWidget();
        for (int i = 0; i < MAX_PROCESSES; i++) {
            final int processIndex = i;
            child.addChild(
                new ButtonWidget().setPlayClickSound(true)
                    .setOnClick(
                        (clickData, widget) -> {
                            if (!widget.isClient()) widget.getContext()
                                .openSyncedWindow(PROCESS_WINDOW_BASE_ID + processIndex);
                        })
                    .setBackground(GTUITextures.BUTTON_STANDARD, GTUITextures.OVERLAY_BUTTON_WHITELIST)
                    .setSize(18, 18)
                    .setEnabled((widget -> processIndex < maxComplexParallels))
                    .setPos(20 * (i % 4) + 18, 18 + (i / 4) * 20));
        }
        child.addChild(
            new NumericWidget().setGetter(() -> maxComplexParallels)
                .setSetter(parallel -> setMaxComplexParallels((int) parallel, true))
                .setBounds(1, MAX_PROCESSES)
                .setTextColor(Color.WHITE.normal)
                .setTextAlignment(Alignment.Center)
                .addTooltip("Tier")
                .setBackground(GTUITextures.BACKGROUND_TEXT_FIELD)
                .setSize(18, 18)
                .setPos(130, 85));
        return child;
    }

    @Override
    public short getCasingRegistryID() {
        return 0;
    }

    @Override
    public void readMultiTileNBT(NBTTagCompound nbt) {
        super.readMultiTileNBT(nbt);
        setMaxComplexParallels(nbt.getInteger("processors"), false);
    }

    @Override
    public void writeMultiTileNBT(NBTTagCompound nbt) {
        super.writeMultiTileNBT(nbt);
        nbt.setInteger("processors", maxComplexParallels);
    }

    @Override
    public int getCasingMeta() {
        return GT_MultiTileCasing.LaserEngraver.getId();
    }

    @Override
    protected MultiblockTooltipBuilder createTooltip() {
        final MultiblockTooltipBuilder tt = new MultiblockTooltipBuilder();
        tt.addMachineType("Laser Engraver")
            .addInfo("Used for Engraving")
            .addSeparator()
            .beginStructureBlock(3, 3, 5, true)
            .addController("Front right center")
            .toolTipFinisher(GTValues.AuthorTheEpicGamer274);
        return tt;
    }

    @Override
    @Nonnull
    protected LaserEngraverProcessingLogic createProcessingLogic() {
        return new LaserEngraverProcessingLogic();
    }

}