-
Notifications
You must be signed in to change notification settings - Fork 497
/
TriggerParameterSignal.java
130 lines (108 loc) · 3.42 KB
/
TriggerParameterSignal.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
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
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.transport.statements;
import java.util.Locale;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import buildcraft.api.core.NetworkData;
import buildcraft.api.statements.IStatement;
import buildcraft.api.statements.IStatementContainer;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.api.transport.PipeWire;
import buildcraft.core.utils.StringUtils;
public class TriggerParameterSignal implements IStatementParameter {
@NetworkData
public boolean active = false;
@NetworkData
public PipeWire color = null;
private static IIcon[] icons;
public TriggerParameterSignal() {
}
@Override
public ItemStack getItemStack() {
return null;
}
@Override
public IIcon getIcon() {
int id = 0;
if (color == null) {
return null;
}
return icons[color.ordinal() + (active ? 4 : 0)];
}
@Override
public void onClick(IStatementContainer source, IStatement stmt, ItemStack stack, int mouseButton) {
if (mouseButton == 0) {
if (color == null) {
active = true;
color = PipeWire.RED;
} else if (active) {
active = false;
} else if (color == PipeWire.YELLOW) {
color = null;
} else {
color = PipeWire.values()[color.ordinal() + 1];
active = true;
}
} else {
if (color == null) {
active = false;
color = PipeWire.YELLOW;
} else if (!active) {
active = true;
} else if (color == PipeWire.RED) {
color = null;
} else {
color = PipeWire.values()[color.ordinal() - 1];
active = false;
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
nbt.setBoolean("active", active);
if (color != null) {
nbt.setByte("color", (byte) color.ordinal());
}
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
active = nbt.getBoolean("active");
if (nbt.hasKey("color")) {
color = PipeWire.values()[nbt.getByte("color")];
}
}
@Override
public String getDescription() {
return String.format(StringUtils.localize("gate.trigger.pipe.wire." + (active ? "active" : "inactive")), StringUtils.localize("color." + color.name().toLowerCase(Locale.ENGLISH)));
}
@Override
public String getUniqueTag() {
return "buildcraft:pipeWireTrigger";
}
@Override
public void registerIcons(IIconRegister iconRegister) {
icons = new IIcon[]{
iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_red_inactive"),
iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_blue_inactive"),
iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_green_inactive"),
iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_yellow_inactive"),
iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_red_active"),
iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_blue_active"),
iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_green_active"),
iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_yellow_active")
};
}
@Override
public IStatementParameter rotateLeft() {
return this;
}
}