Skip to content

Commit 6cfb27c

Browse files
committed
Fix bed spraying from a tool belt
1 parent 60e58a4 commit 6cfb27c

2 files changed

Lines changed: 22 additions & 24 deletions

File tree

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

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -504,32 +504,20 @@ public void setSelectedTool(int slot, ItemStack stack) {
504504
@NotNull BlockPos pos, @NotNull EnumFacing side, float hitX,
505505
float hitY, float hitZ, @NotNull EnumHand hand) {
506506
EnumActionResult result = IDyeableItem.super.onItemUseFirst(player, world, pos, side, hitX, hitY, hitZ, hand);
507-
if (result == EnumActionResult.PASS) {
508-
ItemStack stack = player.getHeldItem(hand);
509-
ToolStackHandler handler = getHandler(stack);
510-
if (handler.getSelectedStack().isEmpty() &&
511-
world.getTileEntity(pos) instanceof MetaTileEntityHolder holder &&
512-
holder.getMetaTileEntity() instanceof MetaTileEntityMaintenanceHatch maintenance) {
513-
maintenance.fixMaintenanceProblemsWithToolbelt(player, this, stack);
514-
return EnumActionResult.SUCCESS;
515-
}
516-
return super.onItemUseFirst(player, world, pos, side, hitX, hitY, hitZ, hand);
517-
} else return result;
518-
}
507+
if (result != EnumActionResult.PASS) return result;
519508

520-
@Override
521-
public @NotNull EnumActionResult onItemUse(@NotNull EntityPlayer player, @NotNull World world,
522-
@NotNull BlockPos pos, @NotNull EnumHand hand,
523-
@NotNull EnumFacing facing, float hitX, float hitY, float hitZ) {
524-
ToolStackHandler handler = getHandler(player.getHeldItem(hand));
525-
ItemStack selected = handler.getSelectedStack();
526-
if (!selected.isEmpty()) {
527-
EnumActionResult result = AbstractSprayBehavior.handleExternalSpray(player, world, pos, facing, selected);
528-
if (result != EnumActionResult.PASS) {
529-
return result;
530-
}
509+
ItemStack thisToolBelt = player.getHeldItem(hand);
510+
ToolStackHandler handler = getHandler(thisToolBelt);
511+
ItemStack selectedToolBeltStack = handler.getSelectedStack();
512+
if (selectedToolBeltStack.isEmpty() && world.getTileEntity(pos) instanceof MetaTileEntityHolder holder &&
513+
holder.getMetaTileEntity() instanceof MetaTileEntityMaintenanceHatch maintenance) {
514+
maintenance.fixMaintenanceProblemsWithToolbelt(player, this, thisToolBelt);
515+
return EnumActionResult.SUCCESS;
516+
} else if (AbstractSprayBehavior.isSprayCan(selectedToolBeltStack)) {
517+
return AbstractSprayBehavior.handleExternalSpray(player, world, pos, side, selectedToolBeltStack);
531518
}
532-
return super.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
519+
520+
return super.onItemUseFirst(player, world, pos, side, hitX, hitY, hitZ, hand);
533521
}
534522

535523
@Override

src/main/java/gregtech/common/items/behaviors/spray/AbstractSprayBehavior.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,23 @@ public static boolean isSprayCan(@NotNull ItemStack stack) {
8080
return getSprayCanBehavior(stack) != null;
8181
}
8282

83+
/**
84+
* Call from your items
85+
* {@link net.minecraft.item.Item#onItemUseFirst(EntityPlayer, World, BlockPos, EnumFacing, float, float, float, EnumHand)}
86+
* or the meta item equivalent to check if block is sprayable early enough in the click handling chain.
87+
*/
8388
@SuppressWarnings("UnusedReturnValue")
8489
public static @NotNull EnumActionResult handleExternalSpray(@NotNull EntityPlayer player, @NotNull EnumHand hand,
8590
@NotNull World world, @NotNull BlockPos pos,
8691
@NotNull EnumFacing facing) {
8792
return handleExternalSpray(player, world, pos, facing, player.getHeldItem(hand));
8893
}
8994

95+
/**
96+
* Call from your items
97+
* {@link net.minecraft.item.Item#onItemUseFirst(EntityPlayer, World, BlockPos, EnumFacing, float, float, float, EnumHand)}
98+
* or the meta item equivalent to check if block is sprayable early enough in the click handling chain.
99+
*/
90100
public static @NotNull EnumActionResult handleExternalSpray(@NotNull EntityPlayer player,
91101
@NotNull World world, @NotNull BlockPos pos,
92102
@NotNull EnumFacing facing,

0 commit comments

Comments
 (0)