From 1e8d48cf11a4a93779736cf6b83a6824c9f89e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Fri, 11 Oct 2013 15:09:54 +0200 Subject: [PATCH] added textures for power blocks and reworked rendering of tile entity overlays a little (better way of ignoring lighting now) --- .../textures/blocks/gradient.png | Bin 384 -> 0 bytes .../textures/blocks/power_converter.png | Bin 0 -> 608 bytes .../textures/blocks/power_distributor.png | Bin 0 -> 678 bytes .../textures/blocks/power_distributor_on.png | Bin 0 -> 178 bytes li/cil/oc/client/ComputerRenderer.scala | 12 ++-- .../oc/client/PowerDistributorRenderer.scala | 60 ++++++++++++++++++ li/cil/oc/client/Proxy.scala | 8 +-- li/cil/oc/client/RenderUtil.scala | 28 ++++++++ li/cil/oc/client/ScreenRenderer.scala | 18 ++---- li/cil/oc/common/block/Computer.scala | 2 +- li/cil/oc/common/block/Delegate.scala | 2 + li/cil/oc/common/block/Delegator.scala | 6 ++ li/cil/oc/common/block/PowerDistributor.scala | 41 ++++++++++-- li/cil/oc/common/block/PowerSupply.scala | 34 +++++++++- 14 files changed, 181 insertions(+), 30 deletions(-) delete mode 100644 assets/opencomputers/textures/blocks/gradient.png create mode 100644 assets/opencomputers/textures/blocks/power_converter.png create mode 100644 assets/opencomputers/textures/blocks/power_distributor.png create mode 100644 assets/opencomputers/textures/blocks/power_distributor_on.png create mode 100644 li/cil/oc/client/PowerDistributorRenderer.scala create mode 100644 li/cil/oc/client/RenderUtil.scala diff --git a/assets/opencomputers/textures/blocks/gradient.png b/assets/opencomputers/textures/blocks/gradient.png deleted file mode 100644 index 7183d08997ff13e4b6bfd79b9b74e946afd5f61f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 384 zcmV-`0e}99P)e!PF+mn|Zc>RDjEGNA5-YwwV!PxUf zJCu3T5C%;WjP85}wDEBCjO`J%N^AAm{=!13V`sBXMibPwGPTh$mV~^G1e25@O8u=? ziTqGVH)-blr*95a7*uWHq0ai)d<~G|redYH9>fI90Ol7k{b{ zRy4W%(>-{}BH@`}SyhVrAx>o!YT7_$i0`q=`_R7SV{0$e@SCA5#%0=R&J9jEL&~_7 ej#l?afB^vWC%nO$z3Dap0000000*k7j12AG&D3d zH8pE%Yj1CFXlQ6bK|yM2YF=JmJUl!`Mn*e3J0&G0FE1}JFfcecIBaZeTU%Q>IXNdM zCnO{!E-o%}b8|jEK1@tZWMpJ;aBwCjCUJ3bH#aw9V`EE8OLlg4X=!OOF)=eUGf`1d zcXxMqcz8raL^d`yD=RB9GBR{@bW&1M78Vw6Zf-0rEI>d&LqkJaT3U5=bvimaSy@>> zKR+reDnvv@MMOj+BO_;LXJBAp8X6inIXPx#W>r;HQ&Uq>8pH#Oajb=33l~xGVz#2vnbwQZYao*}J#yO?= zq=%438;ei~sv3f}CIUv3uEc6buR=Y%33Z@IrS~NPbe{W4f>3p7Ziqkdy+LJmo-~Bb z=$K@_=Xrki@@|6Y?Lo9fNCvt46Fq>&a&(^%lAIEQht<8H+7qC^3^T7KsmSV z>BXy?rib>~qYaJ1FuwPtq|`8`pT-qJCq>~{&YlxnmKDE&v7p`N@$CA@34(xgIBdum uAI{kyo6Q+#-~|@p`UChEYugzA3ormo9u}WH2T<<-0000uMHv|x7#J8A7Z+`9Z8S7AZ*Ol# zMn-CCYHMq2H8nL}US3R0OhG|GOG`^^Y-~6>c3GH`HkUteEoX=!(NcQ!UQXJ=TU=a#fKP&gPdGU_J32aCTwGRGR#{nDe0)qgIyz=%W_NcNklxSbxPrUi{%Z^C;{pnard=%tK_+vqxi{K9kRVCwets@LvF7`Y zcLKy54CF@j?Wb;z+{HEaJV}C0PF%c4e&3(02!ejolnPo_5c6? M07*qoM6N<$f-#i}RR910 literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..c5c7fe0ead0a743eeadffb5d9f80585d5d1d2318 GIT binary patch literal 178 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!WQl7;NpOBzNqJ&XDuZK6ep0G} zXKrG8YEWuoN@d~6R2!fowg8_H*Z==#{{R2q+c0)BP=u)@$S?Rm!_(~sUO=9Sr;B4q z#jT_S7iOL#Tm}m`4GatxtZwK&kjcijN9#ZhTZt&oi?jt?28%ci5>_ePD`sG1W2oe0 VcwjA`&;!)Z;OXk;vd$@?2>`YJG>ZTL literal 0 HcmV?d00001 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) }