mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-26 23:13:07 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b0e99024d | ||
|
|
a1db9a100e | ||
|
|
3c42abd7ac |
No files matched your search
+3
-3
@@ -1,9 +1,9 @@
|
||||
// Add your dependencies here
|
||||
|
||||
dependencies {
|
||||
implementation("com.github.GTNewHorizons:CodeChickenCore:1.4.3:dev")
|
||||
compileOnly("com.github.GTNewHorizons:Angelica:1.0.0-beta53:dev")
|
||||
devOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.7.69-GTNH:dev") {
|
||||
implementation("com.github.GTNewHorizons:CodeChickenCore:1.4.7:dev")
|
||||
compileOnly("com.github.GTNewHorizons:Angelica:1.0.0-beta62:dev")
|
||||
devOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.8.20-GTNH:dev") {
|
||||
exclude group: 'com.github.GTNewHorizons', module: 'CodeChickenCore'
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -96,7 +96,9 @@ usesMixinDebug = false
|
||||
# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise.
|
||||
mixinPlugin =
|
||||
|
||||
# Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail!
|
||||
# Specify the package that contains all of your Mixins. The package must exist or
|
||||
# the build will fail. If you have a package property defined in your mixins.<modid>.json,
|
||||
# it must match with this or the build will fail.
|
||||
mixinsPackage =
|
||||
|
||||
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ pluginManagement {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.41'
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.46'
|
||||
}
|
||||
|
||||
|
||||
@@ -305,10 +305,7 @@ class BlockMultipart extends Block(Material.rock) {
|
||||
}
|
||||
|
||||
override def getLightValue(world: IBlockAccess, x: Int, y: Int, z: Int): Int =
|
||||
getTile(world, x, y, z) match {
|
||||
case null => 0
|
||||
case tile => tile.getLightValue
|
||||
}
|
||||
world.getBlockMetadata(x, y, z)
|
||||
|
||||
override def randomDisplayTick(
|
||||
world: World,
|
||||
|
||||
@@ -33,7 +33,7 @@ object MultipartRenderer
|
||||
f: Float
|
||||
) {
|
||||
val tmpart = t.asInstanceOf[TileMultipartClient]
|
||||
if (tmpart.partList.isEmpty)
|
||||
if (tmpart.partList.isEmpty | !tmpart.hasDynamicParts)
|
||||
return
|
||||
|
||||
val state = CCRenderState.instance
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -34,6 +40,8 @@ class TileMultipart extends TileEntity with IChunkLoadTile {
|
||||
|
||||
private var doesTick = false
|
||||
|
||||
private var cachedLightValue: Int = 0
|
||||
|
||||
private[multipart] def from(that: TileMultipart) {
|
||||
copyFrom(that)
|
||||
loadFrom(that)
|
||||
@@ -162,7 +170,51 @@ class TileMultipart extends TileEntity with IChunkLoadTile {
|
||||
*/
|
||||
def getWeakChanges = false
|
||||
|
||||
def getLightValue = partList.view.map(_.getLightValue).max
|
||||
def getLightValue: Int = cachedLightValue
|
||||
|
||||
override def shouldRefresh(
|
||||
oldBlock: Block,
|
||||
newBlock: Block,
|
||||
oldMeta: Int,
|
||||
newMeta: Int,
|
||||
world: World,
|
||||
x: Int,
|
||||
y: Int,
|
||||
z: Int
|
||||
): Boolean = {
|
||||
oldBlock != newBlock
|
||||
}
|
||||
|
||||
private def updateLight(): Unit = {
|
||||
if (partList.isEmpty) {
|
||||
cachedLightValue = 0
|
||||
return
|
||||
}
|
||||
|
||||
var max = 0
|
||||
val it = partList.iterator
|
||||
while (it.hasNext) {
|
||||
val l = it.next().getLightValue
|
||||
if (l > max) max = l
|
||||
}
|
||||
cachedLightValue = max
|
||||
|
||||
if (
|
||||
worldObj != null && worldObj.getBlockMetadata(
|
||||
xCoord,
|
||||
yCoord,
|
||||
zCoord
|
||||
) != cachedLightValue
|
||||
) {
|
||||
worldObj.setBlockMetadataWithNotify(
|
||||
xCoord,
|
||||
yCoord,
|
||||
zCoord,
|
||||
cachedLightValue,
|
||||
3
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
def getExplosionResistance(entity: Entity) =
|
||||
partList.view.map(_.explosionResistance(entity)).max
|
||||
@@ -284,6 +336,10 @@ class TileMultipart extends TileEntity with IChunkLoadTile {
|
||||
bindPart(part)
|
||||
part.bind(this)
|
||||
|
||||
if (part.getLightValue > cachedLightValue) {
|
||||
cachedLightValue = part.getLightValue
|
||||
}
|
||||
|
||||
if (!doesTick && part.doesTick)
|
||||
setTicking(true)
|
||||
}
|
||||
@@ -326,6 +382,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)
|
||||
|
||||
@@ -336,6 +394,10 @@ class TileMultipart extends TileEntity with IChunkLoadTile {
|
||||
part.onRemoved()
|
||||
part.tile = null
|
||||
|
||||
if (removedLightValue == cachedLightValue && removedLightValue > 0) {
|
||||
updateLight()
|
||||
}
|
||||
|
||||
if (partList.isEmpty) {
|
||||
worldObj.setBlockToAir(xCoord, yCoord, zCoord)
|
||||
} else {
|
||||
@@ -357,6 +419,9 @@ class TileMultipart extends TileEntity with IChunkLoadTile {
|
||||
private[multipart] def loadParts(parts: scala.Iterable[TMultiPart]) {
|
||||
clearParts()
|
||||
parts.foreach(p => addPart_do(p))
|
||||
|
||||
updateLight()
|
||||
|
||||
if (worldObj != null) {
|
||||
if (worldObj.isRemote)
|
||||
operate(_.onWorldJoin())
|
||||
@@ -369,6 +434,7 @@ class TileMultipart extends TileEntity with IChunkLoadTile {
|
||||
*/
|
||||
def clearParts() {
|
||||
partList = Seq()
|
||||
cachedLightValue = 0
|
||||
}
|
||||
|
||||
/** Writes the description of this tile, and all parts composing it, to packet
|
||||
@@ -449,24 +515,108 @@ 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(_.doesTick)
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,11 @@ object MultipartCPH extends MultipartPH with IClientPacketHandler {
|
||||
for (i <- 0 until num)
|
||||
TileMultipart.handleDescPacket(
|
||||
world,
|
||||
indexInChunk(cc, packet.readShort),
|
||||
new BlockCoord(
|
||||
packet.readByte + (cc.chunkXPos << 4),
|
||||
packet.readInt,
|
||||
packet.readByte + (cc.chunkZPos << 4)
|
||||
),
|
||||
packet
|
||||
)
|
||||
}
|
||||
@@ -220,7 +224,9 @@ object MultipartSPH
|
||||
while (it.hasNext) {
|
||||
val tile = it.next
|
||||
if (tile.isInstanceOf[TileMultipart]) {
|
||||
s.writeShort(indexInChunk(new BlockCoord(tile)))
|
||||
s.writeByte(tile.xCoord & 0xf)
|
||||
s.writeInt(tile.yCoord)
|
||||
s.writeByte(tile.zCoord & 0xf)
|
||||
tile.asInstanceOf[TileMultipart].writeDesc(s)
|
||||
num += 1
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user