aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/tectech/mechanics/tesla/TeslaCoverConnection.java
blob: 0ab421361fcd0e859d5112a038609700ce6d673b (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
package tectech.mechanics.tesla;

import static tectech.mechanics.tesla.ITeslaConnectable.TeslaUtil.teslaSimpleNodeSetRemoveScheduled;

import net.minecraftforge.common.util.ForgeDirection;

import com.google.common.base.Objects;
import com.gtnewhorizon.structurelib.util.Vec3Impl;

import gregtech.api.interfaces.tileentity.IGregTechTileEntity;

public class TeslaCoverConnection implements ITeslaConnectableSimple {

    private final IGregTechTileEntity IGT;
    private final Vec3Impl pos;
    private final byte teslaReceptionCapability;

    public TeslaCoverConnection(IGregTechTileEntity IGT, byte teslaReceptionCapability) {
        this.IGT = IGT;
        this.pos = new Vec3Impl(IGT.getXCoord(), IGT.getYCoord(), IGT.getZCoord());

        this.teslaReceptionCapability = teslaReceptionCapability;
    }

    @Override
    public byte getTeslaReceptionCapability() {
        return teslaReceptionCapability;
    }

    @Override
    public float getTeslaReceptionCoefficient() {
        return 1;
    }

    @Override
    public boolean isTeslaReadyToReceive() {
        return true;
    }

    @Override
    public long getTeslaStoredEnergy() {
        return IGT.getStoredEU();
    }

    @Override
    public Vec3Impl getTeslaPosition() {
        return pos;
    }

    @Override
    public Integer getTeslaDimension() {
        return IGT.getWorld().provider.dimensionId;
    }

    @Override
    public boolean teslaInjectEnergy(long teslaVoltageInjected) {
        // Same as in the microwave transmitters, this does not account for amp limits
        boolean output = false;

        if (!IGT.isDead()) {
            output = IGT.injectEnergyUnits(ForgeDirection.UP, teslaVoltageInjected, 1L) > 0L;
        } else {
            teslaSimpleNodeSetRemoveScheduled(this);
        }

        return output;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        TeslaCoverConnection that = (TeslaCoverConnection) o;
        return Objects.equal(IGT, that.IGT);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(IGT);
    }
}