Advertisement
HalestormXV

Untitled

Mar 3rd, 2018
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.02 KB | None | 0 0
  1. package halestormxv.capabilities.learnedspells;
  2.  
  3. import halestormxv.utility.Reference;
  4. import net.minecraft.entity.player.EntityPlayer;
  5. import net.minecraft.entity.player.EntityPlayerMP;
  6. import net.minecraft.nbt.*;
  7. import net.minecraft.util.EnumFacing;
  8. import net.minecraft.util.ResourceLocation;
  9. import net.minecraftforge.common.capabilities.Capability;
  10. import net.minecraftforge.common.capabilities.CapabilityInject;
  11. import net.minecraftforge.common.capabilities.ICapabilitySerializable;
  12.  
  13. import javax.annotation.Nonnull;
  14. import javax.annotation.Nullable;
  15. import java.util.Arrays;
  16. import java.util.List;
  17.  
  18.  
  19. public class LearnedSpellsMain
  20. {
  21.     /***********************************
  22.      * This class is the Functions Class
  23.      * The actions take place in this
  24.      * code segment.
  25.      **********************************/
  26.     public class LearnedSpellsFunctions implements ILearnedSpells
  27.     {
  28.         private List<Integer> spellIDs = Arrays.asList();
  29.         private int  SPELL_ID = 0;
  30.  
  31.         public void learnedSpell(EntityPlayer thePlayer, int spellLearned)
  32.         {
  33.             this.SPELL_ID = spellLearned;
  34.             //writeNBT(this.SPELL_ID);
  35.         }
  36.  
  37.         private NBTTagCompound writeNBT()
  38.         {
  39.  
  40.             return null;
  41.         }
  42.  
  43.         @Override
  44.         public NBTTagCompound serializeNBT()
  45.         {
  46.             return writeNBT();
  47.         }
  48.  
  49.         @Override
  50.         public void deserializeNBT(NBTTagCompound nbt)
  51.         {
  52.  
  53.         }
  54.  
  55.         @Override
  56.         public void sync(EntityPlayerMP entityPlayer) {
  57.  
  58.         }
  59.     }
  60.  
  61.     /***********************************
  62.      * This class is the Provider Class
  63.      * It gives us the Capability and
  64.      * looks for it
  65.      **********************************/
  66.     public class LearnedSpellsProvider implements ICapabilitySerializable<NBTTagCompound>
  67.     {
  68.         @CapabilityInject(ILearnedSpells.class)
  69.         public final Capability<ILearnedSpells> LEARNED_SPELLS_CAP = null;
  70.         public ILearnedSpells instance = LEARNED_SPELLS_CAP.getDefaultInstance();
  71.         public final ResourceLocation NAME = new ResourceLocation(Reference.MODID, "learned_spells");
  72.         private final ILearnedSpells cap = new LearnedSpellsFunctions();
  73.  
  74.         @Override
  75.         public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
  76.             return capability == LEARNED_SPELLS_CAP;
  77.         }
  78.  
  79.         @Override
  80.         public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
  81.             if (capability == LEARNED_SPELLS_CAP) {
  82.                 return LEARNED_SPELLS_CAP.cast(cap);
  83.             }
  84.  
  85.             return null;
  86.         }
  87.  
  88.         @Override
  89.         public NBTTagCompound serializeNBT() {
  90.             return cap.serializeNBT();
  91.         }
  92.  
  93.         @Override
  94.         public void deserializeNBT(NBTTagCompound nbt) {
  95.             cap.deserializeNBT(nbt);
  96.         }
  97.     }
  98.  
  99.     /***********************************
  100.      * This class is the Storage Class
  101.      * It gives us the Capability Storage
  102.      * like a good little egg.
  103.      **********************************/
  104.     public class LearnedSpellsStorage implements Capability.IStorage<ILearnedSpells>
  105.     {
  106.  
  107.         @Override
  108.         public NBTTagCompound writeNBT(Capability<ILearnedSpells> capability, ILearnedSpells instance, EnumFacing side)
  109.         {
  110.             return instance.serializeNBT();
  111.         }
  112.  
  113.         @Override
  114.         public void readNBT(Capability<ILearnedSpells> capability, ILearnedSpells instance, EnumFacing side, NBTBase nbt)
  115.         {
  116.             if (nbt instanceof NBTTagIntArray)
  117.                 instance.deserializeNBT(((NBTTagCompound) nbt));
  118.         }
  119.     }
  120.  
  121.     /***********************************
  122.      * This class is the Handler Class
  123.      * It gives us out interactions
  124.      * and getters and setters like a
  125.      * good little egg.
  126.      **********************************/
  127.     public class LearnedSpellsHandler implements ICapabilitySerializable<NBTBase>
  128.     {
  129.         @CapabilityInject(ILearnedSpells.class)
  130.         public  final Capability<ILearnedSpells> LEARNED_SPELLS_CAP = null;
  131.  
  132.         private ILearnedSpells instance = LEARNED_SPELLS_CAP.getDefaultInstance();
  133.  
  134.         @Override
  135.         public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing)
  136.         {
  137.             return capability == LEARNED_SPELLS_CAP;
  138.         }
  139.  
  140.         @Nullable
  141.         @Override
  142.         public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
  143.             return capability == LEARNED_SPELLS_CAP ? LEARNED_SPELLS_CAP.<T> cast(this.instance) : null;
  144.         }
  145.  
  146.         @Override
  147.         public NBTBase serializeNBT()
  148.         {
  149.             return LEARNED_SPELLS_CAP.getStorage().writeNBT(LEARNED_SPELLS_CAP, this.instance, null);
  150.         }
  151.  
  152.         @Override
  153.         public void deserializeNBT(NBTBase nbt)
  154.         {
  155.             LEARNED_SPELLS_CAP.getStorage().readNBT(LEARNED_SPELLS_CAP, this.instance, null, nbt);
  156.         }
  157.     }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement