Skip to content

Commit

Permalink
Textures for terminal server.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnuecke committed Nov 14, 2015
1 parent 39db143 commit f579524
Show file tree
Hide file tree
Showing 17 changed files with 137 additions and 54 deletions.
Binary file modified assets/blocks.psd
Binary file not shown.
48 changes: 41 additions & 7 deletions src/main/java/li/cil/oc/api/event/RackMountableRenderEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.ForgeDirection;

Expand Down Expand Up @@ -65,11 +66,32 @@ public static class Block extends RackMountableRenderEvent {
*/
public final RenderBlocks renderer;

public Block(Rack rack, int mountable, NBTTagCompound data, ForgeDirection side, RenderBlocks renderer) {
/**
* Texture to use for the front of the mountable.
*/
private IIcon frontTextureOverride;

public Block(final Rack rack, final int mountable, final NBTTagCompound data, final ForgeDirection side, final RenderBlocks renderer) {
super(rack, mountable, data);
this.side = side;
this.renderer = renderer;
}

/**
* The texture currently set to use for the front of the mountable, or <tt>null</tt>.
*/
public IIcon getFrontTextureOverride() {
return frontTextureOverride;
}

/**
* Set the texture to use for the front of the mountable.
*
* @param texture the texture to use.
*/
public void setFrontTextureOverride(final IIcon texture) {
frontTextureOverride = texture;
}
}

/**
Expand All @@ -95,25 +117,37 @@ public static class TileEntity extends RackMountableRenderEvent {
*/
public final float v0, v1;

public TileEntity(Rack rack, int mountable, NBTTagCompound data, float v0, float v1) {
public TileEntity(final Rack rack, final int mountable, final NBTTagCompound data, final float v0, final float v1) {
super(rack, mountable, data);
this.v0 = v0;
this.v1 = v1;
}

/**
* Utility method for rendering a texture as the front-side overlay.
*
* @param texture the texture to use to render the overlay.
*/
public void renderOverlay(final ResourceLocation texture) {
renderOverlay(texture, 0, 1);
}

/**
* Utility method for rendering a texture as the front-side overlay
* over a specified horizontal area.
*
* @param texture the texture to use to render the overlay.
* @param u0 the lower end of the vertical area to render at.
* @param u1 the upper end of the vertical area to render at.
*/
public void renderOverlay(ResourceLocation texture) {
public void renderOverlay(final ResourceLocation texture, final float u0, final float u1) {
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
final Tessellator t = Tessellator.instance;
t.startDrawingQuads();
t.addVertexWithUV(0, v1, 0, 0, v1);
t.addVertexWithUV(1, v1, 0, 1, v1);
t.addVertexWithUV(1, v0, 0, 1, v0);
t.addVertexWithUV(0, v0, 0, 0, v0);
t.addVertexWithUV(u0, v1, 0, u0, v1);
t.addVertexWithUV(u1, v1, 0, u1, v1);
t.addVertexWithUV(u1, v0, 0, u1, v0);
t.addVertexWithUV(u0, v0, 0, u0, v0);
t.draw();
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 8 additions & 4 deletions src/main/scala/li/cil/oc/client/Textures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ object Textures {
val blockMicrocontrollerFrontLight = new ResourceLocation(Settings.resourceDomain, "textures/blocks/MicrocontrollerFrontLight.png")
val blockMicrocontrollerFrontOn = new ResourceLocation(Settings.resourceDomain, "textures/blocks/MicrocontrollerFrontOn.png")
val blockMicrocontrollerFrontError = new ResourceLocation(Settings.resourceDomain, "textures/blocks/MicrocontrollerFrontError.png")
val blockRackFrontOn = new ResourceLocation(Settings.resourceDomain, "textures/blocks/ServerRackFrontOn.png")
val blockRackFrontError = new ResourceLocation(Settings.resourceDomain, "textures/blocks/ServerRackFrontError.png")
val blockRackFrontActivity = new ResourceLocation(Settings.resourceDomain, "textures/blocks/ServerRackFrontActivity.png")
val blockRaidFrontError = new ResourceLocation(Settings.resourceDomain, "textures/blocks/RaidFrontError.png")
val blockRaidFrontActivity = new ResourceLocation(Settings.resourceDomain, "textures/blocks/RaidFrontActivity.png")
val blockRobot = new ResourceLocation(Settings.resourceDomain, "textures/blocks/robot.png")
val blockScreenUpIndicator = new ResourceLocation(Settings.resourceDomain, "textures/blocks/screen/up_indicator.png")
val blockServerFrontOn = new ResourceLocation(Settings.resourceDomain, "textures/blocks/ServerFrontOn.png")
val blockServerFrontError = new ResourceLocation(Settings.resourceDomain, "textures/blocks/ServerFrontError.png")
val blockServerFrontActivity = new ResourceLocation(Settings.resourceDomain, "textures/blocks/ServerFrontActivity.png")
val blockTerminalServerFrontOn = new ResourceLocation(Settings.resourceDomain, "textures/blocks/TerminalServerFrontOn.png")
val blockTerminalServerFrontPresence = new ResourceLocation(Settings.resourceDomain, "textures/blocks/TerminalServerFrontPresence.png")

val upgradeCrafting = new ResourceLocation(Settings.resourceDomain, "textures/model/UpgradeCrafting.png")
val upgradeGenerator = new ResourceLocation(Settings.resourceDomain, "textures/model/UpgradeGenerator.png")
Expand Down Expand Up @@ -95,6 +97,8 @@ object Textures {

object Rack {
val icons = Array.fill[IIcon](6)(null)
var server: IIcon = _
var terminal: IIcon = _
}

object Assembler {
Expand Down Expand Up @@ -142,7 +146,7 @@ object Textures {
tm.bindTexture(blockHologram)
tm.bindTexture(blockMicrocontrollerFrontLight)
tm.bindTexture(blockMicrocontrollerFrontOn)
tm.bindTexture(blockRackFrontOn)
tm.bindTexture(blockServerFrontOn)
tm.bindTexture(blockRobot)
tm.bindTexture(blockScreenUpIndicator)

Expand Down
49 changes: 24 additions & 25 deletions src/main/scala/li/cil/oc/client/renderer/block/BlockRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package li.cil.oc.client.renderer.block
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler
import li.cil.oc.Settings
import li.cil.oc.client.renderer.tileentity.RobotRenderer
import li.cil.oc.common.block._
import li.cil.oc.common.tileentity
import li.cil.oc.common
import li.cil.oc.util.RenderState
import net.minecraft.block.Block
import net.minecraft.client.renderer.RenderBlocks
Expand All @@ -25,49 +24,49 @@ object BlockRenderer extends ISimpleBlockRenderingHandler {
val renderer = patchedRenderer(realRenderer, block)
GL11.glPushMatrix()
block match {
case _: Assembler =>
case _: common.block.Assembler =>
GL11.glTranslatef(-0.5f, -0.5f, -0.5f)
Tessellator.instance.startDrawingQuads()
Assembler.render(block, metadata, renderer)
Tessellator.instance.draw()

RenderState.checkError(getClass.getName + ".renderInventoryBlock: assembler")
case _: Cable =>
case _: common.block.Cable =>
GL11.glScalef(1.6f, 1.6f, 1.6f)
GL11.glTranslatef(-0.5f, -0.5f, -0.5f)
Tessellator.instance.startDrawingQuads()
Cable.render(block, metadata, renderer)
Tessellator.instance.draw()

RenderState.checkError(getClass.getName + ".renderInventoryBlock: cable")
case _: Hologram =>
case _: common.block.Hologram =>
GL11.glTranslatef(-0.5f, -0.5f, -0.5f)
Tessellator.instance.startDrawingQuads()
Hologram.render(block, metadata, renderer)
Tessellator.instance.draw()

RenderState.checkError(getClass.getName + ".renderInventoryBlock: hologram")
case _: Printer =>
case _: common.block.Printer =>
GL11.glTranslatef(-0.5f, -0.5f, -0.5f)
Tessellator.instance.startDrawingQuads()
Printer.render(block, metadata, renderer)
Tessellator.instance.draw()

RenderState.checkError(getClass.getName + ".renderInventoryBlock: printer")
case _@(_: RobotProxy | _: RobotAfterimage) =>
case _@(_: common.block.RobotProxy | _: common.block.RobotAfterimage) =>
GL11.glScalef(1.5f, 1.5f, 1.5f)
GL11.glTranslatef(-0.5f, -0.4f, -0.5f)
RobotRenderer.renderChassis()

RenderState.checkError(getClass.getName + ".renderInventoryBlock: robot")
case _: NetSplitter =>
case _: common.block.NetSplitter =>
GL11.glTranslatef(-0.5f, -0.5f, -0.5f)
Tessellator.instance.startDrawingQuads()
NetSplitter.render(block, metadata, renderer)
Tessellator.instance.draw()

RenderState.checkError(getClass.getName + ".renderInventoryBlock: splitter")
case _: Transposer =>
case _: common.block.Transposer =>
GL11.glTranslatef(-0.5f, -0.5f, -0.5f)
Tessellator.instance.startDrawingQuads()
Transposer.render(block, metadata, renderer)
Expand All @@ -76,7 +75,7 @@ object BlockRenderer extends ISimpleBlockRenderingHandler {
RenderState.checkError(getClass.getName + ".renderInventoryBlock: transposer")
case _ =>
block match {
case simple: SimpleBlock =>
case simple: common.block.SimpleBlock =>
simple.setBlockBoundsForItemRender(metadata)
simple.preItemRender(metadata)
case _ => block.setBlockBoundsForItemRender()
Expand Down Expand Up @@ -104,55 +103,55 @@ object BlockRenderer extends ISimpleBlockRenderingHandler {

val renderer = patchedRenderer(realRenderer, block)
world.getTileEntity(x, y, z) match {
case assembler: tileentity.Assembler =>
case assembler: common.tileentity.Assembler =>
Assembler.render(assembler.block, assembler.getBlockMetadata, x, y, z, renderer)

RenderState.checkError(getClass.getName + ".renderWorldBlock: assembler")

true
case _: tileentity.Cable =>
case _: common.tileentity.Cable =>
Cable.render(world, x, y, z, block, renderer)

RenderState.checkError(getClass.getName + ".renderWorldBlock: cable")

true
case hologram: tileentity.Hologram =>
case hologram: common.tileentity.Hologram =>
Hologram.render(hologram.block, hologram.getBlockMetadata, x, y, z, renderer)

RenderState.checkError(getClass.getName + ".renderWorldBlock: hologram")

true
case keyboard: tileentity.Keyboard =>
case keyboard: common.tileentity.Keyboard =>
val result = Keyboard.render(keyboard, x, y, z, block, renderer)

RenderState.checkError(getClass.getName + ".renderWorldBlock: keyboard")

result
case print: tileentity.Print =>
case print: common.tileentity.Print =>
Print.render(print.data, print.state, print.facing, x, y, z, block, renderer)

RenderState.checkError(getClass.getName + ".renderWorldBlock: print")

true
case _: tileentity.Printer =>
case _: common.tileentity.Printer =>
Printer.render(block, x, y, z, renderer)

RenderState.checkError(getClass.getName + ".renderWorldBlock: printer")

true
case rack: tileentity.Rack =>
Rack.render(rack, x, y, z, block, renderer)
case rack: common.tileentity.Rack =>
Rack.render(rack, x, y, z, block.asInstanceOf[common.block.Rack], renderer)

RenderState.checkError(getClass.getName + ".renderWorldBlock: rack")

true
case splitter: tileentity.NetSplitter =>
case splitter: common.tileentity.NetSplitter =>
NetSplitter.render(ForgeDirection.VALID_DIRECTIONS.map(splitter.isSideOpen), block, x, y, z, renderer)

RenderState.checkError(getClass.getName + ".renderWorldBlock: splitter")

true
case _: tileentity.Transposer =>
case _: common.tileentity.Transposer =>
Transposer.render(block, x, y, z, renderer)

RenderState.checkError(getClass.getName + ".renderWorldBlock: transposer")
Expand All @@ -168,11 +167,11 @@ object BlockRenderer extends ISimpleBlockRenderingHandler {
}

private def needsFlipping(block: Block) =
block.isInstanceOf[Hologram] ||
block.isInstanceOf[Printer] ||
block.isInstanceOf[Print] ||
block.isInstanceOf[NetSplitter] ||
block.isInstanceOf[Transposer]
block.isInstanceOf[common.block.Hologram] ||
block.isInstanceOf[common.block.Printer] ||
block.isInstanceOf[common.block.Print] ||
block.isInstanceOf[common.block.NetSplitter] ||
block.isInstanceOf[common.block.Transposer]

// The texture flip this works around only seems to occur for blocks with custom block renderers?
def patchedRenderer(renderer: RenderBlocks, block: Block) =
Expand Down
13 changes: 8 additions & 5 deletions src/main/scala/li/cil/oc/client/renderer/block/Rack.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package li.cil.oc.client.renderer.block

import li.cil.oc.api.event.RackMountableRenderEvent
import li.cil.oc.client.Textures
import li.cil.oc.common.tileentity
import net.minecraft.block.Block
import li.cil.oc.common
import net.minecraft.client.renderer.RenderBlocks
import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.common.util.ForgeDirection

object Rack {
def render(rack: tileentity.Rack, x: Int, y: Int, z: Int, block: Block, renderer: RenderBlocks): Unit = {
def render(rack: common.tileentity.Rack, x: Int, y: Int, z: Int, block: common.block.Rack, renderer: RenderBlocks): Unit = {
val previousRenderAllFaces = renderer.renderAllFaces
val u1 = 1 / 16f
val u2 = 15 / 16f
Expand Down Expand Up @@ -40,10 +39,14 @@ object Rack {
renderer.setRenderBounds(lx + u1, v2 - (i + 1) * fs, u1, hx - u1, v2 - i * fs, hz)
case _ =>
}

val event = new RackMountableRenderEvent.Block(rack, i, rack.lastData(i), side, renderer)
MinecraftForge.EVENT_BUS.post(event)
renderer.renderStandardBlock(block, x, y, z)
renderer.clearOverrideBlockTexture()
if (!event.isCanceled) {
block.frontOverride = event.getFrontTextureOverride
renderer.renderStandardBlock(block, x, y, z)
block.frontOverride = null
}
}
}
else {
Expand Down
19 changes: 15 additions & 4 deletions src/main/scala/li/cil/oc/common/block/Rack.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import li.cil.oc.common.GuiType
import li.cil.oc.common.tileentity
import net.minecraft.client.renderer.texture.IIconRegister
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.util.IIcon
import net.minecraft.world.IBlockAccess
import net.minecraft.world.World
import net.minecraftforge.common.util.ForgeDirection
Expand All @@ -17,15 +18,25 @@ class Rack extends RedstoneAware with traits.SpecialBlock with traits.PowerAccep
override protected def customTextures = Array(
None,
None,
Some("ServerRackSide"),
Some("ServerRackFront"),
Some("ServerRackSide"),
Some("ServerRackSide")
Some("RackSide"),
Some("RackFront"),
Some("RackSide"),
Some("RackSide")
)

var frontOverride: IIcon = _

override def registerBlockIcons(iconRegister: IIconRegister) = {
super.registerBlockIcons(iconRegister)
System.arraycopy(icons, 0, Textures.Rack.icons, 0, icons.length)
Textures.Rack.server = iconRegister.registerIcon(Settings.resourceDomain + ":" + "ServerFront")
Textures.Rack.terminal = iconRegister.registerIcon(Settings.resourceDomain + ":" + "TerminalServerFront")
}

@SideOnly(Side.CLIENT)
override def getIcon(world: IBlockAccess, x: Int, y: Int, z: Int, globalSide: ForgeDirection, localSide: ForgeDirection): IIcon = {
if (localSide == ForgeDirection.SOUTH && frontOverride != null) frontOverride
else super.getIcon(world, x, y, z, globalSide, localSide)
}

@SideOnly(Side.CLIENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ class TerminalServer(val rack: tileentity.Rack, val slot: Int) extends Environme
var range = Settings.get.maxWirelessRange
val keys = mutable.ListBuffer.empty[String]

def address = rack.getMountableData(slot).getString(Settings.namespace + "terminalAddress")
def address = rack.getMountableData(slot).getString("terminalAddress")

def sidedKeys = {
if (rack.isServer) keys
else rack.getMountableData(slot).getTagList(Settings.namespace + "keys", NBT.TAG_STRING).map((tag: NBTTagString) => tag.func_150285_a_())
else rack.getMountableData(slot).getTagList("keys", NBT.TAG_STRING).map((tag: NBTTagString) => tag.func_150285_a_())
}

// ----------------------------------------------------------------------- //
Expand Down Expand Up @@ -109,8 +109,8 @@ class TerminalServer(val rack: tileentity.Rack, val slot: Int) extends Environme
if (node.address == null) api.Network.joinNewNetwork(node)

val nbt = new NBTTagCompound()
nbt.setNewTagList(Settings.namespace + "keys", keys)
nbt.setString(Settings.namespace + "terminalAddress", node.address)
nbt.setNewTagList("keys", keys)
nbt.setString("terminalAddress", node.address)
nbt
}

Expand Down
Loading

0 comments on commit f579524

Please sign in to comment.