Skip to content

Commit

Permalink
add button to clear grid
Browse files Browse the repository at this point in the history
  • Loading branch information
ghzdude committed Jan 30, 2025
1 parent 478a54d commit 876b785
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/java/gregtech/api/mui/GTGuiTextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ public static class IDs {
public static final UITexture BUTTON_AUTO_COLLAPSE = fullImage(
"textures/gui/widget/button_auto_collapse_overlay.png");
public static final UITexture BUTTON_X = fullImage("textures/gui/widget/button_x_overlay.png", true);
public static final UITexture BUTTON_CLEAR_GRID = fullImage("textures/gui/widget/button_clear_grid.png", false);

public static final UITexture BUTTON_CROSS = fullImage("textures/gui/widget/button_cross.png");
public static final UITexture BUTTON_REDSTONE_ON = fullImage("textures/gui/widget/button_redstone_on.png");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,13 @@ public int handleCacheMiss(ItemStack stack) {
return -1;
}

public void writeMatrix(PacketBuffer buffer) {
buffer.writeVarInt(craftingMatrix.getSizeInventory());
for (int i = 0; i < craftingMatrix.getSizeInventory(); i++) {
NetworkUtils.writeItemStack(buffer, craftingMatrix.getStackInSlot(i));
}
}

@Override
public void readOnClient(int id, PacketBuffer buf) {
if (id == UPDATE_INGREDIENTS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
import com.cleanroommc.modularui.value.sync.SyncHandlers;
import com.cleanroommc.modularui.widget.scroll.VerticalScrollData;
import com.cleanroommc.modularui.widgets.ButtonWidget;
import com.cleanroommc.modularui.widgets.ItemSlot;
import com.cleanroommc.modularui.widgets.PageButton;
import com.cleanroommc.modularui.widgets.PagedWidget;
Expand Down Expand Up @@ -291,7 +292,21 @@ public IWidget createCraftingGrid() {
}
})
.background(GTGuiTextures.SLOT))
.build();
.build()
.child(new ButtonWidget<>()
.margin(2)
.size(8)
.topRel(0f)
.rightRel(0f, 0, 1f)
.background(GTGuiTextures.BUTTON_CLEAR_GRID)
.disableHoverBackground()
.onMousePressed(mouseButton -> {
this.recipeLogic.clearCraftingGrid();
this.recipeLogic.syncToServer(
CraftingRecipeLogic.UPDATE_MATRIX,
this.recipeLogic::writeMatrix);
return true;
}));
}

public IWidget createCraftingOutput(PosGuiData guiData, PanelSyncManager syncManager) {
Expand Down

0 comments on commit 876b785

Please sign in to comment.