-
Notifications
You must be signed in to change notification settings - Fork 497
/
EnergyPulser.java
77 lines (62 loc) · 1.83 KB
/
EnergyPulser.java
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
package buildcraft.transport;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
import buildcraft.api.power.IPowerReceptor;
public class EnergyPulser {
private final IPowerReceptor powerReceptor;
private boolean isActive;
private boolean singlePulse;
private boolean hasPulsed;
private int pulseCount;
private int tick;
public EnergyPulser(IPowerReceptor receptor) {
powerReceptor = receptor;
}
public void update() {
if (!isActive && hasPulsed)
hasPulsed = false;
if (powerReceptor == null || !isActive || tick++ % 10 != 0)
return;
if (!singlePulse || !hasPulsed) {
powerReceptor.getPowerProvider(null).receiveEnergy(Math.min(1 << (pulseCount - 1), 64), ForgeDirection.WEST);
hasPulsed = true;
}
}
public void enableSinglePulse(int count) {
singlePulse = true;
isActive = true;
pulseCount = count;
}
public void enablePulse(int count) {
isActive = true;
singlePulse = false;
pulseCount = count;
}
public void disablePulse() {
if (!isActive) {
hasPulsed = false;
}
isActive = false;
pulseCount = 0;
}
public boolean isActive() {
return isActive;
}
private float getPulseSpeed() {
return 0.1F;
}
public void writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setBoolean("SinglePulse", singlePulse);
nbttagcompound.setBoolean("IsActive", isActive);
nbttagcompound.setBoolean("hasPulsed", hasPulsed);
nbttagcompound.setInteger("pulseCount", pulseCount);
nbttagcompound.setInteger("tick", tick);
}
public void readFromNBT(NBTTagCompound nbttagcompound) {
isActive = nbttagcompound.getBoolean("IsActive");
singlePulse = nbttagcompound.getBoolean("SinglePulse");
hasPulsed = nbttagcompound.getBoolean("hasPulsed");
pulseCount = nbttagcompound.getInteger("pulseCount");
tick = nbttagcompound.getInteger("tick");
}
}