Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toolbelt #2493

Open
wants to merge 88 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 77 commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
d9916e9
Pain
M-W-K Jun 5, 2024
31dfb44
Recipe & texture
M-W-K Jun 5, 2024
b31987d
Finalize in-world handling
M-W-K Jun 5, 2024
58705fb
Spotless
M-W-K Jun 5, 2024
7c37fa8
Maintenance
M-W-K Jun 5, 2024
d8079df
Shift-click
M-W-K Jun 5, 2024
b2162f9
Spotless, once more
M-W-K Jun 5, 2024
affb2f5
Passthrough methods
M-W-K Jun 5, 2024
307ef14
Less cringe
M-W-K Jun 5, 2024
aca0e87
Oops
M-W-K Jun 5, 2024
0fc4a3d
Passthrough / toolbelt detection improvements
M-W-K Jun 5, 2024
3c14c4f
Prevent unexpected behavior on removal of selected tool
M-W-K Jun 5, 2024
31fd761
Better toolbelt GUI handling
M-W-K Jun 5, 2024
a7c3cb5
mui2 (pain)
M-W-K Jun 5, 2024
d426c64
sp3tless
M-W-K Jun 5, 2024
b319b28
improve a fallback
M-W-K Jun 5, 2024
6488ebb
I'm dyeing
M-W-K Jun 6, 2024
cd6e017
improve passthrough
M-W-K Jun 6, 2024
bd2bf01
More universal solution to toolbelt crafting
M-W-K Jun 6, 2024
a2d6f0c
sp4tless
M-W-K Jun 6, 2024
d88e658
Dynamic toolbelt render
M-W-K Jun 15, 2024
bf38ef0
Fix excessive passthrough and toolbelt render and improve IDyeableItem
M-W-K Jun 15, 2024
0158726
Sp4tless
M-W-K Jun 15, 2024
f783a33
Pain
M-W-K Jun 5, 2024
724884d
Recipe & texture
M-W-K Jun 5, 2024
74a4878
Finalize in-world handling
M-W-K Jun 5, 2024
0dceb77
Spotless
M-W-K Jun 5, 2024
247cc31
Maintenance
M-W-K Jun 5, 2024
d062ae8
Shift-click
M-W-K Jun 5, 2024
deeb74e
Spotless, once more
M-W-K Jun 5, 2024
2e81c34
Passthrough methods
M-W-K Jun 5, 2024
e922f65
Less cringe
M-W-K Jun 5, 2024
d85110e
Oops
M-W-K Jun 5, 2024
edbe78f
Passthrough / toolbelt detection improvements
M-W-K Jun 5, 2024
002074f
Prevent unexpected behavior on removal of selected tool
M-W-K Jun 5, 2024
6d2716d
Better toolbelt GUI handling
M-W-K Jun 5, 2024
86c5b20
mui2 (pain)
M-W-K Jun 5, 2024
1d69ba1
sp3tless
M-W-K Jun 5, 2024
48f543f
improve a fallback
M-W-K Jun 5, 2024
05f423d
I'm dyeing
M-W-K Jun 6, 2024
93e17ba
improve passthrough
M-W-K Jun 6, 2024
d7d29f4
More universal solution to toolbelt crafting
M-W-K Jun 6, 2024
f9eeb27
sp4tless
M-W-K Jun 6, 2024
0da1cf9
Dynamic toolbelt render
M-W-K Jun 15, 2024
81ab217
Fix excessive passthrough and toolbelt render and improve IDyeableItem
M-W-K Jun 15, 2024
64a7b67
Sp4tless
M-W-K Jun 15, 2024
57e8438
convert asm to mixin
ghzdude Jun 28, 2024
adec6c6
Merge branch 'toolbelt' into toolbelt
M-W-K Jun 28, 2024
c278468
Merge pull request #1 from ghzdude/toolbelt
M-W-K Jun 28, 2024
76bd281
fix an oops in the merge process
M-W-K Jun 28, 2024
002d772
toolbelt JEI complete
M-W-K Jun 28, 2024
b0ccde3
improve JEI shift-complete behavior
M-W-K Jun 28, 2024
647285c
sp6tless
M-W-K Jun 28, 2024
b9fdd95
sound
M-W-K Jun 28, 2024
2af2cf8
Alternate mixin
M-W-K Jun 30, 2024
899b2de
Merge remote-tracking branch 'main/master' into toolbelt
M-W-K Oct 16, 2024
5628363
Merge with master
M-W-K Oct 16, 2024
03c55bc
Fixes and change to JEI behavior
M-W-K Nov 8, 2024
f374049
Allow toolbelt to fix maintenance in-world and prevent merge crafting
M-W-K Nov 8, 2024
a862a1d
Tweaks and rebalance slot counts
M-W-K Nov 8, 2024
e836de9
Behold, RENDERING
M-W-K Nov 8, 2024
566ed93
Sync moment
M-W-K Nov 9, 2024
45f4bb8
Merge remote-tracking branch 'main/master' into toolbelt
M-W-K Nov 9, 2024
c6c0276
Hide durability until damaged
M-W-K Nov 9, 2024
860db4e
Minor Tweaks
M-W-K Nov 9, 2024
a23249b
spotless
M-W-K Nov 9, 2024
38f5902
actually spotless
M-W-K Nov 9, 2024
ee1a9ea
Fixes
M-W-K Nov 9, 2024
1de6728
rework `buildUI()` (it bothered me)
ghzdude Nov 9, 2024
2b197fe
rework toolbelt's `buildUI()` (it looked at me wrong)
ghzdude Nov 9, 2024
f91468a
Refactor
M-W-K Nov 9, 2024
dad2678
Merge remote-tracking branch 'personal/toolbelt' into toolbelt
M-W-K Nov 9, 2024
f2100bd
Minor change
M-W-K Nov 22, 2024
9ad3259
Address review
M-W-K Nov 24, 2024
531f868
spotless
M-W-K Nov 26, 2024
f46d4d6
mixin to relocate tool highlight text
M-W-K Nov 26, 2024
b1d9262
WrapOperation-ify
M-W-K Nov 27, 2024
a1ae9d2
address review
M-W-K Nov 27, 2024
2fd02a4
fix my side of reviews
ghzdude Nov 29, 2024
c37e0c7
fix aoe size flickering
ghzdude Nov 29, 2024
33bd4f8
add ui title
ghzdude Nov 30, 2024
65b9ff8
address review
M-W-K Nov 30, 2024
6e4f40a
i hate this, but it works
ghzdude Nov 30, 2024
ee3d959
resize arrays on load
ghzdude Nov 30, 2024
6ad5e61
Merge branch 'master' into toolbelt
M-W-K Nov 30, 2024
d190f05
better fix for resizing arrays
ghzdude Nov 30, 2024
7c39e00
initialize threadlocal
ghzdude Dec 18, 2024
8561291
actually fix syncing to client (please)
ghzdude Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions src/main/java/gregtech/api/items/IDyeableItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package gregtech.api.items;

