Posted May 2, 20205 yr I've been trying to create my own capability. However, when I try to write the storage class I'm getting an error. Whenever I use the writeNBT funciton and try to write my own float value to the FloatNBT object, it gives the error that FloatNBT has private access. I understand that this prevents me from writing my own value on the FloatNBT, but I haven't found a way around it. I've checked various tutorials and other people's code (that's also from 1.15.2). Using "FloatNBT.valueOf(instance.getPower());" doesn't work either (yet I've seen it working in other mods), since it can't resolve the symbol. This is my instance class: package com.github.viperdream.vnecro.capability.instances; import com.github.viperdream.vnecro.capability.interfaces.IRunicPower; import net.minecraft.nbt.FloatNBT; import net.minecraft.nbt.INBT; import net.minecraft.util.Direction; import net.minecraftforge.common.capabilities.Capability; import javax.annotation.Nullable; public class RunicPower implements IRunicPower { private float rp = 0.0F; public void consume(float points) { this.rp -= points; if(this.rp < 0.0F) this.rp = 0.0F; } public void fill(float points) { this.rp += points; } public void set(float points) { this.rp = points; } public float getPower() { return this.rp; } public static class Storage implements Capability.IStorage<IRunicPower> { @Nullable @Override public INBT writeNBT(Capability<IRunicPower> capability, IRunicPower instance, Direction side) { return new FloatNBT.valueOf(instance.getPower()); } @Override public void readNBT(Capability<IRunicPower> capability, IRunicPower instance, Direction side, INBT nbt) { instance.set(((FloatNBT) nbt).getInt()); } } } Could someone please point me in the right direction? I have the feeling I'm missing something obvious, but I can't see it at the moment. Thanks in advance! Edited May 2, 20205 yr by Viperdream
May 2, 20205 yr 33 minutes ago, Viperdream said: I've been trying to create my own capability. However, when I try to write the storage class I'm getting an error. Whenever I use the writeNBT funciton and try to write my own float value to the FloatNBT object, it gives the error that FloatNBT has private access. I understand that this prevents me from writing my own value on the FloatNBT, but I haven't found a way around it. I've checked various tutorials and other people's code (that's also from 1.15.2). Using "FloatNBT.valueOf(instance.getPower());" doesn't work either (yet I've seen it working in other mods), since it can't resolve the symbol. This is my instance class: package com.github.viperdream.vnecro.capability.instances; import com.github.viperdream.vnecro.capability.interfaces.IRunicPower; import net.minecraft.nbt.FloatNBT; import net.minecraft.nbt.INBT; import net.minecraft.util.Direction; import net.minecraftforge.common.capabilities.Capability; import javax.annotation.Nullable; public class RunicPower implements IRunicPower { private float rp = 0.0F; public void consume(float points) { this.rp -= points; if(this.rp < 0.0F) this.rp = 0.0F; } public void fill(float points) { this.rp += points; } public void set(float points) { this.rp = points; } public float getPower() { return this.rp; } public static class Storage implements Capability.IStorage<IRunicPower> { @Nullable @Override public INBT writeNBT(Capability<IRunicPower> capability, IRunicPower instance, Direction side) { return new FloatNBT.valueOf(instance.getPower()); } @Override public void readNBT(Capability<IRunicPower> capability, IRunicPower instance, Direction side, INBT nbt) { instance.set(((FloatNBT) nbt).getInt()); } } } Could someone please point me in the right direction? I have the feeling I'm missing something obvious, but I can't see it at the moment. Thanks in advance! You don't need to have the 'new' in front of the FloatNBT#valueOf. The method is already creating one. Also, you want a float, not an int so use FloatNBT#getFloat instead of FloatNBT#getInt.
May 2, 20205 yr Author 9 minutes ago, kaydogz said: You don't need to have the 'new' in front of the FloatNBT#valueOf. The method is already creating one. Also, you want a float, not an int so use FloatNBT#getFloat instead of FloatNBT#getInt. I've changed those things, it still isn't working. The valueOf method still says it cannot resolve the method: public static class Storage implements Capability.IStorage<IRunicPower> { @Nullable @Override public INBT writeNBT(Capability<IRunicPower> capability, IRunicPower instance, Direction side) { return FloatNBT.valueOf(instance.getPower()); } @Override public void readNBT(Capability<IRunicPower> capability, IRunicPower instance, Direction side, INBT nbt) { instance.set(((FloatNBT) nbt).getFloat()); } }
May 3, 20205 yr Hi My guess: your IRunicPower.getPower() does not return a float. (it's not enough for RunicPower implements IRunicPower .getPower() to return a float, IRunicPower.getPower() must also do so). -TGG
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.