Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gudenau.machine.capability;
- import net.minecraft.nbt.NBTBase;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.util.EnumFacing;
- import net.minecraftforge.common.capabilities.Capability;
- /**
- * Created by gudenau on 8/26/2016.
- */
- public class GravityStorage implements Capability.IStorage<GravityCapability> {
- @Override
- public NBTBase writeNBT(Capability<GravityCapability> capability, GravityCapability instance, EnumFacing side) {
- NBTTagCompound nbtTagCompound = new NBTTagCompound();
- if(instance.direction != null) {
- nbtTagCompound.setInteger("direction", instance.direction.ordinal());
- nbtTagCompound.setBoolean("gravity", instance.gravity);
- }
- return nbtTagCompound;
- }
- @Override
- public void readNBT(Capability<GravityCapability> capability, GravityCapability instance, EnumFacing side, NBTBase nbt) {
- if(nbt instanceof NBTTagCompound){
- NBTTagCompound tagCompound = (NBTTagCompound) nbt;
- if(tagCompound.hasKey("gravity")) {
- instance.direction = EnumFacing.values()[tagCompound.getInteger("direction")];
- instance.gravity = tagCompound.getBoolean("gravity");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment