blob: 1f0dfed906b0b8666aca261613c287c80d539948 [file] [log] [blame] [raw]
package li.cil.oc.common.tileentity
import li.cil.oc.Settings
import li.cil.oc.api
import li.cil.oc.api.network.Visibility
import li.cil.oc.common.tileentity.traits.BundledRedstoneAware
import li.cil.oc.common.tileentity.traits.Environment
import li.cil.oc.integration.util.BundledRedstone
import li.cil.oc.server.component
import li.cil.oc.util.ExtendedNBT._
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.common.util.ForgeDirection
class Redstone extends Environment with BundledRedstoneAware {
val instance =
if (BundledRedstone.isAvailable)
new component.Redstone.Bundled(this)
else
new component.Redstone.Vanilla(this)
val node = instance.node
val dummyNode = if (node != null) {
node.setVisibility(Visibility.Network)
_isOutputEnabled = true
api.Network.newNode(this, Visibility.None).create()
}
else null
override def canUpdate = isServer
// ----------------------------------------------------------------------- //
override def readFromNBTForServer(nbt: NBTTagCompound) {
super.readFromNBTForServer(nbt)
instance.load(nbt.getCompoundTag(Settings.namespace + "redstone"))
}
override def writeToNBTForServer(nbt: NBTTagCompound) {
super.writeToNBTForServer(nbt)
nbt.setNewCompoundTag(Settings.namespace + "redstone", instance.save)
}
// ----------------------------------------------------------------------- //
override protected def onRedstoneInputChanged(side: ForgeDirection, oldMaxValue: Int, newMaxValue: Int) {
super.onRedstoneInputChanged(side, oldMaxValue, newMaxValue)
if (node != null && node.network != null) {
node.connect(dummyNode)
dummyNode.sendToNeighbors("redstone.changed", side, int2Integer(oldMaxValue), int2Integer(newMaxValue))
}
}
}