Skip to content

Commit b58ccc0

Browse files
committed
Fixed mode toggle buttons
1 parent 4d53a5b commit b58ccc0

File tree

1 file changed

+13
-28
lines changed
  • src/main/java/igentuman/nc/client/gui/element/button

1 file changed

+13
-28
lines changed

src/main/java/igentuman/nc/client/gui/element/button/Button.java

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ public RedstoneConfig(int xPos, int yPos, AbstractContainerScreen<?> screen, Blo
7373
this.pos = pos;
7474
height = 18;
7575
width = 18;
76-
btn = new ImageButton(X(), Y(), width, height, 184, 220, 18, TEXTURE, pButton -> {
77-
NuclearCraft.packetHandler().sendToServer(new PacketGuiButtonPress(pos, BTN_ID));
78-
});
7976
}
8077

8178
public List<Component> getTooltips() {
@@ -84,12 +81,9 @@ public List<Component> getTooltips() {
8481

8582
public void setMode(int redstoneMode) {
8683
mode = redstoneMode;
87-
try {
88-
Field f = btn.getClass().getDeclaredField("yTexStart");
89-
f.setAccessible(true);
90-
f.set(btn, 220 - redstoneMode * 36);
91-
} catch (NoSuchFieldException | IllegalAccessException ignore) {
92-
}
84+
btn = new ImageButton(X(), Y(), width, height, 184, 220 - redstoneMode * 36, 18, TEXTURE, pButton -> {
85+
NuclearCraft.packetHandler().sendToServer(new PacketGuiButtonPress(pos, BTN_ID));
86+
});
9387
}
9488
}
9589

@@ -154,12 +148,9 @@ public List<Component> getTooltips() {
154148
public void setMode(boolean reactorMode) {
155149
mode = reactorMode;
156150
int y = reactorMode ? 1 : 0;
157-
try {
158-
Field f = btn.getClass().getDeclaredField("yTexStart");
159-
f.setAccessible(true);
160-
f.set(btn, 184 - (y+1) * 36);
161-
} catch (NoSuchFieldException | IllegalAccessException ignore) {
162-
}
151+
btn = new ImageButton(X(), Y(), width, height, 220, 184 - (y+1) * 36, 18, TEXTURE, pButton -> {
152+
NuclearCraft.packetHandler().sendToServer(new PacketGuiButtonPress(pos, BTN_ID));
153+
});
163154
}
164155

165156
public void setTimer(int modeTimer) {
@@ -176,17 +167,14 @@ public FusionReactorRedstoneModeButton(int xPos, int yPos, AbstractContainerScre
176167
@Override
177168
public void setMode(byte redstoneMode) {
178169
mode = redstoneMode;
179-
try {
180-
Field f = btn.getClass().getDeclaredField("yTexStart");
181-
f.setAccessible(true);
182-
f.set(btn, 256 - (redstoneMode-10) * 36);
183-
} catch (NoSuchFieldException | IllegalAccessException ignore) {
184-
}
170+
btn = new ImageButton(X(), Y(), width, height, 238, 256 - (redstoneMode-10) * 36, 18, TEXTURE, pButton -> {
171+
NuclearCraft.packetHandler().sendToServer(new PacketGuiButtonPress(pos, BTN_ID));
172+
});
185173
}
186174
}
187175

188176
public static class ReactorPortRedstoneModeButton extends Button {
189-
private final BlockPos pos;
177+
public final BlockPos pos;
190178
public static final int BTN_ID = 71;
191179
public byte mode = 2;
192180
public byte strength = 0;
@@ -220,12 +208,9 @@ public List<Component> getTooltips() {
220208

221209
public void setMode(byte redstoneMode) {
222210
mode = redstoneMode;
223-
try {
224-
Field f = btn.getClass().getDeclaredField("yTexStart");
225-
f.setAccessible(true);
226-
f.set(btn, 256 - (redstoneMode+1) * 36);
227-
} catch (NoSuchFieldException | IllegalAccessException ignore) {
228-
}
211+
btn = new ImageButton(X(), Y(), width, height, 238, 256 - (redstoneMode+1) * 36, 18, TEXTURE, pButton -> {
212+
NuclearCraft.packetHandler().sendToServer(new PacketGuiButtonPress(pos, BTN_ID));
213+
});
229214
}
230215
}
231216
}

0 commit comments

Comments
 (0)