Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.15.2] Can't return a FloatNBT


Viperdream
 Share

Recommended Posts

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 by Viperdream
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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());
        }
    }

 

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
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.