Skip to content

Commit

Permalink
-Adding writeToNBT() and readFromNBT()
Browse files Browse the repository at this point in the history
  • Loading branch information
gottsch committed Jan 7, 2018
1 parent 5618b41 commit 593120c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import javax.annotation.concurrent.Immutable;

import com.someguyssoftware.gottschcore.GottschCore;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;

/**
Expand Down Expand Up @@ -288,6 +291,24 @@ public int get(char axis) {
}
}

/**
*
* @param nbt
* @return
*/
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
try {
nbt.setInteger("x", getX());
nbt.setInteger("y", getY());
nbt.setInteger("z", getZ());
}
catch(Exception e) {
GottschCore.logger.error("Unable to write state to NBT:", e);
}
return nbt;
}

@Override
public int getX() {
return x;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.someguyssoftware.gottschcore.positional;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;

/**
Expand Down Expand Up @@ -167,4 +168,34 @@ public interface ICoords {
*/
ICoords resetX(int x);

/**
*
* @param parentNBT
*/
public static ICoords readFromNBT(NBTTagCompound nbt) {
Integer x = null;
Integer y = null;
Integer z = null;
ICoords coords = null;
if (nbt.hasKey("x")) {
x = nbt.getInteger("x");
}
if (nbt.hasKey("y")) {
y = nbt.getInteger("y");
}
if (nbt.hasKey("z")) {
z = nbt.getInteger("z");
}
if (x != null && y != null && z != null) {
coords = new Coords(x, y, z);
}
return coords;
}

/**
*
* @param nbt
* @return
*/
NBTTagCompound writeToNBT(NBTTagCompound nbt);
}

0 comments on commit 593120c

Please sign in to comment.