added textures for power blocks and reworked rendering of tile entity overlays a little (better way of ignoring lighting now)

This commit is contained in:
Florian Nücke 2013-10-11 15:09:54 +02:00
parent 266732f799
commit 1e8d48cf11
14 changed files with 181 additions and 30 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 384 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 608 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 678 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 B

View File

@ -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)

View File

@ -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()
}
}
}

View File

@ -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)
}

View File

@ -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)
}
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)

View File

@ -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)

View File

@ -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)
}

View File

@ -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)
}