perromercenary00 Posted March 14, 2015 Posted March 14, 2015 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() ? Quote
Ernio Posted March 14, 2015 Posted March 14, 2015 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). Quote 1.7.10 is no longer supported by forge, you are on your own.
perromercenary00 Posted March 14, 2015 Author Posted March 14, 2015 interesting this was fast, i gonna use that in my code Quote
perromercenary00 Posted March 16, 2015 Author Posted March 16, 2015 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. Quote
Recommended Posts
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.