Cardinal Components API

Cardinal Components API

28M Downloads

Some confusion about how syncing works

Eilux opened this issue ยท 1 comments

commented

So I'm trying to sync some values I have tried several different kinds but I always get the same error message:
Caused by: java.lang.ClassCastException: class <classpath of whatever I tried syncing> cannot be cast to class dev.onyxstudios.cca.api.v3.component.ComponentProvider The code for my component is:

interface PlaceModeComponent extends Component {
    void incrementPlaceMode();
    SlabPlaceMode getPlaceMode();
}

public class PlaceModeComponentImpl implements PlaceModeComponent, AutoSyncedComponent {
    private SlabPlaceMode mode;

    public PlaceModeComponentImpl(){
        this.mode = SlabPlaceMode.ALL;
    }

    @Override
    public void incrementPlaceMode() {
        this.mode = this.mode.next();
        Components.MODE_KEY.sync(this.mode);
    }

    @Override
    public SlabPlaceMode getPlaceMode() {
        return this.mode;
    }

    @Override
    public void readFromNbt(CompoundTag compoundTag) {
        try{
            this.mode = SlabPlaceMode.fromString(compoundTag.getString("placemode"));
            Components.MODE_KEY.sync(this.mode);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void writeToNbt(CompoundTag compoundTag) {
        compoundTag.putString("placemode", SlabPlaceMode.toString(this.mode));
    }
}

commented

wait I see what I did wrong now