Jump to content

Recommended Posts

Posted (edited)

I have created a wrench item. When right-clicking a rotatable block, such as a piston, with said wrench, it rotates the block. This works fine but;
If I rotate the block during 'onItemUse' and the block has an inventory, the inventory is shown - is there a way I can stop that but still rotate the block?
If I rotate the block during 'onItemUseFirst' no gui is opened but the block resets after a block update - is there a way to make the rotation stick, or is this just the wrong place to do the rotation.

I have my own rotate code, but for testing purposes I am just using the default method and still getting the results stated above:

    @Override
    public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
    	if (hand == EnumHand.OFF_HAND)
    	{
    		return EnumActionResult.FAIL;
    	}

    	Block block = world.getBlockState(pos).getBlock();
    	if (!player.canPlayerEdit(pos, facing, player.getHeldItem(hand)))
    	{
    		return EnumActionResult.PASS;
    	}
    	
    	if (block.getValidRotations(world, pos) != null)
    	{
            if (!player.capabilities.isCreativeMode)
            {
                player.getHeldItem(hand).damageItem(1, player);
            }
            block.rotateBlock(world, pos, facing);
    		SoundType soundtype = block.getSoundType(world.getBlockState(pos), world, pos, player);
            world.playSound(player, pos, soundtype.getHitSound(), SoundCategory.BLOCKS, soundtype.getVolume() * 0.5F, soundtype.getPitch() * 0.75F);
        	player.swingArm(hand);
        	return EnumActionResult.SUCCESS;
    	}
    	return EnumActionResult.PASS;
    }

 

Edited by PegBeard
Posted

Not meaning to sound rude, but I had figured that much out and it doesn't really answer my question.
Are you saying that there is no good way to get the rotation to stick when using  onItemUseFirst and no good way to give my item preference with  onItemUse except when sneaking?

 

I don't mind sticking with  onItemUse and sneaking, I am just curious if there is a way to do what I am asking, for versatility reasons.

Posted
30 minutes ago, diesieben07 said:

If you want the item to always rotate the block, even if it has a GUI and even if the player is not sneaking (this is counter-intuitive!)

To a degree. 

I can see the rational both ways, but I'd have to play with it for a while before I could decide if the counter-intuitive method would cause me more frustrating than the must-crouch method. 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)

It was identical to the code shown above, but in the  onItemUseFirst method. So I didn't want to over complicate the original post.

 

    @Override
    public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, EnumHand hand)
    {
    	if (hand == EnumHand.OFF_HAND)
    	{
    		return EnumActionResult.FAIL;
    	}

    	Block block = world.getBlockState(pos).getBlock();
    	if (!player.canPlayerEdit(pos, facing, player.getHeldItem(hand)))
    	{
    		return EnumActionResult.PASS;
    	}
    	
    	if (block.getValidRotations(world, pos) != null)
    	{
            if (!player.capabilities.isCreativeMode)
            {
                player.getHeldItem(hand).damageItem(1, player);
            }
            block.rotateBlock(world, pos, facing);
    		SoundType soundtype = block.getSoundType(world.getBlockState(pos), world, pos, player);
            world.playSound(player, pos, soundtype.getHitSound(), SoundCategory.BLOCKS, soundtype.getVolume() * 0.5F, soundtype.getPitch() * 0.75F);
        	player.swingArm(hand);
        	return EnumActionResult.SUCCESS;
    	}
    	return EnumActionResult.PASS;
    }

When doing the rotation this way, it appears to rotate, but when the block is updated, it reverts the rotation.

Edited by PegBeard

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.