|
|
|
@@ -1,10 +1,12 @@
|
|
|
|
|
package codechicken.multipart
|
|
|
|
|
|
|
|
|
|
import net.minecraft.tileentity.TileEntity
|
|
|
|
|
|
|
|
|
|
import scala.collection.mutable.ListBuffer
|
|
|
|
|
import codechicken.lib.packet.PacketCustom
|
|
|
|
|
import codechicken.lib.vec.{Cuboid6, BlockCoord, Vector3}
|
|
|
|
|
import codechicken.lib.vec.{BlockCoord, Cuboid6, Vector3}
|
|
|
|
|
import net.minecraft.world.World
|
|
|
|
|
|
|
|
|
|
import java.util.List
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound
|
|
|
|
|
import codechicken.lib.data.MCDataOutput
|
|
|
|
@@ -15,16 +17,20 @@ import codechicken.multipart.handler.{
|
|
|
|
|
}
|
|
|
|
|
import net.minecraft.item.ItemStack
|
|
|
|
|
import net.minecraft.nbt.NBTTagList
|
|
|
|
|
|
|
|
|
|
import java.util.Random
|
|
|
|
|
import net.minecraft.entity.item.EntityItem
|
|
|
|
|
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 net.minecraft.util.{AxisAlignedBB, Vec3}
|
|
|
|
|
|
|
|
|
|
import java.lang.Iterable
|
|
|
|
|
import codechicken.lib.world.IChunkLoadTile
|
|
|
|
|
import net.minecraft.block.Block
|
|
|
|
|
|
|
|
|
|
class TileMultipart extends TileEntity with IChunkLoadTile {
|
|
|
|
|
|
|
|
|
@@ -110,6 +116,7 @@ class TileMultipart extends TileEntity with IChunkLoadTile {
|
|
|
|
|
|
|
|
|
|
override def validate() {
|
|
|
|
|
super.validate()
|
|
|
|
|
|
|
|
|
|
if (worldObj != null && worldObj.isRemote)
|
|
|
|
|
TileCache.add(this)
|
|
|
|
|
}
|
|
|
|
@@ -162,7 +169,20 @@ class TileMultipart extends TileEntity with IChunkLoadTile {
|
|
|
|
|
*/
|
|
|
|
|
def getWeakChanges = false
|
|
|
|
|
|
|
|
|
|
def getLightValue = partList.view.map(_.getLightValue).max
|
|
|
|
|
def getLightValue: Int = {
|
|
|
|
|
if (partList.isEmpty) {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var max = 0
|
|
|
|
|
val it = partList.iterator
|
|
|
|
|
while (it.hasNext) {
|
|
|
|
|
val l = it.next().getLightValue
|
|
|
|
|
if (l > max) max = l
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
max
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def getExplosionResistance(entity: Entity) =
|
|
|
|
|
partList.view.map(_.explosionResistance(entity)).max
|
|
|
|
@@ -326,6 +346,8 @@ class TileMultipart extends TileEntity with IChunkLoadTile {
|
|
|
|
|
if (r < 0)
|
|
|
|
|
throw new IllegalArgumentException("Tried to remove a non-existant part")
|
|
|
|
|
|
|
|
|
|
val removedLightValue = part.getLightValue
|
|
|
|
|
|
|
|
|
|
part.preRemove()
|
|
|
|
|
partList = partList.filterNot(_ == part)
|
|
|
|
|
|
|
|
|
@@ -357,6 +379,7 @@ class TileMultipart extends TileEntity with IChunkLoadTile {
|
|
|
|
|
private[multipart] def loadParts(parts: scala.Iterable[TMultiPart]) {
|
|
|
|
|
clearParts()
|
|
|
|
|
parts.foreach(p => addPart_do(p))
|
|
|
|
|
|
|
|
|
|
if (worldObj != null) {
|
|
|
|
|
if (worldObj.isRemote)
|
|
|
|
|
operate(_.onWorldJoin())
|
|
|
|
@@ -449,24 +472,109 @@ class TileMultipart extends TileEntity with IChunkLoadTile {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trait TileMultipartClient extends TileMultipart {
|
|
|
|
|
def renderStatic(pos: Vector3, pass: Int) =
|
|
|
|
|
partList.foldLeft(false)((r, part) => part.renderStatic(pos, pass) || r)
|
|
|
|
|
private var cachedRenderBounds: AxisAlignedBB = null
|
|
|
|
|
private var staticCache: Array[TMultiPart] = null
|
|
|
|
|
private var dynamicCache: Array[TMultiPart] = null
|
|
|
|
|
|
|
|
|
|
var hasDynamicParts: Boolean = false
|
|
|
|
|
|
|
|
|
|
def updateRenderCache() {
|
|
|
|
|
if (partList != null) {
|
|
|
|
|
val (dynamic, static) =
|
|
|
|
|
partList.partition(p => p.doesTick || p.shouldRenderDynamic)
|
|
|
|
|
val sArr = static.toArray
|
|
|
|
|
val dArr = dynamic.toArray
|
|
|
|
|
|
|
|
|
|
var c: Cuboid6 = null
|
|
|
|
|
var i = 0
|
|
|
|
|
val allParts = sArr ++ dArr
|
|
|
|
|
while (i < allParts.length) {
|
|
|
|
|
val b = allParts(i).getRenderBounds
|
|
|
|
|
if (c == null) c = b.copy
|
|
|
|
|
else c.enclose(b)
|
|
|
|
|
i += 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c == null) c = Cuboid6.full
|
|
|
|
|
|
|
|
|
|
c.add(Vector3.fromTileEntity(this))
|
|
|
|
|
cachedRenderBounds = c.toAABB
|
|
|
|
|
staticCache = sArr
|
|
|
|
|
dynamicCache = dArr
|
|
|
|
|
hasDynamicParts = dArr.length > 0
|
|
|
|
|
} else {
|
|
|
|
|
staticCache = Array.empty
|
|
|
|
|
dynamicCache = Array.empty
|
|
|
|
|
hasDynamicParts = false
|
|
|
|
|
cachedRenderBounds = AxisAlignedBB.getBoundingBox(
|
|
|
|
|
xCoord,
|
|
|
|
|
yCoord,
|
|
|
|
|
zCoord,
|
|
|
|
|
xCoord + 1,
|
|
|
|
|
yCoord + 1,
|
|
|
|
|
zCoord + 1
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def renderStatic(pos: Vector3, pass: Int) = {
|
|
|
|
|
if (staticCache == null) updateRenderCache()
|
|
|
|
|
var rendered = false
|
|
|
|
|
|
|
|
|
|
val statics = staticCache
|
|
|
|
|
if (statics != null) {
|
|
|
|
|
var i = 0
|
|
|
|
|
val len = statics.length
|
|
|
|
|
while (i < len) {
|
|
|
|
|
if (statics(i) != null && statics(i).renderStatic(pos, pass))
|
|
|
|
|
rendered = true
|
|
|
|
|
i += 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val dynamics = dynamicCache
|
|
|
|
|
if (dynamics != null) {
|
|
|
|
|
var i = 0
|
|
|
|
|
val len = dynamics.length
|
|
|
|
|
while (i < len) {
|
|
|
|
|
if (dynamics(i) != null && dynamics(i).renderStatic(pos, pass))
|
|
|
|
|
rendered = true
|
|
|
|
|
i += 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
rendered
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def renderDynamic(pos: Vector3, frame: Float, pass: Int) {
|
|
|
|
|
partList.foreach(part => part.renderDynamic(pos, frame, pass: Int))
|
|
|
|
|
if (!hasDynamicParts) return
|
|
|
|
|
|
|
|
|
|
val dynamics = dynamicCache
|
|
|
|
|
if (dynamics != null) {
|
|
|
|
|
var i = 0
|
|
|
|
|
val len = dynamics.length
|
|
|
|
|
while (i < len) {
|
|
|
|
|
if (dynamics(i) != null) dynamics(i).renderDynamic(pos, frame, pass)
|
|
|
|
|
i += 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def randomDisplayTick(random: Random) {}
|
|
|
|
|
|
|
|
|
|
override def shouldRenderInPass(pass: Int) = {
|
|
|
|
|
MultipartRenderer.pass = pass
|
|
|
|
|
true
|
|
|
|
|
if (staticCache == null) updateRenderCache()
|
|
|
|
|
hasDynamicParts
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override def getRenderBoundingBox = {
|
|
|
|
|
val c = Cuboid6.full.copy
|
|
|
|
|
partList.foreach(part => c.enclose(part.getRenderBounds))
|
|
|
|
|
c.add(Vector3.fromTileEntity(this)).toAABB
|
|
|
|
|
if (cachedRenderBounds == null) updateRenderCache()
|
|
|
|
|
cachedRenderBounds
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override def markRender(): Unit = {
|
|
|
|
|
super.markRender()
|
|
|
|
|
updateRenderCache()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|