Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I'm trying to make some capabilities in 1.17 after moving from 1.16 and I can't figure out how I am supposed to do them now.


This is how I did them in 1.16.

public class Cooldowns implements ICooldowns {
    private int summonCooldown = 0;

    @Override
    public void setSummonCooldown(int var) {
        this.summonCooldown = var;
    }

    @Override
    public int getSummonCooldown() {
        return this.summonCooldown;
    }
}
public class CooldownCapability implements ICapabilitySerializable<CompoundNBT> {

    @CapabilityInject(ICooldowns.class)
    public static final Capability<ICooldowns> CAPABILITY = null;
    private LazyOptional<ICooldowns> instance = LazyOptional.of(CAPABILITY::getDefaultInstance);

    @Override
    public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
        return cap == CAPABILITY ? instance.cast() : LazyOptional.empty();
    }

    @Override
    public CompoundNBT serializeNBT() {
        return (CompoundNBT) CAPABILITY.getStorage().writeNBT(CAPABILITY, instance.orElseThrow(() -> new IllegalArgumentException("LazyOptional must not be empty!")), null);
    }

    @Override
    public void deserializeNBT(CompoundNBT nbt) {
        CAPABILITY.getStorage().readNBT(CAPABILITY, instance.orElseThrow(() -> new IllegalArgumentException("LazyOptional must not be empty!")), null, nbt);
    }
}
public class CooldownStorage implements IStorage<ICooldowns> {

    @Override
    public CompoundNBT writeNBT(Capability<ICooldowns> capability, ICooldowns instance, Direction side) {
        CompoundNBT cnbt = new CompoundNBT();
        cnbt.putInt("summoncooldown",instance.getSummonCooldown());
        return cnbt;
    }

    @Override
    public void readNBT(Capability<ICooldowns> capability, ICooldowns instance, Direction side, INBT nbt) {
        CompoundNBT inbt = (CompoundNBT) nbt;
        instance.setSummonCooldown(inbt.getInt("summoncooldown"));
    }
}

 

From I understand IStorage and getDefaultInstance are depreciated. What do I need to change in order to run this code on 1.17? I've tired to do a lot of research on this but it seems forge's read the docs for 1.17 is outdated as it still tells me to use IStorage.

the Factory and Storage of the Capability has been removed
also you need to use RegisterCapabilitiesEvent to register your Capabilities

  • Author

I am aware that I need to register the capabilities, I just haven't provided that code as far as I am pretty sure nothing has changed in that department.

What do I do in place of the Factory and Storage for the capability?

nothing you need to remove them,
move the code from CooldownStorage#writeNBT & CooldownStorage#readNBT
into the CooldownCapability#serializeNBT & CooldownCapability#deserializeNBT

  • Author
18 minutes ago, Luis_ST said:

nothing you need to remove them,
move the code from CooldownStorage#writeNBT & CooldownStorage#readNBT
into the CooldownCapability#serializeNBT & CooldownCapability#deserializeNBT

Then what do I do with this? It needs the instance

    @Override
    public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
        return cap == CAPABILITY ? instance.cast() : LazyOptional.empty();
    }

 

  • Author
6 minutes ago, diesieben07 said:

You just create a new instance of your capability.

How can I do that? It requires that a LazyOptional must be returned in getCapability
 

public class ChaosActsProvider implements ICapabilitySerializable<CompoundTag> {
    @CapabilityInject(IChaosActs.class)
    public static final Capability<IChaosActs> CAPABILITY = null;
    public static final ChaosActs instance = new ChaosActs();

    @Nonnull
    @Override
    public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
        return cap == CAPABILITY ? instance : LazyOptional.empty();
    }

    @Override
    public CompoundTag serializeNBT() {
        CompoundTag cnbt = new CompoundTag();

        cnbt.putInt("timer",instance.getTimer());

        return cnbt;
    }

    @Override
    public void deserializeNBT(CompoundTag nbt) {
        instance.setTimer(nbt.getInt("timer"));

    }
}

 

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.