From 734615e78b2988aa176a95823751afbb4b7f31dc Mon Sep 17 00:00:00 2001 From: Chicken-Bones Date: Wed, 1 Apr 2015 23:06:48 +1000 Subject: [PATCH] More cleaning and generalisation of microblock classes --- .../microblock/CommonMicroblock.scala | 12 +++--- .../microblock/CornerMicroblock.scala | 16 +++----- .../microblock/EdgeMicroblock.scala | 41 +++++++------------ .../microblock/FaceMicroblock.scala | 16 ++------ .../microblock/HollowMicroblock.scala | 18 +++----- .../microblock/ItemMicroPart.scala | 3 +- .../microblock/MicroblockClass.scala | 4 +- .../microblock/MicroblockClassRegistry.scala | 2 +- .../microblock/MicroblockPlacement.scala | 6 ++- 9 files changed, 44 insertions(+), 74 deletions(-) diff --git a/src/codechicken/microblock/CommonMicroblock.scala b/src/codechicken/microblock/CommonMicroblock.scala index 5af8c4c..cd27958 100644 --- a/src/codechicken/microblock/CommonMicroblock.scala +++ b/src/codechicken/microblock/CommonMicroblock.scala @@ -96,10 +96,10 @@ trait MicroblockClient extends Microblock with TIconHitEffects with IMicroMateri override def getRenderBounds = getBounds } -abstract class Microblock(var shape:Byte = 0, var material:Int = 0) extends TCuboidPart +abstract class Microblock(var material:Int = 0) extends TCuboidPart { - def this(size:Int, shape:Int, material:Int) = this((size<<4|shape).toByte, material) - + var shape:Byte = 0 + override def getStrength(hit:MovingObjectPosition, player:EntityPlayer) = getIMaterial match { case null => super.getStrength(hit, player) case mat => mat.getStrength(player) @@ -111,6 +111,8 @@ abstract class Microblock(var shape:Byte = 0, var material:Int = 0) extends TCub def getShape = shape&0xF + def setShape(size:Int, slot:Int) = shape = (size<<4|shape).toByte + def getMaterial = material def getIMaterial = MicroMaterialRegistry.getMaterial(material) @@ -190,12 +192,12 @@ trait CommonMicroblockClient extends CommonMicroblock with MicroblockClient with } } -abstract class CommonMicroblock(shape$:Byte = 0, material$:Int = 0) extends Microblock(shape$, material$) with JPartialOcclusion with TMicroOcclusion with TSlottedPart +abstract class CommonMicroblock(material$:Int) extends Microblock(material$) with JPartialOcclusion with TMicroOcclusion with TSlottedPart { def microClass:MicroblockClass def getType = microClass.getName - + def getSlot = getShape def getSlotMask = 1<>1, pmt.material, pmt.world.isRemote) + val part = PostMicroClass.create(pmt.world.isRemote, pmt.material) + part.setShape(pmt.size, pmt.hit.sideHit>>1) if(pmt.doExpand) { val hpart = pmt.htile.partList(ExtendedMOP.getData[(Int, _)](pmt.hit)._1) @@ -86,27 +87,21 @@ object EdgeMicroClass extends MicroblockClass def getName = "mcr_edge" - def create(client:Boolean) = + def create(client:Boolean, material:Int) = if(client) - new EdgeMicroblock with CommonMicroblockClient + new EdgeMicroblock(material) with CommonMicroblockClient else - new EdgeMicroblock - - def create(size:Int, slot:Int, material:Int, client:Boolean) = - if(client) - new EdgeMicroblock(size, slot, material) with CommonMicroblockClient - else - new EdgeMicroblock(size, slot, material) + new EdgeMicroblock(material) def placementProperties = EdgePlacement def getResistanceFactor = 0.5F } -class EdgeMicroblock(shape$:Byte = 0, material$:Int = 0) extends CommonMicroblock(shape$, material$) with TEdgePart +class EdgeMicroblock(material$:Int = 0) extends CommonMicroblock(material$) with TEdgePart { - def this(size:Int, slot:Int, material:Int) = this((size<<4|(slot-15)).toByte, material) - + override def setShape(size: Int, slot: Int) = shape = (size<<4|(slot-15)).toByte + def microClass = EdgeMicroClass def getBounds = EdgeMicroClass.aBounds(shape) @@ -131,19 +126,13 @@ object PostMicroClass def getName = "mcr_post" - def create(client:Boolean) = + def create(client:Boolean, material:Int) = if(client) - new PostMicroblock with PostMicroblockClient + new PostMicroblock(material) with PostMicroblockClient else - new PostMicroblock + new PostMicroblock(material) - def create(size:Int, slot:Int, material:Int, client:Boolean) = - if(client) - new PostMicroblock(size, slot, material) with PostMicroblockClient - else - new PostMicroblock(size, slot, material) - - def register() = MultiPartRegistry.registerParts((_, c:Boolean) => create(c), getName) + def register() = MultiPartRegistry.registerParts((_, c:Boolean) => create(c, 0), getName) def getResistanceFactor = 0.5F } @@ -225,12 +214,10 @@ trait PostMicroblockClient extends PostMicroblock with MicroblockClient } } -class PostMicroblock(shape$:Byte = 0, material$:Int = 0) extends Microblock(shape$, material$) with JPartialOcclusion with TNormalOcclusion +class PostMicroblock(material$:Int = 0) extends Microblock(material$) with JPartialOcclusion with TNormalOcclusion { - def this(size:Int, orient:Int, material:Int) = this((size<<4|orient).toByte, material) - override def getType = PostMicroClass.getName - + def getBounds = PostMicroClass.aBounds(shape) def getOcclusionBoxes = Seq(getBounds) diff --git a/src/codechicken/microblock/FaceMicroblock.scala b/src/codechicken/microblock/FaceMicroblock.scala index 1cc4d20..17fa549 100644 --- a/src/codechicken/microblock/FaceMicroblock.scala +++ b/src/codechicken/microblock/FaceMicroblock.scala @@ -38,17 +38,11 @@ object FaceMicroClass extends MicroblockClass def getName = "mcr_face" - def create(client:Boolean) = + def create(client:Boolean, material:Int) = if(client) - new FaceMicroblock with FaceMicroblockClient + new FaceMicroblock(material) with FaceMicroblockClient else - new FaceMicroblock - - def create(size:Int, slot:Int, material:Int, client:Boolean) = - if(client) - new FaceMicroblock(size, slot, material) with FaceMicroblockClient - else - new FaceMicroblock(size, slot, material) + new FaceMicroblock(material) def placementProperties = FacePlacement @@ -70,10 +64,8 @@ trait FaceMicroblockClient extends CommonMicroblockClient } } -class FaceMicroblock(shape$:Byte = 0, material$:Int = 0) extends CommonMicroblock(shape$, material$) with TFacePart +class FaceMicroblock(material$:Int = 0) extends CommonMicroblock(material$) with TFacePart { - def this(size:Int, shape:Int, material:Int) = this((size<<4|shape).toByte, material) - def microClass = FaceMicroClass def getBounds = FaceMicroClass.aBounds(shape) diff --git a/src/codechicken/microblock/HollowMicroblock.scala b/src/codechicken/microblock/HollowMicroblock.scala index 99dc542..8ec3eb7 100644 --- a/src/codechicken/microblock/HollowMicroblock.scala +++ b/src/codechicken/microblock/HollowMicroblock.scala @@ -54,17 +54,11 @@ object HollowMicroClass extends MicroblockClass def getName = "mcr_hllw" - def create(client: Boolean) = - if (client) - new HollowMicroblock with HollowMicroblockClient + def create(client:Boolean, material:Int) = + if(client) + new HollowMicroblock(material) with HollowMicroblockClient else - new HollowMicroblock - - def create(size: Int, slot: Int, material: Int, client: Boolean) = - if (client) - new HollowMicroblock(size, slot, material) with HollowMicroblockClient - else - new HollowMicroblock(size, slot, material) + new HollowMicroblock(material) def placementProperties = HollowPlacement @@ -178,10 +172,8 @@ trait HollowMicroblockClient extends HollowMicroblock with CommonMicroblockClien } } -class HollowMicroblock(shape$: Byte = 0, material$: Int = 0) extends CommonMicroblock(shape$, material$) with TFacePart with TNormalOcclusion +class HollowMicroblock(material$: Int = 0) extends CommonMicroblock(material$) with TFacePart with TNormalOcclusion { - def this(size: Int, shape: Int, material: Int) = this((size << 4 | shape).toByte, material) - def microClass = HollowMicroClass def getBounds: Cuboid6 = FaceMicroClass.aBounds(shape) diff --git a/src/codechicken/microblock/ItemMicroPart.scala b/src/codechicken/microblock/ItemMicroPart.scala index 545ec8b..b47a236 100644 --- a/src/codechicken/microblock/ItemMicroPart.scala +++ b/src/codechicken/microblock/ItemMicroPart.scala @@ -150,7 +150,8 @@ object ItemMicroPartRenderer extends IItemRenderer CCRenderState.useNormals = true CCRenderState.pullLightmap() CCRenderState.startDrawing() - val part = mcrClass.create(size, mcrClass.itemSlot, getMaterialID(item), true).asInstanceOf[MicroblockClient] + val part = mcrClass.create(true, getMaterialID(item)).asInstanceOf[MicroblockClient] + part.setShape(size, mcrClass.itemSlot) part.render(new Vector3(0.5, 0.5, 0.5).subtract(part.getBounds.center), -1) CCRenderState.draw() GL11.glPopMatrix() diff --git a/src/codechicken/microblock/MicroblockClass.scala b/src/codechicken/microblock/MicroblockClass.scala index 78d9cd6..ae7015c 100644 --- a/src/codechicken/microblock/MicroblockClass.scala +++ b/src/codechicken/microblock/MicroblockClass.scala @@ -8,9 +8,7 @@ trait MicroblockClass def getName:String - def create(client:Boolean):CommonMicroblock - - def create(size:Int, slot:Int, material:Int, client:Boolean):CommonMicroblock + def create(client:Boolean, material:Int):CommonMicroblock def placementProperties:PlacementProperties diff --git a/src/codechicken/microblock/MicroblockClassRegistry.scala b/src/codechicken/microblock/MicroblockClassRegistry.scala index 984e447..7f9f978 100644 --- a/src/codechicken/microblock/MicroblockClassRegistry.scala +++ b/src/codechicken/microblock/MicroblockClassRegistry.scala @@ -15,6 +15,6 @@ object MicroblockClassRegistry classes(id) = mcrClass mcrClass.classID = id - MultiPartRegistry.registerParts((_, c:Boolean) => mcrClass.create(c), mcrClass.getName) + MultiPartRegistry.registerParts((_, c:Boolean) => mcrClass.create(c, 0), mcrClass.getName) } } \ No newline at end of file diff --git a/src/codechicken/microblock/MicroblockPlacement.scala b/src/codechicken/microblock/MicroblockPlacement.scala index 3d45aa4..303faba 100644 --- a/src/codechicken/microblock/MicroblockPlacement.scala +++ b/src/codechicken/microblock/MicroblockPlacement.scala @@ -159,5 +159,9 @@ class MicroblockPlacement(val player:EntityPlayer, val hit:MovingObjectPosition, def getHitDepth(vhit:Vector3, side:Int):Double = vhit.copy.scalarProject(Rotation.axes(side)) + (side%2^1) - def create(size:Int, slot:Int, material:Int) = mcrClass.create(size, slot, material, world.isRemote) + def create(size:Int, slot:Int, material:Int) = { + val part = mcrClass.create(world.isRemote, material) + part.setShape(size, slot) + part + } } \ No newline at end of file