Fixed direct redstone wire connection

Matched CCC updates
Expanded micro occlusion to java parts
This commit is contained in:
Chicken Bones committed 2013-06-28 05:05:59 +10:00
1 parent 18c1b79361
commit 5594e269a5
13 files changed
+144 -126

No files matched your search

@@ -85,10 +85,9 @@ import CommonMicroblock._
if(olm != null)
lightMatrix = olm.lightMatrix
RenderUtils.renderBlock(c, sideMask, pos, lightMatrix,
new IFaceRenderer()
RenderUtils.renderBlock(c, sideMask, new IFaceRenderer()
{
def renderFace(face:Array[Vertex5], side:Int, pos:Vector3, lightMatrix:LightMatrix) =
def renderFace(face:Array[Vertex5], side:Int) =
mat.renderMicroFace(face, side, pos, lightMatrix, MicroblockClient.this)
})
}
@@ -3,7 +3,7 @@ package codechicken.microblock
import codechicken.core.vec.Cuboid6
import codechicken.core.vec.Scale
import codechicken.core.vec.Vector3
import codechicken.core.raytracer.SelectionBox
import Vector3._
object CornerPlacement extends PlacementProperties
{
@@ -23,13 +23,12 @@ object CornerMicroClass extends MicroblockClass
val rx = if((s&4) != 0) -1 else 1
val ry = if((s&1) != 0) -1 else 1
val rz = if((s&2) != 0) -1 else 1
val transform = new Scale(new Vector3(rx, ry, rz)).at(Vector3.center)
val transform = new Scale(new Vector3(rx, ry, rz)).at(center)
for(t <- 1 until 8)
{
val d = t/8D
aBounds(t<<4|s) = new SelectionBox(new Cuboid6(0, 0, 0, d, d, d))
.transform(transform).bound
aBounds(t<<4|s) = new Cuboid6(0, 0, 0, d, d, d).transform(transform)
}
}
+6 -7
View File
@@ -3,10 +3,11 @@ package codechicken.microblock
import codechicken.core.vec.Cuboid6
import codechicken.core.vec.Scale
import codechicken.core.vec.Vector3
import codechicken.core.raytracer.SelectionBox
import codechicken.core.vec.TransformationList
import codechicken.core.vec.AxisCycle
import codechicken.core.vec.Rotation
import Vector3._
import Rotation._
import codechicken.multipart.TMultiPart
import codechicken.multipart.TNormalOcclusion
import codechicken.multipart.JPartialOcclusion
@@ -74,13 +75,12 @@ object EdgeMicroClass extends MicroblockClass
{
val rx = if((s&2) != 0) -1 else 1
val rz = if((s&1) != 0) -1 else 1
val transform = new TransformationList(new Scale(new Vector3(rx, 1, rz)), AxisCycle.cycles(s>>2)).at(Vector3.center)
val transform = new TransformationList(new Scale(new Vector3(rx, 1, rz)), AxisCycle.cycles(s>>2)).at(center)
for(t <- 1 until 8)
{
val d = t/8D
aBounds(t<<4|s) = new SelectionBox(new Cuboid6(0, 0, 0, d, 1, d))
.transform(transform).bound
aBounds(t<<4|s) = new Cuboid6(0, 0, 0, d, 1, d).transform(transform)
}
}
@@ -134,13 +134,12 @@ object PostMicroClass
for(s <- 0 until 3)
{
val transform = Rotation.sideRotations(s<<1).at(Vector3.center)
val transform = sideRotations(s<<1).at(center)
for(t <- 2 until 8 by 2)
{
val d1 = 0.5-t/16D
val d2 = 0.5+t/16D
aBounds(t<<4|s) = new SelectionBox(new Cuboid6(d1, 0, d1, d2, 1, d2))
.transform(transform).bound
aBounds(t<<4|s) = new Cuboid6(d1, 0, d1, d2, 1, d2).transform(transform)
}
}
+4 -4
View File
@@ -9,7 +9,6 @@ import net.minecraft.entity.player.EntityPlayer
import codechicken.multipart.TCuboidPart
import codechicken.multipart.TFacePart
import codechicken.core.vec.Vector3
import codechicken.core.raytracer.SelectionBox
import codechicken.core.vec.Rotation
import codechicken.multipart.PartMap
import cpw.mods.fml.relauncher.SideOnly
@@ -26,6 +25,8 @@ import scala.collection.immutable.Vector
import scala.collection.mutable.ListBuffer
import codechicken.multipart.BlockMultipart
import codechicken.core.lighting.LazyLightMatrix
import Rotation._
import Vector3._
object FacePlacement extends PlacementProperties
{
@@ -46,12 +47,11 @@ object FaceMicroClass extends MicroblockClass
for(s <- 0 until 6)
{
val transform = Rotation.sideRotations(s).at(Vector3.center)
val transform = sideRotations(s).at(center)
for(t <- 1 until 8)
{
val d = t/8D
aBounds(t<<4|s) = new SelectionBox(new Cuboid6(0, 0, 0, 1, d, 1))
.transform(transform).bound
aBounds(t<<4|s) = new Cuboid6(0, 0, 0, 1, d, 1).transform(transform)
}
}
+10 -10
View File
@@ -6,7 +6,6 @@ import net.minecraft.util.MovingObjectPosition
import codechicken.multipart.TFacePart
import codechicken.core.vec.BlockCoord
import codechicken.core.vec.Cuboid6
import codechicken.core.raytracer.SelectionBox
import codechicken.core.vec.Rotation
import codechicken.core.vec.Vector3
import codechicken.multipart.TNormalOcclusion
@@ -17,6 +16,8 @@ import codechicken.core.render.IconTransformation
import codechicken.core.render.RenderUtils
import codechicken.core.render.CCRenderState
import scala.collection.JavaConversions._
import Rotation._
import Vector3._
object HollowPlacement extends PlacementProperties
{
@@ -37,20 +38,19 @@ object HollowMicroClass extends MicroblockClass
var occBounds:Array[Cuboid6] = new Array(256)
for(s <- 0 until 6)
{
val transform = Rotation.sideRotations(s).at(Vector3.center)
val transform = sideRotations(s).at(center)
for(t <- 1 until 8)
{
val d = t/8D
val w1 = 1/8D
val w2 = 3/16D
pBoxes(t<<4|s) = Seq(
new SelectionBox(new Cuboid6(0, 0, 0, w1, d, 1)),
new SelectionBox(new Cuboid6(1-w1, 0, 0, 1, d, 1)),
new SelectionBox(new Cuboid6(w1, 0, 0, 1-w1, d, w1)),
new SelectionBox(new Cuboid6(w1, 0, 1-w1, 1-w1, d, 1)))
.map(_.transform(transform).bound)
occBounds(t<<4|s) = new SelectionBox(new Cuboid6(1/8D, 0, 1/8D, 7/8D, d, 7/8D))
.transform(transform).bound
new Cuboid6(0, 0, 0, w1, d, 1),
new Cuboid6(1-w1, 0, 0, 1, d, 1),
new Cuboid6(w1, 0, 0, 1-w1, d, w1),
new Cuboid6(w1, 0, 1-w1, 1-w1, d, 1))
.map(_.transform(transform))
occBounds(t<<4|s) = new Cuboid6(1/8D, 0, 1/8D, 7/8D, d, 7/8D).transform(transform)
}
}
@@ -91,7 +91,7 @@ class HollowMicroblockClient(shape$:Byte = 0, material$:Int = 0) extends HollowM
val icont = new IconTransformation(renderBlocks.overrideBlockTexture)
renderHollow(Vector3.fromTileEntity(tile), null, null, getBounds, 0, false,
(pos:Vector3, olm:LazyLightMatrix, mat:IMicroMaterial, c:Cuboid6, sideMask:Int)=>
RenderUtils.renderBlock(c, sideMask, pos, null, -1, icont))
RenderUtils.renderBlock(c, sideMask, pos.translation(), icont, null))
}
override def render(pos:Vector3, olm:LazyLightMatrix, mat:IMicroMaterial, c:Cuboid6, sideMask:Int)
+3 -2
View File
@@ -4,6 +4,7 @@ import codechicken.core.vec.Vector3
import org.lwjgl.opengl.GL11
import codechicken.core.vec.BlockCoord
import codechicken.core.vec.Rotation
import Rotation._
trait PlacementGrid
{
@@ -16,8 +17,8 @@ trait PlacementGrid
val pos = new BlockCoord(hit)
GL11.glPushMatrix()
GL11.glTranslated(pos.x+0.5, pos.y+0.5, pos.z+0.5)
Rotation.sideRotations(side).glApply()
val rhit = new Vector3(pos.x+0.5, pos.y+0.5, pos.z+0.5).subtract(hit).rotate(Rotation.sideQuatsR(side^1))
sideRotations(side).glApply()
val rhit = new Vector3(pos.x+0.5, pos.y+0.5, pos.z+0.5).subtract(hit).apply(sideRotations(side^1).inverse)
GL11.glTranslated(0, rhit.y-0.002, 0)
}
}
+98 -84
View File
@@ -9,69 +9,22 @@ import codechicken.multipart.PartMap._
object MicroOcclusion
{
def shrink(renderBounds:Cuboid6, b:Cuboid6, side:Int)
def shrink(renderBounds:Cuboid6, b:Cuboid6, side:Int) = side match
{
side match
{
case -1 =>
case 0 => if(renderBounds.min.y < b.max.y)renderBounds.min.y = b.max.y
case 1 => if(renderBounds.max.y > b.min.y)renderBounds.max.y = b.min.y
case 2 => if(renderBounds.min.z < b.max.z)renderBounds.min.z = b.max.z
case 3 => if(renderBounds.max.z > b.min.z)renderBounds.max.z = b.min.z
case 4 => if(renderBounds.min.x < b.max.x)renderBounds.min.x = b.max.x
case 5 => if(renderBounds.max.x > b.min.x)renderBounds.max.x = b.min.x
}
}
}
trait TMicroOcclusionClient extends TMicroOcclusion
{
var renderBounds:Cuboid6 = _
var renderMask:Int = _
def isTransparent():Boolean
override def onPartChanged()
{
super.onPartChanged()
recalcBounds()
case -1 =>
case 0 => if(renderBounds.min.y < b.max.y)renderBounds.min.y = b.max.y
case 1 => if(renderBounds.max.y > b.min.y)renderBounds.max.y = b.min.y
case 2 => if(renderBounds.min.z < b.max.z)renderBounds.min.z = b.max.z
case 3 => if(renderBounds.max.z > b.min.z)renderBounds.max.z = b.min.z
case 4 => if(renderBounds.min.x < b.max.x)renderBounds.min.x = b.max.x
case 5 => if(renderBounds.max.x > b.min.x)renderBounds.max.x = b.min.x
}
def recalcBounds()
def shrinkFrom(p:JMicroShrinkRender, other:JMicroShrinkRender, renderBounds:Cuboid6):Int =
{
renderBounds = getBounds.copy
if(getSlot < 6)
shrink(6)
else if(getSlot < 15)
shrink(15)
else
shrink(27)
}
def thisShrinks(other:TMicroOcclusionClient):Boolean =
{
val shape1 = shapePriority
val shape2 = other.shapePriority
if(shape1 != shape2)return shape1 > shape2
if(getSlot < 6)//transparency takes precedence for covers
if(shrinkTest(p, other))
{
if(isTransparent != other.isTransparent) return isTransparent
if(getSize != other.getSize) return getSize < other.getSize
}
else
{
if(getSize != other.getSize) return getSize < other.getSize
if(isTransparent != other.isTransparent) return isTransparent
}
return getSlot < other.getSlot
}
def shrinkThis(other:TMicroOcclusionClient)
{
if(thisShrinks(other))
{
MicroOcclusion.shrink(renderBounds, other.getBounds, shrinkSide(getSlot, other.getSlot))
shrink(renderBounds, other.getBounds, shrinkSide(p.getSlot, other.getSlot))
}
else if(other.getSlot < 6 && !other.isTransparent)//other gets full face, we didn't shrink, flag rendermask
{
@@ -83,8 +36,24 @@ trait TMicroOcclusionClient extends TMicroOcclusion
case 4 => renderBounds.min.x <= 0
case 5 => renderBounds.max.x >= 1
})
renderMask|=1<<other.getSlot
return 1<<other.getSlot
}
return 0
}
def shrink(p:JMicroShrinkRender, renderBounds:Cuboid6, m:Int):Int =
{
var renderMask = 0
val part = p.asInstanceOf[TMultiPart]
val tile = part.tile
for(i <- 0 until m)
if(i != p.getSlot)
tile.partMap(i) match {
case other:JMicroShrinkRender =>
renderMask |= shrinkFrom(p, other, renderBounds)
case _ =>
}
return renderMask
}
def shrinkSide(s1:Int, s2:Int):Int = {
@@ -146,23 +115,76 @@ trait TMicroOcclusionClient extends TMicroOcclusion
throw new IllegalArgumentException("Switch Falloff")
}
def shrink(m:Int)
def recalcBounds(p:JMicroShrinkRender, renderBounds:Cuboid6) =
{
renderMask = 0
for(i <- 0 until m)
{
if(i != getSlot)
{
val part = tile.partMap(i)
if(part.isInstanceOf[TMicroOcclusionClient])
shrinkThis(part.asInstanceOf[TMicroOcclusionClient])
}
}
if(p.getSlot < 6)
shrink(p, renderBounds, 6)
else if(p.getSlot < 15)
shrink(p, renderBounds, 15)
else
shrink(p, renderBounds, 27)
}
def shapePriority(slot:Int):Int =
if(slot < 6)
return 2
else if(slot < 15)
return 1
else
return 0
def shrinkTest(a:JMicroShrinkRender, b:JMicroShrinkRender):Boolean =
{
if(a.getPriorityClass != b.getPriorityClass) return a.getPriorityClass < b.getPriorityClass
val shape1 = shapePriority(a.getSlot)
val shape2 = shapePriority(b.getSlot)
if(shape1 != shape2) return shape1 < shape2
if(a.getSlot < 6)//transparency takes precedence for covers
{
if(a.isTransparent != b.isTransparent) return a.isTransparent
if(a.getSize != b.getSize) return a.getSize < b.getSize
}
else
{
if(a.getSize != b.getSize) return a.getSize < b.getSize
if(a.isTransparent != b.isTransparent) return a.isTransparent
}
return a.getSlot < b.getSlot
}
}
trait JMicroShrinkRender
{
def getPriorityClass():Int
def getSlot():Int
def getSize():Int
def isTransparent():Boolean
def getBounds():Cuboid6
}
trait TMicroOcclusionClient extends TMicroOcclusion with JMicroShrinkRender
{
import MicroOcclusion._
var renderBounds:Cuboid6 = _
var renderMask:Int = _
override def onPartChanged()
{
super.onPartChanged()
renderBounds = getBounds.copy
renderMask = recalcBounds(this, renderBounds)
}
override def getPriorityClass = 0
}
trait TMicroOcclusion extends TMultiPart
{
import MicroOcclusion._
def getSlot():Int
def getSize():Int
def getMaterial():Int
@@ -177,12 +199,12 @@ trait TMicroOcclusion extends TMultiPart
return true
val mpart = npart.asInstanceOf[TMicroOcclusion]
val shape1 = shapePriority
val shape2 = mpart.shapePriority
val shape1 = shapePriority(getSlot)
val shape2 = shapePriority(mpart.getSlot)
if(mpart.getSize + getSize > 8)//intersecting if opposite
{
if(shape1 == 0 && shape2 == 0)
if(shape1 == 2 && shape2 == 2)
if(mpart.getSlot == (getSlot^1))
return false
@@ -195,15 +217,15 @@ trait TMicroOcclusion extends TMultiPart
return false
}
if(shape1 == 2 && shape2 == 1)
if(shape1 == 0 && shape2 == 1)
if(!edgeCornerOcclusionTest(this, mpart))
return false
if(shape1 == 1 && shape2 == 2)
if(shape1 == 1 && shape2 == 0)
if(!edgeCornerOcclusionTest(mpart, this))
return false
if(shape1 == 2 && shape2 == 2)
if(shape1 == 0 && shape2 == 0)
{
val e1 = getSlot-15
val e2 = mpart.getSlot-15
@@ -220,12 +242,4 @@ trait TMicroOcclusion extends TMultiPart
{
((corner.getSlot-7)&edgeAxisMask(edge.getSlot-15)) == unpackEdgeBits(edge.getSlot-15)
}
def shapePriority():Int =
if(getSlot < 6)
return 0
else if(getSlot < 15)
return 1
else
return 2
}
+12 -7
View File
@@ -59,17 +59,17 @@ object RedstoneInteractions
val vanillaSideMap = Array(-2, -1, 0, 2, 3, 1)
val sideVanillaMap = Array(1, 2, 5, 3, 4)
def getWeakPowerTo(p:TMultiPart, side:Int):Int =
def getPowerTo(p:TMultiPart, side:Int):Int =
{
val tile = p.tile
return getWeakPowerTo(tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord, side,
return getPowerTo(tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord, side,
tile.asInstanceOf[IRedstoneTile].openConnections(side)&connectionMask(p, side))
}
def getWeakPowerTo(world:World, x:Int, y:Int, z:Int, side:Int, mask:Int):Int =
getWeakPower(world, x+offsetsXForSide(side), y+offsetsYForSide(side), z+offsetsZForSide(side), side^1, mask)
def getPowerTo(world:World, x:Int, y:Int, z:Int, side:Int, mask:Int):Int =
getPower(world, x+offsetsXForSide(side), y+offsetsYForSide(side), z+offsetsZForSide(side), side^1, mask)
def getWeakPower(world:World, x:Int, y:Int, z:Int, side:Int, mask:Int):Int =
def getPower(world:World, x:Int, y:Int, z:Int, side:Int, mask:Int):Int =
{
val tile = world.getBlockTileEntity(x, y, z)
if(tile.isInstanceOf[IRedstoneConnector])
@@ -84,7 +84,12 @@ object RedstoneInteractions
val vmask = vanillaConnectionMask(block, world, x, y, z, side, true)
if((vmask&mask) > 0)
return world.getIndirectPowerLevelTo(x, y, z, side^1)
{
var m = world.getIndirectPowerLevelTo(x, y, z, side^1)
if(m < 15 && block == Block.redstoneWire)
m = Math.max(m, world.getBlockMetadata(x, y, z))//painful vanilla kludge
return m
}
return 0
}
@@ -98,7 +103,7 @@ object RedstoneInteractions
if(p.isInstanceOf[IRedstonePart] && p.asInstanceOf[IRedstonePart].canConnectRedstone(side))
{
if(p.isInstanceOf[IFaceRedstonePart])
return rotationTo(side, p.asInstanceOf[IFaceRedstonePart].getFace)
return 1<<rotationTo(side&6, p.asInstanceOf[IFaceRedstonePart].getFace)
return 0x1F
}
return 0
+2 -1
View File
@@ -9,6 +9,7 @@ import codechicken.core.vec.Vector3
import codechicken.core.render.IconTransformation
import scala.collection.JavaConversions._
import java.lang.Iterable
import codechicken.core.vec.Translation
abstract class JCuboidPart extends TCuboidPart
@@ -23,6 +24,6 @@ trait TCuboidPart extends TMultiPart
override def drawBreaking(renderBlocks:RenderBlocks)
{
CCRenderState.reset()
RenderUtils.renderBlock(getBounds, 0, Vector3.fromTileEntity(tile), null, -1, new IconTransformation(renderBlocks.overrideBlockTexture))
RenderUtils.renderBlock(getBounds, 0, new Translation(x, y, z), new IconTransformation(renderBlocks.overrideBlockTexture), null)
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
package codechicken.multipart
trait TEdgePart extends TMultiPart
trait TEdgePart extends TSlottedPart
{
def conductsRedstone = false
}
+1 -1
View File
@@ -1,6 +1,6 @@
package codechicken.multipart
trait TFacePart extends TMultiPart
trait TFacePart extends TSlottedPart
{
def solid(side:Int):Boolean = true
def redstoneConductionMap = 0
+1 -1
View File
@@ -4,7 +4,7 @@ package codechicken.multipart
* Interface for parts that fill a slot based configuration as defined in PartMap.
* If this is implemented, calling partMap(slot) on the host tile will return this part if the corresponding bit in the slotMask is set
*/
trait TSlottedPart
trait TSlottedPart extends TMultiPart
{
/**
* a bitmask of slots that this part fills. slot x is 1<<x
@@ -126,7 +126,7 @@ public class RedstoneTorchPart extends TorchPart implements IRedstonePart, IRand
public boolean isBeingPowered()
{
int side = metaSideMap[meta&7];
return RedstoneInteractions.getWeakPowerTo(this, side) > 0;
return RedstoneInteractions.getPowerTo(this, side) > 0;
}
@Override