mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-21 12:42:51 +00:00
Added neighbor tile change events to multiparts
Put an operation sync around the onMoved event
This commit is contained in:
1 parent
982c21a97b
commit
686789acfd
6 files changed
+75
-4
No files matched your search
@@ -28,6 +28,7 @@ import codechicken.lib.render.TextureUtils
|
||||
import net.minecraft.world.IBlockAccess
|
||||
import codechicken.lib.raytracer.ExtendedMOP
|
||||
import scala.collection.JavaConversions._
|
||||
import codechicken.multipart.scalatraits.TTileChangeTile
|
||||
|
||||
object BlockMultipart
|
||||
{
|
||||
@@ -76,7 +77,7 @@ trait BlockMultipart extends Block
|
||||
{
|
||||
val tile = getTile(world, x, y, z)
|
||||
if(tile != null)
|
||||
tile.onNeighborBlockChange(world, x, y, z, id)
|
||||
tile.onNeighborBlockChange()
|
||||
}
|
||||
|
||||
override def collisionRayTrace(world:World, x:Int, y:Int, z:Int, start:Vec3, end:Vec3):MovingObjectPosition =
|
||||
@@ -277,6 +278,15 @@ trait BlockMultipart extends Block
|
||||
tile.onEntityCollision(entity)
|
||||
}
|
||||
|
||||
override def onNeighborTileChange(world:World, x:Int, y:Int, z:Int, tileX:Int, tileY:Int, tileZ:Int)
|
||||
{
|
||||
val tile = getTile(world, x, y, z)
|
||||
if(tile != null)
|
||||
tile.onNeighborTileChange(tileX, tileY, tileZ)
|
||||
}
|
||||
|
||||
override def weakTileChanges() = true
|
||||
|
||||
override def canProvidePower = true
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package codechicken.multipart
|
||||
|
||||
trait INeighborTileChange {
|
||||
def weakTileChanges():Boolean
|
||||
|
||||
def onNeighborTileChanged(side:Int, weak:Boolean)
|
||||
}
|
||||
@@ -41,7 +41,8 @@ object MultipartGenerator
|
||||
return superClasses
|
||||
}
|
||||
|
||||
ret = heirachy(part.getClass).flatMap(c => interfaceTraitMap_c.get(c.getName)).distinct
|
||||
val interfaceTraitMap = if(client) interfaceTraitMap_c else interfaceTraitMap_s
|
||||
ret = heirachy(part.getClass).flatMap(c => interfaceTraitMap.get(c.getName)).distinct
|
||||
if(client)
|
||||
partTraitMap_c = partTraitMap_c+(part.getClass -> ret)
|
||||
else
|
||||
|
||||
@@ -106,8 +106,11 @@ class TileMultipart extends TileEntity
|
||||
{
|
||||
val wasInvalid = isInvalid
|
||||
super.validate()
|
||||
if(wasInvalid)
|
||||
if(wasInvalid) {
|
||||
TileMultipart.startOperation(this)
|
||||
partList.foreach(_.onMoved())
|
||||
TileMultipart.finishOperation(this)
|
||||
}
|
||||
}
|
||||
|
||||
private[multipart] def prepareSwap()
|
||||
@@ -163,13 +166,18 @@ class TileMultipart extends TileEntity
|
||||
TileMultipart.finishOperation(this)
|
||||
}
|
||||
|
||||
def onNeighborBlockChange(world:World, x:Int, y:Int, z:Int, id:Int)
|
||||
def onNeighborBlockChange()
|
||||
{
|
||||
TileMultipart.startOperation(this)
|
||||
partList.foreach(_.onNeighborChanged())
|
||||
TileMultipart.finishOperation(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Blank implementation, overriden by TTileChangeTile
|
||||
*/
|
||||
def onNeighborTileChange(tileX:Int, tileY:Int, tileZ:Int) {}
|
||||
|
||||
def getLightValue() = partList.foldLeft(0)((l, p) => Math.max(l, p.getLightValue))
|
||||
|
||||
def markDirty()
|
||||
|
||||
@@ -40,6 +40,7 @@ class MultipartProxy_serverImpl
|
||||
MultipartGenerator.registerTrait("codechicken.multipart.JPartialOcclusion", "codechicken.multipart.scalatraits.TPartialOcclusionTile")
|
||||
MultipartGenerator.registerTrait("codechicken.multipart.IRedstonePart", "codechicken.multipart.scalatraits.TRedstoneTile")
|
||||
MultipartGenerator.registerTrait("codechicken.multipart.IRandomDisplayTick", "codechicken.multipart.scalatraits.TRandomDisplayTickTile", null)
|
||||
MultipartGenerator.registerTrait("codechicken.multipart.INeighborTileChange", null, "codechicken.multipart.scalatraits.TTileChangeTile")
|
||||
}
|
||||
|
||||
def postInit()
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package codechicken.multipart.scalatraits
|
||||
|
||||
import codechicken.multipart.TMultiPart
|
||||
import codechicken.multipart.INeighborTileChange
|
||||
import codechicken.multipart.TileMultipart
|
||||
import codechicken.lib.vec.BlockCoord
|
||||
|
||||
trait TTileChangeTile extends TileMultipart {
|
||||
var weakTileChanges = false
|
||||
|
||||
override def partAdded(part:TMultiPart)
|
||||
{
|
||||
super.partAdded(part)
|
||||
if(part.isInstanceOf[INeighborTileChange])
|
||||
weakTileChanges|=part.asInstanceOf[INeighborTileChange].weakTileChanges
|
||||
}
|
||||
|
||||
override def partRemoved(part:TMultiPart, p:Int) {
|
||||
super.partRemoved(part, p)
|
||||
weakTileChanges = partList.find{p =>
|
||||
p.isInstanceOf[INeighborTileChange] && p.asInstanceOf[INeighborTileChange].weakTileChanges
|
||||
}.isDefined
|
||||
}
|
||||
|
||||
override def onNeighborTileChange(tileX:Int, tileY:Int, tileZ:Int)
|
||||
{
|
||||
super.onNeighborTileChange(tileX, tileY, tileZ)
|
||||
val offset = new BlockCoord(tileX, tileY, tileZ).sub(xCoord, yCoord, zCoord)
|
||||
val diff = offset.absSum
|
||||
val side = offset.toSide
|
||||
|
||||
if(side < 0 || diff <= 0 || diff > 2)
|
||||
return
|
||||
|
||||
val weak = diff == 2
|
||||
if(weak && !weakTileChanges)
|
||||
return
|
||||
|
||||
TileMultipart.startOperation(this)
|
||||
for(p@(_p: INeighborTileChange) <- partList.iterator)
|
||||
p.onNeighborTileChanged(side, weak)
|
||||
TileMultipart.finishOperation(this)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user