Bektor Posted January 8, 2016 Share Posted January 8, 2016 Hi, I'm wondering how to create NBT tags for Items in MC 1.8.9, so that every item got a different timer and all timers will be saved, so that after reloading the world, they are not resetted. Thanks in advance. Bektor Quote Developer of Primeval Forest. Link to comment Share on other sites More sharing options...
Bektor Posted January 8, 2016 Author Share Posted January 8, 2016 Ok, I did it now this way: public int tickExist = -1; @Override public void onCreated(ItemStack stack, World worldIn, EntityPlayer playerIn) { stack.getSubCompound(Constants.MOD_ID, true); if(stack.getTagCompound() != null && stack.getTagCompound().getInteger("timer") == -1) stack.getTagCompound().setInteger("timer", tickExist); } @Override @SideOnly(Side.CLIENT) public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) { if(stack.getTagCompound() != null) { this.tickExist = stack.getTagCompound().getInteger("timer"); } tooltip.add(EnumChatFormatting.DARK_AQUA + "" + (15 - TimeUtil.ticksToSeconds(tickExist) < 0 ? "0" : 15 - TimeUtil.ticksToSeconds(tickExist) + " seconds left")); } In the update method, the tickExist are going to be updated. So, is it correct that I'm using stack.getTagCompound().getInteger("timer"); Oh and now all items got the same value. So, what is wrong? Quote Developer of Primeval Forest. Link to comment Share on other sites More sharing options...
Bektor Posted January 8, 2016 Author Share Posted January 8, 2016 So I should do it that way: stack.getSubCompound(Constants.MOD_ID, true).getInteger("timer") And set it the same way? Correct? And does I need to have a check in the addInformation to see if the NBTTagCompound is null or not? And when will the onCreated method called? Only when the item gets created or when the object gets re-created (like after the Game was restarted)? (just want to know, because I want to know if I have to check if the NBT Tag I want to set already exists or if I just can create it because it will never override an existing one, because it will never be called when the Game was loaded and the item already exists in the world which was loaded) EDIT: oh and how much performance does stack.getSubCompound(Constants.MOD_ID, true).getInteger("timer") cost? Because I'm wondering if its a good idea to use it in the update method, too, to set and get the "timer" variable. (use it here multiply times per update) Quote Developer of Primeval Forest. Link to comment Share on other sites More sharing options...
Bektor Posted January 8, 2016 Author Share Posted January 8, 2016 Ok, thx. Now its working perfectly. And yeah, MC has such a performance, there are such things really negligible. (I'm wondering how the performance would be when MC would use OpenGL 3.3, Java 8 and would be optimised on performance and speed (same graphics), I think it would run faster) Quote Developer of Primeval Forest. Link to comment Share on other sites More sharing options...
Bektor Posted January 8, 2016 Author Share Posted January 8, 2016 So, what else makes Minecraft so slow? But Minecraft with OpenGL 3.3 would still be cool and would make it more cool, because I'm currently learning OpenGL 3.3 with GLSL 330. Quote Developer of Primeval Forest. Link to comment Share on other sites More sharing options...
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.