Improve redstone mode persistance

This commit is contained in:
Raoul Van den Berge
2016-09-20 16:48:50 +02:00
parent c8a42e29b3
commit a16898231a
3 changed files with 18 additions and 9 deletions

View File

@@ -692,9 +692,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
energy.readFromNBT(tag);
if (tag.hasKey(RedstoneMode.NBT)) {
redstoneMode = RedstoneMode.getById(tag.getInteger(RedstoneMode.NBT));
}
redstoneMode = RedstoneMode.read(tag);
if (tag.hasKey(NBT_CRAFTING_TASKS)) {
NBTTagList taskList = tag.getTagList(NBT_CRAFTING_TASKS, Constants.NBT.TAG_COMPOUND);
@@ -731,7 +729,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
energy.writeToNBT(tag);
tag.setInteger(RedstoneMode.NBT, redstoneMode.ordinal());
redstoneMode.write(tag);
NBTTagList list = new NBTTagList();

View File

@@ -148,9 +148,7 @@ public abstract class TileNode extends TileBase implements INetworkNode, IRedsto
public void read(NBTTagCompound tag) {
super.read(tag);
if (tag.hasKey(RedstoneMode.NBT)) {
redstoneMode = RedstoneMode.getById(tag.getInteger(RedstoneMode.NBT));
}
redstoneMode = RedstoneMode.read(tag);
if (tag.hasKey(NBT_NETWORK)) {
networkPos = BlockPos.fromLong(tag.getLong(NBT_NETWORK));
@@ -161,7 +159,7 @@ public abstract class TileNode extends TileBase implements INetworkNode, IRedsto
public NBTTagCompound write(NBTTagCompound tag) {
super.write(tag);
tag.setInteger(RedstoneMode.NBT, redstoneMode.ordinal());
redstoneMode.write(tag);
if (network != null) {
tag.setLong(NBT_NETWORK, network.getPosition().toLong());

View File

@@ -1,5 +1,6 @@
package refinedstorage.tile.config;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
@@ -11,7 +12,7 @@ import refinedstorage.tile.data.TileDataParameter;
public enum RedstoneMode {
IGNORE, HIGH, LOW;
public static final String NBT = "RedstoneMode";
private static final String NBT = "RedstoneMode";
public boolean isEnabled(World world, BlockPos pos) {
switch (this) {
@@ -26,6 +27,18 @@ public enum RedstoneMode {
return false;
}
public void write(NBTTagCompound tag) {
tag.setInteger(NBT, ordinal());
}
public static RedstoneMode read(NBTTagCompound tag) {
if (tag.hasKey(RedstoneMode.NBT)) {
return getById(tag.getInteger(NBT));
}
return IGNORE;
}
public static RedstoneMode getById(int id) {
return id < 0 || id >= values().length ? IGNORE : values()[id];
}