Skip to content

Commit 9ad3259

Browse files
committed
Address review
1 parent f2100bd commit 9ad3259

File tree

17 files changed

+74
-141
lines changed

17 files changed

+74
-141
lines changed

src/main/java/gregtech/api/items/IDyeableItem.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,13 @@ public interface IDyeableItem {
1818

1919
default boolean hasColor(ItemStack stack) {
2020
NBTTagCompound nbttagcompound = stack.getTagCompound();
21-
return nbttagcompound != null && nbttagcompound.hasKey("display", Constants.NBT.TAG_COMPOUND) &&
22-
nbttagcompound.getCompoundTag("display").hasKey("color", Constants.NBT.TAG_INT);
21+
return nbttagcompound != null && nbttagcompound.hasKey("color", Constants.NBT.TAG_INT);
2322
}
2423

2524
default int getColor(ItemStack stack) {
2625
NBTTagCompound nbttagcompound = stack.getTagCompound();
27-
if (nbttagcompound != null) {
28-
NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");
29-
if (nbttagcompound1.hasKey("color", Constants.NBT.TAG_INT)) {
30-
return nbttagcompound1.getInteger("color");
31-
}
26+
if (nbttagcompound != null && nbttagcompound.hasKey("color", Constants.NBT.TAG_INT)) {
27+
return nbttagcompound.getInteger("color");
3228
}
3329
return getDefaultColor(stack);
3430
}
@@ -39,11 +35,8 @@ default int getDefaultColor(ItemStack stack) {
3935

4036
default void removeColor(ItemStack stack) {
4137
NBTTagCompound nbttagcompound = stack.getTagCompound();
42-
if (nbttagcompound != null) {
43-
NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");
44-
if (nbttagcompound1.hasKey("color")) {
45-
nbttagcompound1.removeTag("color");
46-
}
38+
if (nbttagcompound != null && nbttagcompound.hasKey("color")) {
39+
nbttagcompound.removeTag("color");
4740
}
4841
}
4942

@@ -53,11 +46,7 @@ default void setColor(ItemStack stack, int color) {
5346
nbttagcompound = new NBTTagCompound();
5447
stack.setTagCompound(nbttagcompound);
5548
}
56-
NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");
57-
if (!nbttagcompound.hasKey("display", Constants.NBT.TAG_COMPOUND)) {
58-
nbttagcompound.setTag("display", nbttagcompound1);
59-
}
60-
nbttagcompound1.setInteger("color", color);
49+
nbttagcompound.setInteger("color", color);
6150
}
6251

6352
default @NotNull EnumActionResult onItemUseFirst(@NotNull EntityPlayer player, @NotNull World world,

src/main/java/gregtech/api/items/toolitem/IGTTool.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -647,13 +647,12 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {
647647
default EnumActionResult definition$onItemUseFirst(@NotNull EntityPlayer player, @NotNull World world,
648648
@NotNull BlockPos pos, @NotNull EnumFacing facing, float hitX,
649649
float hitY, float hitZ, @NotNull EnumHand hand) {
650-
ItemStack stack = player.getHeldItem(hand);
651-
stack = toolbeltPassthrough(stack);
650+
ItemStack stack = toolbeltPassthrough(player.getHeldItem(hand));
652651
List<IToolBehavior> behaviors;
653652
if (stack.getItem() instanceof IGTTool tool) behaviors = tool.getToolStats().getBehaviors();
654653
else return EnumActionResult.PASS;
655654
for (IToolBehavior behavior : behaviors) {
656-
if (behavior.onItemUseFirst(stack, player, world, pos, facing, hitX, hitY, hitZ, hand) ==
655+
if (behavior.onItemUseFirst(player, world, pos, facing, hitX, hitY, hitZ, hand) ==
657656
EnumActionResult.SUCCESS) {
658657
return EnumActionResult.SUCCESS;
659658
}
@@ -664,14 +663,13 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {
664663

665664
default EnumActionResult definition$onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand,
666665
EnumFacing facing, float hitX, float hitY, float hitZ) {
667-
ItemStack stack = player.getHeldItem(hand);
668-
stack = toolbeltPassthrough(stack);
666+
ItemStack stack = toolbeltPassthrough(player.getHeldItem(hand));
669667
List<IToolBehavior> behaviors;
670668
if (stack.getItem() instanceof IGTTool tool) behaviors = tool.getToolStats().getBehaviors();
671669
else return EnumActionResult.PASS;
672670

673671
for (IToolBehavior behavior : behaviors) {
674-
if (behavior.onItemUse(stack, player, world, pos, hand, facing, hitX, hitY, hitZ) ==
672+
if (behavior.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ) ==
675673
EnumActionResult.SUCCESS) {
676674
return EnumActionResult.SUCCESS;
677675
}
@@ -696,7 +694,7 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {
696694
else return ActionResult.newResult(EnumActionResult.PASS, original);
697695

698696
for (IToolBehavior behavior : behaviors) {
699-
if (behavior.onItemRightClick(stack, world, player, hand).getType() == EnumActionResult.SUCCESS) {
697+
if (behavior.onItemRightClick(world, player, hand).getType() == EnumActionResult.SUCCESS) {
700698
return ActionResult.newResult(EnumActionResult.SUCCESS, original);
701699
}
702700
}

src/main/java/gregtech/api/items/toolitem/ItemGTToolbelt.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ public void addInformation(@NotNull ItemStack stack, @Nullable World world, @Not
322322
tooltip.add(I18n.format("item.gt.tool.toolbelt.tooltip"));
323323
tooltip.add("");
324324
tooltip.add(I18n.format("item.gt.tool.toolbelt.paint"));
325-
tooltip.add(I18n.format("item.gt.tool.toolbelt.dye"));
326325
tooltip.add("");
327326
tooltip.add(I18n.format("item.gt.tool.toolbelt.maintenance"));
328327
} else tooltip.add(I18n.format("gregtech.tooltip.hold_shift"));

src/main/java/gregtech/api/items/toolitem/behavior/IToolBehavior.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ default boolean canDisableShield(ItemStack stack, ItemStack shield, EntityLiving
7979
}
8080

8181
/**
82-
* Called when a Block is right-clicked with this Item, but before the block is activated
82+
* Called when a Block is right-clicked with this Item, but before the block is activated.
83+
* If actions not going through {@link gregtech.api.items.toolitem.ToolHelper} are performed, such as
84+
* {@link ItemStack#shrink(int)}, don't forget to perform toolbelt passthrough via
85+
* {@link gregtech.api.items.toolitem.ToolHelper#toolbeltPassthrough(ItemStack)}
8386
*
8487
* @param player the player clicking with the item
8588
* @param world the world in which the block is clicked
@@ -90,16 +93,18 @@ default boolean canDisableShield(ItemStack stack, ItemStack shield, EntityLiving
9093
* @param hitZ the z location of the block hit
9194
* @param hand the hand holding the item
9295
*/
93-
default EnumActionResult onItemUseFirst(@NotNull ItemStack stack, @NotNull EntityPlayer player,
94-
@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing facing,
95-
float hitX, float hitY, float hitZ, @NotNull EnumHand hand) {
96+
default EnumActionResult onItemUseFirst(@NotNull EntityPlayer player, @NotNull World world, @NotNull BlockPos pos,
97+
@NotNull EnumFacing facing, float hitX, float hitY, float hitZ,
98+
@NotNull EnumHand hand) {
9699
return EnumActionResult.PASS;
97100
}
98101

99102
/**
100-
* Called when a Block is right-clicked with this Item
103+
* Called when a Block is right-clicked with this Item.
104+
* If actions not going through {@link gregtech.api.items.toolitem.ToolHelper} are performed, such as
105+
* {@link ItemStack#shrink(int)}, don't forget to perform toolbelt passthrough via
106+
* {@link gregtech.api.items.toolitem.ToolHelper#toolbeltPassthrough(ItemStack)}
101107
*
102-
* @param stack the itemstack of the tool
103108
* @param player the player clicking with the item
104109
* @param world the world in which the block is clicked
105110
* @param pos the position of the blocked clicked
@@ -110,23 +115,25 @@ default EnumActionResult onItemUseFirst(@NotNull ItemStack stack, @NotNull Entit
110115
* @param hitZ the z location of the block hit
111116
*/
112117
@NotNull
113-
default EnumActionResult onItemUse(@NotNull ItemStack stack, @NotNull EntityPlayer player, @NotNull World world,
114-
@NotNull BlockPos pos,
118+
default EnumActionResult onItemUse(@NotNull EntityPlayer player, @NotNull World world, @NotNull BlockPos pos,
115119
@NotNull EnumHand hand, @NotNull EnumFacing facing, float hitX, float hitY,
116120
float hitZ) {
117121
return EnumActionResult.PASS;
118122
}
119123

120124
/**
121125
* Called when the equipped item is right-clicked.
126+
* If actions not going through {@link gregtech.api.items.toolitem.ToolHelper} are performed, such as
127+
* {@link ItemStack#shrink(int)}, don't forget to perform toolbelt passthrough via
128+
* {@link gregtech.api.items.toolitem.ToolHelper#toolbeltPassthrough(ItemStack)}
122129
*
123130
* @param world the world in which the click happened
124131
* @param player the player clicking the item
125132
* @param hand the hand holding the item
126133
*/
127134
@NotNull
128-
default ActionResult<ItemStack> onItemRightClick(@NotNull ItemStack stack, @NotNull World world,
129-
@NotNull EntityPlayer player, @NotNull EnumHand hand) {
135+
default ActionResult<ItemStack> onItemRightClick(@NotNull World world, @NotNull EntityPlayer player,
136+
@NotNull EnumHand hand) {
130137
return ActionResult.newResult(EnumActionResult.PASS, player.getHeldItem(hand));
131138
}
132139

src/main/java/gregtech/asm/hooks/OreIngredientHooks.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/main/java/gregtech/asm/visitors/OreIngredientVisitor.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/main/java/gregtech/common/items/ToolItems.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import gregtech.common.items.tool.*;
99
import gregtech.core.sound.GTSoundEvents;
1010

11+
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
12+
1113
import net.minecraft.client.Minecraft;
1214
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
1315
import net.minecraft.enchantment.EnumEnchantmentType;
@@ -21,6 +23,7 @@
2123
import net.minecraftforge.fml.relauncher.Side;
2224
import net.minecraftforge.fml.relauncher.SideOnly;
2325

26+
import org.jetbrains.annotations.ApiStatus;
2427
import org.jetbrains.annotations.NotNull;
2528

2629
import java.util.ArrayList;

src/main/java/gregtech/common/items/tool/BlockRotatingBehavior.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public class BlockRotatingBehavior implements IToolBehavior {
3333
protected BlockRotatingBehavior() {/**/}
3434

3535
@Override
36-
public EnumActionResult onItemUseFirst(@NotNull ItemStack stack, @NotNull EntityPlayer player,
37-
@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing side,
38-
float hitX, float hitY, float hitZ, @NotNull EnumHand hand) {
36+
public EnumActionResult onItemUseFirst(@NotNull EntityPlayer player, @NotNull World world, @NotNull BlockPos pos,
37+
@NotNull EnumFacing side, float hitX, float hitY, float hitZ,
38+
@NotNull EnumHand hand) {
3939
TileEntity te = world.getTileEntity(pos);
4040
// MTEs have special handling on rotation
4141
if (te instanceof IGregTechTileEntity) {

src/main/java/gregtech/common/items/tool/GrassPathBehavior.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ protected GrassPathBehavior() {/**/}
3434

3535
@NotNull
3636
@Override
37-
public EnumActionResult onItemUse(@NotNull ItemStack stack, @NotNull EntityPlayer player, @NotNull World world,
38-
@NotNull BlockPos pos, @NotNull EnumHand hand, @NotNull EnumFacing facing,
39-
float hitX, float hitY, float hitZ) {
37+
public EnumActionResult onItemUse(@NotNull EntityPlayer player, @NotNull World world, @NotNull BlockPos pos,
38+
@NotNull EnumHand hand, @NotNull EnumFacing facing, float hitX, float hitY,
39+
float hitZ) {
4040
if (facing == EnumFacing.DOWN) return EnumActionResult.PASS;
4141

42+
ItemStack stack = player.getHeldItem(hand);
43+
4244
AoESymmetrical aoeDefinition = ToolHelper.getAoEDefinition(stack);
4345

4446
Set<BlockPos> blocks;

src/main/java/gregtech/common/items/tool/HarvestCropsBehavior.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ protected HarvestCropsBehavior() {/**/}
3636

3737
@NotNull
3838
@Override
39-
public EnumActionResult onItemUse(@NotNull ItemStack stack, @NotNull EntityPlayer player, @NotNull World world,
40-
@NotNull BlockPos pos, @NotNull EnumHand hand, @NotNull EnumFacing facing,
41-
float hitX, float hitY, float hitZ) {
39+
public EnumActionResult onItemUse(@NotNull EntityPlayer player, @NotNull World world, @NotNull BlockPos pos,
40+
@NotNull EnumHand hand, @NotNull EnumFacing facing, float hitX, float hitY,
41+
float hitZ) {
4242
if (world.isRemote) {
4343
return EnumActionResult.PASS;
4444
}
4545

46+
ItemStack stack = player.getHeldItem(hand);
47+
4648
AoESymmetrical aoeDefinition = ToolHelper.getAoEDefinition(stack);
4749

4850
Set<BlockPos> blocks;

0 commit comments

Comments
 (0)