aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/GoodGenerator/Blocks/TEs/LargeEssentiaGenerator.java
blob: 6af2e59e1400bf09f88b3b4294628d0780a69258 (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
package GoodGenerator.Blocks.TEs;

import GoodGenerator.Loader.Loaders;
import com.github.bartimaeusnek.crossmod.tectech.TecTechEnabledMulti;
import com.github.technus.tectech.mechanics.constructable.IConstructable;
import com.github.technus.tectech.mechanics.structure.IStructureDefinition;
import com.github.technus.tectech.mechanics.structure.StructureDefinition;
import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_DynamoMulti;
import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_EnergyMulti;
import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_EnergyTunnel;
import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM;
import gregtech.api.enums.Textures;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.*;
import gregtech.api.objects.GT_RenderedTexture;
import gregtech.api.render.TextureFactory;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.common.config.ConfigBlocks;

import java.util.ArrayList;
import java.util.List;

import static com.github.technus.tectech.mechanics.structure.StructureUtility.*;

public class LargeEssentiaGenerator extends GT_MetaTileEntity_MultiblockBase_EM implements TecTechEnabledMulti, IConstructable {

    private IStructureDefinition<LargeEssentiaGenerator> multiDefinition = null;
    protected final int ENERGY_PER_ESSENTIA = 512;
    protected int mStableValue = 0;
    protected ArrayList<EssentiaHatch> mEssentiaHatch = new ArrayList<>();

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

    public LargeEssentiaGenerator(int id, String name, String nameRegional){
        super(id,name,nameRegional);
    }

    @Override
    public List<GT_MetaTileEntity_Hatch_Energy> getVanillaEnergyHatches() {
        return this.mEnergyHatches;
    }

    @Override
    public List<GT_MetaTileEntity_Hatch_EnergyTunnel> getTecTechEnergyTunnels() {
        return new ArrayList<>();
    }

    @Override
    public List<GT_MetaTileEntity_Hatch_EnergyMulti> getTecTechEnergyMultis() {
        return new ArrayList<>();
    }

    @Override
    public void construct(ItemStack itemStack, boolean b) {
        structureBuild_EM(mName, 4, 0, 4, b, itemStack);
    }

    @Override
    public boolean checkMachine_EM(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) {
        mStableValue = 0;
        return structureCheck_EM(mName, 4, 0, 4);
    }

    @Override
    public void loadNBTData(NBTTagCompound aNBT){
        super.loadNBTData(aNBT);
        this.mStableValue = aNBT.getInteger("mStableValue");
    }

    @Override
    public void saveNBTData(NBTTagCompound aNBT){
        super.saveNBTData(aNBT);
        aNBT.setInteger("mStableValue", this.mStableValue);
    }

    public void getEssentiaHatch() {
        IGregTechTileEntity aTileEntity = getBaseMetaTileEntity();
        if (aTileEntity == null) return;
        mEssentiaHatch.clear();
        TileEntity hatch = aTileEntity.getTileEntityOffset(4,-2, 0);
        addEssentiaHatch(hatch);
        hatch = aTileEntity.getTileEntityOffset(-4,-2, 0);
        addEssentiaHatch(hatch);
        hatch = aTileEntity.getTileEntityOffset(0,-2, 4);
        addEssentiaHatch(hatch);
        hatch = aTileEntity.getTileEntityOffset(0,-2, -4);
        addEssentiaHatch(hatch);
    }

    public void addEssentiaHatch(TileEntity aHatch) {
        if (aHatch instanceof EssentiaHatch) {
            mEssentiaHatch.add((EssentiaHatch) aHatch);
        }
    }

    @Override
    public boolean onWrenchRightClick(byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ) {
        if (aWrenchingSide == 0 || aWrenchingSide == 1) return false;
        if (getBaseMetaTileEntity().isValidFacing(aWrenchingSide)) {
            getBaseMetaTileEntity().setFrontFacing(aWrenchingSide);
            return true;
        }
        return false;
    }

    @Override
    public IStructureDefinition<LargeEssentiaGenerator> getStructure_EM() {
        if(multiDefinition == null) {
            multiDefinition = StructureDefinition
                    .<LargeEssentiaGenerator>builder()
                    .addShape(mName,
                            transpose(new String[][]{
                                    {"A       A","         ","         ","         ","    ~    ","         ","         ","         ","A       A"},
                                    {"T   C   T","   CEC   ","  CEEEC  "," CEEEEEC ","CEEEEEEEC"," CEEEEEC ","  CEEEC  ","   CEC   ","T   C   T"},
                                    {"T  TXT  T","  TCCCT  "," TCCCCCT ","TCCCCCCCT","XCCCCCCCX","TCCCCCCCT"," TCCCCCT ","  TCCCT  ","T  TXT  T"}
                            })
                    ).addElement(
                            'A',
                            ofBlock(
                                    ConfigBlocks.blockCosmeticOpaque, 1
                            )
                    ).addElement(
                            'T',
                            ofBlock(
                                    ConfigBlocks.blockCosmeticSolid, 7
                            )
                    ).addElement(
                            'C',
                            ofBlock(
                                    Loaders.magicCasing, 0
                            )
                    ).addElement(
                            'E',
                            ofChain(
                                    onElementPass(
                                            x -> ++x.mStableValue,
                                            ofBlock(
                                                    Loaders.essentiaCell, 0
                                            )
                                    ),
                                    onElementPass(
                                            x -> x.mStableValue += 2,
                                            ofBlock(
                                                    Loaders.essentiaCell, 1
                                            )
                                    ),
                                    onElementPass(
                                            x -> x.mStableValue += 5,
                                            ofBlock(
                                                    Loaders.essentiaCell, 2
                                            )
                                    )
                            )
                    ).addElement(
                            'X',
                            ofChain(
                                    ofHatchAdder(
                                            LargeEssentiaGenerator::addLargeEssentiaGeneratorList,1536,
                                            1
                                    ),
                                    ofBlock(
                                            Loaders.magicCasing, 0
                                    ),
                                    ofBlock(
                                            Loaders.essentiaHatch, 0
                                    )
                            )
                    )
                    .build();
        }
        return multiDefinition;
    }

    public final boolean addLargeEssentiaGeneratorList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) {
        if (aTileEntity == null) {
            return false;
        } else {
            IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity();
            if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input){
                ((GT_MetaTileEntity_Hatch)aMetaTileEntity).updateTexture(aBaseCasingIndex);
                return this.mInputHatches.add((GT_MetaTileEntity_Hatch_Input)aMetaTileEntity);
            } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance){
                ((GT_MetaTileEntity_Hatch)aMetaTileEntity).updateTexture(aBaseCasingIndex);
                return this.mMaintenanceHatches.add((GT_MetaTileEntity_Hatch_Maintenance)aMetaTileEntity);
            } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo){
                ((GT_MetaTileEntity_Hatch)aMetaTileEntity).updateTexture(aBaseCasingIndex);
                return this.mDynamoHatches.add((GT_MetaTileEntity_Hatch_Dynamo)aMetaTileEntity);
            } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_DynamoMulti){
                ((GT_MetaTileEntity_Hatch)aMetaTileEntity).updateTexture(aBaseCasingIndex);
                return this.eDynamoMulti.add((GT_MetaTileEntity_Hatch_DynamoMulti)aMetaTileEntity);
            }
        }
        return false;
    }

    @Override
    public boolean checkRecipe_EM(ItemStack aStack) {
        this.mEfficiency = 10000;
        this.mMaxProgresstime = 1;
        getEssentiaHatch();
        this.mEUt = (int)getEssentiaToEU();
        return true;
    }

    public long getEssentiaToEU(){
        long EUt = 0;
        for (EssentiaHatch hatch: this.mEssentiaHatch){
            AspectList aspects = hatch.getAspects();
            for (Aspect aspect: aspects.aspects.keySet()) {
                while (EUt < 8192 && aspects.getAmount(aspect) > 0) {
                    EUt += ENERGY_PER_ESSENTIA;
                    aspects.reduce(aspect, 1);
                }
            }
        }
        return EUt;
    }

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

    @Override
    public String[] getStructureDescription(ItemStack itemStack) {
        return new String[0];
    }

    @Override
    public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
        return new LargeEssentiaGenerator(this.mName);
    }

    @Override
    @SuppressWarnings("ALL")
    public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) {
        if(aSide == aFacing) {
            if(aActive) return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(1536), new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_DRAGONEGG), TextureFactory.builder().addIcon(Textures.BlockIcons.MACHINE_CASING_DRAGONEGG_GLOW).glow().build()};
            return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(1536), new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_DRAGONEGG)};
        }
        return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(1536)};
    }
}