Guest User

ModTagProvider

a guest
Oct 23rd, 2020
11
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class ModTagProvider implements ICapabilitySerializable<FloatNBT>, IModTag {
  2. private float mod_tag;
  3.  
  4. public ModTagProvider() {
  5. this.mod_tag = 0;
  6. }
  7.  
  8. @Override
  9. public void set(float floatIn) { this.mod_tag = floatIn; }
  10.  
  11. @Override
  12. public float get() {
  13. return this.mod_tag;
  14. }
  15.  
  16. @CapabilityInject(IModTag.class)
  17. public static final Capability<IModTag> MOD_TAG = null;
  18.  
  19. private LazyOptional<IModTag> instance = LazyOptional.of(MOD_TAG::getDefaultInstance);
  20.  
  21. @Override
  22. public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
  23. return cap == MOD_TAG ? instance.cast() : LazyOptional.empty();
  24. }
  25.  
  26. @Override
  27. public FloatNBT serializeNBT() {
  28. return (FloatNBT) MOD_TAG.getStorage().writeNBT(
  29. MOD_TAG, instance.orElseThrow(
  30. () -> new IllegalArgumentException("LazyOptional cannot be empty!")),
  31. null);
  32. }
  33.  
  34. @Override
  35. public void deserializeNBT(FloatNBT nbt) {
  36. MOD_TAG.getStorage().readNBT(
  37. MOD_TAG, instance.orElseThrow(
  38. () -> new IllegalArgumentException("LazyOptional cannot be empty!")),
  39. null, nbt);
  40. }
  41. }
RAW Paste Data