Changed micro material rendering to take a part based interface instead of an actual part to allow other non-microblock things to use the renderer.

Added IMaskedRedstoneConnect for redstone parts with special connection modes
Added null check to TMultiPart.world().
Fixed hollow microblocks not rendering hollow on placement
Fixed a problem with packet send order on part remove.
This commit is contained in:
Chicken Bones committed 2013-08-15 21:31:15 +10:00
1 parent 5cd7f495d5
commit f9eb162770
10 files changed
+74 -37

No files matched your search

@@ -48,9 +48,9 @@ class BlockMicroMaterial(val block:Block, val meta:Int = 0) extends IMicroMateri
def getRenderPass = if(block.canRenderInPass(1)) 1 else 0
def renderMicroFace(verts:Array[Vertex5], side:Int, pos:Vector3, lightMatrix:LightMatrix, part:Microblock)
def renderMicroFace(verts:Array[Vertex5], side:Int, pos:Vector3, lightMatrix:LightMatrix, part:IMicroMaterialRender)
{
renderMicroFace(verts, side, pos, lightMatrix, getColour(part.tile), icont)
renderMicroFace(verts, side, pos, lightMatrix, getColour(part), icont)
}
def renderMicroFace(verts:Array[Vertex5], side:Int, pos:Vector3, lightMatrix:LightMatrix, colour:Int, uvt:IUVTransformation)
@@ -84,11 +84,11 @@ class BlockMicroMaterial(val block:Block, val meta:Int = 0) extends IMicroMateri
}
}
def getColour(tile:TileEntity) =
if(tile == null)
def getColour(part:IMicroMaterialRender) =
if(part.world == null)
block.getBlockColor<<8|0xFF
else
block.colorMultiplier(tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord)<<8|0xFF
block.colorMultiplier(part.world, part.x, part.y, part.z)<<8|0xFF
@SideOnly(Side.CLIENT)
def getBreakingIcon(side:Int) = block.getIcon(side, meta)
+22 -16
View File
@@ -63,7 +63,23 @@ object CommonMicroblock
}
}
trait MicroblockClient extends Microblock with TIconHitEffects
object JMicroblockClient
{
def renderCuboid(pos:Vector3, olm:LazyLightMatrix, mat:IMicroMaterial, c:Cuboid6, sideMask:Int, part:IMicroMaterialRender)
{
var lightMatrix:LightMatrix = null
if(olm != null)
lightMatrix = olm.lightMatrix
RenderUtils.renderBlock(c, sideMask, new IFaceRenderer()
{
def renderFace(face:Array[Vertex5], side:Int) =
mat.renderMicroFace(face, side, pos, lightMatrix, part)
})
}
}
trait MicroblockClient extends Microblock with TIconHitEffects with IMicroMaterialRender
{
import CommonMicroblock._
@@ -75,23 +91,13 @@ import CommonMicroblock._
return Block.stone.getIcon(0, 0)
}
def render(pos:Vector3, olm:LazyLightMatrix, mat:IMicroMaterial, c:Cuboid6, sideMask:Int)
{
def render(pos:Vector3, olm:LazyLightMatrix, mat:IMicroMaterial, c:Cuboid6, sideMask:Int) =
renderCuboid(pos, olm, mat, c, sideMask)
}
def renderCuboid(pos:Vector3, olm:LazyLightMatrix, mat:IMicroMaterial, c:Cuboid6, sideMask:Int)
{
var lightMatrix:LightMatrix = null
if(olm != null)
lightMatrix = olm.lightMatrix
RenderUtils.renderBlock(c, sideMask, new IFaceRenderer()
{
def renderFace(face:Array[Vertex5], side:Int) =
mat.renderMicroFace(face, side, pos, lightMatrix, MicroblockClient.this)
})
}
def renderCuboid(pos:Vector3, olm:LazyLightMatrix, mat:IMicroMaterial, c:Cuboid6, sideMask:Int) =
JMicroblockClient.renderCuboid(pos, olm, mat, c, sideMask, this)
def getRenderBounds = getBounds
}
abstract class Microblock(var shape:Byte = 0, var material:Int = 0) extends TCuboidPart
@@ -31,25 +31,25 @@ class GrassMicroMaterial extends BlockMicroMaterial(Block.grass, 0)
sideIconT = new IconTransformation(BlockGrass.getIconSideOverlay)
}
override def renderMicroFace(verts:Array[Vertex5], side:Int, pos:Vector3, lightMatrix:LightMatrix, part:Microblock)
override def renderMicroFace(verts:Array[Vertex5], side:Int, pos:Vector3, lightMatrix:LightMatrix, part:IMicroMaterialRender)
{
val colour = getColour(part.tile)
val colour = getColour(part)
if(side%6 == 1)
renderMicroFace(verts, side, pos, lightMatrix, colour, icont)
else
renderMicroFace(verts, side, pos, lightMatrix, -1, icont)
if(side%6 > 1 && side%6 < 6)
renderMicroFace(verts, side, pos, lightMatrix, colour, new TopIconTransformation(part.getBounds.max.y, sideIconT))
renderMicroFace(verts, side, pos, lightMatrix, colour, new TopIconTransformation(part.getRenderBounds.max.y, sideIconT))
}
}
class TopMicroMaterial($block:Block, $meta:Int = 0) extends BlockMicroMaterial($block, $meta)
{
override def renderMicroFace(verts:Array[Vertex5], side:Int, pos:Vector3, lightMatrix:LightMatrix, part:Microblock)
override def renderMicroFace(verts:Array[Vertex5], side:Int, pos:Vector3, lightMatrix:LightMatrix, part:IMicroMaterialRender)
{
if(side%6 > 1 && side%6 < 6)
renderMicroFace(verts, side, pos, lightMatrix, getColour(part.tile), new TopIconTransformation(part.getBounds.max.y, icont))
renderMicroFace(verts, side, pos, lightMatrix, getColour(part), new TopIconTransformation(part.getRenderBounds.max.y, icont))
else
super.renderMicroFace(verts, side, pos, lightMatrix, part)
}
+3 -3
View File
@@ -84,9 +84,9 @@ class HollowMicroblockClient(shape$:Byte = 0, material$:Int = 0) extends HollowM
def this(size:Int, shape:Int, material:Int) = this((size<<4|shape).toByte, material)
override def onPartChanged(part:TMultiPart)
override def recalcBounds()
{
super.onPartChanged(part)
super.recalcBounds()
renderMask = renderMask&0xFF | getHollowSize<<8
}
@@ -216,7 +216,7 @@ class HollowMicroblock(shape$:Byte = 0, material$:Int = 0) extends CommonMicrobl
case null => 8
case _ => tile.partMap(6) match
{
case part:IHollowConnect => part.getSize
case part:IHollowConnect => part.getHollowSize
case _ => 8
}
}
+1 -1
View File
@@ -8,5 +8,5 @@ trait IHollowConnect
/**
* @return The size (width and height) of the connection in pixels. Must be be less than 12 and more than 0
*/
def getSize:Int
def getHollowSize:Int
}
@@ -0,0 +1,19 @@
package codechicken.microblock
import codechicken.lib.vec.Cuboid6
import net.minecraft.world.World
trait IMicroMaterialRender {
/**
* May be null for inventory rendering.
*/
def world():World
def x():Int
def y():Int
def z():Int
/**
* Return the bounds of the part for texture mapping side decals like grass
*/
def getRenderBounds():Cuboid6
}
@@ -30,7 +30,7 @@ object MicroMaterialRegistry
def loadIcons(){}
@SideOnly(Side.CLIENT)
def renderMicroFace(verts:Array[Vertex5], side:Int, pos:Vector3, lightMatrix:LightMatrix, part:Microblock)
def renderMicroFace(verts:Array[Vertex5], side:Int, pos:Vector3, lightMatrix:LightMatrix, part:IMicroMaterialRender)
@SideOnly(Side.CLIENT)
def getRenderPass():Int
+12
View File
@@ -23,6 +23,14 @@ trait IFaceRedstonePart extends IRedstonePart
def getFace():Int
}
/**
* For parts that want to define their own connection masks (like center-center parts)
*/
trait IMaskedRedstonePart extends IRedstonePart
{
def getConnectionMask(side:Int):Int
}
/**
* Internal interface for TileMultipart instances hosting IRedstonePart
*/
@@ -110,6 +118,10 @@ object RedstoneInteractions
return 1<<rotationTo(side&6, fside)
}
else if(p.isInstanceOf[IMaskedRedstonePart])
{
return p.asInstanceOf[IMaskedRedstonePart].getConnectionMask(side)
}
return 0x1F
}
return 0
+1 -1
View File
@@ -30,7 +30,7 @@ abstract class TMultiPart
var tile:TileMultipart = _
def getTile():TileEntity = tile
def world() = tile.worldObj
def world() = if(tile == null) null else tile.worldObj
def x = tile.xCoord
def y = tile.yCoord
def z = tile.zCoord
+5 -5
View File
@@ -241,10 +241,7 @@ class TileMultipart extends TileEntity
private[multipart] def remPart_impl(part:TMultiPart):TileMultipart =
{
val i = remPart_do(part)
if(!worldObj.isRemote)
getWriteStream.writeByte(254).writeByte(i)
remPart_do(part, !worldObj.isRemote)
if(!isInvalid())
{
@@ -259,7 +256,7 @@ class TileMultipart extends TileEntity
return null
}
private def remPart_do(part:TMultiPart):Int =
private def remPart_do(part:TMultiPart, sendPacket:Boolean):Int =
{
val r = partList.indexOf(part)
if(r < 0)
@@ -267,6 +264,9 @@ class TileMultipart extends TileEntity
partList-=part
if(sendPacket)
getWriteStream.writeByte(254).writeByte(r)
partRemoved(part, r)
part.onRemoved()
part.tile = null