Posted November 29, 20195 yr It's been a while since I have worked with NBT Data, but it seems like none of the methods that existed before related to nbt exist now. For starters, there doesn't seem to be a "onUpdate" method for items right now. That's where I used to create the tag.So basically, I can't even figure out how to give items tags let alone do anything with it. Also, it seems like there are two types of tags right now?! Looking through some classes, I found mentions of shareTags and normal Tags. What is their difference? Could someone point me in the right direction. How do you setup tag compounds for items in 1.14? Thank you in advance. Edited November 30, 20195 yr by Cerandior
November 29, 20195 yr Maybe look at this? [LINK] A few bytes about me: public class Xander402 extends Modder implements IForumMember { int javaExperience, moddingExperience; LearningWay preferredLearningWay; public Xander402() { this.javaExperience = BIG; this.moddingExperience = NOT_SO_BIG; this.preferredLearningWay = LearningWay.through("exampes"); super(/*displayName*/"Xander402", /*moddingSince*/"1.9", preferredLearningWay); } @Override public Goal getReasonOfJoining(Forum forum) { return new Goal(() -> { while (true) moddingExperience++; }); } }
November 29, 20195 yr Author It is an outdated article. Those are all things I remember in past versions. You can't do the same thing anymore it seems.
November 29, 20195 yr You should be using Capabilities now. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
November 29, 20195 yr Author 45 minutes ago, Draco18s said: You should be using Capabilities now. Never really used them before. Guess it's going to take some time experimenting until I get the hang of them. Thanks!
November 30, 20195 yr Author On 11/29/2019 at 10:15 PM, Draco18s said: You should be using Capabilities now. Those docs are a little outdated. Things were a little different for me for 1.14. I managed to get it working, but I don't understand some of the things I did to get it working. What exactly is LazyOptional? That is so confusing. Why do I have to return an instance of LazyOptional instead of an instance of my Capability when I try to get the capability? I used the .orElse(null) (which seems to return an instance of my Capability automatically?) method to get the capability after looking at the class of LazyOptional, however I am not sure if that's how you are supposed to do it. I must clarify. It did work without errors, but I don't know if it is the correct way of doing things. Apart from having a little trouble understanding capabilities, I can't seem to get the durability bar to display correctly. I am trying to give a certain item a cooldown after usage. I implemented this through capabilities and the cooldown bit seems to work, however I want to use the durability bar to display the "time left" before next use, and the durability bar is not being rendered at all. It probably has to do with showDurabilityBar method, but I am not sure. Everything related to my capabilities you can find here: https://github.com/Cerandior/VanillaExtended/tree/master/src/main/java/teabx/vanillaextended/capabilities And here is the item in question: https://github.com/Cerandior/VanillaExtended/blob/master/src/main/java/teabx/vanillaextended/items/LordStaff.java Thank you for your help. Edited December 2, 20195 yr by Cerandior
December 1, 20195 yr 3 hours ago, Cerandior said: What exactly is LazyOptional? That is so confusing. Why do I have to return an instance of LazyOptional instead of an instance of my Capability when I try to get the capability? A LazyOptional allows you to create the actual Capability when it is needed (but the LazyOptional can exist before then!) For most use-cases, you'll create them both at the same time. 3 hours ago, Cerandior said: I used the .orElse(null) (which seems to return an instance of my Capability automatically?) It will, if your capability was already created. You can also use ifPresent() which takes a lambda expression in the form of x=>{ /* your code here*/ } where x is your capability. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
December 1, 20195 yr Author 52 minutes ago, diesieben07 said: LazyOptional is exactly what it's name suggests: It is an optional value (the requested capability or nothing if the capability is not provided by the queried capability provider) which is lazily computed (only once you ask for it's value is that value actually computed). Don't want to be a nuisance, but I am having trouble with that durability bar. It is not being updated correctly. Is it because there is a lack of communication between the server and the client at the moment? (I haven't setup packets yet). Here is the class of the item: https://github.com/Cerandior/VanillaExtended/blob/master/src/main/java/teabx/vanillaextended/items/LordStaff.java
December 1, 20195 yr Author 1 hour ago, diesieben07 said: Capability NBT is not sent to the client by default. You have to override getShareTag and readShareTag in your Item class. I am still not getting any data in the client even when I use the itemstack.getShareTag. I am little confused, how am I supposed to implement this?
December 1, 20195 yr Author 7 minutes ago, diesieben07 said: Show what you tried. @Nullable @Override public CompoundNBT getShareTag(ItemStack stack) { ICoolDownItem cap = stack.getCapability(CapabilityRegistry.COOLDOWN_ITEM, null).orElse(null); CompoundNBT nbt = new CompoundNBT(); nbt.putInt("cooldown", cap.getCooldown()); nbt.putInt("maxcooldown", cap.getMaxCooldown()); return nbt; } @Override public void readShareTag(ItemStack stack, @Nullable CompoundNBT nbt) { } @Override public boolean showDurabilityBar(ItemStack stack) { return true; } @Override public double getDurabilityForDisplay(ItemStack stack) { return 1-(stack.getShareTag().getInt("cooldown")/stack.getShareTag().getInt("maxcooldown")); } I feel like I am doing the same thing I was doing before with extra steps. I think the problem is at the getShareTag, but I am not sure.
December 1, 20195 yr Author 10 minutes ago, diesieben07 said: Well... your readShareTag does... nothing. What did you expect? Also, why are you using orElse(null), but then blindly calling methods on the result? If you expect the capability to always be there, use orElseThrow with a meaningful error message instead of failing with a meaningless, random NullPointerException. I was doing something before, but I got rid of it before posting it here. I was using the nbt data to update the values in the capability but that didn't work. What am I supposed to do with the data I have stored in the nbt tag at the readShareTag? About the second thing. I just stuck at the first thing that didn't give me any errors, did not think it through. Will change them, thank you.
December 1, 20195 yr Author 2 minutes ago, diesieben07 said: This: Show what you tried. @Override public void readShareTag(ItemStack stack, @Nullable CompoundNBT nbt) { if(nbt != null){ ICoolDownItem cap = stack.getCapability(CapabilityRegistry.COOLDOWN_ITEM, null).orElseThrow(null); cap.setCooldown(nbt.getInt("cooldown")); } }
December 1, 20195 yr Author 18 minutes ago, diesieben07 said: That should work... Are the methods called? Use the debugger. Seems like readShareTag is not being called at all. https://prnt.sc/q4rds0 Here, at the getDurabilityForDisplay, the cooldown has not been updated in the capability. Edited December 1, 20195 yr by Cerandior
December 1, 20195 yr Author Just now, diesieben07 said: That should be impossible, because it is called every time an ItemStack of your item is received on the client. I put the breakpoint at it, and intelliJ didn't pause the debugging nor show any data below. This is the class of my item: https://github.com/Cerandior/VanillaExtended/blob/master/src/main/java/teabx/vanillaextended/items/LordStaff.java in case I have done anything blatantly stupid.
December 1, 20195 yr Author 2 minutes ago, diesieben07 said: Apparently this changed in 1.14.4 and it's now completely impossible to sync the capability data of itemstacks, because the share tag is ignored except for when the client takes stacks from the creative menu. So... nothing you can do. When you say completely impossible, you mean like I can't do anything at all about it? Even with packets? That is kind of disappointing. When is the next version of forge planned for release? Edited December 1, 20195 yr by Cerandior
December 1, 20195 yr Author 11 minutes ago, diesieben07 said: I am stupid and didn't even read the code right... It's that getShareTag is (basically) always used when writing stacks and readShareTag is always used when reading them. It should be impossible for you to see readShareTag not being called. I recorded this quick gif. Am I setting the breakpoint right? Edited December 1, 20195 yr by Cerandior
December 1, 20195 yr Author 8 minutes ago, diesieben07 said: I mean... it looks fine? Well I got everything working except for the representation of the cooldown through the durability bar. The breakpoint is set correctly and readNBT is not called. I don't really know what else I can do from here. Is there any chance that I have screwed up the item in some other way that does not allow it to have a shared tag? The github link I provided before contains all the files of the project I am currently working on. When you got the time maybe you can look at it . At the moment, I can't ask you to do anything more, I have spent enough of your time already. I can't think of anything else to do myself. Anyway, thank you for your help. Edited December 1, 20195 yr by Cerandior
December 1, 20195 yr Author 4 minutes ago, diesieben07 said: There is literally one way for getShareTag not to be called: You have overridden shouldSyncTag to return false. Considering you haven't done that: I'm guessing something about your setup is broken so that the breakpoint doesnt trigger even though the method is called. I even put some System.out.println (which is a stupid way to debug, I know) in both methods, but nothing shows up in the console.
December 1, 20195 yr Author 3 minutes ago, diesieben07 said: I really don't know what to tell you. What version of Forge are you using? I am using Build: 1.14.4-28.0.13
December 2, 20195 yr Author 6 hours ago, diesieben07 said: That is ancient... Please update. I just moved over to Build: 1.14.4-28.1.96. Yet the same problem persists. Can anybody else recreate the same thing in this version of forge? Or has anything similar to this been reported before? Edited December 2, 20195 yr by Cerandior
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.