Jump to content

OnUsingTick() doesn't stop in survival gamemode 1.12.2


poopoodice

Recommended Posts

    @Override
    public void onUsingTick(ItemStack itemstack, EntityLivingBase entity, int count)
    {
        EntityPlayer player = (EntityPlayer) entity;
	    if(fireAble(itemstack))
	    {
	      	fire(player.world, player, itemstack);
	    }
		if (reloadAble((EntityPlayer) player, itemstack) && !(this.loading))
		{
			reload(this.ammoType, (EntityPlayer) player, itemstack);
		}
    }

	@Override
	public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) 
	{
		ItemStack itemstack = playerIn.getHeldItem(handIn);
		if(!worldIn.isRemote)
		{
			if(!playerIn.isHandActive())
            {
				if (fireAble(itemstack))
				{
					fire(worldIn, playerIn, itemstack);
				}
				if (reloadAble(playerIn, itemstack) && !(this.loading))
				{
					reload(this.ammoType, playerIn, itemstack);
				}
				playerIn.setActiveHand(handIn);
                return new ActionResult<>(EnumActionResult.SUCCESS, itemstack);
            }
		}
		return new ActionResult<>(EnumActionResult.FAIL, itemstack);
	}

I've written these codes. They work fine in the creative mode, the gun stopped fire when the right mouse button was released, but in survival mode, sometimes it just doesn't stop, the gun keeps fire although the player has released the mouse.

What might cause this problem and how do I solve it?

Link to comment
Share on other sites

After running a couple of times, I notice the problem is 

itemstack.damageItem(1, player);

If I remove this line of code everything works again, but as soon as I add it in either onitemrightclick() or onusingitem() it acts weird, I think when Minecraft sets the item's damage it interrupts with the using method. Any way to solve this? I have tried to use setdamage instead of damageitem doesn't work either.

Link to comment
Share on other sites

2 hours ago, poopoodice said:

Any way to solve this?

I believe this has been a problem for a long time. It happens whenever the ItemStack changes. I'm thinking you might be able to use Item#shouldCauseRequipAnimation?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

 
 
 
 
1 minute ago, Animefan8888 said:

I believe this has been a problem for a long time. It happens whenever the ItemStack changes. I'm thinking you might be able to use Item#shouldCauseRequipAnimation?

What I mean by doesnt stop isnt just about the animation, it also execute the code in the method. And I did use shouldCauseReequipAnimation and returned false but still not working

Link to comment
Share on other sites

3 hours ago, Animefan8888 said:

I believe this has been a problem for a long time. It happens whenever the ItemStack changes. I'm thinking you might be able to use Item#shouldCauseRequipAnimation?

Is it better to use events instead of onitemrightclick and onusingtick

Edited by poopoodice
Link to comment
Share on other sites

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.