diff --git a/src/main/resources/assets/opencomputers/textures/blocks/adapter_side.png b/src/main/resources/assets/opencomputers/textures/blocks/adapter_side.png index 0fbe70ad4..503580778 100644 Binary files a/src/main/resources/assets/opencomputers/textures/blocks/adapter_side.png and b/src/main/resources/assets/opencomputers/textures/blocks/adapter_side.png differ diff --git a/src/main/resources/assets/opencomputers/textures/blocks/adapter_top.png b/src/main/resources/assets/opencomputers/textures/blocks/adapter_top.png index 8af4f6ff4..3246352da 100644 Binary files a/src/main/resources/assets/opencomputers/textures/blocks/adapter_top.png and b/src/main/resources/assets/opencomputers/textures/blocks/adapter_top.png differ diff --git a/src/main/resources/assets/opencomputers/textures/blocks/case_back.png b/src/main/resources/assets/opencomputers/textures/blocks/case_back.png index f182d0b73..638a181b8 100644 Binary files a/src/main/resources/assets/opencomputers/textures/blocks/case_back.png and b/src/main/resources/assets/opencomputers/textures/blocks/case_back.png differ diff --git a/src/main/resources/assets/opencomputers/textures/blocks/case_back_on.png b/src/main/resources/assets/opencomputers/textures/blocks/case_back_on.png index e319cafca..f2339ab17 100644 Binary files a/src/main/resources/assets/opencomputers/textures/blocks/case_back_on.png and b/src/main/resources/assets/opencomputers/textures/blocks/case_back_on.png differ diff --git a/src/main/resources/assets/opencomputers/textures/blocks/case_front.png b/src/main/resources/assets/opencomputers/textures/blocks/case_front.png index 08915be68..10bf518bb 100644 Binary files a/src/main/resources/assets/opencomputers/textures/blocks/case_front.png and b/src/main/resources/assets/opencomputers/textures/blocks/case_front.png differ diff --git a/src/main/resources/assets/opencomputers/textures/blocks/case_side.png b/src/main/resources/assets/opencomputers/textures/blocks/case_side.png index c8654582d..b5ea153d0 100644 Binary files a/src/main/resources/assets/opencomputers/textures/blocks/case_side.png and b/src/main/resources/assets/opencomputers/textures/blocks/case_side.png differ diff --git a/src/main/resources/assets/opencomputers/textures/blocks/case_side_on.png b/src/main/resources/assets/opencomputers/textures/blocks/case_side_on.png index 4150cf641..02724e856 100644 Binary files a/src/main/resources/assets/opencomputers/textures/blocks/case_side_on.png and b/src/main/resources/assets/opencomputers/textures/blocks/case_side_on.png differ diff --git a/src/main/resources/assets/opencomputers/textures/blocks/case_top.png b/src/main/resources/assets/opencomputers/textures/blocks/case_top.png index b145b2a06..f646fc7f2 100644 Binary files a/src/main/resources/assets/opencomputers/textures/blocks/case_top.png and b/src/main/resources/assets/opencomputers/textures/blocks/case_top.png differ diff --git a/src/main/resources/assets/opencomputers/textures/blocks/charger.png b/src/main/resources/assets/opencomputers/textures/blocks/charger.png deleted file mode 100644 index 0b8bf00a0..000000000 Binary files a/src/main/resources/assets/opencomputers/textures/blocks/charger.png and /dev/null differ diff --git a/src/main/resources/assets/opencomputers/textures/blocks/charger_front.png b/src/main/resources/assets/opencomputers/textures/blocks/charger_front.png new file mode 100644 index 000000000..12ce867cf Binary files /dev/null and b/src/main/resources/assets/opencomputers/textures/blocks/charger_front.png differ diff --git a/src/main/resources/assets/opencomputers/textures/blocks/charger_front_on.png b/src/main/resources/assets/opencomputers/textures/blocks/charger_front_on.png new file mode 100644 index 000000000..020a7b8f2 Binary files /dev/null and b/src/main/resources/assets/opencomputers/textures/blocks/charger_front_on.png differ diff --git a/src/main/resources/assets/opencomputers/textures/blocks/charger_on.png b/src/main/resources/assets/opencomputers/textures/blocks/charger_on.png deleted file mode 100644 index 43969ffee..000000000 Binary files a/src/main/resources/assets/opencomputers/textures/blocks/charger_on.png and /dev/null differ diff --git a/src/main/resources/assets/opencomputers/textures/blocks/charger_side.png b/src/main/resources/assets/opencomputers/textures/blocks/charger_side.png new file mode 100644 index 000000000..9338e0f89 Binary files /dev/null and b/src/main/resources/assets/opencomputers/textures/blocks/charger_side.png differ diff --git a/src/main/resources/assets/opencomputers/textures/blocks/charger_side_on.png b/src/main/resources/assets/opencomputers/textures/blocks/charger_side_on.png new file mode 100644 index 000000000..a00f3d529 Binary files /dev/null and b/src/main/resources/assets/opencomputers/textures/blocks/charger_side_on.png differ diff --git a/src/main/resources/assets/opencomputers/textures/blocks/charger_side_on.png.mcmeta b/src/main/resources/assets/opencomputers/textures/blocks/charger_side_on.png.mcmeta new file mode 100644 index 000000000..9e27d3a97 --- /dev/null +++ b/src/main/resources/assets/opencomputers/textures/blocks/charger_side_on.png.mcmeta @@ -0,0 +1,6 @@ +{ + "animation": { + "frametime": 2, + "frames": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ] + } +} \ No newline at end of file diff --git a/src/main/resources/assets/opencomputers/textures/blocks/power_converter.png b/src/main/resources/assets/opencomputers/textures/blocks/power_converter.png index a0c7f0ae1..becee62ff 100644 Binary files a/src/main/resources/assets/opencomputers/textures/blocks/power_converter.png and b/src/main/resources/assets/opencomputers/textures/blocks/power_converter.png differ diff --git a/src/main/resources/assets/opencomputers/textures/blocks/power_distributor.png b/src/main/resources/assets/opencomputers/textures/blocks/power_distributor.png deleted file mode 100644 index a572764ad..000000000 Binary files a/src/main/resources/assets/opencomputers/textures/blocks/power_distributor.png and /dev/null differ diff --git a/src/main/resources/assets/opencomputers/textures/blocks/power_distributor_on.png b/src/main/resources/assets/opencomputers/textures/blocks/power_distributor_on.png deleted file mode 100644 index c5c7fe0ea..000000000 Binary files a/src/main/resources/assets/opencomputers/textures/blocks/power_distributor_on.png and /dev/null differ diff --git a/src/main/resources/assets/opencomputers/textures/blocks/power_distributor_side.png b/src/main/resources/assets/opencomputers/textures/blocks/power_distributor_side.png new file mode 100644 index 000000000..47a3ab3e5 Binary files /dev/null and b/src/main/resources/assets/opencomputers/textures/blocks/power_distributor_side.png differ diff --git a/src/main/resources/assets/opencomputers/textures/blocks/power_distributor_side_on.png b/src/main/resources/assets/opencomputers/textures/blocks/power_distributor_side_on.png new file mode 100644 index 000000000..dc107500b Binary files /dev/null and b/src/main/resources/assets/opencomputers/textures/blocks/power_distributor_side_on.png differ diff --git a/src/main/resources/assets/opencomputers/textures/blocks/power_distributor_side_on.png.mcmeta b/src/main/resources/assets/opencomputers/textures/blocks/power_distributor_side_on.png.mcmeta new file mode 100644 index 000000000..9e27d3a97 --- /dev/null +++ b/src/main/resources/assets/opencomputers/textures/blocks/power_distributor_side_on.png.mcmeta @@ -0,0 +1,6 @@ +{ + "animation": { + "frametime": 2, + "frames": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ] + } +} \ No newline at end of file diff --git a/src/main/resources/assets/opencomputers/textures/blocks/power_distributor_top.png b/src/main/resources/assets/opencomputers/textures/blocks/power_distributor_top.png new file mode 100644 index 000000000..36707b6fd Binary files /dev/null and b/src/main/resources/assets/opencomputers/textures/blocks/power_distributor_top.png differ diff --git a/src/main/resources/assets/opencomputers/textures/blocks/power_distributor_top_on.png b/src/main/resources/assets/opencomputers/textures/blocks/power_distributor_top_on.png new file mode 100644 index 000000000..24549ce39 Binary files /dev/null and b/src/main/resources/assets/opencomputers/textures/blocks/power_distributor_top_on.png differ diff --git a/src/main/resources/assets/opencomputers/textures/blocks/router_side.png b/src/main/resources/assets/opencomputers/textures/blocks/router_side.png index b790fb163..0afdbe3d9 100644 Binary files a/src/main/resources/assets/opencomputers/textures/blocks/router_side.png and b/src/main/resources/assets/opencomputers/textures/blocks/router_side.png differ diff --git a/src/main/resources/assets/opencomputers/textures/blocks/router_side_active.png b/src/main/resources/assets/opencomputers/textures/blocks/router_side_active.png new file mode 100644 index 000000000..588f70333 Binary files /dev/null and b/src/main/resources/assets/opencomputers/textures/blocks/router_side_active.png differ diff --git a/src/main/scala/li/cil/oc/client/PacketHandler.scala b/src/main/scala/li/cil/oc/client/PacketHandler.scala index caeea648d..9e369abb2 100644 --- a/src/main/scala/li/cil/oc/client/PacketHandler.scala +++ b/src/main/scala/li/cil/oc/client/PacketHandler.scala @@ -42,6 +42,7 @@ class PacketHandler extends CommonPacketHandler { case PacketType.RobotSelectedSlotChange => onRobotSelectedSlotChange(p) case PacketType.RobotXp => onRobotXp(p) case PacketType.RotatableState => onRotatableState(p) + case PacketType.RouterActivity => onRouterActivity(p) case PacketType.ScreenColorChange => onScreenColorChange(p) case PacketType.ScreenCopy => onScreenCopy(p) case PacketType.ScreenDepthChange => onScreenDepthChange(p) @@ -222,6 +223,12 @@ class PacketHandler extends CommonPacketHandler { case _ => // Invalid packet. } + def onRouterActivity(p: PacketParser) = + p.readTileEntity[Router]() match { + case Some(t) => t.lastMessage = System.currentTimeMillis() + case _ => // Invalid packet. + } + def onScreenColorChange(p: PacketParser) { val buffer = p.readTileEntity[TileEntity]() match { case Some(t: TextBuffer) => t.buffer diff --git a/src/main/scala/li/cil/oc/client/Proxy.scala b/src/main/scala/li/cil/oc/client/Proxy.scala index 00be19111..e2ad27162 100644 --- a/src/main/scala/li/cil/oc/client/Proxy.scala +++ b/src/main/scala/li/cil/oc/client/Proxy.scala @@ -33,9 +33,12 @@ private[oc] class Proxy extends CommonProxy { ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.Cable], CableRenderer) ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.Case], CaseRenderer) + ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.Charger], ChargerRenderer) ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.Hologram], HologramRenderer) ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.PowerDistributor], PowerDistributorRenderer) ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.Rack], RackRenderer) + ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.Router], RouterRenderer) + ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.WirelessRouter], RouterRenderer) ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.RobotProxy], RobotRenderer) ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.Screen], ScreenRenderer) diff --git a/src/main/scala/li/cil/oc/client/TexturePreloader.scala b/src/main/scala/li/cil/oc/client/TexturePreloader.scala index b6e7bc80e..349c30582 100644 --- a/src/main/scala/li/cil/oc/client/TexturePreloader.scala +++ b/src/main/scala/li/cil/oc/client/TexturePreloader.scala @@ -23,7 +23,6 @@ object TexturePreloader extends ResourceManagerReloadListener { val blockCable = new ResourceLocation(Settings.resourceDomain, "textures/blocks/cable.png") val blockCaseFrontOn = new ResourceLocation(Settings.resourceDomain, "textures/blocks/case_front_on.png") val blockHologram = new ResourceLocation(Settings.resourceDomain, "textures/blocks/hologram_effect.png") - val blockPowerDistributorOn = new ResourceLocation(Settings.resourceDomain, "textures/blocks/power_distributor_on.png") val blockRackFrontOn = new ResourceLocation(Settings.resourceDomain, "textures/blocks/rack_front_on.png") val blockRobot = new ResourceLocation(Settings.resourceDomain, "textures/blocks/robot.png") val blockScreenUpIndicator = new ResourceLocation(Settings.resourceDomain, "textures/blocks/screen/up_indicator.png") @@ -49,7 +48,6 @@ object TexturePreloader extends ResourceManagerReloadListener { manager.getResource(blockCable) manager.getResource(blockCaseFrontOn) - manager.getResource(blockPowerDistributorOn) manager.getResource(blockRackFrontOn) manager.getResource(blockRobot) manager.getResource(blockScreenUpIndicator) diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/CaseRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/CaseRenderer.scala index 03e7c9a33..64f581e1a 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/CaseRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/CaseRenderer.scala @@ -10,7 +10,7 @@ import net.minecraftforge.common.ForgeDirection import org.lwjgl.opengl.GL11 object CaseRenderer extends TileEntitySpecialRenderer { - override def renderTileEntityAt(tileEntity: TileEntity, x: Double, y: Double, z: Double, f: Float) = { + override def renderTileEntityAt(tileEntity: TileEntity, x: Double, y: Double, z: Double, f: Float) { val computer = tileEntity.asInstanceOf[Case] if (computer.isRunning) { GL11.glPushAttrib(0xFFFFFF) diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/ChargerRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/ChargerRenderer.scala new file mode 100644 index 000000000..5d82f63a8 --- /dev/null +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/ChargerRenderer.scala @@ -0,0 +1,70 @@ +package li.cil.oc.client.renderer.tileentity + +import li.cil.oc.Blocks +import li.cil.oc.common.tileentity.Charger +import li.cil.oc.util.RenderState +import net.minecraft.client.renderer.Tessellator +import net.minecraft.client.renderer.texture.TextureMap +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer +import net.minecraft.tileentity.TileEntity +import net.minecraftforge.common.ForgeDirection +import org.lwjgl.opengl.GL11 + +object ChargerRenderer extends TileEntitySpecialRenderer { + override def renderTileEntityAt(tileEntity: TileEntity, x: Double, y: Double, z: Double, f: Float) { + val charger = tileEntity.asInstanceOf[Charger] + if (charger.chargeSpeed > 0) { + GL11.glPushAttrib(0xFFFFFF) + + RenderState.disableLighting() + RenderState.makeItBlend() + + GL11.glPushMatrix() + + GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5) + + charger.yaw match { + case ForgeDirection.WEST => GL11.glRotatef(-90, 0, 1, 0) + case ForgeDirection.NORTH => GL11.glRotatef(180, 0, 1, 0) + case ForgeDirection.EAST => GL11.glRotatef(90, 0, 1, 0) + case _ => // No yaw. + } + + GL11.glTranslatef(-0.5f, 0.5f, 0.5f) + GL11.glScalef(1, -1, 1) + + val t = Tessellator.instance + + val frontIcon = Blocks.charger.iconFrontCharging + bindTexture(TextureMap.locationBlocksTexture) + t.startDrawingQuads() + + val inverse = 1 - charger.chargeSpeed + t.addVertexWithUV(0, 1, 0.005, frontIcon.getMinU, frontIcon.getMaxV) + t.addVertexWithUV(1, 1, 0.005, frontIcon.getMaxU, frontIcon.getMaxV) + t.addVertexWithUV(1, inverse, 0.005, frontIcon.getMaxU, frontIcon.getInterpolatedV(inverse * 16)) + t.addVertexWithUV(0, inverse, 0.005, frontIcon.getMinU, frontIcon.getInterpolatedV(inverse * 16)) + + val sideIcon = Blocks.charger.iconSideCharging + t.addVertexWithUV(-0.005, 1, -1, sideIcon.getMinU, sideIcon.getMaxV) + t.addVertexWithUV(-0.005, 1, 0, sideIcon.getMaxU, sideIcon.getMaxV) + t.addVertexWithUV(-0.005, 0, 0, sideIcon.getMaxU, sideIcon.getMinV) + t.addVertexWithUV(-0.005, 0, -1, sideIcon.getMinU, sideIcon.getMinV) + + t.addVertexWithUV(1, 1, -1.005, sideIcon.getMinU, sideIcon.getMaxV) + t.addVertexWithUV(0, 1, -1.005, sideIcon.getMaxU, sideIcon.getMaxV) + t.addVertexWithUV(0, 0, -1.005, sideIcon.getMaxU, sideIcon.getMinV) + t.addVertexWithUV(1, 0, -1.005, sideIcon.getMinU, sideIcon.getMinV) + + t.addVertexWithUV(1.005, 1, 0, sideIcon.getMinU, sideIcon.getMaxV) + t.addVertexWithUV(1.005, 1, -1, sideIcon.getMaxU, sideIcon.getMaxV) + t.addVertexWithUV(1.005, 0, -1, sideIcon.getMaxU, sideIcon.getMinV) + t.addVertexWithUV(1.005, 0, 0, sideIcon.getMinU, sideIcon.getMinV) + + t.draw() + + GL11.glPopMatrix() + GL11.glPopAttrib() + } + } +} diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/PowerDistributorRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/PowerDistributorRenderer.scala index 650d8db49..45fd831ad 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/PowerDistributorRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/PowerDistributorRenderer.scala @@ -1,15 +1,16 @@ package li.cil.oc.client.renderer.tileentity -import li.cil.oc.client.TexturePreloader +import li.cil.oc.Blocks import li.cil.oc.common.tileentity import li.cil.oc.util.RenderState import net.minecraft.client.renderer.Tessellator +import net.minecraft.client.renderer.texture.TextureMap import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer import net.minecraft.tileentity.TileEntity import org.lwjgl.opengl.GL11 object PowerDistributorRenderer extends TileEntitySpecialRenderer { - override def renderTileEntityAt(tileEntity: TileEntity, x: Double, y: Double, z: Double, f: Float) = { + override def renderTileEntityAt(tileEntity: TileEntity, x: Double, y: Double, z: Double, f: Float) { val distributor = tileEntity.asInstanceOf[tileentity.PowerDistributor] if (distributor.globalBuffer > 0) { GL11.glPushAttrib(0xFFFFFF) @@ -24,30 +25,36 @@ object PowerDistributorRenderer extends TileEntitySpecialRenderer { GL11.glScalef(1.002f, -1.002f, 1.002f) GL11.glTranslatef(-0.5f, -0.5f, -0.5f) - bindTexture(TexturePreloader.blockPowerDistributorOn) - + bindTexture(TextureMap.locationBlocksTexture) val t = Tessellator.instance t.startDrawingQuads() - t.addVertexWithUV(1, 1, 0, 0, 1) - t.addVertexWithUV(0, 1, 0, 1, 1) - t.addVertexWithUV(0, 0, 0, 1, 0) - t.addVertexWithUV(1, 0, 0, 0, 0) + val topOn = Blocks.powerDistributor.iconTopOn + t.addVertexWithUV(0, 0, 1, topOn.getMinU, topOn.getMaxV) + t.addVertexWithUV(1, 0, 1, topOn.getMaxU, topOn.getMaxV) + t.addVertexWithUV(1, 0, 0, topOn.getMaxU, topOn.getMinV) + t.addVertexWithUV(0, 0, 0, topOn.getMinU, topOn.getMinV) - t.addVertexWithUV(0, 1, 1, 0, 1) - t.addVertexWithUV(1, 1, 1, 1, 1) - t.addVertexWithUV(1, 0, 1, 1, 0) - t.addVertexWithUV(0, 0, 1, 0, 0) + val sideOn = Blocks.powerDistributor.iconSideOn + t.addVertexWithUV(1, 1, 0, sideOn.getMinU, sideOn.getMaxV) + t.addVertexWithUV(0, 1, 0, sideOn.getMaxU, sideOn.getMaxV) + t.addVertexWithUV(0, 0, 0, sideOn.getMaxU, sideOn.getMinV) + t.addVertexWithUV(1, 0, 0, sideOn.getMinU, sideOn.getMinV) - t.addVertexWithUV(1, 1, 1, 0, 1) - t.addVertexWithUV(1, 1, 0, 1, 1) - t.addVertexWithUV(1, 0, 0, 1, 0) - t.addVertexWithUV(1, 0, 1, 0, 0) + t.addVertexWithUV(0, 1, 1, sideOn.getMinU, sideOn.getMaxV) + t.addVertexWithUV(1, 1, 1, sideOn.getMaxU, sideOn.getMaxV) + t.addVertexWithUV(1, 0, 1, sideOn.getMaxU, sideOn.getMinV) + t.addVertexWithUV(0, 0, 1, sideOn.getMinU, sideOn.getMinV) - t.addVertexWithUV(0, 1, 0, 0, 1) - t.addVertexWithUV(0, 1, 1, 1, 1) - t.addVertexWithUV(0, 0, 1, 1, 0) - t.addVertexWithUV(0, 0, 0, 0, 0) + t.addVertexWithUV(1, 1, 1, sideOn.getMinU, sideOn.getMaxV) + t.addVertexWithUV(1, 1, 0, sideOn.getMaxU, sideOn.getMaxV) + t.addVertexWithUV(1, 0, 0, sideOn.getMaxU, sideOn.getMinV) + t.addVertexWithUV(1, 0, 1, sideOn.getMinU, sideOn.getMinV) + + t.addVertexWithUV(0, 1, 0, sideOn.getMinU, sideOn.getMaxV) + t.addVertexWithUV(0, 1, 1, sideOn.getMaxU, sideOn.getMaxV) + t.addVertexWithUV(0, 0, 1, sideOn.getMaxU, sideOn.getMinV) + t.addVertexWithUV(0, 0, 0, sideOn.getMinU, sideOn.getMinV) t.draw() diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/RouterRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/RouterRenderer.scala new file mode 100644 index 000000000..4de961236 --- /dev/null +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/RouterRenderer.scala @@ -0,0 +1,60 @@ +package li.cil.oc.client.renderer.tileentity + +import li.cil.oc.Blocks +import li.cil.oc.common.tileentity +import li.cil.oc.util.RenderState +import net.minecraft.client.renderer.Tessellator +import net.minecraft.client.renderer.texture.TextureMap +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer +import net.minecraft.tileentity.TileEntity +import org.lwjgl.opengl.GL11 + +object RouterRenderer extends TileEntitySpecialRenderer { + override def renderTileEntityAt(tileEntity: TileEntity, x: Double, y: Double, z: Double, f: Float) { + val router = tileEntity.asInstanceOf[tileentity.Router] + val activity = math.max(0, 1 - (System.currentTimeMillis() - router.lastMessage) / 1000.0) + if (activity > 0) { + GL11.glPushAttrib(0xFFFFFF) + + RenderState.disableLighting() + RenderState.makeItBlend() + RenderState.setBlendAlpha(activity.toFloat) + + GL11.glPushMatrix() + + GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5) + GL11.glScalef(1.002f, -1.002f, 1.002f) + GL11.glTranslatef(-0.5f, -0.5f, -0.5f) + + bindTexture(TextureMap.locationBlocksTexture) + val t = Tessellator.instance + t.startDrawingQuads() + + val sideActivity = Blocks.router.iconSideActivity + t.addVertexWithUV(1, 1, 0, sideActivity.getMinU, sideActivity.getMaxV) + t.addVertexWithUV(0, 1, 0, sideActivity.getMaxU, sideActivity.getMaxV) + t.addVertexWithUV(0, 0, 0, sideActivity.getMaxU, sideActivity.getMinV) + t.addVertexWithUV(1, 0, 0, sideActivity.getMinU, sideActivity.getMinV) + + t.addVertexWithUV(0, 1, 1, sideActivity.getMinU, sideActivity.getMaxV) + t.addVertexWithUV(1, 1, 1, sideActivity.getMaxU, sideActivity.getMaxV) + t.addVertexWithUV(1, 0, 1, sideActivity.getMaxU, sideActivity.getMinV) + t.addVertexWithUV(0, 0, 1, sideActivity.getMinU, sideActivity.getMinV) + + t.addVertexWithUV(1, 1, 1, sideActivity.getMinU, sideActivity.getMaxV) + t.addVertexWithUV(1, 1, 0, sideActivity.getMaxU, sideActivity.getMaxV) + t.addVertexWithUV(1, 0, 0, sideActivity.getMaxU, sideActivity.getMinV) + t.addVertexWithUV(1, 0, 1, sideActivity.getMinU, sideActivity.getMinV) + + t.addVertexWithUV(0, 1, 0, sideActivity.getMinU, sideActivity.getMaxV) + t.addVertexWithUV(0, 1, 1, sideActivity.getMaxU, sideActivity.getMaxV) + t.addVertexWithUV(0, 0, 1, sideActivity.getMaxU, sideActivity.getMinV) + t.addVertexWithUV(0, 0, 0, sideActivity.getMinU, sideActivity.getMinV) + + t.draw() + + GL11.glPopMatrix() + GL11.glPopAttrib() + } + } +} diff --git a/src/main/scala/li/cil/oc/common/PacketType.scala b/src/main/scala/li/cil/oc/common/PacketType.scala index 8f909bb75..d1d2d34b7 100644 --- a/src/main/scala/li/cil/oc/common/PacketType.scala +++ b/src/main/scala/li/cil/oc/common/PacketType.scala @@ -22,6 +22,7 @@ object PacketType extends Enumeration { RobotSelectedSlotChange, RobotXp, RotatableState, + RouterActivity, ScreenColorChange, ScreenCopy, ScreenDepthChange, diff --git a/src/main/scala/li/cil/oc/common/block/Case.scala b/src/main/scala/li/cil/oc/common/block/Case.scala index 1ffe21848..daa406c08 100644 --- a/src/main/scala/li/cil/oc/common/block/Case.scala +++ b/src/main/scala/li/cil/oc/common/block/Case.scala @@ -9,7 +9,7 @@ import li.cil.oc.{OpenComputers, Settings} import mcp.mobius.waila.api.{IWailaConfigHandler, IWailaDataAccessor} import net.minecraft.client.renderer.texture.IconRegister import net.minecraft.entity.player.EntityPlayer -import net.minecraft.item.{EnumRarity, ItemStack} +import net.minecraft.item.{ItemDye, EnumRarity, ItemStack} import net.minecraft.util.{StatCollector, Icon} import net.minecraft.world.IBlockAccess import net.minecraft.world.World @@ -105,19 +105,19 @@ object Case { class Tier1(parent: SimpleDelegator) extends Case(parent) { def tier = 0 - override def color = 0x7F7F7F + override def color = ItemDye.dyeColors(ItemDye.dyeColorNames.indexOf("silver")) } class Tier2(parent: SimpleDelegator) extends Case(parent) { def tier = 1 - override def color = 0xFFFF66 + override def color = 0xFFFF66 // ItemDye.dyeColors(ItemDye.dyeColorNames.indexOf("yellow")) } class Tier3(parent: SimpleDelegator) extends Case(parent) { def tier = 2 - override def color = 0x66FFFF + override def color = 0x66FFFF // ItemDye.dyeColors(ItemDye.dyeColorNames.indexOf("lightBlue")) } } diff --git a/src/main/scala/li/cil/oc/common/block/Charger.scala b/src/main/scala/li/cil/oc/common/block/Charger.scala index cd9b16a31..79f13cb96 100644 --- a/src/main/scala/li/cil/oc/common/block/Charger.scala +++ b/src/main/scala/li/cil/oc/common/block/Charger.scala @@ -20,7 +20,8 @@ class Charger(val parent: SimpleDelegator) extends RedstoneAware with SimpleDele val unlocalizedName = "Charger" private val icons = Array.fill[Icon](6)(null) - private val iconsCharging = Array.fill[Icon](6)(null) + var iconFrontCharging: Icon = _ + var iconSideCharging: Icon = _ override def tooltipLines(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) { tooltip.addAll(Tooltip.get(unlocalizedName)) @@ -40,28 +41,19 @@ class Charger(val parent: SimpleDelegator) extends RedstoneAware with SimpleDele override def icon(side: ForgeDirection) = Some(icons(side.ordinal())) @SideOnly(Side.CLIENT) - override def icon(world: IBlockAccess, x: Int, y: Int, z: Int, worldSide: ForgeDirection, localSide: ForgeDirection) = - world.getBlockTileEntity(x, y, z) match { - case charger: tileentity.Charger if charger.chargeSpeed > 0 => Some(iconsCharging(localSide.ordinal())) - case _ => Some(icons(localSide.ordinal())) - } + override def icon(world: IBlockAccess, x: Int, y: Int, z: Int, worldSide: ForgeDirection, localSide: ForgeDirection) = Some(icons(localSide.ordinal())) override def registerIcons(iconRegister: IconRegister) = { icons(ForgeDirection.DOWN.ordinal) = iconRegister.registerIcon(Settings.resourceDomain + ":generic_top") icons(ForgeDirection.UP.ordinal) = icons(ForgeDirection.DOWN.ordinal) - icons(ForgeDirection.NORTH.ordinal) = iconRegister.registerIcon(Settings.resourceDomain + ":charger") - icons(ForgeDirection.SOUTH.ordinal) = icons(ForgeDirection.NORTH.ordinal) + icons(ForgeDirection.NORTH.ordinal) = iconRegister.registerIcon(Settings.resourceDomain + ":charger_side") + icons(ForgeDirection.SOUTH.ordinal) = iconRegister.registerIcon(Settings.resourceDomain + ":charger_front") icons(ForgeDirection.WEST.ordinal) = icons(ForgeDirection.NORTH.ordinal) icons(ForgeDirection.EAST.ordinal) = icons(ForgeDirection.NORTH.ordinal) - iconsCharging(ForgeDirection.DOWN.ordinal) = icons(ForgeDirection.DOWN.ordinal) - iconsCharging(ForgeDirection.UP.ordinal) = icons(ForgeDirection.UP.ordinal) - - iconsCharging(ForgeDirection.NORTH.ordinal) = iconRegister.registerIcon(Settings.resourceDomain + ":charger_on") - iconsCharging(ForgeDirection.SOUTH.ordinal) = iconsCharging(ForgeDirection.NORTH.ordinal) - iconsCharging(ForgeDirection.WEST.ordinal) = iconsCharging(ForgeDirection.NORTH.ordinal) - iconsCharging(ForgeDirection.EAST.ordinal) = iconsCharging(ForgeDirection.NORTH.ordinal) + iconFrontCharging = iconRegister.registerIcon(Settings.resourceDomain + ":charger_front_on") + iconSideCharging = iconRegister.registerIcon(Settings.resourceDomain + ":charger_side_on") } override def createTileEntity(world: World) = Some(new tileentity.Charger()) diff --git a/src/main/scala/li/cil/oc/common/block/Item.scala b/src/main/scala/li/cil/oc/common/block/Item.scala index 16d776398..de3eb9c83 100644 --- a/src/main/scala/li/cil/oc/common/block/Item.scala +++ b/src/main/scala/li/cil/oc/common/block/Item.scala @@ -46,10 +46,8 @@ class Item(id: Int) extends ItemBlock(id) { keyboard.setFromFacing(ForgeDirection.getOrientation(side)) case rotatable: tileentity.traits.Rotatable => rotatable.setFromEntityPitchAndYaw(player) - rotatable match { - case _@(_: tileentity.traits.Computer | _: tileentity.DiskDrive | _: tileentity.Rack) => - rotatable.pitch = ForgeDirection.NORTH - case _ => + if (!rotatable.validFacings.contains(rotatable.pitch)) { + rotatable.pitch = rotatable.validFacings.headOption.getOrElse(ForgeDirection.NORTH) } if (!rotatable.isInstanceOf[tileentity.RobotProxy]) { rotatable.invertRotation() diff --git a/src/main/scala/li/cil/oc/common/block/PowerDistributor.scala b/src/main/scala/li/cil/oc/common/block/PowerDistributor.scala index d387289f0..e8d7c921e 100644 --- a/src/main/scala/li/cil/oc/common/block/PowerDistributor.scala +++ b/src/main/scala/li/cil/oc/common/block/PowerDistributor.scala @@ -15,6 +15,8 @@ class PowerDistributor(val parent: SimpleDelegator) extends SimpleDelegate { val unlocalizedName = "PowerDistributor" private val icons = Array.fill[Icon](6)(null) + var iconSideOn: Icon = _ + var iconTopOn: Icon = _ // ----------------------------------------------------------------------- // @@ -26,12 +28,15 @@ class PowerDistributor(val parent: SimpleDelegator) extends SimpleDelegate { override def registerIcons(iconRegister: IconRegister) = { icons(ForgeDirection.DOWN.ordinal) = iconRegister.registerIcon(Settings.resourceDomain + ":generic_top") - icons(ForgeDirection.UP.ordinal) = icons(ForgeDirection.DOWN.ordinal) + icons(ForgeDirection.UP.ordinal) = iconRegister.registerIcon(Settings.resourceDomain + ":power_distributor_top") - icons(ForgeDirection.NORTH.ordinal) = iconRegister.registerIcon(Settings.resourceDomain + ":power_distributor") + icons(ForgeDirection.NORTH.ordinal) = iconRegister.registerIcon(Settings.resourceDomain + ":power_distributor_side") icons(ForgeDirection.SOUTH.ordinal) = icons(ForgeDirection.NORTH.ordinal) icons(ForgeDirection.WEST.ordinal) = icons(ForgeDirection.NORTH.ordinal) icons(ForgeDirection.EAST.ordinal) = icons(ForgeDirection.NORTH.ordinal) + + iconSideOn = iconRegister.registerIcon(Settings.resourceDomain + ":power_distributor_side_on") + iconTopOn = iconRegister.registerIcon(Settings.resourceDomain + ":power_distributor_top_on") } override def luminance(world: IBlockAccess, x: Int, y: Int, z: Int) = 5 diff --git a/src/main/scala/li/cil/oc/common/block/Router.scala b/src/main/scala/li/cil/oc/common/block/Router.scala index ef4e63eb2..67f79c79b 100644 --- a/src/main/scala/li/cil/oc/common/block/Router.scala +++ b/src/main/scala/li/cil/oc/common/block/Router.scala @@ -16,6 +16,8 @@ class Router(val parent: SimpleDelegator) extends SimpleDelegate { private val icons = Array.fill[Icon](6)(null) + var iconSideActivity: Icon = _ + // ----------------------------------------------------------------------- // override def tooltipLines(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) { @@ -32,6 +34,8 @@ class Router(val parent: SimpleDelegator) extends SimpleDelegate { icons(ForgeDirection.SOUTH.ordinal) = icons(ForgeDirection.NORTH.ordinal) icons(ForgeDirection.WEST.ordinal) = icons(ForgeDirection.NORTH.ordinal) icons(ForgeDirection.EAST.ordinal) = icons(ForgeDirection.NORTH.ordinal) + + iconSideActivity = iconRegister.registerIcon(Settings.resourceDomain + ":router_side_active") } // ----------------------------------------------------------------------- // diff --git a/src/main/scala/li/cil/oc/common/tileentity/Charger.scala b/src/main/scala/li/cil/oc/common/tileentity/Charger.scala index f466ceb4d..1c62aea21 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Charger.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Charger.scala @@ -9,7 +9,7 @@ import net.minecraft.nbt.NBTTagCompound import net.minecraft.util.ChatMessageComponent import net.minecraftforge.common.ForgeDirection -class Charger extends traits.Environment with traits.RedstoneAware with Analyzable { +class Charger extends traits.Environment with traits.RedstoneAware with traits.Rotatable with Analyzable { val node = api.Network.newNode(this, Visibility.None). withConnector(). create() diff --git a/src/main/scala/li/cil/oc/common/tileentity/Keyboard.scala b/src/main/scala/li/cil/oc/common/tileentity/Keyboard.scala index 61435a323..e57f071a2 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Keyboard.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Keyboard.scala @@ -12,6 +12,8 @@ import net.minecraftforge.common.ForgeDirection class Keyboard(isRemote: Boolean) extends traits.Environment with traits.Rotatable with SidedEnvironment with Analyzable { def this() = this(false) + override def validFacings = ForgeDirection.VALID_DIRECTIONS + val keyboard = if (isRemote) null else new component.Keyboard { override def isUseableByPlayer(p: EntityPlayer) = diff --git a/src/main/scala/li/cil/oc/common/tileentity/Router.scala b/src/main/scala/li/cil/oc/common/tileentity/Router.scala index a5d2bbf38..ab1f42e4f 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Router.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Router.scala @@ -4,10 +4,14 @@ import cpw.mods.fml.common.{Loader, Optional} import dan200.computer.api.{ILuaContext, IComputerAccess, IPeripheral} import li.cil.oc.api import li.cil.oc.api.network.{Packet, Message} +import li.cil.oc.server.PacketSender +import net.minecraftforge.common.ForgeDirection import scala.collection.mutable @Optional.Interface(iface = "dan200.computer.api.IPeripheral", modid = "ComputerCraft") class Router extends traits.Hub with traits.NotAnalyzable with IPeripheral { + var lastMessage = 0L + private val computers = mutable.ArrayBuffer.empty[AnyRef] private val openPorts = mutable.Map.empty[AnyRef, mutable.Set[Int]] @@ -86,6 +90,15 @@ class Router extends traits.Hub with traits.NotAnalyzable with IPeripheral { // ----------------------------------------------------------------------- // + override protected def relayPacket(sourceSide: ForgeDirection, packet: Packet) { + super.relayPacket(sourceSide, packet) + val now = System.currentTimeMillis() + if (now - lastMessage > 250) { + lastMessage = now + PacketSender.sendRouterActivity(this) + } + } + override protected def onPlugMessage(plug: Plug, message: Message) { super.onPlugMessage(plug, message) if (message.name == "network.message" && Loader.isModLoaded("ComputerCraft")) { diff --git a/src/main/scala/li/cil/oc/common/tileentity/Screen.scala b/src/main/scala/li/cil/oc/common/tileentity/Screen.scala index 08f267bdb..8c099f418 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Screen.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Screen.scala @@ -22,6 +22,8 @@ class Screen(var tier: Int) extends traits.TextBuffer with SidedEnvironment with _isOutputEnabled = true + override def validFacings = ForgeDirection.VALID_DIRECTIONS + // ----------------------------------------------------------------------- // override protected val _buffer = new component.Buffer(this) { diff --git a/src/main/scala/li/cil/oc/common/tileentity/traits/Rotatable.scala b/src/main/scala/li/cil/oc/common/tileentity/traits/Rotatable.scala index 5e76b8bc3..ced06108e 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/traits/Rotatable.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/traits/Rotatable.scala @@ -149,6 +149,8 @@ trait Rotatable extends RotationAware with api.Rotatable { override def toGlobal(value: ForgeDirection) = cachedInverseTranslation(value.ordinal) + def validFacings = Array(ForgeDirection.NORTH, ForgeDirection.SOUTH, ForgeDirection.WEST, ForgeDirection.EAST) + // ----------------------------------------------------------------------- // protected def onRotationChanged() { @@ -165,8 +167,12 @@ trait Rotatable extends RotationAware with api.Rotatable { override def readFromNBT(nbt: NBTTagCompound) = { super.readFromNBT(nbt) - pitch = ForgeDirection.getOrientation(nbt.getInteger(Settings.namespace + "pitch")) - yaw = ForgeDirection.getOrientation(nbt.getInteger(Settings.namespace + "yaw")) + if (nbt.hasKey(Settings.namespace + "pitch")) { + pitch = ForgeDirection.getOrientation(nbt.getInteger(Settings.namespace + "pitch")) + } + if (nbt.hasKey(Settings.namespace + "yaw")) { + yaw = ForgeDirection.getOrientation(nbt.getInteger(Settings.namespace + "yaw")) + } validatePitchAndYaw() updateTranslation() } diff --git a/src/main/scala/li/cil/oc/server/PacketSender.scala b/src/main/scala/li/cil/oc/server/PacketSender.scala index 2b1f2f26d..022262d1a 100644 --- a/src/main/scala/li/cil/oc/server/PacketSender.scala +++ b/src/main/scala/li/cil/oc/server/PacketSender.scala @@ -198,6 +198,14 @@ object PacketSender { pb.sendToNearbyPlayers(t) } + def sendRouterActivity(t: tileentity.Router) { + val pb = new PacketBuilder(PacketType.RouterActivity) + + pb.writeTileEntity(t) + + pb.sendToNearbyPlayers(t, 64) + } + def sendScreenColorChange(b: common.component.Buffer, foreground: Int, background: Int) { val pb = new PacketBuilder(PacketType.ScreenColorChange) diff --git a/src/main/scala/li/cil/oc/server/network/Network.scala b/src/main/scala/li/cil/oc/server/network/Network.scala index f24e39a8d..732523ed7 100644 --- a/src/main/scala/li/cil/oc/server/network/Network.scala +++ b/src/main/scala/li/cil/oc/server/network/Network.scala @@ -465,7 +465,7 @@ object Network extends api.detail.NetworkAPI { override def newPacket(nbt: NBTTagCompound) = { val source = nbt.getString("source") val destination = - if (nbt.getBoolean("broadcast")) null + if (nbt.hasKey("dest")) null else nbt.getString("dest") val port = nbt.getInteger("port") val ttl = nbt.getInteger("ttl") @@ -596,8 +596,7 @@ object Network extends api.detail.NetworkAPI { override def save(nbt: NBTTagCompound) { nbt.setString("source", source) - nbt.setBoolean("broadcast", destination.isEmpty) - if (destination != null) { + if (destination != null && !destination.isEmpty) { nbt.setString("dest", destination) } nbt.setInteger("port", port)