mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 03:05:30 -04:00
Added hologram projection offset
This commit is contained in:
parent
1da67a0dc6
commit
7fb9ad2ee6
@ -38,6 +38,7 @@ class PacketHandler extends CommonPacketHandler {
|
|||||||
case PacketType.HologramPowerChange => onHologramPowerChange(p)
|
case PacketType.HologramPowerChange => onHologramPowerChange(p)
|
||||||
case PacketType.HologramScale => onHologramScale(p)
|
case PacketType.HologramScale => onHologramScale(p)
|
||||||
case PacketType.HologramSet => onHologramSet(p)
|
case PacketType.HologramSet => onHologramSet(p)
|
||||||
|
case PacketType.HologramPositionOffsetY => onHologramPositionOffsetY(p)
|
||||||
case PacketType.PetVisibility => onPetVisibility(p)
|
case PacketType.PetVisibility => onPetVisibility(p)
|
||||||
case PacketType.PowerState => onPowerState(p)
|
case PacketType.PowerState => onPowerState(p)
|
||||||
case PacketType.RedstoneState => onRedstoneState(p)
|
case PacketType.RedstoneState => onRedstoneState(p)
|
||||||
@ -186,6 +187,13 @@ class PacketHandler extends CommonPacketHandler {
|
|||||||
case _ => // Invalid packet.
|
case _ => // Invalid packet.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def onHologramPositionOffsetY(p: PacketParser) =
|
||||||
|
p.readTileEntity[Hologram]() match {
|
||||||
|
case Some(t) =>
|
||||||
|
t.projectionOffsetY = p.readDouble()
|
||||||
|
case _ => // Invalid packet.
|
||||||
|
}
|
||||||
|
|
||||||
def onPetVisibility(p: PacketParser) {
|
def onPetVisibility(p: PacketParser) {
|
||||||
val count = p.readInt()
|
val count = p.readInt()
|
||||||
for (i <- 0 until count) {
|
for (i <- 0 until count) {
|
||||||
|
@ -85,7 +85,7 @@ object HologramRenderer extends TileEntitySpecialRenderer with Callable[Int] wit
|
|||||||
}
|
}
|
||||||
|
|
||||||
GL11.glScaled(1.001, 1.001, 1.001) // Avoid z-fighting with other blocks.
|
GL11.glScaled(1.001, 1.001, 1.001) // Avoid z-fighting with other blocks.
|
||||||
GL11.glTranslated(-1.5 * hologram.scale, 0, -1.5 * hologram.scale)
|
GL11.glTranslated(-1.5 * hologram.scale, hologram.projectionOffsetY, -1.5 * hologram.scale)
|
||||||
|
|
||||||
// Do a bit of flickering, because that's what holograms do!
|
// Do a bit of flickering, because that's what holograms do!
|
||||||
if (Settings.get.hologramFlickerFrequency > 0 && random.nextDouble() < Settings.get.hologramFlickerFrequency) {
|
if (Settings.get.hologramFlickerFrequency > 0 && random.nextDouble() < Settings.get.hologramFlickerFrequency) {
|
||||||
|
@ -16,6 +16,7 @@ object PacketType extends Enumeration {
|
|||||||
HologramPowerChange,
|
HologramPowerChange,
|
||||||
HologramScale,
|
HologramScale,
|
||||||
HologramSet,
|
HologramSet,
|
||||||
|
HologramPositionOffsetY,
|
||||||
PetVisibility, // Goes both ways.
|
PetVisibility, // Goes both ways.
|
||||||
PowerState,
|
PowerState,
|
||||||
RedstoneState,
|
RedstoneState,
|
||||||
|
@ -29,6 +29,9 @@ class Hologram(var tier: Int) extends traits.Environment with SidedEnvironment w
|
|||||||
// Render scale.
|
// Render scale.
|
||||||
var scale = 1.0
|
var scale = 1.0
|
||||||
|
|
||||||
|
// Projection Y position offset - consider adding X,Z later perhaps
|
||||||
|
var projectionOffsetY: Double = 0.0
|
||||||
|
|
||||||
// Relative number of lit columns (for energy cost).
|
// Relative number of lit columns (for energy cost).
|
||||||
var litRatio = -1.0
|
var litRatio = -1.0
|
||||||
|
|
||||||
@ -211,6 +214,19 @@ class Hologram(var tier: Int) extends traits.Environment with SidedEnvironment w
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Callback(doc = """function():number -- Returns the render projection offset of the hologram.""")
|
||||||
|
def getOffset(computer: Context, args: Arguments): Array[AnyRef] = {
|
||||||
|
result(projectionOffsetY) // consider adding a future axis parameter for X,Y or Z - but for now, just using Y
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback(doc = """function(value:number) -- Sets the render projection offset of the hologram..""")
|
||||||
|
def setOffset(computer: Context, args: Arguments): Array[AnyRef] = {
|
||||||
|
val maxOffset = 3 // this wants to be a config setting / by tier - perhaps
|
||||||
|
projectionOffsetY = math.max(0, math.min(maxOffset, args.checkDouble(0)))
|
||||||
|
ServerPacketSender.sendHologramOffset(this)
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
@Callback(direct = true, doc = """function():number -- The color depth supported by the hologram.""")
|
@Callback(direct = true, doc = """function():number -- The color depth supported by the hologram.""")
|
||||||
def maxDepth(context: Context, args: Arguments): Array[AnyRef] = {
|
def maxDepth(context: Context, args: Arguments): Array[AnyRef] = {
|
||||||
result(tier + 1)
|
result(tier + 1)
|
||||||
@ -302,7 +318,7 @@ class Hologram(var tier: Int) extends traits.Environment with SidedEnvironment w
|
|||||||
|
|
||||||
def getFadeStartDistanceSquared = scale / Settings.get.hologramMaxScaleByTier.max * Settings.get.hologramFadeStartDistance * Settings.get.hologramFadeStartDistance
|
def getFadeStartDistanceSquared = scale / Settings.get.hologramMaxScaleByTier.max * Settings.get.hologramFadeStartDistance * Settings.get.hologramFadeStartDistance
|
||||||
|
|
||||||
override def getRenderBoundingBox = AxisAlignedBB.getAABBPool.getAABB(xCoord + 0.5 - 1.5 * scale, yCoord, zCoord - scale, xCoord + 0.5 + 1.5 * scale, yCoord + 0.25 + 2 * scale, zCoord + 0.5 + 1.5 * scale)
|
override def getRenderBoundingBox = AxisAlignedBB.getAABBPool.getAABB(xCoord + 0.5 - 1.5 * scale, yCoord + projectionOffsetY, zCoord - scale, xCoord + 0.5 + 1.5 * scale, yCoord + 0.25 + projectionOffsetY + 2 * scale, zCoord + 0.5 + 1.5 * scale)
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
@ -319,6 +335,7 @@ class Hologram(var tier: Int) extends traits.Environment with SidedEnvironment w
|
|||||||
tag.getIntArray("colors").map(convertColor).copyToArray(colors)
|
tag.getIntArray("colors").map(convertColor).copyToArray(colors)
|
||||||
}
|
}
|
||||||
scale = nbt.getDouble(Settings.namespace + "scale")
|
scale = nbt.getDouble(Settings.namespace + "scale")
|
||||||
|
projectionOffsetY = nbt.getDouble(Settings.namespace + "offsetY")
|
||||||
}
|
}
|
||||||
|
|
||||||
override def writeToNBT(nbt: NBTTagCompound) = this.synchronized {
|
override def writeToNBT(nbt: NBTTagCompound) = this.synchronized {
|
||||||
@ -329,6 +346,7 @@ class Hologram(var tier: Int) extends traits.Environment with SidedEnvironment w
|
|||||||
tag.setIntArray("colors", colors.map(convertColor))
|
tag.setIntArray("colors", colors.map(convertColor))
|
||||||
})
|
})
|
||||||
nbt.setDouble(Settings.namespace + "scale", scale)
|
nbt.setDouble(Settings.namespace + "scale", scale)
|
||||||
|
nbt.setDouble(Settings.namespace + "offsetY", projectionOffsetY)
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
@ -338,6 +356,7 @@ class Hologram(var tier: Int) extends traits.Environment with SidedEnvironment w
|
|||||||
nbt.getIntArray("colors").copyToArray(colors)
|
nbt.getIntArray("colors").copyToArray(colors)
|
||||||
scale = nbt.getDouble("scale")
|
scale = nbt.getDouble("scale")
|
||||||
hasPower = nbt.getBoolean("hasPower")
|
hasPower = nbt.getBoolean("hasPower")
|
||||||
|
projectionOffsetY = nbt.getDouble("offsetY")
|
||||||
}
|
}
|
||||||
|
|
||||||
override def writeToNBTForClient(nbt: NBTTagCompound) {
|
override def writeToNBTForClient(nbt: NBTTagCompound) {
|
||||||
@ -346,5 +365,6 @@ class Hologram(var tier: Int) extends traits.Environment with SidedEnvironment w
|
|||||||
nbt.setIntArray("colors", colors)
|
nbt.setIntArray("colors", colors)
|
||||||
nbt.setDouble("scale", scale)
|
nbt.setDouble("scale", scale)
|
||||||
nbt.setBoolean("hasPower", hasPower)
|
nbt.setBoolean("hasPower", hasPower)
|
||||||
|
nbt.setDouble("offsetY", projectionOffsetY)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,6 +139,16 @@ object PacketSender {
|
|||||||
pb.sendToNearbyPlayers(t)
|
pb.sendToNearbyPlayers(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def sendHologramOffset(t: tileentity.Hologram) {
|
||||||
|
val pb = new SimplePacketBuilder(PacketType.HologramPositionOffsetY)
|
||||||
|
|
||||||
|
pb.writeTileEntity(t)
|
||||||
|
pb.writeDouble(t.projectionOffsetY)
|
||||||
|
|
||||||
|
pb.sendToNearbyPlayers(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def sendPetVisibility(name: Option[String] = None, player: Option[EntityPlayerMP] = None) {
|
def sendPetVisibility(name: Option[String] = None, player: Option[EntityPlayerMP] = None) {
|
||||||
val pb = new SimplePacketBuilder(PacketType.PetVisibility)
|
val pb = new SimplePacketBuilder(PacketType.PetVisibility)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user