package mcjty.rftools.blocks.logic;
import mcjty.lib.entity.GenericTileEntity;
import mcjty.lib.varia.BlockTools;
import net.minecraft.nbt.NBTTagCompound;
public class RedstoneReceiverTileEntity extends GenericTileEntity {
private boolean redstoneOut = false;
private int channel = -1;
public RedstoneReceiverTileEntity() {
}
public int getChannel() {
return channel;
}
public void setChannel(int channel) {
this.channel = channel;
markDirty();
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
@Override
protected void checkStateServer() {
super.checkStateServer();
if (channel != -1) {
RedstoneChannels channels = RedstoneChannels.getChannels(worldObj);
RedstoneChannels.RedstoneChannel ch = channels.getChannel(channel);
boolean newout = false;
if (ch != null) {
newout = ch.getValue() != 0;
}
if (newout != redstoneOut) {
redstoneOut = newout;
notifyBlockUpdate();
}
}
}
@Override
protected int updateMetaData(int meta) {
meta = super.updateMetaData(meta);
return BlockTools.setRedstoneSignalOut(meta, redstoneOut);
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
redstoneOut = tagCompound.getBoolean("rs");
}
@Override
public void readRestorableFromNBT(NBTTagCompound tagCompound) {
super.readRestorableFromNBT(tagCompound);
channel = tagCompound.getInteger("channel");
}
@Override
public void writeToNBT(NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
tagCompound.setBoolean("rs", redstoneOut);
}
@Override
public void writeRestorableToNBT(NBTTagCompound tagCompound) {
super.writeRestorableToNBT(tagCompound);
tagCompound.setInteger("channel", channel);
}
}