aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/tileentities/machines/basic/MTECharger.java
blob: 52c15cc6df5511e487847151aa9f40ecef72be48 (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
package gregtech.common.tileentities.machines.basic;

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

import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.BaseMetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.implementations.MTEBasicBatteryBuffer;
import gregtech.api.util.GTModHandler;
import gregtech.api.util.GTUtility;

public class MTECharger extends MTEBasicBatteryBuffer {

    public MTECharger(int aID, String aName, String aNameRegional, int aTier, String aDescription, int aSlotCount) {
        super(aID, aName, aNameRegional, aTier, aDescription, aSlotCount);
    }

    public MTECharger(String aName, int aTier, String aDescription, ITexture[][][] aTextures, int aSlotCount) {
        super(aName, aTier, aDescription, aTextures, aSlotCount);
    }

    public MTECharger(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures, int aSlotCount) {
        super(aName, aTier, aDescription, aTextures, aSlotCount);
    }

    @Override
    public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
        return new MTECharger(mName, mTier, mDescriptionArray, mTextures, mInventory.length);
    }

    @Override
    public long getMinimumStoredEU() {
        return V[mTier] * 64L * mInventory.length;
    }

    @Override
    public long maxEUStore() {
        return V[mTier] * 256L * mInventory.length;
    }

    @Override
    public long maxAmperesIn() {
        return Math.max(mChargeableCount * 8L, 4L);
    }

    @Override
    public long maxAmperesOut() {
        return Math.max(mBatteryCount * 4L, 2L);
    }

    @Override
    public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
        if (aBaseMetaTileEntity.isServerSide()) {
            super.onPostTick(aBaseMetaTileEntity, aTick);
            if (this.getBaseMetaTileEntity() instanceof BaseMetaTileEntity) {
                BaseMetaTileEntity mBaseMetaTileEntity = (BaseMetaTileEntity) getBaseMetaTileEntity();
                if (mBaseMetaTileEntity.getMetaTileEntity() instanceof MetaTileEntity mMetaTileEntity) {
                    // for (int t = 0; t < 6; t++) {
                    if (mMetaTileEntity.dechargerSlotCount() > 0
                        && mBaseMetaTileEntity.getStoredEU() < mBaseMetaTileEntity.getEUCapacity()) {
                        for (int i = mMetaTileEntity.dechargerSlotStartIndex(),
                            k = mMetaTileEntity.dechargerSlotCount() + i; i < k; i++) {
                            if (mMetaTileEntity.mInventory[i] != null
                                && mBaseMetaTileEntity.getStoredEU() < mBaseMetaTileEntity.getEUCapacity()) {
                                mBaseMetaTileEntity.increaseStoredEnergyUnits(
                                    GTModHandler.dischargeElectricItem(
                                        mMetaTileEntity.mInventory[i],
                                        GTUtility.safeInt(
                                            Math.min(
                                                V[mTier] * 15,
                                                mBaseMetaTileEntity.getEUCapacity()
                                                    - mBaseMetaTileEntity.getStoredEU())),
                                        (int) Math.min(Integer.MAX_VALUE, mMetaTileEntity.getInputTier()),
                                        true,
                                        false,
                                        false),
                                    true);
                                if (mMetaTileEntity.mInventory[i].stackSize <= 0) mMetaTileEntity.mInventory[i] = null;
                            }
                        }
                    }
                    if (mMetaTileEntity.rechargerSlotCount() > 0 && mBaseMetaTileEntity.getStoredEU() > 0) {
                        for (int i = mMetaTileEntity.rechargerSlotStartIndex(),
                            k = mMetaTileEntity.rechargerSlotCount() + i; i < k; i++) {
                            if (mBaseMetaTileEntity.getStoredEU() > 0 && mMetaTileEntity.mInventory[i] != null) {
                                mBaseMetaTileEntity
                                    .decreaseStoredEU(
                                        GTModHandler.chargeElectricItem(
                                            mMetaTileEntity.mInventory[i],
                                            GTUtility
                                                .safeInt(Math.min(V[mTier] * 15, mBaseMetaTileEntity.getStoredEU())),
                                            (int) Math.min(Integer.MAX_VALUE, mMetaTileEntity.getOutputTier()),
                                            true,
                                            false),
                                        true);
                                if (mMetaTileEntity.mInventory[i].stackSize <= 0) mMetaTileEntity.mInventory[i] = null;
                            }
                        }
                        // }
                    }
                }
            }
        }
    }
}