aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/util/CoverBehaviorBase.java
blob: 0c8ef815338471c1da0473d4f6db4c22967b3a4b (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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
package gregtech.api.util;

import static gregtech.api.enums.GTValues.E;

import java.lang.ref.WeakReference;
import java.util.List;
import java.util.function.Supplier;

import javax.annotation.Nullable;

import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagInt;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;

import org.jetbrains.annotations.NotNull;

import com.google.common.collect.ImmutableList;
import com.gtnewhorizons.modularui.api.ModularUITextures;
import com.gtnewhorizons.modularui.api.drawable.ItemDrawable;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.common.widget.ButtonWidget;
import com.gtnewhorizons.modularui.common.widget.TextWidget;

import gregtech.api.GregTechAPI;
import gregtech.api.gui.GUIColorOverride;
import gregtech.api.gui.modularui.CoverUIBuildContext;
import gregtech.api.gui.modularui.GTUIInfos;
import gregtech.api.gui.modularui.GUITextureSet;
import gregtech.api.gui.widgets.CoverTickRateButton;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.ICoverable;
import gregtech.common.covers.CoverInfo;

/**
 * For Covers with a special behavior.
 *
 * @author glease
 */
public abstract class CoverBehaviorBase<T extends ISerializableObject> {

    public WeakReference<EntityPlayer> lastPlayer = null;
    private final Class<T> typeToken;
    private final ITexture coverFGTexture;

    protected CoverBehaviorBase(Class<T> typeToken) {
        this(typeToken, null);
    }

    protected CoverBehaviorBase(Class<T> typeToken, ITexture coverTexture) {
        this.typeToken = typeToken;
        this.coverFGTexture = coverTexture;
        reloadColorOverride();
    }

    public void reloadColorOverride() {
        this.colorOverride = GUIColorOverride.get(guiTexturePath);
    }

    public abstract T createDataObject(int aLegacyData);

    public abstract T createDataObject();

    public final T createDataObject(NBTBase aNBT) {
        // Handle legacy data (migrating from GT_CoverBehavior to GT_CoverBehaviorBase)
        if (aNBT instanceof NBTTagInt) {
            return createDataObject(((NBTTagInt) aNBT).func_150287_d());
        }

        final T ret = createDataObject();
        ret.loadDataFromNBT(aNBT);
        return ret;
    }

    public final T cast(ISerializableObject aData) {
        if (typeToken.isInstance(aData)) return forceCast(aData);
        return null;
    }

    private T forceCast(ISerializableObject aData) {
        try {
            return typeToken.cast(aData);
        } catch (Exception e) {
            throw new RuntimeException("Casting data in " + this.getClass() + ", data " + aData, e);
        }
    }

    // region facade

    /**
     * Get target facade block. Does not affect rendering of **this** block. It is only used as a hint for other block
     * in case of CTM
     *
     * @return null if none, otherwise return facade target block
     */
    public final Block getFacadeBlock(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity) {
        return getFacadeBlockImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity);
    }

    /**
     * Get target facade block. Does not affect rendering of **this** block. It is only used as a hint for other block
     * in case of CTM
     *
     * @return 0 if none, otherwise return facade target meta
     */
    public final int getFacadeMeta(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity) {
        return getFacadeMetaImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity);
    }

    /**
     * Get the display stack. Default to {@code int2Stack(aCoverID)}
     */
    public final ItemStack getDisplayStack(int aCoverID, ISerializableObject aCoverVariable) {
        return getDisplayStackImpl(aCoverID, forceCast(aCoverVariable));
    }

    /**
     * Get the special foreground cover texture associated with this cover. Return null if one should use the texture
     * passed to {@link GregTechAPI#registerCover(ItemStack, ITexture, CoverBehaviorBase)} or its
     * overloads.
     */
    public final ITexture getSpecialCoverFGTexture(ForgeDirection side, int aCoverID,
        ISerializableObject aCoverVariable, ICoverable aTileEntity) {
        return getSpecialCoverFGTextureImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity);
    }

    /**
     * Get the special cover texture associated with this cover. Return null if one should use the texture passed to
     * {@link GregTechAPI#registerCover(ItemStack, ITexture, CoverBehaviorBase)} or its overloads.
     */
    public final ITexture getSpecialCoverTexture(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity) {
        return getSpecialCoverTextureImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity);
    }

    /**
     * Return whether cover data needs to be synced to client upon tile entity creation or cover placement.
     * <p>
     * Note if you want to sync the data afterwards you will have to manually do it by calling
     * {@link ICoverable#issueCoverUpdate(ForgeDirection)} This option only affects the initial sync.
     */
    public final boolean isDataNeededOnClient(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity) {
        return isDataNeededOnClientImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity);
    }

    /**
     * Called upon receiving data from network. Use {@link ICoverable#isClientSide()} to determine the side.
     */
    public final void onDataChanged(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity) {
        onDataChangedImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity);
    }

    /**
     * Called before receiving data from network. Use {@link ICoverable#isClientSide()} to determine the side.
     */
    public final void preDataChanged(ForgeDirection side, int aCoverID, int aNewCoverId,
        ISerializableObject aCoverVariable, ISerializableObject aNewCoverVariable, ICoverable aTileEntity) {
        preDataChangedImpl(
            side,
            aCoverID,
            aNewCoverId,
            forceCast(aCoverVariable),
            forceCast(aNewCoverVariable),
            aTileEntity);
    }

    /**
     * Called upon cover being removed. Called on both server and client.
     */
    public final void onDropped(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity) {
        onDroppedImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity);
    }

    public final boolean isRedstoneSensitive(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity, long aTimer) {
        return isRedstoneSensitiveImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity, aTimer);
    }

    /**
     * Called by updateEntity inside the covered TileEntity. aCoverVariable is the Value you returned last time.
     */
    public final T doCoverThings(ForgeDirection side, byte aInputRedstone, int aCoverID,
        ISerializableObject aCoverVariable, ICoverable aTileEntity, long aTimer) {
        return doCoverThingsImpl(side, aInputRedstone, aCoverID, forceCast(aCoverVariable), aTileEntity, aTimer);
    }

    /**
     * Called when someone rightclicks this Cover.
     * <p/>
     * return true, if something actually happens.
     */
    public final boolean onCoverRightClick(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) {
        return onCoverRightClickImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer, aX, aY, aZ);
    }

    /**
     * Called when someone rightclicks this Cover with a Screwdriver. Doesn't call @onCoverRightclick in this Case.
     * <p/>
     * return the new Value of the Cover Variable
     */
    public final T onCoverScrewdriverClick(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) {
        return onCoverScrewdriverClickImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer, aX, aY, aZ);
    }

    /**
     * Called when someone shift-rightclicks this Cover with no tool. Doesn't call @onCoverRightclick in this Case.
     */
    public final boolean onCoverShiftRightClick(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity, EntityPlayer aPlayer) {
        return onCoverShiftRightClickImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer);
    }

    /**
     * Removes the Cover if this returns true, or if aForced is true. Doesn't get called when the Machine Block is
     * getting broken, only if you break the Cover away from the Machine.
     */
    public final boolean onCoverRemoval(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity, boolean aForced) {
        return onCoverRemovalImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity, aForced);
    }

    /**
     * Called upon Base TE being destroyed (once getDrops is called), thus getting called only when destroyed in
     * survival.
     */
    public final void onBaseTEDestroyed(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity) {
        onBaseTEDestroyedImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity);
    }

    /**
     * Gives a small Text for the status of the Cover.
     */
    public final String getDescription(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity) {
        return getDescriptionImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity);
    }

    /**
     * Called when Base TE being unloaded.
     */
    public void onCoverUnload(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity) {
        onCoverUnloadImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity);
    }

    /**
     * How Blast Proof the Cover is. 30 is normal.
     */
    public final float getBlastProofLevel(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity) {
        return getBlastProofLevelImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity);
    }

    /**
     * If it lets RS-Signals into the Block
     * <p/>
     * This is just Informative so that Machines know if their Redstone Input is blocked or not
     */
    public final boolean letsRedstoneGoIn(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity) {
        return letsRedstoneGoInImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity);
    }

    /**
     * If it lets RS-Signals out of the Block
     */
    public final boolean letsRedstoneGoOut(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity) {
        return letsRedstoneGoOutImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity);
    }

    /**
     * If it lets Energy into the Block
     */
    public final boolean letsEnergyIn(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity) {
        return letsEnergyInImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity);
    }

    /**
     * If it lets Energy out of the Block
     */
    public final boolean letsEnergyOut(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity) {
        return letsEnergyOutImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity);
    }

    /**
     * If it lets Liquids into the Block, aFluid can be null meaning if this is generally allowing Fluids or not.
     */
    public final boolean letsFluidIn(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        Fluid aFluid, ICoverable aTileEntity) {
        return letsFluidInImpl(side, aCoverID, forceCast(aCoverVariable), aFluid, aTileEntity);
    }

    /**
     * If it lets Liquids out of the Block, aFluid can be null meaning if this is generally allowing Fluids or not.
     */
    public final boolean letsFluidOut(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        Fluid aFluid, ICoverable aTileEntity) {
        return letsFluidOutImpl(side, aCoverID, forceCast(aCoverVariable), aFluid, aTileEntity);
    }

    /**
     * If it lets Items into the Block, aSlot = -1 means if it is generally accepting Items (return false for no
     * reaction at all), aSlot = -2 means if it would accept for all Slots Impl(return true to skip the Checks for each
     * Slot).
     */
    public final boolean letsItemsIn(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, int aSlot,
        ICoverable aTileEntity) {
        return letsItemsInImpl(side, aCoverID, forceCast(aCoverVariable), aSlot, aTileEntity);
    }

    /**
     * If it lets Items out of the Block, aSlot = -1 means if it is generally accepting Items (return false for no
     * reaction at all), aSlot = -2 means if it would accept for all Slots Impl(return true to skip the Checks for each
     * Slot).
     */
    public final boolean letsItemsOut(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, int aSlot,
        ICoverable aTileEntity) {
        return letsItemsOutImpl(side, aCoverID, forceCast(aCoverVariable), aSlot, aTileEntity);
    }

    /**
     * If it lets you rightclick the Machine normally
     */
    public final boolean isGUIClickable(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity) {
        return isGUIClickableImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity);
    }

    /**
     * Needs to return true for Covers, which have a Redstone Output on their Facing.
     */
    public final boolean manipulatesSidedRedstoneOutput(ForgeDirection side, int aCoverID,
        ISerializableObject aCoverVariable, ICoverable aTileEntity) {
        return manipulatesSidedRedstoneOutputImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity);
    }

    /**
     * if this Cover should let Pipe Connections look connected even if it is not the case.
     */
    public final boolean alwaysLookConnected(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity) {
        return alwaysLookConnectedImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity);
    }

    /**
     * Called to determine the incoming Redstone Signal of a Machine. Returns the original Redstone per default. The
     * Cover should @letsRedstoneGoIn or the aInputRedstone Parameter is always 0.
     */
    public final byte getRedstoneInput(ForgeDirection side, byte aInputRedstone, int aCoverID,
        ISerializableObject aCoverVariable, ICoverable aTileEntity) {
        return getRedstoneInputImpl(side, aInputRedstone, aCoverID, forceCast(aCoverVariable), aTileEntity);
    }

    /**
     * Gets the Tick Rate for doCoverThings of the Cover
     * <p/>
     * 0 = No Ticks! Yes, 0 is Default, you have to override this
     */
    public final int getTickRate(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity) {
        return getTickRateImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity);
    }

    /**
     * The MC Color of this Lens. -1 for no Color (meaning this isn't a Lens then).
     */
    public final byte getLensColor(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity) {
        return getLensColorImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity);
    }

    /**
     * @return the ItemStack dropped by this Cover
     */
    public final ItemStack getDrop(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity) {
        return getDropImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity);
    }

    /**
     * Called when the cover is initially attached to a machine.
     *
     * @param player      The attaching player
     * @param aCover      An {@link ItemStack} containing the cover
     * @param aTileEntity The machine receiving the cover
     * @param side        Which side the cover is attached to
     */
    public void onPlayerAttach(EntityPlayer player, ItemStack aCover, ICoverable aTileEntity, ForgeDirection side) {
        // Do nothing by default.
    }

    // endregion

    // region UI stuff

    protected GT_TooltipDataCache mTooltipCache = new GT_TooltipDataCache();
    protected GUIColorOverride colorOverride;
    private static final String guiTexturePath = "gregtech:textures/gui/GuiCover.png";

    public ModularWindow createWindow(CoverUIBuildContext buildContext) {
        return new UIFactory(buildContext).createWindow();
    }

    /**
     * Creates {@link ModularWindow} for this cover. This is separated from base class, as attaching the same covers in
     * different sides of the same tile needs different UI with different context.
     */
    protected class UIFactory {

        private final CoverUIBuildContext uiBuildContext;

        public UIFactory(CoverUIBuildContext buildContext) {
            this.uiBuildContext = buildContext;
        }

        public ModularWindow createWindow() {
            ModularWindow.Builder builder = ModularWindow.builder(getGUIWidth(), getGUIHeight());
            builder.setBackground(ModularUITextures.VANILLA_BACKGROUND);
            builder.setGuiTint(getUIBuildContext().getGuiColorization());
            maybeBindPlayerInventory(builder);
            addTitleToUI(builder);
            addUIWidgets(builder);
            if (getUIBuildContext().isAnotherWindow()) {
                builder.widget(
                    ButtonWidget.closeWindowButton(true)
                        .setPos(getGUIWidth() - 15, 3));
            }

            final CoverInfo coverInfo = uiBuildContext.getTile()
                .getCoverInfoAtSide(uiBuildContext.getCoverSide());
            final CoverBehaviorBase<?> behavior = coverInfo.getCoverBehavior();
            if (coverInfo.getMinimumTickRate() > 0 && behavior.allowsTickRateAddition()) {
                builder.widget(
                    new CoverTickRateButton(coverInfo, builder).setPos(getGUIWidth() - 24, getGUIHeight() - 24));
            }

            return builder.build();
        }

        protected void maybeBindPlayerInventory(ModularWindow.Builder builder) {
            if (doesBindPlayerInventory() && !getUIBuildContext().isAnotherWindow()) {
                builder.bindPlayerInventory(getUIBuildContext().getPlayer(), 7, GUITextureSet.DEFAULT.getItemSlot());
            }
        }

        /**
         * Override this to add widgets for your UI.
         */
        protected void addUIWidgets(ModularWindow.Builder builder) {}

        public CoverUIBuildContext getUIBuildContext() {
            return uiBuildContext;
        }

        /**
         * Can return null when cover data is invalid e.g. tile is broken or cover is removed
         */
        @Nullable
        public T getCoverData() {
            if (isCoverValid()) {
                return forceCast(
                    getUIBuildContext().getTile()
                        .getComplexCoverDataAtSide(getUIBuildContext().getCoverSide()));
            } else {
                return null;
            }
        }

        public boolean setCoverData(T data) {
            if (isCoverValid()) {
                getUIBuildContext().getTile()
                    .receiveCoverData(
                        getUIBuildContext().getCoverSide(),
                        getUIBuildContext().getCoverID(),
                        data,
                        getUIBuildContext().getPlayer() instanceof EntityPlayerMP
                            ? (EntityPlayerMP) getUIBuildContext().getPlayer()
                            : null);
                return true;
            } else {
                return false;
            }
        }

        public boolean isCoverValid() {
            return !getUIBuildContext().getTile()
                .isDead()
                && getUIBuildContext().getTile()
                    .getCoverBehaviorAtSideNew(getUIBuildContext().getCoverSide()) != GregTechAPI.sNoBehavior;
        }

        protected void addTitleToUI(ModularWindow.Builder builder) {
            ItemStack coverItem = GTUtility.intToStack(getUIBuildContext().getCoverID());
            if (coverItem != null) {
                builder.widget(
                    new ItemDrawable(coverItem).asWidget()
                        .setPos(5, 5)
                        .setSize(16, 16))
                    .widget(
                        new TextWidget(coverItem.getDisplayName()).setDefaultColor(COLOR_TITLE.get())
                            .setPos(25, 9));
            }
        }

        protected int getGUIWidth() {
            return 176;
        }

        protected int getGUIHeight() {
            return 107;
        }

        protected boolean doesBindPlayerInventory() {
            return false;
        }

        protected int getTextColorOrDefault(String textType, int defaultColor) {
            return colorOverride.getTextColorOrDefault(textType, defaultColor);
        }

        protected final Supplier<Integer> COLOR_TITLE = () -> getTextColorOrDefault("title", 0x222222);
        protected final Supplier<Integer> COLOR_TEXT_GRAY = () -> getTextColorOrDefault("text_gray", 0x555555);
        protected final Supplier<Integer> COLOR_TEXT_WARN = () -> getTextColorOrDefault("text_warn", 0xff0000);
    }

    // endregion

    // region impl

    protected Block getFacadeBlockImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) {
        return null;
    }

    protected int getFacadeMetaImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) {
        return 0;
    }

    protected ItemStack getDisplayStackImpl(int aCoverID, T aCoverVariable) {
        return GTUtility.intToStack(aCoverID);
    }

    protected ITexture getSpecialCoverFGTextureImpl(ForgeDirection side, int aCoverID, T aCoverVariable,
        ICoverable aTileEntity) {
        return coverFGTexture;
    }

    protected ITexture getSpecialCoverTextureImpl(ForgeDirection side, int aCoverID, T aCoverVariable,
        ICoverable aTileEntity) {
        return null;
    }

    protected boolean isDataNeededOnClientImpl(ForgeDirection side, int aCoverID, T aCoverVariable,
        ICoverable aTileEntity) {
        return false;
    }

    protected void onDataChangedImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) {}

    protected void preDataChangedImpl(ForgeDirection side, int aCoverID, int aNewCoverId, T aCoverVariable,
        T aNewCoverVariable, ICoverable aTileEntity) {}

    protected void onDroppedImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) {}

    protected void onBaseTEDestroyedImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) {}

    protected void onCoverUnloadImpl(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable,
        ICoverable aTileEntity) {}

    protected boolean isRedstoneSensitiveImpl(ForgeDirection side, int aCoverID, T aCoverVariable,
        ICoverable aTileEntity, long aTimer) {
        return false;
    }

    /**
     * Called by updateEntity inside the covered TileEntity. aCoverVariable is the Value you returned last time.
     */
    protected T doCoverThingsImpl(ForgeDirection side, byte aInputRedstone, int aCoverID, T aCoverVariable,
        ICoverable aTileEntity, long aTimer) {
        return aCoverVariable;
    }

    /**
     * Called when someone rightclicks this Cover.
     * <p/>
     * return true, if something actually happens.
     */
    protected boolean onCoverRightClickImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity,
        EntityPlayer aPlayer, float aX, float aY, float aZ) {
        return false;
    }

    /**
     * Called when someone rightclicks this Cover with a Screwdriver. Doesn't call @onCoverRightclick in this Case.
     * <p/>
     * return the new Value of the Cover Variable
     */
    protected T onCoverScrewdriverClickImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity,
        EntityPlayer aPlayer, float aX, float aY, float aZ) {
        return aCoverVariable;
    }

    /**
     * Called when someone shift-rightclicks this Cover with no tool. Doesn't call @onCoverRightclick in this Case.
     */
    protected boolean onCoverShiftRightClickImpl(ForgeDirection side, int aCoverID, T aCoverVariable,
        ICoverable aTileEntity, EntityPlayer aPlayer) {
        if (hasCoverGUI() && aPlayer instanceof EntityPlayerMP) {
            lastPlayer = new WeakReference<>(aPlayer);
            GTUIInfos.openCoverUI(aTileEntity, aPlayer, side);
            return true;
        }
        return false;
    }

    /**
     * Removes the Cover if this returns true, or if aForced is true. Doesn't get called when the Machine Block is
     * getting broken, only if you break the Cover away from the Machine.
     */
    protected boolean onCoverRemovalImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity,
        boolean aForced) {
        return true;
    }

    /**
     * Gives a small Text for the status of the Cover.
     */
    protected String getDescriptionImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) {
        return E;
    }

    /**
     * How Blast Proof the Cover is. 30 is normal.
     */
    protected float getBlastProofLevelImpl(ForgeDirection side, int aCoverID, T aCoverVariable,
        ICoverable aTileEntity) {
        return 10.0F;
    }

    /**
     * If it lets RS-Signals into the Block
     * <p/>
     * This is just Informative so that Machines know if their Redstone Input is blocked or not
     */
    protected boolean letsRedstoneGoInImpl(ForgeDirection side, int aCoverID, T aCoverVariable,
        ICoverable aTileEntity) {
        return false;
    }

    /**
     * If it lets RS-Signals out of the Block
     */
    protected boolean letsRedstoneGoOutImpl(ForgeDirection side, int aCoverID, T aCoverVariable,
        ICoverable aTileEntity) {
        return false;
    }

    /**
     * If it lets Energy into the Block
     */
    protected boolean letsEnergyInImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) {
        return false;
    }

    /**
     * If it lets Energy out of the Block
     */
    protected boolean letsEnergyOutImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) {
        return false;
    }

    /**
     * If it lets Liquids into the Block, aFluid can be null meaning if this is generally allowing Fluids or not.
     */
    protected boolean letsFluidInImpl(ForgeDirection side, int aCoverID, T aCoverVariable, Fluid aFluid,
        ICoverable aTileEntity) {
        return false;
    }

    /**
     * If it lets Liquids out of the Block, aFluid can be null meaning if this is generally allowing Fluids or not.
     */
    protected boolean letsFluidOutImpl(ForgeDirection side, int aCoverID, T aCoverVariable, Fluid aFluid,
        ICoverable aTileEntity) {
        return false;
    }

    /**
     * If it lets Items into the Block, aSlot = -1 means if it is generally accepting Items (return false for no
     * Interaction at all), aSlot = -2 means if it would accept for all Slots (return true to skip the Checks for each
     * Slot).
     */
    protected boolean letsItemsInImpl(ForgeDirection side, int aCoverID, T aCoverVariable, int aSlot,
        ICoverable aTileEntity) {
        return false;
    }

    /**
     * If it lets Items out of the Block, aSlot = -1 means if it is generally accepting Items (return false for no
     * Interaction at all), aSlot = -2 means if it would accept for all Slots (return true to skip the Checks for each
     * Slot).
     */
    protected boolean letsItemsOutImpl(ForgeDirection side, int aCoverID, T aCoverVariable, int aSlot,
        ICoverable aTileEntity) {
        return false;
    }

    /**
     * If it lets you rightclick the Machine normally
     */
    protected boolean isGUIClickableImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) {
        return true;
    }

    /**
     * Needs to return true for Covers, which have a Redstone Output on their Facing.
     */
    protected boolean manipulatesSidedRedstoneOutputImpl(ForgeDirection side, int aCoverID, T aCoverVariable,
        ICoverable aTileEntity) {
        return false;
    }

    /**
     * if this Cover should let Pipe Connections look connected even if it is not the case.
     */
    protected boolean alwaysLookConnectedImpl(ForgeDirection side, int aCoverID, T aCoverVariable,
        ICoverable aTileEntity) {
        return false;
    }

    /**
     * Called to determine the incoming Redstone Signal of a Machine. Returns the original Redstone per default. The
     * Cover should @letsRedstoneGoIn or the aInputRedstone Parameter is always 0.
     */
    protected byte getRedstoneInputImpl(ForgeDirection side, byte aInputRedstone, int aCoverID, T aCoverVariable,
        ICoverable aTileEntity) {
        return letsRedstoneGoIn(side, aCoverID, aCoverVariable, aTileEntity) ? aInputRedstone : 0;
    }

    /**
     * Gets the Tick Rate for doCoverThings of the Cover
     * <p/>
     * 0 = No Ticks! Yes, 0 is Default, you have to override this
     */
    protected int getTickRateImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) {
        return 0;
    }

    /**
     * The MC Color of this Lens. -1 for no Color (meaning this isn't a Lens then).
     */
    protected byte getLensColorImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) {
        return -1;
    }

    /**
     * @return the ItemStack dropped by this Cover
     */
    protected ItemStack getDropImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) {
        return GTOreDictUnificator.get(true, aTileEntity.getCoverItemAtSide(side));
    }

    // endregion

    // region no data

    /**
     * Checks if the Cover can be placed on this.
     */
    public boolean isCoverPlaceable(ForgeDirection side, ItemStack aStack, ICoverable aTileEntity) {
        return true;
    }

    public boolean hasCoverGUI() {
        return false;
    }

    /**
     * Called when someone rightclicks this Cover Client Side
     * <p/>
     * return true, if something actually happens.
     */
    public boolean onCoverRightclickClient(ForgeDirection side, ICoverable aTileEntity, EntityPlayer aPlayer, float aX,
        float aY, float aZ) {
        return false;
    }

    /**
     * If this is a simple Cover, which can also be used on Bronze Machines and similar.
     */
    public boolean isSimpleCover() {
        return false;
    }

    /**
     * sets the Cover upon placement.
     */
    public void placeCover(ForgeDirection side, ItemStack aCover, ICoverable aTileEntity) {
        aTileEntity.setCoverIDAtSide(side, GTUtility.stackToInt(aCover));
    }

    public boolean allowsCopyPasteTool() {
        return true;
    }

    public boolean allowsTickRateAddition() {
        return true;
    }

    @NotNull
    public final List<String> getAdditionalTooltip(ISerializableObject coverData) {
        return getAdditionalTooltipImpl(forceCast(coverData));
    }

    /**
     * Override to add to the tooltip generated when a user hovers over the cover on the left side of a machine's UI.
     *
     * @param coverData The cover data associated with the cover on a particular side.
     * @return A list of new tooltip entries. Entries are inserted at the top, just after the name and direction line.
     */
    protected List<String> getAdditionalTooltipImpl(T coverData) {
        return ImmutableList.of();
    }
    // endregion
}