Skip to content

Commit 4939f2f

Browse files
Improve Lighter Opening (#2323)
1 parent e4dc5c3 commit 4939f2f

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/main/java/gregtech/common/items/behaviors/LighterBehaviour.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@
2424
import net.minecraft.item.Item;
2525
import net.minecraft.item.ItemStack;
2626
import net.minecraft.nbt.NBTTagCompound;
27-
import net.minecraft.util.*;
27+
import net.minecraft.util.ActionResult;
28+
import net.minecraft.util.EnumActionResult;
29+
import net.minecraft.util.EnumFacing;
30+
import net.minecraft.util.EnumHand;
31+
import net.minecraft.util.NonNullList;
32+
import net.minecraft.util.ResourceLocation;
33+
import net.minecraft.util.SoundCategory;
2834
import net.minecraft.util.math.BlockPos;
2935
import net.minecraft.world.World;
3036
import net.minecraftforge.fluids.FluidStack;
@@ -89,20 +95,27 @@ public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity en
8995
}
9096

9197
@Override
92-
public EnumActionResult onItemUseFirst(@NotNull EntityPlayer player, @NotNull World world, BlockPos pos,
93-
EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
98+
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
9499
ItemStack stack = player.getHeldItem(hand);
95100
NBTTagCompound compound = GTUtility.getOrCreateNbtCompound(stack);
96101

97102
if (canOpen && player.isSneaking()) {
98103
compound.setBoolean(LIGHTER_OPEN, !compound.getBoolean(LIGHTER_OPEN));
99104
stack.setTagCompound(compound);
100-
return EnumActionResult.PASS;
101105
}
106+
return ActionResult.newResult(EnumActionResult.PASS, stack);
107+
}
108+
109+
@Override
110+
public EnumActionResult onItemUseFirst(@NotNull EntityPlayer player, @NotNull World world, BlockPos pos,
111+
EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
112+
ItemStack stack = player.getHeldItem(hand);
113+
NBTTagCompound compound = GTUtility.getOrCreateNbtCompound(stack);
102114

103115
if (!player.canPlayerEdit(pos, side, player.getHeldItem(hand))) return EnumActionResult.FAIL;
104116
// If this item does not have opening mechanics, or if it does and is currently open
105-
if ((!canOpen || compound.getBoolean(LIGHTER_OPEN)) && consumeFuel(player, stack)) {
117+
// If the item has opening mechanics, and the player is sneaking, close the item instead
118+
if ((!canOpen || (compound.getBoolean(LIGHTER_OPEN)) && !player.isSneaking()) && consumeFuel(player, stack)) {
106119
player.getEntityWorld().playSound(null, player.getPosition(), SoundEvents.ITEM_FLINTANDSTEEL_USE,
107120
SoundCategory.PLAYERS, 1.0F, GTValues.RNG.nextFloat() * 0.4F + 0.8F);
108121
IBlockState blockState = world.getBlockState(pos);

0 commit comments

Comments
 (0)