Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ModCap implements ICapabilitySerializable<FloatNBT> {
- @CapabilityInject(IModCap.class)
- public static final Capability<IModCap> MOD_CAP = null;
- private final LazyOptional<IModCap> instance = LazyOptional.of(MOD_CAP::getDefaultInstance);
- //method to register the capability in main class without having too much text.
- public static void register() {
- CapabilityManager.INSTANCE.register(IModCap.class, new ModCapStorage(), ModCapMethods::new);
- }
- @Nonnull
- @Override
- public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> tag, @Nullable Direction side) {
- return MOD_CAP.orEmpty(tag, instance);
- }
- @Override
- public FloatNBT serializeNBT() {
- return (FloatNBT) MOD_CAP.getStorage().writeNBT(
- MOD_CAP,
- instance.orElseThrow(
- () -> new IllegalArgumentException("LazyOptional cannot be empty!")),
- null);
- }
- @Override
- public void deserializeNBT(FloatNBT nbt) {
- MOD_CAP.getStorage().readNBT(
- MOD_CAP,
- instance.orElseThrow(
- () -> new IllegalArgumentException("LazyOptional cannot be empty!")),
- null, nbt);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement