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); energy.readFromNBT(tag);
if (tag.hasKey(RedstoneMode.NBT)) { redstoneMode = RedstoneMode.read(tag);
redstoneMode = RedstoneMode.getById(tag.getInteger(RedstoneMode.NBT));
}
if (tag.hasKey(NBT_CRAFTING_TASKS)) { if (tag.hasKey(NBT_CRAFTING_TASKS)) {
NBTTagList taskList = tag.getTagList(NBT_CRAFTING_TASKS, Constants.NBT.TAG_COMPOUND); 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); energy.writeToNBT(tag);
tag.setInteger(RedstoneMode.NBT, redstoneMode.ordinal()); redstoneMode.write(tag);
NBTTagList list = new NBTTagList(); NBTTagList list = new NBTTagList();

View File

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

View File

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