Guest User

Untitled

a guest
Aug 31st, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. package com.gudenau.machine.capability;
  2.  
  3. import net.minecraft.nbt.NBTBase;
  4. import net.minecraft.nbt.NBTTagCompound;
  5. import net.minecraft.util.EnumFacing;
  6. import net.minecraftforge.common.capabilities.Capability;
  7.  
  8. /**
  9.  * Created by gudenau on 8/26/2016.
  10.  */
  11. public class GravityStorage implements Capability.IStorage<GravityCapability> {
  12.     @Override
  13.     public NBTBase writeNBT(Capability<GravityCapability> capability, GravityCapability instance, EnumFacing side) {
  14.         NBTTagCompound nbtTagCompound = new NBTTagCompound();
  15.         if(instance.direction != null) {
  16.             nbtTagCompound.setInteger("direction", instance.direction.ordinal());
  17.             nbtTagCompound.setBoolean("gravity", instance.gravity);
  18.         }
  19.         return nbtTagCompound;
  20.     }
  21.  
  22.     @Override
  23.     public void readNBT(Capability<GravityCapability> capability, GravityCapability instance, EnumFacing side, NBTBase nbt) {
  24.         if(nbt instanceof NBTTagCompound){
  25.             NBTTagCompound tagCompound = (NBTTagCompound) nbt;
  26.             if(tagCompound.hasKey("gravity")) {
  27.                 instance.direction = EnumFacing.values()[tagCompound.getInteger("direction")];
  28.                 instance.gravity = tagCompound.getBoolean("gravity");
  29.             }
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment