Jump to content

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


perromercenary00

Recommended Posts

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() ?

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.