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.

[1.8]Is posible to write nbtTags in onUsingTick() method ?? bug?

Featured Replies

Posted

good days

 

im triying to make an animated item swiching json files but i been notice when in my code try to write an nbt in the onUsingTick()  method i just break and causes the playerIn.setItemInUse(pistola, this.getMaxItemUseDuration(pistola));  to stop and execute  onPlayerStoppedUsing()

 

for example

 

@Override
 public int getMaxItemUseDuration(ItemStack pistola)
 {
     return 1000;
 }

 @Override
 public EnumAction getItemUseAction(ItemStack pistola)
 {
     return EnumAction.NONE;
 }

//######################################################################################3	
@Override
public ItemStack onItemRightClick(ItemStack pistola, World worldIn, EntityPlayer playerIn)
  {
            playerIn.setItemInUse(pistola, this.getMaxItemUseDuration(pistola));
            return pistola;
          }
//######################################################################################3	
 @Override
 public void onUsingTick(ItemStack pistola, EntityPlayer playerIn, int count)
 {
              setInttag(pistola,"munition", 0 );
          }
//#########################################################################3

public static void setInttag(ItemStack its, String tag, int value){

	try{
	NBTTagCompound nsInt= its.getTagCompound();
	nsInt.setInteger(tag, value);
	its.setTagCompound(nsInt);

	}catch(Throwable any) {

	NBTTagCompound nsInt = new NBTTagCompound();
	nsInt.setInteger(tag, value);	
	its.setTagCompound(nsInt);	

}}
//#########################################################################3
 @Override
 public void onPlayerStoppedUsing(ItemStack pistola, World worldIn, EntityPlayer playerIn, int timeLeft)
 {

System.out.println(" timeLeft"+ timeLeft);

         }


 

 

when i release rigth click it get stuck  and dont reach  onPlayerStoppedUsing , it continues until it counts to 1000,

but if i comment //setInttag(pistola,"munition", 0 ); in onUsingTick()

 

[22:13:17] [Client thread/INFO] [sTDOUT]: [mercenarymod.items.armasdefuego.pistola75nf.pistola75NF:onPlayerStoppedUsing:460]:  timeLeft999

[22:13:17] [server thread/INFO] [sTDOUT]: [mercenarymod.items.armasdefuego.pistola75nf.pistola75NF:onPlayerStoppedUsing:460]:  timeLeft999

[22:13:18] [Client thread/INFO] [sTDOUT]: [mercenarymod.items.armasdefuego.pistola75nf.pistola75NF:onPlayerStoppedUsing:460]:  timeLeft996

[22:13:18] [server thread/INFO] [sTDOUT]: [mercenarymod.items.armasdefuego.pistola75nf.pistola75NF:onPlayerStoppedUsing:460]:  timeLeft996

[22:13:20] [Client thread/INFO] [sTDOUT]: [mercenarymod.items.armasdefuego.pistola75nf.pistola75NF:onPlayerStoppedUsing:460]:  timeLeft988

[22:13:20] [server thread/INFO] [sTDOUT]: [mercenarymod.items.armasdefuego.pistola75nf.pistola75NF:onPlayerStoppedUsing:460]:  timeLeft988

[22:13:21] [Client thread/INFO] [sTDOUT]: [mercenarymod.items.armasdefuego.pistola75nf.pistola75NF:onPlayerStoppedUsing:460]:  timeLeft984

[22:13:21] [server thread/INFO] [sTDOUT]: [mercenarymod.items.armasdefuego.pistola75nf.pistola75NF:onPlayerStoppedUsing:460]:  timeLeft984

[22:13:23] [Client thread/INFO] [sTDOUT]: [mercenarymod.items.armasdefuego.pistola75nf.pistola75NF:onPlayerStoppedUsing:460]:  timeLeft987

[22:13:23] [server thread/INFO] [sTDOUT]: [mercenarymod.items.armasdefuego.pistola75nf.pistola75NF:onPlayerStoppedUsing:460]:  timeLeft987

 

it begins to work like it must

 

 

jummmm

¿is there a work aroun thath alow my to writte nbts from onUsingTick() ?

 

 

 

Aside from the fact that is the worst way of animating, you shouldn't be using try/catch.

 

NBTTagCompound tag = stack.getTagCompound();
if (tag == null) tag = new NBTTagCompound();
// Do your stuff.

 

Other than that I don't really see anything out of ordinary that could cause problems. Your operations SEEM valid (not very good tho, animating should be done by client and rendering engine, not data manipulation).

1.7.10 is no longer supported by forge, you are on your own.

  • Author

no

 

i do the changes in the nbtags  and no, the trouble persist

mabi is a bug  i been triying other tings  looks that when  no mather where i doit , if something change the nbttags from an item this get reset and

playerIn.setItemInUse get restarted.

 

//#########################################################################3

public static int getInttag(ItemStack item, String tag){	

		NBTTagCompound etiquetas = item.getTagCompound();
		if (etiquetas == null){ 
			intialize(item);	
			etiquetas = item.getTagCompound();
		                      }

		int ex=etiquetas.getInteger(tag); 
		return ex;

}

//#########################################################################3

public static void setInttag(ItemStack item, String tag, int value){

	NBTTagCompound etiquetas = item.getTagCompound();
	if (etiquetas == null){ 
		intialize(item);	
		etiquetas = item.getTagCompound();
	                      }

	etiquetas.setInteger(tag, value);
	item.setTagCompound(etiquetas);


}
//#########################################################################3

 

 

i gonna make another post exposing my teories.

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.