Guest User

ModCap Class

a guest
Oct 22nd, 2020
23
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class ModCap implements ICapabilitySerializable<FloatNBT> {
  2.  
  3. @CapabilityInject(IModCap.class)
  4. public static final Capability<IModCap> MOD_CAP = null;
  5.  
  6. private final LazyOptional<IModCap> instance = LazyOptional.of(MOD_CAP::getDefaultInstance);
  7.  
  8. //method to register the capability in main class without having too much text.
  9. public static void register() {
  10. CapabilityManager.INSTANCE.register(IModCap.class, new ModCapStorage(), ModCapMethods::new);
  11. }
  12.  
  13. @Nonnull
  14. @Override
  15. public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> tag, @Nullable Direction side) {
  16. return MOD_CAP.orEmpty(tag, instance);
  17. }
  18.  
  19. @Override
  20. public FloatNBT serializeNBT() {
  21. return (FloatNBT) MOD_CAP.getStorage().writeNBT(
  22. MOD_CAP,
  23. instance.orElseThrow(
  24. () -> new IllegalArgumentException("LazyOptional cannot be empty!")),
  25. null);
  26. }
  27.  
  28. @Override
  29. public void deserializeNBT(FloatNBT nbt) {
  30. MOD_CAP.getStorage().readNBT(
  31. MOD_CAP,
  32. instance.orElseThrow(
  33. () -> new IllegalArgumentException("LazyOptional cannot be empty!")),
  34. null, nbt);
  35. }
  36. }
RAW Paste Data