-
Notifications
You must be signed in to change notification settings - Fork 497
/
TriggerParameterSignal.java
136 lines (117 loc) · 3.21 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
131
132
133
134
135
136
/**
* 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.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import buildcraft.api.core.NetworkData;
import buildcraft.api.gates.IStatement;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.api.transport.IPipeTile;
import buildcraft.api.transport.PipeWire;
import buildcraft.core.statements.StatementIconProvider;
import buildcraft.core.utils.StringUtils;
public class TriggerParameterSignal implements ITriggerParameter {
@NetworkData
public boolean active = false;
@NetworkData
public PipeWire color = null;
public TriggerParameterSignal() {
}
@Override
public ItemStack getItemStackToDraw() {
return null;
}
@Override
public IIcon getIconToDraw() {
int id = 0;
if (color == null) {
return null;
}
if (active) {
switch (color) {
case RED:
id = StatementIconProvider.Trigger_PipeSignal_Red_Active;
break;
case BLUE:
id = StatementIconProvider.Trigger_PipeSignal_Blue_Active;
break;
case GREEN:
id = StatementIconProvider.Trigger_PipeSignal_Green_Active;
break;
case YELLOW:
id = StatementIconProvider.Trigger_PipeSignal_Yellow_Active;
break;
}
} else {
switch (color) {
case RED:
id = StatementIconProvider.Trigger_PipeSignal_Red_Inactive;
break;
case BLUE:
id = StatementIconProvider.Trigger_PipeSignal_Blue_Inactive;
break;
case GREEN:
id = StatementIconProvider.Trigger_PipeSignal_Green_Inactive;
break;
case YELLOW:
id = StatementIconProvider.Trigger_PipeSignal_Yellow_Inactive;
break;
}
}
return StatementIconProvider.INSTANCE.getIcon(id);
}
@Override
public void clicked(IPipeTile pipe, 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)));
}
}