Skip to content

Commit bb0c7f1

Browse files
fix a bunch of stuff so that it works again
1 parent 161bcd2 commit bb0c7f1

File tree

7 files changed

+42
-32
lines changed

7 files changed

+42
-32
lines changed

src/main/java/com/gregtechceu/gtceu/api/mui/value/sync/PanelSyncManager.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ private void putSyncValue(String name, int id, SyncHandler syncHandler) {
190190
if (!currentKey.equals(key)) {
191191
boolean auto = name.startsWith(ModularSyncManager.AUTO_SYNC_PREFIX);
192192
if (auto != currentKey.startsWith(ModularSyncManager.AUTO_SYNC_PREFIX)) {
193-
throw new IllegalStateException("Old and new sync handler must both be either not auto or auto!");
193+
throw new IllegalStateException(
194+
"Old and new sync handler must both be either not auto or auto! (old key = \"%s\", new key = \"%s\""
195+
.formatted(currentKey, key));
194196
}
195197
if (auto && !currentKey.startsWith(name)) {
196198
throw new IllegalStateException("Sync Handler was previously added with a different panel!");

src/main/java/com/gregtechceu/gtceu/api/placeholder/PlaceholderHandler.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,9 @@ public static Flow createPlaceholderEditor(PanelSyncManager syncManager,
256256
@Nullable IIntValue<?> updateInterval,
257257
@Nullable IBoolValue<?> pause,
258258
@Nullable Runnable updateText) {
259-
IPanelHandler helpPanel = syncManager.panel("placeholder_language_help",
260-
(syncManager1, panelHandler1) -> createHelpPanel(syncManager1), true);
259+
IPanelHandler helpPanel = syncManager.syncedPanel("placeholder_language_help",
260+
true,
261+
(syncManager1, panelHandler1) -> createHelpPanel(syncManager1));
261262
InteractionSyncHandler runCodeOnce = new InteractionSyncHandler();
262263
if (updateText != null) runCodeOnce.setOnMousePressed(mouseData -> updateText.run());
263264
syncManager.syncValue("run_code_sync_handler", runCodeOnce);
@@ -305,7 +306,7 @@ public static Flow createPlaceholderEditor(PanelSyncManager syncManager,
305306
.background(GTGuiTextures.RIGHTLOAD)
306307
.hoverBackground(GTGuiTextures.RIGHTLOAD, new BorderDrawable())
307308
.addTooltipLine(IKey.lang("gtceu.gui.central_monitor.update_once"))
308-
.syncHandler(runCodeOnce))
309+
.syncHandler("run_code_sync_handler"))
309310
.child(new ButtonWidget<>()
310311
.background(GTGuiTextures.HELP)
311312
.hoverBackground(GTGuiTextures.HELP, new BorderDrawable())

src/main/java/com/gregtechceu/gtceu/client/renderer/machine/impl/CentralMonitorRender.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public void render(CentralMonitorMachine machine, float partialTick, PoseStack p
4242
RenderUtil.moveToFace(poseStack, 0.5f, 0.5f, 0.5f, machine.getFrontFacing());
4343
RenderUtil.rotateToFace(poseStack, machine.getFrontFacing(), machine.getUpwardsFacing());
4444
poseStack.translate(-machine.getRightDist() - 0.5f, -machine.getUpDist() - 0.5f, SCREEN_OFFSET_Z);
45-
4645
if (machine.getRecipeLogic().isActive()) {
4746
for (MonitorGroup group : machine.getMonitorGroups()) {
4847
ItemStack itemStack = group.getItemStackHandler().getStackInSlot(0);

src/main/java/com/gregtechceu/gtceu/client/renderer/monitor/MonitorGuiRenderer.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public void renderGuiToBuffer(GuiGraphics guiGraphics, float partialTick) {
140140
if (renderTarget.width != RESOLUTION_COEF * width || renderTarget.height != RESOLUTION_COEF * height)
141141
renderTarget.resize(RESOLUTION_COEF * width, RESOLUTION_COEF * height, Minecraft.ON_OSX);
142142
renderTarget.enableStencil();
143+
renderTarget.clear(Minecraft.ON_OSX);
143144

144145
renderTarget.bindWrite(true);
145146

@@ -204,8 +205,7 @@ public void render(CentralMonitorMachine machine, MonitorGroup group, float part
204205
if (hit instanceof BlockHitResult blockHit) {
205206
BlockPos pos = blockHit.getBlockPos();
206207
BlockPos relPos = machine.toRelative(pos);
207-
if (MetaMachine.getMachine(player.level(), pos) instanceof MonitorPartMachine monitor &&
208-
monitor.getControllers().contains(machine)) {
208+
if (MetaMachine.getMachine(player.level(), pos) instanceof MonitorPartMachine monitor) {
209209
Vector2d monitorMousePos = monitor.getMousePos(hit);
210210
mouseX = relPos.getX() - rel.getX() + monitorMousePos.x();
211211
mouseY = relPos.getY() - rel.getY() + 1 - monitorMousePos.y();
@@ -219,8 +219,10 @@ public void render(CentralMonitorMachine machine, MonitorGroup group, float part
219219
}
220220
}
221221
}
222-
this.mouseX = (int) (mouseX * 256);
223-
this.mouseY = (int) (mouseY * 256);
222+
if (mouseX >= 0 && mouseY >= 0 && mouseX * 256 <= width && mouseY * 256 <= height) {
223+
this.mouseX = (int) (mouseX * 256);
224+
this.mouseY = (int) (mouseY * 256);
225+
}
224226
renderGui(size.getX(), size.getY(), poseStack, buffer, partialTick, (int) (mouseX * 256), (int) (mouseY * 256));
225227
}
226228
}

src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/CentralMonitorMachine.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
import com.gregtechceu.gtceu.syncsystem.annotations.SaveField;
3131
import com.gregtechceu.gtceu.syncsystem.annotations.SyncToClient;
3232

33-
import com.lowdragmc.lowdraglib.gui.texture.*;
34-
import com.lowdragmc.lowdraglib.gui.widget.*;
35-
3633
import net.minecraft.MethodsReturnNonnullByDefault;
3734
import net.minecraft.core.BlockPos;
3835
import net.minecraft.core.Direction;
@@ -64,7 +61,7 @@ public class CentralMonitorMachine extends WorkableElectricMultiblockMachine
6461
@SyncToClient
6562
@RerenderOnChanged
6663
@Getter
67-
private final List<MonitorGroup> monitorGroups = new ArrayList<>();
64+
private List<MonitorGroup> monitorGroups = new ArrayList<>();
6865

6966
private MultiblockState patternFindingState;
7067

@@ -131,6 +128,8 @@ public void tick() {
131128
new SCPacketMonitorGroupNBTChange(stack, group, this));
132129
}
133130
}
131+
getSyncDataHolder().markClientSyncFieldDirty("monitorGroups");
132+
getSyncDataHolder().markClientSyncFieldDirty("recipeLogic");
134133
}
135134

136135
@Override
@@ -202,6 +201,10 @@ public void updateStructureDimensions() {
202201
posDown.move(down);
203202
downDist++;
204203
}
204+
getSyncDataHolder().markClientSyncFieldDirty("leftDist");
205+
getSyncDataHolder().markClientSyncFieldDirty("rightDist");
206+
getSyncDataHolder().markClientSyncFieldDirty("upDist");
207+
getSyncDataHolder().markClientSyncFieldDirty("downDist");
205208
}
206209

207210
private boolean isValidMonitorBlockRow(Level level, BlockPos pos, int leftDist, int rightDist, Direction left,
@@ -288,8 +291,10 @@ public void addDisplayText(List<Component> textList) {
288291
}
289292

290293
public void setMonitorGroups(List<MonitorGroup> groups) {
294+
if (!(monitorGroups instanceof ArrayList<MonitorGroup>)) monitorGroups = new ArrayList<>(monitorGroups);
291295
monitorGroups.clear();
292296
monitorGroups.addAll(groups);
297+
getSyncDataHolder().markClientSyncFieldDirty("monitorGroups");
293298
}
294299

295300
@Override

src/main/java/com/gregtechceu/gtceu/common/machine/trait/CentralMonitorLogic.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public void serverTick() {
6161
isActive = false;
6262
progress = Math.max(progress - 2, 1);
6363
}
64+
getSyncDataHolder().markClientSyncFieldDirty("isActive");
65+
getSyncDataHolder().markClientSyncFieldDirty("progress");
6466
}
6567

6668
@Override

src/main/java/com/gregtechceu/gtceu/common/mui/factory/CentralMonitorUIFactory.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.gregtechceu.gtceu.common.mui.factory;
22

3+
import com.gregtechceu.gtceu.GTCEu;
34
import com.gregtechceu.gtceu.api.capability.IMonitorComponent;
45
import com.gregtechceu.gtceu.api.item.IComponentItem;
56
import com.gregtechceu.gtceu.api.item.component.IItemComponent;
@@ -58,18 +59,16 @@ public ModularPanel buildUIFunction(PosGuiData data, PanelSyncManager syncManage
5859
syncManager.syncValue("monitor_groups_sync", groupSync);
5960
List<MonitorGroup> groups = new ArrayList<>(groupSync.getValue());
6061
SortableListWidget<MonitorGroup> listWidget = new SortableListWidget<>();
61-
IPanelHandler helpPanel = syncManager.panel(
62-
"help_panel",
63-
(syncManager1, panelHandler1) -> createHelpPanel(),
64-
true);
62+
IPanelHandler helpPanel = syncManager.syncedPanel(
63+
"help_panel", true,
64+
(syncManager1, panelHandler1) -> createHelpPanel());
6565
Function<SortableListWidget.Item<MonitorGroup>, SortableListWidget.Item<MonitorGroup>> processGroupItem = item -> {
66-
IPanelHandler panelHandler = syncManager.panel(
67-
"editor_" + groups.indexOf(item.getWidgetValue()),
66+
IPanelHandler panelHandler = syncManager.syncedPanel(
67+
"editor_" + groups.indexOf(item.getWidgetValue()), true,
6868
(syncManager1, panelHandler1) -> this.createGroupEditorPanel(
6969
syncManager1, groupSync,
7070
machine, item.getWidgetValue(),
71-
groups, helpPanel),
72-
true);
71+
groups, helpPanel));
7372
return item.child(Flow.row()
7473
.height(20)
7574
.child(new TextWidget<>(IKey.dynamic(() -> Component.literal(item.getWidgetValue().getName())))
@@ -92,18 +91,18 @@ public ModularPanel buildUIFunction(PosGuiData data, PanelSyncManager syncManage
9291
return true;
9392
})));
9493
};
95-
IPanelHandler newGroupPanelHandler = syncManager.panel(
96-
"editor_" + groups.size(),
94+
IPanelHandler newGroupPanelHandler = syncManager.syncedPanel(
95+
"editor_" + groups.size(), true,
9796
(syncManager1, panelHandler1) -> {
9897
MonitorGroup group = new MonitorGroup(getNewGroupName(groupSync));
9998
groups.add(group);
10099
listWidget.child(processGroupItem.apply(new SortableListWidget.Item<>(group)));
100+
GTCEu.LOGGER.info("adding group: {} isClient = {}", groups, syncManager1.isClient());
101101
groupSync.setValue(groups, true, false);
102102
return this.createGroupEditorPanel(
103103
syncManager1, groupSync,
104104
machine, group, groups, helpPanel);
105-
},
106-
true);
105+
});
107106
return new Dialog<>("main")
108107
.setDraggable(true)
109108
.padding(5)
@@ -152,7 +151,9 @@ private ModularPanel createGroupEditorPanel(PanelSyncManager syncManager,
152151
int finalRow = row;
153152
IPanelHandler slotDialogHandler = component == null || component.getDataItems() == null ?
154153
null :
155-
syncManager.panel("slot_dialog_" + finalCol + "_" + finalRow + "_" + groups.indexOf(group),
154+
syncManager.syncedPanel(
155+
"slot_dialog_" + finalCol + "_" + finalRow + "_" + groups.indexOf(group),
156+
true,
156157
(syncManager1, panelHandler1) -> new SimpleDialog<>(
157158
"slot_number_dialog_" + finalCol + "_" + finalRow + "_" + groups.indexOf(group),
158159
slot -> {
@@ -166,8 +167,7 @@ private ModularPanel createGroupEditorPanel(PanelSyncManager syncManager,
166167
return Integer.parseInt(w.getText());
167168
},
168169
IKey.lang("gtceu.central_monitor.gui.data_slot")).setDraggable(true)
169-
.size(160, 80),
170-
true);
170+
.size(160, 80));
171171
IntSupplier colorSupplier = () -> {
172172
if (component == null) return 0;
173173
boolean inGroup = group.contains(component.getPos());
@@ -363,11 +363,10 @@ private IPanelHandler createModulePanelHandler(PanelSyncManager syncManager, Ite
363363
}
364364
}
365365
IMonitorModuleItem finalModuleItem = moduleItem;
366-
return moduleItem == null ? null : syncManager.panel(
367-
"module_editor_" + index,
366+
return moduleItem == null ? null : syncManager.syncedPanel(
367+
"module_editor_" + index, true,
368368
(syncManager1, panelHandler1) -> finalModuleItem.createModularPanel(stack, machine, group, syncManager1,
369-
panelHandler1),
370-
true);
369+
panelHandler1));
371370
}
372371

373372
private String getNewGroupName(IValue<List<MonitorGroup>> groupSync) {

0 commit comments

Comments
 (0)