Improve redstone mode persistance
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user