aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/common/tileentities/TE_SpaceElevatorCapacitor.java
blob: 22a4954b0f139533ffd4be046aa53571e18bfa59 (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
package common.tileentities;

import net.minecraft.tileentity.TileEntity;

public class TE_SpaceElevatorCapacitor extends TileEntity {

    private float chargeLevel = 0.0F;

    /**
     * Called by the space elevator controller while charging
     * @param charge
     *              Current elevator charge
     * @param maxCharge
     *              Charge level it is trying to reach
     */
    public void updateChargeLevel(int charge, int maxCharge) {
        chargeLevel = ((float) charge) / ((float) maxCharge);
    }

    /**
     * Called by this block's renderer to calculate the block's colour saturation
     * @return
     *          Charge level from 0.0F to 1.0F
     */
    public float getChargeLevel() {
        return chargeLevel;
    }

    /**
     * Called by the space elevator in case of power loss
     */
    public void resetChargeLevel() {
        chargeLevel = 0.0F;
    }

    long tickCounter = 0;
    @Override
    public void updateEntity() {
        if(tickCounter == 20){
            chargeLevel = Float.compare(chargeLevel, 0.0F) == 0 ? 1.0F : 0.0F;
            tickCounter = 0;
        }
        tickCounter++;
    }
}