Skip to content

Commit a6dbac5

Browse files
committed
clarify gui actions and simplify syncing changes
compact ids simplify crate change listener address todo only interact when not ghost dragging
1 parent 4018512 commit a6dbac5

File tree

5 files changed

+18
-24
lines changed

5 files changed

+18
-24
lines changed

src/main/java/gregtech/common/metatileentities/storage/CraftingRecipeLogic.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import it.unimi.dsi.fastutil.ints.Int2IntMap;
3131
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
3232
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
33+
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
3334
import it.unimi.dsi.fastutil.ints.IntArraySet;
3435
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
3536
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenCustomHashMap;
@@ -43,7 +44,7 @@ public class CraftingRecipeLogic extends SyncHandler {
4344
// client only
4445
public static final int UPDATE_INGREDIENTS = 1;
4546
public static final int RESET_INGREDIENTS = 2;
46-
public static final int SYNC_STACK = 4;
47+
public static final int SYNC_STACK = 3;
4748

4849
// server only
4950
public static final int UPDATE_MATRIX = 0;
@@ -71,7 +72,7 @@ public class CraftingRecipeLogic extends SyncHandler {
7172
private final Int2IntMap compactedIndexes = new Int2IntArrayMap(9);
7273
private final Int2IntMap slotMap = new Int2IntArrayMap();
7374

74-
private final Map<Integer, Object2BooleanMap<ItemStack>> replaceAttemptMap = new Int2ObjectArrayMap<>();
75+
private final Int2ObjectMap<Object2BooleanMap<ItemStack>> replaceAttemptMap = new Int2ObjectArrayMap<>();
7576
private final InventoryCrafting craftingMatrix;
7677
private final IInventory craftingResultInventory = new InventoryCraftResult();
7778
private final CachedRecipeData cachedRecipeData;

src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityCrate.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager)
152152
widgets.get(i).add(new ItemSlot().slot(SyncHandlers.itemSlot(inventory, index)
153153
.slotGroup("item_inv")
154154
.changeListener((newItem, onlyAmountChanged, client, init) -> {
155-
if (!onlyAmountChanged && !client && !init) {
156-
for (var facing : EnumFacing.VALUES) {
157-
var neighbor = getNeighbor(facing);
158-
if (neighbor instanceof IGregTechTileEntity gregTechTileEntity) {
159-
gregTechTileEntity.getMetaTileEntity().onNeighborChanged();
160-
}
155+
if (client || init) return;
156+
157+
for (var facing : EnumFacing.VALUES) {
158+
var neighbor = getNeighbor(facing);
159+
if (neighbor instanceof IGregTechTileEntity gtte) {
160+
gtte.getMetaTileEntity().onNeighborChanged();
161161
}
162162
}
163163
})));

src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityWorkbench.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ public IWidget createCraftingGrid() {
325325
public IWidget createCraftingOutput(PosGuiData guiData, PanelSyncManager syncManager) {
326326
var amountCrafted = new IntSyncValue(this::getItemsCrafted, this::setItemsCrafted);
327327
syncManager.syncValue("amount_crafted", amountCrafted);
328-
amountCrafted.updateCacheFromSource(true); // todo remove on mui2 rc3
329328

330329
return Flow.column()
331330
.size(54)
@@ -418,8 +417,7 @@ public void readHandler(PacketBuffer buf) {
418417
this.toolInventory,
419418
this.connectedInventory));
420419

421-
getCraftingRecipeLogic()
422-
.updateInventory(this.combinedInventory);
420+
getCraftingRecipeLogic().updateInventory(this.combinedInventory);
423421
}
424422

425423
@Override

src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ private CraftingInputSlot(IItemHandlerModifiable handler, int index) {
4343
tooltip.addFromItem(stack);
4444
});
4545

46+
// for hovering with items in hand
4647
listenGuiAction((IGuiAction.MouseDrag) (m, t) -> {
4748
if (isHovering() && dragging && syncHandler.isValid()) {
4849
var player = syncHandler.getSyncManager().getCursorItem();
@@ -53,6 +54,7 @@ private CraftingInputSlot(IItemHandlerModifiable handler, int index) {
5354
return false;
5455
});
5556

57+
// dragging has stopped
5658
listenGuiAction((IGuiAction.MouseReleased) mouseButton -> {
5759
dragging = false;
5860
return true;
@@ -162,7 +164,7 @@ public InputSyncHandler(IItemHandlerModifiable handler, int index) {
162164
@Override
163165
public void init(String key, PanelSyncManager syncHandler) {
164166
super.init(key, syncHandler);
165-
this.lastStoredItem = this.handler.getStackInSlot(this.index).copy();
167+
this.lastStoredItem = getStack().copy();
166168
}
167169

168170
@Override
@@ -185,16 +187,9 @@ public void readOnServer(int id, PacketBuffer buf) {
185187
public void detectAndSendChanges(boolean init) {
186188
ItemStack itemStack = getStack();
187189
if (itemStack.isEmpty() && this.lastStoredItem.isEmpty()) return;
188-
boolean onlyAmountChanged = false;
189-
if (init ||
190-
!ItemHandlerHelper.canItemStacksStack(this.lastStoredItem, itemStack) ||
191-
(onlyAmountChanged = itemStack.getCount() != this.lastStoredItem.getCount())) {
192-
this.listener.onChange(itemStack, onlyAmountChanged, false, init);
193-
if (onlyAmountChanged) {
194-
this.lastStoredItem.setCount(itemStack.getCount());
195-
} else {
196-
this.lastStoredItem = itemStack.isEmpty() ? ItemStack.EMPTY : itemStack.copy();
197-
}
190+
if (init || !ItemHandlerHelper.canItemStacksStack(this.lastStoredItem, itemStack)) {
191+
this.listener.onChange(itemStack, false, false, init);
192+
this.lastStoredItem = itemStack.isEmpty() ? ItemStack.EMPTY : itemStack.copy();
198193
syncToClient(SLOT_CHANGED, buffer -> NetworkUtils.writeItemStack(buffer, itemStack));
199194
}
200195
}

src/main/java/gregtech/mixins/mui2/ModularPanelMixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ public abstract class ModularPanelMixin extends ParentWidget<ModularPanel> imple
6868
loop:
6969
for (LocatedWidget widget : this.hovering) {
7070
widget.applyMatrix(getContext());
71+
GhostIngredientDrag<?> drag = gregTech$getGhostDrag();
7172
if (widget.getElement() instanceof JeiGhostIngredientSlot<?>ghostSlot &&
7273
Mods.JustEnoughItems.isModLoaded()) {
73-
GhostIngredientDrag<?> drag = gregTech$getGhostDrag();
7474
if (drag != null && gregTech$insertGhostIngredient(drag, ghostSlot)) {
7575
gregTech$stopDrag();
7676
pressed = LocatedWidget.EMPTY;
@@ -79,7 +79,7 @@ public abstract class ModularPanelMixin extends ParentWidget<ModularPanel> imple
7979
break;
8080
}
8181
}
82-
if (widget.getElement() instanceof Interactable interactable) {
82+
if (drag == null && widget.getElement() instanceof Interactable interactable) {
8383
switch (interactable.onMousePressed(mouseButton)) {
8484
case IGNORE:
8585
break;

0 commit comments

Comments
 (0)