diff --git a/assets/opencomputers/textures/blocks/gradient.png b/assets/opencomputers/textures/blocks/gradient.png deleted file mode 100644 index 7183d0899..000000000 Binary files a/assets/opencomputers/textures/blocks/gradient.png and /dev/null differ diff --git a/assets/opencomputers/textures/blocks/power_converter.png b/assets/opencomputers/textures/blocks/power_converter.png new file mode 100644 index 000000000..a7de68d14 Binary files /dev/null and b/assets/opencomputers/textures/blocks/power_converter.png differ diff --git a/assets/opencomputers/textures/blocks/power_distributor.png b/assets/opencomputers/textures/blocks/power_distributor.png new file mode 100644 index 000000000..28f5b777b Binary files /dev/null and b/assets/opencomputers/textures/blocks/power_distributor.png differ diff --git a/assets/opencomputers/textures/blocks/power_distributor_on.png b/assets/opencomputers/textures/blocks/power_distributor_on.png new file mode 100644 index 000000000..c5c7fe0ea Binary files /dev/null and b/assets/opencomputers/textures/blocks/power_distributor_on.png differ diff --git a/li/cil/oc/client/ComputerRenderer.scala b/li/cil/oc/client/ComputerRenderer.scala index bee4f4e7e..be2677724 100644 --- a/li/cil/oc/client/ComputerRenderer.scala +++ b/li/cil/oc/client/ComputerRenderer.scala @@ -2,7 +2,6 @@ package li.cil.oc.client import li.cil.oc.Config import li.cil.oc.common.tileentity.Computer -import net.minecraft.client.renderer.OpenGlHelper import net.minecraft.client.renderer.Tessellator import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer import net.minecraft.tileentity.TileEntity @@ -17,7 +16,12 @@ object ComputerRenderer extends TileEntitySpecialRenderer { val computer = tileEntity.asInstanceOf[Computer] if (computer.isOn) { GL11.glPushAttrib(0xFFFFFF) + + RenderUtil.disableLighting() + RenderUtil.makeItBlend() + GL11.glPushMatrix() + GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5) computer.yaw match { @@ -27,12 +31,6 @@ object ComputerRenderer extends TileEntitySpecialRenderer { case _ => // No yaw. } - GL11.glEnable(GL11.GL_BLEND) - GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_COLOR) - GL11.glDepthFunc(GL11.GL_LEQUAL) - - OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 200, 200) - GL11.glTranslatef(-0.5f, 0.5f, 0.501f) GL11.glScalef(1, -1, 1) diff --git a/li/cil/oc/client/PowerDistributorRenderer.scala b/li/cil/oc/client/PowerDistributorRenderer.scala new file mode 100644 index 000000000..80ff3e6f5 --- /dev/null +++ b/li/cil/oc/client/PowerDistributorRenderer.scala @@ -0,0 +1,60 @@ +package li.cil.oc.client + +import li.cil.oc.Config +import li.cil.oc.common.tileentity +import net.minecraft.client.renderer.Tessellator +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer +import net.minecraft.tileentity.TileEntity +import net.minecraft.util.ResourceLocation +import org.lwjgl.opengl.GL11 + +object PowerDistributorRenderer extends TileEntitySpecialRenderer { + private val sideOn = new ResourceLocation(Config.resourceDomain, "textures/blocks/power_distributor_on.png") + + override def renderTileEntityAt(tileEntity: TileEntity, x: Double, y: Double, z: Double, f: Float) = { + val distributor = tileEntity.asInstanceOf[tileentity.PowerDistributor] + if (distributor.isActive) { + GL11.glPushAttrib(0xFFFFFF) + + RenderUtil.disableLighting() + RenderUtil.makeItBlend() + + 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(sideOn) + + 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) + + 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) + + 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, 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.draw() + + GL11.glPopMatrix() + GL11.glPopAttrib() + } + } + +} diff --git a/li/cil/oc/client/Proxy.scala b/li/cil/oc/client/Proxy.scala index 922444393..06845f910 100644 --- a/li/cil/oc/client/Proxy.scala +++ b/li/cil/oc/client/Proxy.scala @@ -6,8 +6,7 @@ import cpw.mods.fml.common.network.NetworkRegistry import cpw.mods.fml.common.registry.TickRegistry import cpw.mods.fml.relauncher.Side import li.cil.oc.OpenComputers -import li.cil.oc.common.tileentity.Computer -import li.cil.oc.common.tileentity.Screen +import li.cil.oc.common.tileentity import li.cil.oc.common.{Proxy => CommonProxy} private[oc] class Proxy extends CommonProxy { @@ -16,8 +15,9 @@ private[oc] class Proxy extends CommonProxy { NetworkRegistry.instance.registerGuiHandler(OpenComputers, GuiHandler) - ClientRegistry.bindTileEntitySpecialRenderer(classOf[Screen], ScreenRenderer) - ClientRegistry.bindTileEntitySpecialRenderer(classOf[Computer], ComputerRenderer) + ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.Screen], ScreenRenderer) + ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.Computer], ComputerRenderer) + ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.PowerDistributor], PowerDistributorRenderer) TickRegistry.registerTickHandler(ScreenRenderer, Side.CLIENT) } diff --git a/li/cil/oc/client/RenderUtil.scala b/li/cil/oc/client/RenderUtil.scala new file mode 100644 index 000000000..e94df5288 --- /dev/null +++ b/li/cil/oc/client/RenderUtil.scala @@ -0,0 +1,28 @@ +package li.cil.oc.client + +import net.minecraft.client.renderer.OpenGlHelper +import org.lwjgl.opengl.{ARBMultitexture, GLContext, GL11, GL13} + +object RenderUtil { + val arb = GLContext.getCapabilities.GL_ARB_multitexture && !GLContext.getCapabilities.OpenGL13 + + def disableLighting() { + GL11.glDisable(GL11.GL_LIGHTING) + if (arb) { + ARBMultitexture.glActiveTextureARB(OpenGlHelper.lightmapTexUnit) + GL11.glDisable(GL11.GL_TEXTURE_2D) + ARBMultitexture.glActiveTextureARB(OpenGlHelper.defaultTexUnit) + } + else { + GL13.glActiveTexture(OpenGlHelper.lightmapTexUnit) + GL11.glDisable(GL11.GL_TEXTURE_2D) + GL13.glActiveTexture(OpenGlHelper.defaultTexUnit) + } + } + + def makeItBlend() { + GL11.glEnable(GL11.GL_BLEND) + GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_COLOR) + GL11.glDepthFunc(GL11.GL_LEQUAL) + } +} diff --git a/li/cil/oc/client/ScreenRenderer.scala b/li/cil/oc/client/ScreenRenderer.scala index 14d8662cc..09c39b913 100644 --- a/li/cil/oc/client/ScreenRenderer.scala +++ b/li/cil/oc/client/ScreenRenderer.scala @@ -7,8 +7,8 @@ import java.util.concurrent.{TimeUnit, Callable} import li.cil.oc.client.gui.MonospaceFontRenderer import li.cil.oc.common.tileentity.Screen import net.minecraft.client.Minecraft +import net.minecraft.client.renderer.GLAllocation import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer -import net.minecraft.client.renderer.{GLAllocation, OpenGlHelper} import net.minecraft.tileentity.TileEntity import net.minecraftforge.common.ForgeDirection import org.lwjgl.opengl.{GL14, GL11} @@ -51,22 +51,20 @@ object ScreenRenderer extends TileEntitySpecialRenderer with Callable[Int] with return GL11.glPushAttrib(0xFFFFFF) + + RenderUtil.disableLighting() + RenderUtil.makeItBlend() + GL11.glPushMatrix() GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5) - GL11.glDepthMask(false) - GL11.glDisable(GL11.GL_LIGHTING) - GL11.glEnable(GL11.GL_BLEND) - GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_COLOR) - GL11.glDepthFunc(GL11.GL_LEQUAL) - if (playerDistance > fadeDistanceSq) { val fade = 1f min ((playerDistance - fadeDistanceSq) / (maxRenderDistanceSq - fadeDistanceSq)) GL14.glBlendColor(0, 0, 0, 1 - fade) - //GL11.glBlendFunc(GL11.GL_CONSTANT_ALPHA, GL11.GL_ONE_MINUS_CONSTANT_ALPHA​) - GL11.glBlendFunc(0x8003, 0x8004) // For some reason the compiler doesn't like the above. + GL11.glBlendFunc(GL11.GL_CONSTANT_ALPHA, GL11.GL_ONE) } + MonospaceFontRenderer.init(tileEntityRenderer.renderEngine) val list = cache.get(tileEntity, this) compile(list) @@ -108,8 +106,6 @@ object ScreenRenderer extends TileEntitySpecialRenderer with Callable[Int] with // Flip text upside down. GL11.glScalef(1, -1, 1) - OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 200, 200) - for ((line, i) <- tileEntity.screen.lines.zipWithIndex) { MonospaceFontRenderer.drawString(line, 0, i * MonospaceFontRenderer.fontHeight) } diff --git a/li/cil/oc/common/block/Computer.scala b/li/cil/oc/common/block/Computer.scala index 8df714b7e..3feac647a 100644 --- a/li/cil/oc/common/block/Computer.scala +++ b/li/cil/oc/common/block/Computer.scala @@ -20,7 +20,7 @@ class Computer(val parent: Delegator) extends Delegate { // Rendering stuff // ----------------------------------------------------------------------- // - object Icons { + private object Icons { val on = Array.fill[Icon](6)(null) val off = Array.fill[Icon](6)(null) } diff --git a/li/cil/oc/common/block/Delegate.scala b/li/cil/oc/common/block/Delegate.scala index 7986b8087..49a1c2f79 100644 --- a/li/cil/oc/common/block/Delegate.scala +++ b/li/cil/oc/common/block/Delegate.scala @@ -40,6 +40,8 @@ trait Delegate { def getLightOpacity(world: World, x: Int, y: Int, z: Int) = 255 + def getLightValue(world: IBlockAccess, x: Int, y: Int, z: Int) = 0 + def getValidRotations(world: World, x: Int, y: Int, z: Int) = RotationHelper.getValidVanillaBlockRotations(Block.stone) diff --git a/li/cil/oc/common/block/Delegator.scala b/li/cil/oc/common/block/Delegator.scala index a3655c43d..d6d046560 100644 --- a/li/cil/oc/common/block/Delegator.scala +++ b/li/cil/oc/common/block/Delegator.scala @@ -153,6 +153,12 @@ class Delegator(id: Int) extends Block(id, Material.iron) { } } + override def getLightValue(world: IBlockAccess, x: Int, y: Int, z: Int) = + subBlock(world, x, y, z) match { + case None => 0 + case Some(subBlock) => subBlock.getLightValue(world, x, y, z) + } + override def getIcon(side: Int, metadata: Int) = subBlock(metadata) match { case None => super.getIcon(side, metadata) diff --git a/li/cil/oc/common/block/PowerDistributor.scala b/li/cil/oc/common/block/PowerDistributor.scala index 20415f84a..dce23b9f9 100644 --- a/li/cil/oc/common/block/PowerDistributor.scala +++ b/li/cil/oc/common/block/PowerDistributor.scala @@ -1,18 +1,36 @@ package li.cil.oc.common.block import cpw.mods.fml.common.registry.GameRegistry +import li.cil.oc.Config import li.cil.oc.common.tileentity -import net.minecraft.world.World +import net.minecraft.client.renderer.texture.IconRegister +import net.minecraft.util.Icon +import net.minecraft.world.{IBlockAccess, World} +import net.minecraftforge.common.ForgeDirection +class PowerDistributor(val parent: Delegator) extends Delegate { + GameRegistry.registerTileEntity(classOf[tileentity.PowerDistributor], "oc.powerdistributor") -class PowerDistributor (val parent: Delegator) extends Delegate { - GameRegistry.registerTileEntity(classOf[tileentity.PowerDistributor], "oc.powerdistributor" ) val unlocalizedName = "PowerDistributor" - override def breakBlock(world: World, x: Int, y: Int, z: Int, blockId: Int, metadata: Int) = { - //world.getBlockTileEntity(x, y, z).asInstanceOf[tileentity.PowerDistributer] - super.breakBlock(world, x, y, z, blockId, metadata) + // ----------------------------------------------------------------------- // + + private val icons = Array.fill[Icon](6)(null) + + override def icon(side: ForgeDirection) = Some(icons(side.ordinal())) + + override def registerIcons(iconRegister: IconRegister) = { + icons(ForgeDirection.DOWN.ordinal) = iconRegister.registerIcon(Config.resourceDomain + ":computer_top") + icons(ForgeDirection.UP.ordinal) = icons(ForgeDirection.DOWN.ordinal) + + icons(ForgeDirection.NORTH.ordinal) = iconRegister.registerIcon(Config.resourceDomain + ":power_distributor") + icons(ForgeDirection.SOUTH.ordinal) = icons(ForgeDirection.NORTH.ordinal) + icons(ForgeDirection.WEST.ordinal) = icons(ForgeDirection.NORTH.ordinal) + icons(ForgeDirection.EAST.ordinal) = icons(ForgeDirection.NORTH.ordinal) } + + override def getLightValue(world: IBlockAccess, x: Int, y: Int, z: Int) = 5 + // ----------------------------------------------------------------------- // // Tile entity // ----------------------------------------------------------------------- // @@ -20,5 +38,16 @@ class PowerDistributor (val parent: Delegator) extends Delegate { override def hasTileEntity = true override def createTileEntity(world: World, metadata: Int) = Some(new tileentity.PowerDistributor) + + // ----------------------------------------------------------------------- // + + override def getValidRotations(world: World, x: Int, y: Int, z: Int) = validRotations + + /** Avoid creating new arrays. */ + private val validRotations = Array( + ForgeDirection.SOUTH, + ForgeDirection.WEST, + ForgeDirection.NORTH, + ForgeDirection.EAST) } diff --git a/li/cil/oc/common/block/PowerSupply.scala b/li/cil/oc/common/block/PowerSupply.scala index 1f80b7f97..4f3b37c52 100644 --- a/li/cil/oc/common/block/PowerSupply.scala +++ b/li/cil/oc/common/block/PowerSupply.scala @@ -2,7 +2,11 @@ package li.cil.oc.common.block import cpw.mods.fml.common.registry.GameRegistry import li.cil.oc.common.tileentity -import net.minecraft.world.World +import net.minecraft.world.{IBlockAccess, World} +import net.minecraft.util.Icon +import net.minecraftforge.common.ForgeDirection +import net.minecraft.client.renderer.texture.IconRegister +import li.cil.oc.Config /** * Created with IntelliJ IDEA. @@ -19,6 +23,23 @@ class PowerSupply(val parent: Delegator) extends Delegate { world.getBlockTileEntity(x, y, z).asInstanceOf[tileentity.PowerSupply].onUnload() super.breakBlock(world, x, y, z, blockId, metadata) } + + // ----------------------------------------------------------------------- // + + private val icons = Array.fill[Icon](6)(null) + + override def icon(side: ForgeDirection) = Some(icons(side.ordinal)) + + override def registerIcons(iconRegister: IconRegister) = { + icons(ForgeDirection.DOWN.ordinal) = iconRegister.registerIcon(Config.resourceDomain + ":computer_top") + icons(ForgeDirection.UP.ordinal) = icons(ForgeDirection.DOWN.ordinal) + + icons(ForgeDirection.NORTH.ordinal) = iconRegister.registerIcon(Config.resourceDomain + ":power_converter") + icons(ForgeDirection.SOUTH.ordinal) = icons(ForgeDirection.NORTH.ordinal) + icons(ForgeDirection.WEST.ordinal) = icons(ForgeDirection.NORTH.ordinal) + icons(ForgeDirection.EAST.ordinal) = icons(ForgeDirection.NORTH.ordinal) + } + // ----------------------------------------------------------------------- // // Tile entity // ----------------------------------------------------------------------- // @@ -26,4 +47,15 @@ class PowerSupply(val parent: Delegator) extends Delegate { override def hasTileEntity = true override def createTileEntity(world: World, metadata: Int) = Some(new tileentity.PowerSupply) + + // ----------------------------------------------------------------------- // + + override def getValidRotations(world: World, x: Int, y: Int, z: Int) = validRotations + + /** Avoid creating new arrays. */ + private val validRotations = Array( + ForgeDirection.SOUTH, + ForgeDirection.WEST, + ForgeDirection.NORTH, + ForgeDirection.EAST) }