Allow changing the color of drones' lights to an arbitrary color via API (drone.setLightColor/drone.getLightColor).

This commit is contained in:
Florian Nücke 2014-12-28 15:51:45 +01:00
parent f763e176c9
commit c4227d2476
5 changed files with 29 additions and 1 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 631 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 555 B

View File

@ -11,7 +11,7 @@ import net.minecraft.util.Vec3
import org.lwjgl.opengl.GL11
final class ModelQuadcopter extends ModelBase {
val texture = new ResourceLocation(Settings.resourceDomain, "textures/entity/drone.png")
val texture = new ResourceLocation(Settings.resourceDomain, "textures/model/drone.png")
val body = new ModelRenderer(this, "body")
val wing0 = new ModelRenderer(this, "wing0")
@ -109,6 +109,15 @@ final class ModelQuadcopter extends ModelBase {
light3.rotateAngleX = drone.flapAngles(3)(0)
light3.rotateAngleZ = drone.flapAngles(3)(1)
// Additive blending for the lights.
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE)
// Light color.
val lightColor = drone.lightColor
val r = ((lightColor >>> 16) & 0xFF).toByte
val g = ((lightColor >>> 8) & 0xFF).toByte
val b = ((lightColor >>> 0) & 0xFF).toByte
GL11.glColor3ub(r, g, b)
light0.render(scale)
light1.render(scale)
light2.render(scale)
@ -147,6 +156,9 @@ final class ModelQuadcopter extends ModelBase {
light3.rotateAngleX = tilt
light3.rotateAngleZ = -tilt
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE)
GL11.glColor3ub(0x66.toByte, 0xDD.toByte, 0x55.toByte)
light0.render(scale)
light1.render(scale)
light2.render(scale)

View File

@ -196,6 +196,8 @@ class Drone(val world: World) extends Entity(world) with MachineHost with intern
dataWatcher.addObject(10, "")
// Inventory size for client.
dataWatcher.addObject(11, byte2Byte(0: Byte))
// Light color.
dataWatcher.addObject(12, int2Integer(0x66DD55))
}
def initializeAfterPlacement(stack: ItemStack, player: EntityPlayer, position: Vec3) {
@ -232,6 +234,7 @@ class Drone(val world: World) extends Entity(world) with MachineHost with intern
def globalBufferSize = dataWatcher.getWatchableObjectInt(9)
def statusText = dataWatcher.getWatchableObjectString(10)
def inventorySize = dataWatcher.getWatchableObjectByte(11) & 0xFF
def lightColor = dataWatcher.getWatchableObjectInt(12)
def setRunning(value: Boolean) = dataWatcher.updateObject(2, byte2Byte(if (value) 1: Byte else 0: Byte))
// Round target values to low accuracy to avoid floating point errors accumulating.
@ -244,6 +247,7 @@ class Drone(val world: World) extends Entity(world) with MachineHost with intern
def globalBufferSize_=(value: Int) = dataWatcher.updateObject(9, int2Integer(value))
def statusText_=(value: String) = dataWatcher.updateObject(10, Option(value).map(_.lines.map(_.take(10)).take(2).mkString("\n")).getOrElse(""))
def inventorySize_=(value: Int) = dataWatcher.updateObject(11, byte2Byte(value.toByte))
def lightColor_=(value: Int) = dataWatcher.updateObject(12, int2Integer(value))
@SideOnly(Side.CLIENT)
override def setPositionAndRotation2(x: Double, y: Double, z: Double, yaw: Float, pitch: Float, data: Int) {
@ -436,6 +440,7 @@ class Drone(val world: World) extends Entity(world) with MachineHost with intern
selectedSlot = nbt.getByte("selectedSlot") & 0xFF
selectedTank = nbt.getByte("selectedTank") & 0xFF
statusText = nbt.getString("statusText")
lightColor = nbt.getInteger("lightColor")
}
override def writeEntityToNBT(nbt: NBTTagCompound) {
@ -455,5 +460,6 @@ class Drone(val world: World) extends Entity(world) with MachineHost with intern
nbt.setByte("selectedSlot", selectedSlot.toByte)
nbt.setByte("selectedTank", selectedTank.toByte)
nbt.setString("statusText", statusText)
nbt.setInteger("lightColor", lightColor)
}
}

View File

@ -58,6 +58,16 @@ class Drone(val host: entity.Drone) extends prefab.ManagedEnvironment with trait
result(host.statusText)
}
@Callback(doc = "function():number -- Get the current color of the flap lights as an integer encoded RGB value (0xRRGGBB).")
def getLightColor(context: Context, args: Arguments): Array[AnyRef] = result(host.lightColor)
@Callback(doc = "function(value:number):number -- Set the color of the flap lights to the specified integer encoded RGB value (0xRRGGBB).")
def setLightColor(context: Context, args: Arguments): Array[AnyRef] = {
host.lightColor = args.checkInteger(0)
context.pause(0.1)
result(host.lightColor)
}
// ----------------------------------------------------------------------- //
@Callback(doc = "function(dx:number, dy:number, dz:number) -- Change the target position by the specified offset.")