Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I have an item with NBT data that I want to be reset to 0 when the player releases the right mouse button, but I can't figure out why onPlayerStoppedUsing() isn't being called. I'm probably overlooking something simple, here's the code:

 

public void onPlayerStoppedUsing(ItemStack itemStack, World world, EntityPlayer player, int ticks)
    {
	System.out.println("working");
	itemStack.stackTagCompound.setInteger("castTime", 0);
    }

public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)
    {
	if(!world.isRemote)
	{
		ChunkCoordinates coords = player.getBedLocation(player.dimension);
		if(coords != null)
		{
			if(itemStack.stackTagCompound.getInteger("cooldown") == 0)
			{
				player.setItemInUse(itemStack, getMaxItemUseDuration(itemStack));
				if(itemStack.stackTagCompound.getInteger("castTime") >= maxCastTime)
				{
					player.setPositionAndUpdate(coords.posX + .5, coords.posY + 1, coords.posZ + .5);
					itemStack.stackTagCompound.setInteger("cooldown", maxCooldown);
					itemStack.stackTagCompound.setInteger("castTime", 0);
				}
				else
				{
					int timeCast = itemStack.stackTagCompound.getInteger("castTime") + 1;
					itemStack.stackTagCompound.setInteger("castTime", timeCast);
				}
			}
			return itemStack;
		}
		else
		{
			player.addChatMessage(new ChatComponentTranslation("msg.hearthstoneFailed.txt"));
			return itemStack;
		}
	}
	else
		return itemStack;
    }

public int getMaxItemUseDuration(ItemStack itemStack)
    {
        return 100;
    }

Try adding @Override on onPlayerStoppedUsing method, to check if it overrides the correct method on item.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

I have an item with NBT data that I want to be reset to 0 when the player releases the right mouse button, but I can't figure out why onPlayerStoppedUsing() isn't being called. I'm probably overlooking something simple, here's the code:

 

public void onPlayerStoppedUsing(ItemStack itemStack, World world, EntityPlayer player, int ticks)
    {
	System.out.println("working");
	itemStack.stackTagCompound.setInteger("castTime", 0);
    }

public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)
    {
	if(!world.isRemote)
	{
		ChunkCoordinates coords = player.getBedLocation(player.dimension);
		if(coords != null)
		{
			if(itemStack.stackTagCompound.getInteger("cooldown") == 0)
			{
				player.setItemInUse(itemStack, getMaxItemUseDuration(itemStack));
				if(itemStack.stackTagCompound.getInteger("castTime") >= maxCastTime)
				{
					player.setPositionAndUpdate(coords.posX + .5, coords.posY + 1, coords.posZ + .5);
					itemStack.stackTagCompound.setInteger("cooldown", maxCooldown);
					itemStack.stackTagCompound.setInteger("castTime", 0);
				}
				else
				{
					int timeCast = itemStack.stackTagCompound.getInteger("castTime") + 1;
					itemStack.stackTagCompound.setInteger("castTime", timeCast);
				}
			}
			return itemStack;
		}
		else
		{
			player.addChatMessage(new ChatComponentTranslation("msg.hearthstoneFailed.txt"));
			return itemStack;
		}
	}
	else
		return itemStack;
    }

public int getMaxItemUseDuration(ItemStack itemStack)
    {
        return 100;
    }

 

1.Every function you are overriding (right click, etc) must have @Override above it in order for it to be called.

2.Have you looked the code for ItemBow?

What are you saying deadrecon? You don't need @Override, it just helps.

 

I thought that @Override specified that you were overriding a parent method. Otherwise it would just be a regular method called only if you did it manually.

The way it's used is to check if it overrides a method. If a method does not override another, but it has the annotation, it won't compile.

Maker of the Craft++ mod.

  • Author

1.Every function you are overriding (right click, etc) must have @Override above it in order for it to be called.

2.Have you looked the code for ItemBow?

 

I have tried putting @Override on just about everything, but it neither fixes the issue nor breaks my code, so I left them out. And I did read through ItemBow, but I didn't see anything I was missing.

Of course it has no effect.. @Override is just a check. And if it doesnt give any errors, then it is fine.

+ does "working" not get printed?

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.