diff --git a/codechicken/multipart/BlockMultipart.scala b/codechicken/multipart/BlockMultipart.scala index bb1f764..19cbd6d 100644 --- a/codechicken/multipart/BlockMultipart.scala +++ b/codechicken/multipart/BlockMultipart.scala @@ -1,6 +1,7 @@ package codechicken.multipart import java.util.List +import java.lang.Iterable import net.minecraft.block.Block import net.minecraft.block.material.Material import net.minecraft.entity.Entity @@ -81,38 +82,20 @@ trait BlockMultipart extends Block tile.onNeighborBlockChange() } - override def collisionRayTrace(world:World, x:Int, y:Int, z:Int, start:Vec3, end:Vec3):MovingObjectPosition = + override def collisionRayTrace(world:World, x:Int, y:Int, z:Int, start:Vec3, end:Vec3):ExtendedMOP = { - val tile = getTile(world, x, y, z) - if(tile == null) - return null - - return RayTracer.instance.rayTraceCuboids(new Vector3(start), new Vector3(end), - getRayTraceCuboids(tile), new BlockCoord(x, y, z), this) - } - - def getRayTraceCuboids(tile:TileMultipart):LinkedList[IndexedCuboid6] = { - val boxes:LinkedList[IndexedCuboid6] = new LinkedList - - for(i <- 0 until tile.partList.size) - tile.partList(i).getSubParts.foreach{ c => - boxes.add(new IndexedCuboid6((i, c.data), c.copy.add(new Vector3(tile.xCoord, tile.yCoord, tile.zCoord)))) - } - - return boxes + getTile(world, x, y, z) match { + case tile => tile.collisionRayTrace(start, end) + case _ => null + } } def rayTraceAll(world:World, x:Int, y:Int, z:Int, start:Vec3, end:Vec3):Iterable[ExtendedMOP] = { - val tile = getTile(world, x, y, z) - if(tile == null) - return Seq() - - val list = new LinkedList[ExtendedMOP]() - RayTracer.instance.rayTraceCuboids(new Vector3(start), new Vector3(end), - getRayTraceCuboids(tile), new BlockCoord(x, y, z), this, list) - Collections.sort(list) - return list + getTile(world, x, y, z) match { + case tile => tile.rayTraceAll(start, end) + case _ => Seq() + } } override def removeBlockByPlayer(world:World, player:EntityPlayer, x:Int, y:Int, z:Int):Boolean = diff --git a/codechicken/multipart/TMultiPart.scala b/codechicken/multipart/TMultiPart.scala index 95bc230..c3a5731 100644 --- a/codechicken/multipart/TMultiPart.scala +++ b/codechicken/multipart/TMultiPart.scala @@ -24,6 +24,9 @@ import codechicken.lib.data.MCDataInput import net.minecraft.entity.Entity import java.lang.Iterable import scala.collection.JavaConversions._ +import net.minecraft.util.Vec3 +import codechicken.lib.raytracer.ExtendedMOP +import codechicken.lib.raytracer.RayTracer abstract class TMultiPart { @@ -44,6 +47,12 @@ abstract class TMultiPart def occlusionTest(npart:TMultiPart):Boolean = true def getSubParts:Iterable[IndexedCuboid6] = Seq() def getCollisionBoxes:Iterable[Cuboid6] = Seq() + def collisionRayTrace(start: Vec3, end: Vec3): ExtendedMOP = { + val offset = new Vector3(x, y, z) + val boxes = getSubParts.map(c => new IndexedCuboid6(c.data, c.copy.add(offset))) + return RayTracer.instance.rayTraceCuboids(new Vector3(start), new Vector3(end), boxes.toList, + new BlockCoord(x, y, z), tile.blockType).asInstanceOf[ExtendedMOP] + } def getDrops:Iterable[ItemStack] = Seq() def getStrength(hit:MovingObjectPosition, player:EntityPlayer):Float = 1 diff --git a/codechicken/multipart/TileMultipart.scala b/codechicken/multipart/TileMultipart.scala index 24a8007..59e7743 100644 --- a/codechicken/multipart/TileMultipart.scala +++ b/codechicken/multipart/TileMultipart.scala @@ -39,6 +39,9 @@ import net.minecraft.entity.player.EntityPlayer import net.minecraft.entity.Entity import scala.collection.JavaConversions._ import java.util.Collection +import codechicken.lib.raytracer.ExtendedMOP +import net.minecraft.util.Vec3 +import java.lang.Iterable class TileMultipart extends TileEntity { @@ -357,6 +360,23 @@ class TileMultipart extends TileEntity } } + def rayTraceAll(start:Vec3, end:Vec3):Iterable[ExtendedMOP] = + { + var list = ListBuffer[ExtendedMOP]() + for((p, i) <- partList.zipWithIndex) + p.collisionRayTrace(start, end) match { + case mop:ExtendedMOP => { + mop.data = (i, mop.data) + list+=mop + } + case _ => + } + + return list.sorted + } + + def collisionRayTrace(start:Vec3, end:Vec3):ExtendedMOP = rayTraceAll(start, end).headOption.getOrElse(null) + def harvestPart(index:Int, drop:Boolean):Boolean = { val part = partList(index)