From 5594e269a5531629310e44caa7cbafa2b1c77ac0 Mon Sep 17 00:00:00 2001 From: Chicken Bones Date: Fri, 28 Jun 2013 05:05:59 +1000 Subject: [PATCH] Fixed direct redstone wire connection Matched CCC updates Expanded micro occlusion to java parts --- codechicken/microblock/CommonMicroblock.scala | 5 +- codechicken/microblock/CornerMicroblock.scala | 7 +- codechicken/microblock/EdgeMicroblock.scala | 13 +- codechicken/microblock/FaceMicroblock.scala | 8 +- codechicken/microblock/HolloMicroblock.scala | 20 +- codechicken/microblock/PlacementGrids.scala | 5 +- codechicken/microblock/TMicroOcclusion.scala | 182 ++++++++++-------- codechicken/multipart/IRedstonePart.scala | 19 +- codechicken/multipart/TCuboidPart.scala | 3 +- codechicken/multipart/TEdgePart.scala | 2 +- codechicken/multipart/TFacePart.scala | 2 +- codechicken/multipart/TSlottedPart.scala | 2 +- .../minecraft/RedstoneTorchPart.java | 2 +- 13 files changed, 144 insertions(+), 126 deletions(-) diff --git a/codechicken/microblock/CommonMicroblock.scala b/codechicken/microblock/CommonMicroblock.scala index 9b739f7..d5d95b0 100644 --- a/codechicken/microblock/CommonMicroblock.scala +++ b/codechicken/microblock/CommonMicroblock.scala @@ -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) }) } diff --git a/codechicken/microblock/CornerMicroblock.scala b/codechicken/microblock/CornerMicroblock.scala index b124501..9d6957f 100644 --- a/codechicken/microblock/CornerMicroblock.scala +++ b/codechicken/microblock/CornerMicroblock.scala @@ -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) } } diff --git a/codechicken/microblock/EdgeMicroblock.scala b/codechicken/microblock/EdgeMicroblock.scala index a95a015..c84ba7c 100644 --- a/codechicken/microblock/EdgeMicroblock.scala +++ b/codechicken/microblock/EdgeMicroblock.scala @@ -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) } } diff --git a/codechicken/microblock/FaceMicroblock.scala b/codechicken/microblock/FaceMicroblock.scala index 9eee5a1..6b26cf6 100644 --- a/codechicken/microblock/FaceMicroblock.scala +++ b/codechicken/microblock/FaceMicroblock.scala @@ -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) } } diff --git a/codechicken/microblock/HolloMicroblock.scala b/codechicken/microblock/HolloMicroblock.scala index 06f5205..5e535a2 100644 --- a/codechicken/microblock/HolloMicroblock.scala +++ b/codechicken/microblock/HolloMicroblock.scala @@ -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) diff --git a/codechicken/microblock/PlacementGrids.scala b/codechicken/microblock/PlacementGrids.scala index 4bf656b..834b378 100644 --- a/codechicken/microblock/PlacementGrids.scala +++ b/codechicken/microblock/PlacementGrids.scala @@ -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) } } diff --git a/codechicken/microblock/TMicroOcclusion.scala b/codechicken/microblock/TMicroOcclusion.scala index 3b05ea6..d36c398 100644 --- a/codechicken/microblock/TMicroOcclusion.scala +++ b/codechicken/microblock/TMicroOcclusion.scala @@ -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< + 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 } \ No newline at end of file diff --git a/codechicken/multipart/IRedstonePart.scala b/codechicken/multipart/IRedstonePart.scala index 1eab3db..53f08be 100644 --- a/codechicken/multipart/IRedstonePart.scala +++ b/codechicken/multipart/IRedstonePart.scala @@ -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< 0; + return RedstoneInteractions.getPowerTo(this, side) > 0; } @Override