Skip to content

Commit

Permalink
Merge remote-tracking branch 'personal/toolbelt' into toolbelt
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/gregtech/api/items/toolitem/ItemGTToolbelt.java
  • Loading branch information
M-W-K committed Nov 9, 2024
2 parents f91468a + 2b197fe commit dad2678
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 202 deletions.
151 changes: 76 additions & 75 deletions src/main/java/gregtech/api/items/toolitem/IGTTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import gregtech.api.items.toolitem.behavior.IToolBehavior;
import gregtech.api.mui.GTGuiTextures;
import gregtech.api.mui.GTGuis;
import gregtech.api.mui.sync.NBTSyncValue;
import gregtech.api.recipes.ModHandler;
import gregtech.api.unification.OreDictUnifier;
import gregtech.api.unification.material.Material;
Expand Down Expand Up @@ -61,14 +60,20 @@
import appeng.api.implementations.items.IAEWrench;
import buildcraft.api.tools.IToolWrench;
import cofh.api.item.IToolHammer;
import com.cleanroommc.modularui.api.drawable.IDrawable;
import com.cleanroommc.modularui.api.drawable.IKey;
import com.cleanroommc.modularui.api.widget.IWidget;
import com.cleanroommc.modularui.api.widget.Interactable;
import com.cleanroommc.modularui.factory.HandGuiData;
import com.cleanroommc.modularui.factory.ItemGuiFactory;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.utils.Alignment;
import com.cleanroommc.modularui.value.sync.IntSyncValue;
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
import com.cleanroommc.modularui.widgets.ButtonWidget;
import com.cleanroommc.modularui.widgets.TextWidget;
import com.cleanroommc.modularui.widgets.layout.Column;
import com.cleanroommc.modularui.widgets.layout.Row;
import com.enderio.core.common.interfaces.IOverlayRenderAware;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
Expand Down Expand Up @@ -927,83 +932,79 @@ default void playSound(EntityPlayer player) {
}
}

IDrawable PLUS = IKey.str("+").asIcon().marginLeft(1);
IDrawable MINUS = IKey.str("-").asIcon().marginLeft(1);

