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

So I've had this problem for a while now and nobody's been able to fix it, including me, so I thought I'd take it here again.

 

Below, you can see the methods in an item that will fire a projectile when right clicked. The problem is when I was switching the player specific values for the gun, so it would work on servers, the value "clipCount" will be set to the correct amount and then subsequently be set to 0 after each reload. I checked the value while the reload loop was running; it would get set to 1, 2, 3, 4, etc without any zeros in the middle, but after the maximum value was reached and exited the reload loop the value would be set to 0.

 

Help?

 

 

@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)
{
	FalloutPlayer props = FalloutPlayer.get(player);
	float actualDamage = damage * ((50 + (props.getSkillValue("guns") * .5F)) / 100);

	if (player.capabilities.isCreativeMode && !world.isRemote)
	{
		if  (itemStack.stackTagCompound.getInteger("currentShotTime") >= shotTime * 20.0)
		{
			world.spawnEntityInWorld(new EntityBullet(world, player, actualDamage, spread));
			world.playSoundAtEntity(player, fireSound, 1.0F, 1);
			itemStack.stackTagCompound.setInteger("currentShotTime", 0);
		}
	}

	else if (itemStack.stackTagCompound.getInteger("clipCount") > 0 && itemStack.stackTagCompound.getInteger("currentShotTime") >= shotTime * 20.0 &&
			!world.isRemote && itemStack.stackTagCompound.getInteger("currentReloadTime") > (35 * reloadTime))	
	{
		if (!Fallout.isReloading)
		{
			world.spawnEntityInWorld(new EntityBullet(world, player, actualDamage, spread));
			world.playSoundAtEntity(player, fireSound, 1.0F, 1);
			itemStack.stackTagCompound.setInteger("currentShotTime", 0);
			itemStack.stackTagCompound.setInteger("clipCount", itemStack.stackTagCompound.getInteger("clipCount") - 1);
		}
	}

	return itemStack;
}

@Override
public void onUpdate(ItemStack itemStack, World world, Entity entity, int metadata, boolean bool)
{
	if (itemStack.stackTagCompound == null)
	{
		itemStack.stackTagCompound = new NBTTagCompound();
		itemStack.stackTagCompound.setInteger("clipCount", 0);
		itemStack.stackTagCompound.setInteger("currentReloadTime", 0);
		itemStack.stackTagCompound.setInteger("currentShotTime", 0);
	}

	if (itemStack.stackTagCompound != null)
	{
		itemStack.stackTagCompound.setInteger("currentShotTime", itemStack.stackTagCompound.getInteger("currentShotTime") + 1);
		itemStack.stackTagCompound.setInteger("currentReloadTime", itemStack.stackTagCompound.getInteger("currentReloadTime") + 1);

		if (entity instanceof EntityPlayer)
		{
			EntityPlayer player = (EntityPlayer) entity;
			FalloutPlayer extPlayer = FalloutPlayer.get(player);

			if (itemStack.stackTagCompound.getInteger("clipCount") < clipSize && Fallout.isReloading && player.inventory.hasItem(ammoType))
			{
				player.playSound(reloadSound, 1.0F, 1);

				for (int i = 0; i < clipSize; i++)
				{
					if (player.inventory.hasItem(ammoType) && itemStack.stackTagCompound.getInteger("clipCount") < clipSize)
					{
						int currentClip = itemStack.stackTagCompound.getInteger("clipCount");
						player.inventory.consumeInventoryItem(ammoType);
						itemStack.stackTagCompound.setInteger("clipCount", currentClip + 1);
						System.out.println(itemStack.stackTagCompound.getInteger("clipCount"));
					}
				}

				System.out.println(itemStack.stackTagCompound.getInteger("clipCount"));
				itemStack.stackTagCompound.setInteger("currentReloadTime", 0);
				Fallout.isReloading = false;
			}
		}
	}
}

 

  • Author

So I tested each individual NBT data value and it seems that the values just don't store. Does anyone know what I'm doing wrong?

  • Author

Any ideas anyone?

-EDIT- I've been testing it more and the value doesn't always revert to zero, it reverts to what you originally set it to. The problem seems to come from the onItemRightClick method.

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.