import net.minecraft.block.BlockCauldron;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;

import org.jetbrains.annotations.NotNull;

public interface IDyeableItem {

default boolean hasColor(ItemStack stack) {
NBTTagCompound nbttagcompound = stack.getTagCompound();
return nbttagcompound != null && nbttagcompound.hasKey("color", Constants.NBT.TAG_INT);
M-W-K marked this conversation as resolved.
Show resolved Hide resolved
}

default int getColor(ItemStack stack) {
NBTTagCompound nbttagcompound = stack.getTagCompound();
if (nbttagcompound != null && nbttagcompound.hasKey("color", Constants.NBT.TAG_INT)) {
return nbttagcompound.getInteger("color");
}
return getDefaultColor(stack);
}

default int getDefaultColor(ItemStack stack) {
M-W-K marked this conversation as resolved.
Show resolved Hide resolved
return 0xFFFFFF;
}

default void removeColor(ItemStack stack) {
NBTTagCompound nbttagcompound = stack.getTagCompound();
if (nbttagcompound != null && nbttagcompound.hasKey("color")) {
nbttagcompound.removeTag("color");
}
}

default void setColor(ItemStack stack, int color) {
NBTTagCompound nbttagcompound = stack.getTagCompound();
if (nbttagcompound == null) {
nbttagcompound = new NBTTagCompound();
stack.setTagCompound(nbttagcompound);
}
nbttagcompound.setInteger("color", color);
}

default @NotNull EnumActionResult onItemUseFirst(@NotNull EntityPlayer player, @NotNull World world,
M-W-K marked this conversation as resolved.
Show resolved Hide resolved
@NotNull BlockPos pos, @NotNull EnumFacing side, float hitX,
float hitY, float hitZ, @NotNull EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
if (this.hasColor(stack)) {
IBlockState iblockstate = world.getBlockState(pos);
if (iblockstate.getBlock() instanceof BlockCauldron cauldron) {
int water = iblockstate.getValue(BlockCauldron.LEVEL);
if (water > 0) {
this.removeColor(stack);
cauldron.setWaterLevel(world, pos, iblockstate, water - 1);
return EnumActionResult.SUCCESS;
}
}
}
return EnumActionResult.PASS;
}

/**
* Controls whether the dyeing recipe simply removes the dyeable item from the crafting grid,
* or calls {@link net.minecraftforge.common.ForgeHooks#getContainerItem(ItemStack)} on it.
*/
default boolean shouldGetContainerItem() {
return true;
}
}
165 changes: 113 additions & 52 deletions src/main/java/gregtech/api/items/toolitem/IGTTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
import gregtech.api.capability.GregtechCapabilities;
import gregtech.api.capability.impl.CombinedCapabilityProvider;
import gregtech.api.capability.impl.ElectricItem;
import gregtech.api.gui.GuiTextures;
import gregtech.api.gui.ModularUI;
import gregtech.api.gui.widgets.ClickButtonWidget;
import gregtech.api.gui.widgets.DynamicLabelWidget;
import gregtech.api.items.gui.ItemUIFactory;
import gregtech.api.items.gui.PlayerInventoryHolder;
import gregtech.api.items.metaitem.ElectricStats;
import gregtech.api.items.toolitem.aoe.AoESymmetrical;
import gregtech.api.items.toolitem.behavior.IToolBehavior;
import gregtech.api.mui.GTGuiTextures;
import gregtech.api.mui.GTGuis;
import gregtech.api.recipes.ModHandler;
import gregtech.api.unification.OreDictUnifier;
import gregtech.api.unification.material.Material;
Expand Down Expand Up @@ -63,6 +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 @@ -636,7 +647,11 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {
default EnumActionResult definition$onItemUseFirst(@NotNull EntityPlayer player, @NotNull World world,
@NotNull BlockPos pos, @NotNull EnumFacing facing, float hitX,
float hitY, float hitZ, @NotNull EnumHand hand) {
for (IToolBehavior behavior : getToolStats().getBehaviors()) {
ItemStack stack = toolbeltPassthrough(player.getHeldItem(hand));
List<IToolBehavior> behaviors;
if (stack.getItem() instanceof IGTTool tool) behaviors = tool.getToolStats().getBehaviors();
else return EnumActionResult.PASS;
for (IToolBehavior behavior : behaviors) {
M-W-K marked this conversation as resolved.
Show resolved Hide resolved
if (behavior.onItemUseFirst(player, world, pos, facing, hitX, hitY, hitZ, hand) ==
EnumActionResult.SUCCESS) {
return EnumActionResult.SUCCESS;
Expand All @@ -648,8 +663,14 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {

default EnumActionResult definition$onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand,
EnumFacing facing, float hitX, float hitY, float hitZ) {
for (IToolBehavior behavior : getToolStats().getBehaviors()) {
if (behavior.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ) == EnumActionResult.SUCCESS) {
ItemStack stack = toolbeltPassthrough(player.getHeldItem(hand));
List<IToolBehavior> behaviors;
if (stack.getItem() instanceof IGTTool tool) behaviors = tool.getToolStats().getBehaviors();
else return EnumActionResult.PASS;

for (IToolBehavior behavior : behaviors) {
if (behavior.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ) ==
EnumActionResult.SUCCESS) {
return EnumActionResult.SUCCESS;
}
}
Expand All @@ -659,20 +680,25 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {

default ActionResult<ItemStack> definition$onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
ItemStack original = stack;
stack = toolbeltPassthrough(stack);
M-W-K marked this conversation as resolved.
Show resolved Hide resolved
if (!world.isRemote) {
// TODO: relocate to keybind action when keybind PR happens
if (player.isSneaking() && getMaxAoEDefinition(stack) != AoESymmetrical.none()) {
PlayerInventoryHolder.openHandItemUI(player, hand);
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
ItemGuiFactory.open((EntityPlayerMP) player, hand);
return ActionResult.newResult(EnumActionResult.SUCCESS, original);
M-W-K marked this conversation as resolved.
Show resolved Hide resolved
}
}
List<IToolBehavior> behaviors;
if (stack.getItem() instanceof IGTTool tool) behaviors = tool.getToolStats().getBehaviors();
else return ActionResult.newResult(EnumActionResult.PASS, original);

for (IToolBehavior behavior : getToolStats().getBehaviors()) {
for (IToolBehavior behavior : behaviors) {
if (behavior.onItemRightClick(world, player, hand).getType() == EnumActionResult.SUCCESS) {
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
return ActionResult.newResult(EnumActionResult.SUCCESS, original);
}
}
return ActionResult.newResult(EnumActionResult.PASS, stack);
return ActionResult.newResult(EnumActionResult.PASS, original);
}

default void definition$getSubItems(@NotNull NonNullList<ItemStack> items) {
Expand Down Expand Up @@ -878,6 +904,7 @@ default ModelResourceLocation getModelLocation() {

// Sound Playing
default void playCraftingSound(EntityPlayer player, ItemStack stack) {
stack = toolbeltPassthrough(stack);
// player null check for things like auto-crafters
if (ConfigHolder.client.toolCraftingSounds && getSound() != null && player != null) {
if (canPlaySound(stack)) {
Expand All @@ -903,45 +930,79 @@ default void playSound(EntityPlayer player) {
}
}

default ModularUI createUI(PlayerInventoryHolder holder, EntityPlayer entityPlayer) {
NBTTagCompound tag = getBehaviorsTag(holder.getCurrentItem());
AoESymmetrical defaultDefinition = getMaxAoEDefinition(holder.getCurrentItem());
return ModularUI.builder(GuiTextures.BORDERED_BACKGROUND, 120, 80)
.label(6, 10, "item.gt.tool.aoe.columns")
.label(49, 10, "item.gt.tool.aoe.rows")
.label(79, 10, "item.gt.tool.aoe.layers")
.widget(new ClickButtonWidget(15, 24, 20, 20, "+", data -> {
AoESymmetrical.increaseColumn(tag, defaultDefinition);
holder.markAsDirty();
}))
.widget(new ClickButtonWidget(15, 44, 20, 20, "-", data -> {
AoESymmetrical.decreaseColumn(tag, defaultDefinition);
holder.markAsDirty();
}))
.widget(new ClickButtonWidget(50, 24, 20, 20, "+", data -> {
AoESymmetrical.increaseRow(tag, defaultDefinition);
holder.markAsDirty();
}))
.widget(new ClickButtonWidget(50, 44, 20, 20, "-", data -> {
AoESymmetrical.decreaseRow(tag, defaultDefinition);
holder.markAsDirty();
}))
.widget(new ClickButtonWidget(85, 24, 20, 20, "+", data -> {
AoESymmetrical.increaseLayer(tag, defaultDefinition);
holder.markAsDirty();
}))
.widget(new ClickButtonWidget(85, 44, 20, 20, "-", data -> {
AoESymmetrical.decreaseLayer(tag, defaultDefinition);
holder.markAsDirty();
}))
.widget(new DynamicLabelWidget(23, 65, () -> Integer.toString(
1 + 2 * AoESymmetrical.getColumn(getBehaviorsTag(holder.getCurrentItem()), defaultDefinition))))
.widget(new DynamicLabelWidget(58, 65, () -> Integer.toString(
1 + 2 * AoESymmetrical.getRow(getBehaviorsTag(holder.getCurrentItem()), defaultDefinition))))
.widget(new DynamicLabelWidget(93, 65,
() -> Integer.toString(1 +
AoESymmetrical.getLayer(getBehaviorsTag(holder.getCurrentItem()), defaultDefinition))))
.build(holder, entityPlayer);
IDrawable PLUS = IKey.str("+").asIcon().marginLeft(1);
IDrawable MINUS = IKey.str("-").asIcon().marginLeft(1);
ghzdude marked this conversation as resolved.
Show resolved Hide resolved

@Override
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;
});

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;
});

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
Loading