@Override
default ModularPanel buildUI(HandGuiData guiData, PanelSyncManager guiSyncManager) {
ModularPanel panel = GTGuis.createPanel(guiData.getUsedItemStack().getDisplayName(), 120, 80);

Supplier<NBTTagCompound> tag = () -> getBehaviorsTag(guiData.getUsedItemStack());
AoESymmetrical defaultDefinition = getMaxAoEDefinition(guiData.getUsedItemStack());

NBTSyncValue nbtSyncer = new NBTSyncValue(tag, (nbt) -> setBehaviorsTag(guiData.getUsedItemStack(), nbt));
guiSyncManager.syncValue("NBTSync", nbtSyncer);

Column columns = new Column();
columns.flex().coverChildren().leftRel(0.07f).bottomRel(0.5f);
columns.child(new TextWidget(IKey.lang("item.gt.tool.aoe.columns")).paddingBottom(5));
columns.child(new ButtonWidget<>().background(GTGuiTextures.BUTTON_THROTTLE_PLUS).size(9, 18)
.disableHoverBackground().onMousePressed(data -> {
NBTTagCompound nbt = tag.get();
AoESymmetrical.increaseColumn(nbt, defaultDefinition);
nbtSyncer.setValue(nbt, true);
return true;
}));
columns.child(new ButtonWidget<>().background(GTGuiTextures.BUTTON_THROTTLE_MINUS).size(9, 18)
.disableHoverBackground().onMousePressed(data -> {
NBTTagCompound nbt = tag.get();
AoESymmetrical.decreaseColumn(nbt, defaultDefinition);
nbtSyncer.setValue(nbt, true);
return true;
}));
columns.child(new TextWidget(
IKey.dynamic(() -> String.valueOf(1 + 2 * AoESymmetrical.getColumn(tag.get(), defaultDefinition))))
.paddingTop(5));
panel.child(columns);

Column rows = new Column();
rows.flex().coverChildren().rightRel(0.5f).bottomRel(0.5f);
rows.child(new TextWidget(IKey.lang("item.gt.tool.aoe.rows")).paddingBottom(5));
rows.child(new ButtonWidget<>().background(GTGuiTextures.BUTTON_THROTTLE_PLUS).size(9, 18)
.disableHoverBackground().onMousePressed(data -> {
NBTTagCompound nbt = tag.get();
AoESymmetrical.increaseRow(nbt, defaultDefinition);
nbtSyncer.setValue(nbt, true);
default ModularPanel buildUI(HandGuiData guiData, PanelSyncManager manager) {
final var usedStack = guiData.getUsedItemStack();
final var behaviorsTag = getBehaviorsTag(usedStack);
final var defaultDefinition = getMaxAoEDefinition(usedStack);

var columnValue = new IntSyncValue(
() -> AoESymmetrical.getColumn(behaviorsTag, defaultDefinition),
i -> AoESymmetrical.setColumn(behaviorsTag, i, defaultDefinition));
var rowValue = new IntSyncValue(
() -> AoESymmetrical.getRow(behaviorsTag, defaultDefinition),
i -> AoESymmetrical.setRow(behaviorsTag, i, defaultDefinition));
var layerValue = new IntSyncValue(
() -> AoESymmetrical.getLayer(behaviorsTag, defaultDefinition),
i -> AoESymmetrical.setLayer(behaviorsTag, i, defaultDefinition));

manager.syncValue("row_value", rowValue);
manager.syncValue("column_value", columnValue);
manager.syncValue("layer_value", layerValue);

return GTGuis.createPanel(usedStack.getTranslationKey(), 120, 80)
.child(new Row()
.widthRel(1f)
.margin(4, 0)
.alignY(0.5f)
.coverChildrenHeight()
.mainAxisAlignment(Alignment.MainAxis.SPACE_BETWEEN)
.child(createColumn(columnValue, "columns", true))
.child(createColumn(rowValue, "rows", true))
.child(createColumn(layerValue, "layers", false)));
}

default Column createColumn(IntSyncValue syncValue, String lang, boolean shouldDouble) {
final var display = IKey.dynamic(
() -> String.valueOf(1 + (shouldDouble ? 2 * syncValue.getIntValue() : syncValue.getIntValue())));

IWidget increaseButton = new ButtonWidget<>()
.size(9, 18)
.background(GTGuiTextures.MC_BUTTON)
.overlay(PLUS)
.disableHoverBackground()
.onMousePressed(data -> {
syncValue.setIntValue(syncValue.getIntValue() + 1, true, true);
Interactable.playButtonClickSound();
return true;
}));
rows.child(new ButtonWidget<>().background(GTGuiTextures.BUTTON_THROTTLE_MINUS).size(9, 18)
.disableHoverBackground().onMousePressed(data -> {
NBTTagCompound nbt = tag.get();
AoESymmetrical.decreaseRow(nbt, defaultDefinition);
nbtSyncer.setValue(nbt, true);
});

IWidget decreaseButton = new ButtonWidget<>()
.size(9, 18)
.background(GTGuiTextures.MC_BUTTON)
.overlay(MINUS)
.disableHoverBackground()
.onMousePressed(data -> {
syncValue.setIntValue(syncValue.getIntValue() - 1, true, true);
Interactable.playButtonClickSound();
return true;
}));
rows.child(new TextWidget(
IKey.dynamic(() -> String.valueOf(1 + 2 * AoESymmetrical.getRow(tag.get(), defaultDefinition))))
.paddingTop(5));
panel.child(rows);

Column layers = new Column();
layers.flex().coverChildren().rightRel(0.07f).bottomRel(0.5f);
layers.child(new TextWidget(IKey.lang("item.gt.tool.aoe.layers")).paddingBottom(5));
layers.child(new ButtonWidget<>().background(GTGuiTextures.BUTTON_THROTTLE_PLUS).size(9, 18)
.disableHoverBackground().onMousePressed(data -> {
NBTTagCompound nbt = tag.get();
AoESymmetrical.increaseLayer(nbt, defaultDefinition);
nbtSyncer.setValue(nbt, true);
return true;
}));
layers.child(new ButtonWidget<>().background(GTGuiTextures.BUTTON_THROTTLE_MINUS).size(9, 18)
.disableHoverBackground().onMousePressed(data -> {
NBTTagCompound nbt = tag.get();
AoESymmetrical.decreaseLayer(nbt, defaultDefinition);
nbtSyncer.setValue(nbt, true);
return true;
}));
layers.child(new TextWidget(
IKey.dynamic(() -> String.valueOf(1 + AoESymmetrical.getLayer(tag.get(), defaultDefinition))))
.paddingTop(5));
panel.child(layers);

return panel;
});

return new Column()
.coverChildren()
.child(new TextWidget(IKey.lang("item.gt.tool.aoe." + lang))
.marginBottom(5))
.child(new Row()
.coverChildren()
.marginBottom(5)
.child(increaseButton)
.child(decreaseButton))
.child(new TextWidget(display)
.alignment(Alignment.Center)
.widthRel(1f));
}

Set<String> getToolClasses(ItemStack stack);
Expand Down
44 changes: 24 additions & 20 deletions src/main/java/gregtech/api/items/toolitem/ItemGTToolbelt.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
import com.cleanroommc.modularui.value.sync.SyncHandlers;
import com.cleanroommc.modularui.widgets.ItemSlot;
import com.cleanroommc.modularui.widgets.SlotGroupWidget;
import com.cleanroommc.modularui.widgets.layout.Grid;
import com.cleanroommc.modularui.widgets.slot.SlotGroup;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
Expand Down Expand Up @@ -106,35 +106,39 @@ public ItemStack getToolInSlot(@NotNull ItemStack toolbelt, int slot) {

@Override
public ModularPanel buildUI(HandGuiData guiData, PanelSyncManager guiSyncManager) {
ToolStackHandler handler = getHandler(guiData.getUsedItemStack());
ItemStack selected = handler.getSelectedStack();
final var usedStack = guiData.getUsedItemStack();
final var handler = getHandler(usedStack);
final var selected = handler.getSelectedStack();
if (!selected.isEmpty() && selected.getItem() instanceof ItemUIFactory factory) {
return factory.buildUI(guiData, guiSyncManager);
}

int heightBonus = (handler.getSlots() / 9) * 18;

ModularPanel panel = GTGuis.createPanel(guiData.getUsedItemStack().getDisplayName(), 176, 120 + heightBonus);

SlotGroup group = new SlotGroup("toolbelt_inventory", 9);
guiSyncManager.registerSlotGroup(group);

SlotGroupWidget slotGroupWidget = new SlotGroupWidget();
slotGroupWidget.flex().coverChildren().leftRel(0.5f).top(7);
slotGroupWidget.debugName("toolbelt_inventory");
List<ItemSlot> slots = new ArrayList<>();
for (int i = 0; i < handler.getSlots(); i++) {
int finalI = i;
slotGroupWidget.child(new ItemSlot()
.slot(SyncHandlers.itemSlot(handler, i).slotGroup(group)
.changeListener(
(newItem, onlyAmountChanged, client, init) -> handler.onContentsChanged(finalI)))
.background(GTGuiTextures.SLOT, GTGuiTextures.TOOL_SLOT_OVERLAY)
.pos(i % 9 * 18, i / 9 * 18)
.debugName("slot_" + i));
}
panel.child(slotGroupWidget);

return panel.bindPlayerInventory();
slots.add(new ItemSlot());
}

return GTGuis.createPanel(usedStack.getTranslationKey(), 176, 120 + heightBonus)
.child(new Grid()
.margin(0)
.leftRel(0.5f)
.top(7)
.coverChildren()
.mapTo(group.getRowSize(), slots, (index, value) -> value
.slot(SyncHandlers.itemSlot(handler, index)
.slotGroup(group)
.changeListener(
(newItem, onlyAmountChanged, client, init) -> handler
.onContentsChanged(index)))
.background(GTGuiTextures.SLOT, GTGuiTextures.TOOL_SLOT_OVERLAY)
.debugName("slot_" + index))
.debugName("toolbelt_inventory"))
.bindPlayerInventory();
}

public static boolean isToolbeltableOredict(String oredict) {
Expand Down
73 changes: 25 additions & 48 deletions src/main/java/gregtech/api/items/toolitem/aoe/AoESymmetrical.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import gregtech.api.items.toolitem.ToolHelper;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.common.util.Constants;

import com.google.common.base.Preconditions;
Expand Down Expand Up @@ -73,70 +74,46 @@ public static int getLayer(NBTTagCompound tag, AoESymmetrical defaultDefinition)
return defaultDefinition.layer;
}

public static void setColumn(NBTTagCompound tag, int i, AoESymmetrical defaultDefinition) {
tag.setInteger(ToolHelper.AOE_COLUMN_KEY, MathHelper.clamp(i, 0, defaultDefinition.column));
}

public static void setRow(NBTTagCompound tag, int i, AoESymmetrical defaultDefinition) {
tag.setInteger(ToolHelper.AOE_ROW_KEY, MathHelper.clamp(i, 0, defaultDefinition.row));
}

public static void setLayer(NBTTagCompound tag, int i, AoESymmetrical defaultDefinition) {
tag.setInteger(ToolHelper.AOE_LAYER_KEY, MathHelper.clamp(i, 0, defaultDefinition.layer));
}

public static void increaseColumn(NBTTagCompound tag, AoESymmetrical defaultDefinition) {
if (!tag.hasKey(ToolHelper.AOE_COLUMN_KEY, Constants.NBT.TAG_INT)) {
tag.setInteger(ToolHelper.AOE_COLUMN_KEY, defaultDefinition.column);
} else {
int currentColumn = tag.getInteger(ToolHelper.AOE_COLUMN_KEY);
if (currentColumn < defaultDefinition.column) {
tag.setInteger(ToolHelper.AOE_COLUMN_KEY, currentColumn + 1);
}
}
int currentColumn = getColumn(tag, defaultDefinition);
setColumn(tag, currentColumn + 1, defaultDefinition);
}

public static void increaseRow(NBTTagCompound tag, AoESymmetrical defaultDefinition) {
if (!tag.hasKey(ToolHelper.AOE_ROW_KEY, Constants.NBT.TAG_INT)) {
tag.setInteger(ToolHelper.AOE_ROW_KEY, defaultDefinition.row);
} else {
int currentRow = tag.getInteger(ToolHelper.AOE_ROW_KEY);
if (currentRow < defaultDefinition.row) {
tag.setInteger(ToolHelper.AOE_ROW_KEY, currentRow + 1);
}
}
int currentRow = getRow(tag, defaultDefinition);
setRow(tag, currentRow + 1, defaultDefinition);
}

public static void increaseLayer(NBTTagCompound tag, AoESymmetrical defaultDefinition) {
if (!tag.hasKey(ToolHelper.AOE_LAYER_KEY, Constants.NBT.TAG_INT)) {
tag.setInteger(ToolHelper.AOE_LAYER_KEY, defaultDefinition.layer);
} else {
int currentLayer = tag.getInteger(ToolHelper.AOE_LAYER_KEY);
if (currentLayer < defaultDefinition.layer) {
tag.setInteger(ToolHelper.AOE_LAYER_KEY, currentLayer + 1);
}
}
int currentLayer = getLayer(tag, defaultDefinition);
setLayer(tag, currentLayer + 1, defaultDefinition);
}

public static void decreaseColumn(NBTTagCompound tag, AoESymmetrical defaultDefinition) {
if (!tag.hasKey(ToolHelper.AOE_COLUMN_KEY, Constants.NBT.TAG_INT)) {
tag.setInteger(ToolHelper.AOE_COLUMN_KEY, defaultDefinition.column);
} else {
int currentColumn = tag.getInteger(ToolHelper.AOE_COLUMN_KEY);
if (currentColumn > 0) {
tag.setInteger(ToolHelper.AOE_COLUMN_KEY, currentColumn - 1);
}
}
int currentColumn = getColumn(tag, defaultDefinition);
setColumn(tag, currentColumn - 1, defaultDefinition);
}

public static void decreaseRow(NBTTagCompound tag, AoESymmetrical defaultDefinition) {
if (!tag.hasKey(ToolHelper.AOE_ROW_KEY, Constants.NBT.TAG_INT)) {
tag.setInteger(ToolHelper.AOE_ROW_KEY, defaultDefinition.row);
} else {
int currentRow = tag.getInteger(ToolHelper.AOE_ROW_KEY);
if (currentRow > 0) {
tag.setInteger(ToolHelper.AOE_ROW_KEY, currentRow - 1);
}
}
int currentRow = getRow(tag, defaultDefinition);
setRow(tag, currentRow + 1, defaultDefinition);
}

public static void decreaseLayer(NBTTagCompound tag, AoESymmetrical defaultDefinition) {
if (!tag.hasKey(ToolHelper.AOE_LAYER_KEY, Constants.NBT.TAG_INT)) {
tag.setInteger(ToolHelper.AOE_LAYER_KEY, defaultDefinition.layer);
} else {
int currentLayer = tag.getInteger(ToolHelper.AOE_LAYER_KEY);
if (currentLayer > 0) {
tag.setInteger(ToolHelper.AOE_LAYER_KEY, currentLayer - 1);
}
}
int currentLayer = getLayer(tag, defaultDefinition);
setLayer(tag, currentLayer + 1, defaultDefinition);
}

public static AoESymmetrical none() {
Expand Down
Loading

0 comments on commit dad2678

Please sign in to comment.