mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 11:48:02 -04:00
Make prints set to emit redstone but not having a second state emit redstone always.
This commit is contained in:
parent
c0ff965fa7
commit
3fe3f81d7d
@ -168,7 +168,7 @@ object ItemRenderer extends IItemRenderer {
|
||||
val data = new PrintData(stack)
|
||||
Minecraft.getMinecraft.renderEngine.bindTexture(TextureMap.locationBlocksTexture)
|
||||
val state =
|
||||
if (data.stateOn.size > 0 && KeyBindings.showExtendedTooltips)
|
||||
if (data.hasActiveState && KeyBindings.showExtendedTooltips)
|
||||
data.stateOn
|
||||
else
|
||||
data.stateOff
|
||||
|
@ -62,7 +62,7 @@ class Print(protected implicit val tileTag: ClassTag[tileentity.Print]) extends
|
||||
if (data.emitRedstone) {
|
||||
tooltip.add(Localization.Tooltip.PrintRedstoneLevel(data.redstoneLevel))
|
||||
}
|
||||
if (data.lightLevel > 0) {
|
||||
if (data.emitLight) {
|
||||
tooltip.add(Localization.Tooltip.PrintLightValue(data.lightLevel))
|
||||
}
|
||||
}
|
||||
|
@ -29,10 +29,18 @@ class PrintData extends ItemData {
|
||||
var isBeaconBase = false
|
||||
var lightLevel = 0
|
||||
|
||||
def emitRedstone = redstoneLevel > 0 && stateOn.size > 0
|
||||
|
||||
def hasActiveState = stateOn.size > 0
|
||||
|
||||
def emitLight = lightLevel > 0
|
||||
|
||||
def emitRedstone = redstoneLevel > 0
|
||||
|
||||
def emitRedstone(state: Boolean): Boolean = if (state) emitRedstoneWhenOn else emitRedstoneWhenOff
|
||||
|
||||
def emitRedstoneWhenOff = emitRedstone && !hasActiveState
|
||||
|
||||
def emitRedstoneWhenOn = emitRedstone && hasActiveState
|
||||
|
||||
def opacity = {
|
||||
if (opacityDirty) {
|
||||
opacityDirty = false
|
||||
|
@ -19,7 +19,7 @@ class Print extends traits.TileEntity with traits.RedstoneAware with traits.Rota
|
||||
_isOutputEnabled = true
|
||||
|
||||
def activate(): Boolean = {
|
||||
if (data.stateOn.size > 0) {
|
||||
if (data.hasActiveState) {
|
||||
if (!state || !data.isButtonMode) {
|
||||
toggleState()
|
||||
return true
|
||||
@ -32,7 +32,7 @@ class Print extends traits.TileEntity with traits.RedstoneAware with traits.Rota
|
||||
state = !state
|
||||
world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, "random.click", 0.3F, if (state) 0.6F else 0.5F)
|
||||
world.markBlockForUpdate(x, y, z)
|
||||
if (data.emitRedstone) {
|
||||
if (data.emitRedstoneWhenOn) {
|
||||
ForgeDirection.VALID_DIRECTIONS.foreach(output(_, if (state) data.redstoneLevel else 0))
|
||||
}
|
||||
if (state && data.isButtonMode) {
|
||||
@ -89,6 +89,10 @@ class Print extends traits.TileEntity with traits.RedstoneAware with traits.Rota
|
||||
boundsOn = data.stateOn.drop(1).foldLeft(data.stateOn.headOption.fold(ExtendedAABB.unitBounds)(_.bounds))((a, b) => a.func_111270_a(b.bounds))
|
||||
if (boundsOn.volume == 0) boundsOn = ExtendedAABB.unitBounds
|
||||
else boundsOn = boundsOn.rotateTowards(facing)
|
||||
|
||||
if (data.emitRedstoneWhenOff) {
|
||||
ForgeDirection.VALID_DIRECTIONS.foreach(output(_, data.redstoneLevel))
|
||||
}
|
||||
}
|
||||
|
||||
override protected def onRotationChanged(): Unit = {
|
||||
|
@ -57,7 +57,7 @@ class Printer extends traits.Environment with traits.Inventory with traits.Rotat
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
def canPrint = data.stateOff.size > 0 && data.stateOff.size + data.stateOn.size <= Settings.get.maxPrintComplexity
|
||||
def canPrint = data.stateOff.size > 0 && data.stateOff.size < Settings.get.maxPrintComplexity && data.stateOn.size < Settings.get.maxPrintComplexity
|
||||
|
||||
def isPrinting = output.isDefined
|
||||
|
||||
@ -100,6 +100,18 @@ class Printer extends traits.Environment with traits.Inventory with traits.Rotat
|
||||
result(data.tooltip.orNull)
|
||||
}
|
||||
|
||||
@Callback(doc = """function(value:number) -- Set what light level the printed block should have.""")
|
||||
def setLightLevel(context: Context, args: Arguments): Array[Object] = {
|
||||
data.lightLevel = args.checkInteger(0) max 0 min Settings.get.maxPrintLightLevel
|
||||
isActive = false // Needs committing.
|
||||
null
|
||||
}
|
||||
|
||||
@Callback(doc = """function():number -- Get which light level the printed block should have.""")
|
||||
def getLightLevel(context: Context, args: Arguments): Array[Object] = {
|
||||
result(data.lightLevel)
|
||||
}
|
||||
|
||||
@Callback(doc = """function(value:boolean or number) -- Set whether the printed block should emit redstone when in its active state.""")
|
||||
def setRedstoneEmitter(context: Context, args: Arguments): Array[Object] = {
|
||||
if (args.isBoolean(0)) data.redstoneLevel = if (args.checkBoolean(0)) 15 else 0
|
||||
@ -113,18 +125,6 @@ class Printer extends traits.Environment with traits.Inventory with traits.Rotat
|
||||
result(data.emitRedstone, data.redstoneLevel)
|
||||
}
|
||||
|
||||
@Callback(doc = """function(value:number) -- Set what light level the printed block should have.""")
|
||||
def setLightLevel(context: Context, args: Arguments): Array[Object] = {
|
||||
data.lightLevel = args.checkInteger(0) max 0 min Settings.get.maxPrintLightLevel
|
||||
isActive = false // Needs committing.
|
||||
null
|
||||
}
|
||||
|
||||
@Callback(doc = """function():number -- Get which light level the printed block should have.""")
|
||||
def getLightLevel(context: Context, args: Arguments): Array[Object] = {
|
||||
result(data.lightLevel)
|
||||
}
|
||||
|
||||
@Callback(doc = """function(value:boolean) -- Set whether the printed block should automatically return to its off state.""")
|
||||
def setButtonMode(context: Context, args: Arguments): Array[Object] = {
|
||||
data.isButtonMode = args.checkBoolean(0)
|
||||
@ -139,7 +139,7 @@ class Printer extends traits.Environment with traits.Inventory with traits.Rotat
|
||||
|
||||
@Callback(doc = """function(minX:number, minY:number, minZ:number, maxX:number, maxY:number, maxZ:number, texture:string[, state:boolean=false][,tint:number]) -- Adds a shape to the printers configuration, optionally specifying whether it is for the off or on state.""")
|
||||
def addShape(context: Context, args: Arguments): Array[Object] = {
|
||||
if (data.stateOff.size + data.stateOn.size >= Settings.get.maxPrintComplexity) {
|
||||
if (data.stateOff.size >= Settings.get.maxPrintComplexity || data.stateOn.size >= Settings.get.maxPrintComplexity) {
|
||||
return result(null, "model too complex")
|
||||
}
|
||||
val minX = (args.checkInteger(0) max 0 min 16) / 16f
|
||||
@ -173,7 +173,7 @@ class Printer extends traits.Environment with traits.Inventory with traits.Rotat
|
||||
}
|
||||
|
||||
@Callback(doc = """function():number -- Get the number of shapes in the current configuration.""")
|
||||
def getShapeCount(context: Context, args: Arguments): Array[Object] = result(data.stateOff.size + data.stateOn.size)
|
||||
def getShapeCount(context: Context, args: Arguments): Array[Object] = result(data.stateOff.size, data.stateOn.size)
|
||||
|
||||
@Callback(doc = """function():number -- Get the maximum allowed number of shapes.""")
|
||||
def getMaxShapeCount(context: Context, args: Arguments): Array[Object] = result(Settings.get.maxPrintComplexity)
|
||||
|
@ -138,20 +138,20 @@ class PrintPart(val original: Option[tileentity.Print] = None) extends SimpleBlo
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
override def conductsRedstone: Boolean = data.emitRedstone && state
|
||||
override def conductsRedstone: Boolean = if (state) data.emitRedstoneWhenOn else data.emitRedstoneWhenOff
|
||||
|
||||
override def redstoneConductionMap: Int = if (data.emitRedstone && state) 0xFF else 0
|
||||
override def redstoneConductionMap: Int = if (conductsRedstone) 0xFF else 0
|
||||
|
||||
override def canConnectRedstone(side: Int): Boolean = true
|
||||
|
||||
override def strongPowerLevel(side: Int): Int = weakPowerLevel(side)
|
||||
|
||||
override def weakPowerLevel(side: Int): Int = if (data.emitRedstone && state) data.redstoneLevel else 0
|
||||
override def weakPowerLevel(side: Int): Int = if (data.emitRedstone(state)) data.redstoneLevel else 0
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
override def activate(player: EntityPlayer, hit: MovingObjectPosition, item: ItemStack): Boolean = {
|
||||
if (data.stateOn.size > 0) {
|
||||
if (data.hasActiveState) {
|
||||
if (!state || !data.isButtonMode) {
|
||||
toggleState()
|
||||
return true
|
||||
@ -262,7 +262,7 @@ class PrintPart(val original: Option[tileentity.Print] = None) extends SimpleBlo
|
||||
|
||||
protected def checkRedstone(): Unit = {
|
||||
val newMaxValue = computeInput()
|
||||
val newState = newMaxValue > 1 // Fixes oddities in cycling updates.
|
||||
val newState = newMaxValue > 1 // >1 Fixes oddities in cycling updates.
|
||||
if (!data.emitRedstone && data.hasActiveState && state != newState) {
|
||||
toggleState()
|
||||
}
|
||||
@ -270,7 +270,7 @@ class PrintPart(val original: Option[tileentity.Print] = None) extends SimpleBlo
|
||||
|
||||
protected def computeInput(): Int = {
|
||||
val inner = tile.partList.foldLeft(0)((power, part) => part match {
|
||||
case print: PrintPart if print.state && print.data.emitRedstone => math.max(power, print.data.redstoneLevel)
|
||||
case print: PrintPart if print.data.emitRedstone(print.state) => math.max(power, print.data.redstoneLevel)
|
||||
case _ => power
|
||||
})
|
||||
math.max(inner, ForgeDirection.VALID_DIRECTIONS.map(computeInput).max)
|
||||
|
Loading…
x
Reference in New Issue
Block a user