mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-22 21:19:49 +00:00
Separated the trait implementations for the ScalaCompilerFactory
This commit is contained in:
1 parent
35f877ccd8
commit
5dd78b681c
9 files changed
+243
-107
No files matched your search
@@ -6,17 +6,4 @@ import java.util.Random
|
||||
trait IRandomDisplayTick
|
||||
{
|
||||
def randomDisplayTick(random:Random)
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves processor time looping on tiles that don't need it
|
||||
*/
|
||||
trait TRandomDisplayTickTile extends TileMultipartClient
|
||||
{
|
||||
override def randomDisplayTick(random:Random)
|
||||
{
|
||||
partList.foreach(p =>
|
||||
if(p.isInstanceOf[IRandomDisplayTick])
|
||||
p.asInstanceOf[IRandomDisplayTick].randomDisplayTick(random))
|
||||
}
|
||||
}
|
||||
@@ -23,71 +23,13 @@ trait IFaceRedstonePart extends IRedstonePart
|
||||
def getFace():Int
|
||||
}
|
||||
|
||||
trait TRedstoneTile extends TileMultipart with IRedstoneConnector
|
||||
/**
|
||||
* Internal interface for TileMultipart instances hosting IRedstonePart
|
||||
*/
|
||||
trait IRedstoneTile extends IRedstoneConnector
|
||||
{
|
||||
import RedstoneInteractions._
|
||||
|
||||
override def strongPowerLevel(side:Int):Int =
|
||||
{
|
||||
var max = 0
|
||||
partList.foreach(p =>
|
||||
if(p.isInstanceOf[IRedstonePart])
|
||||
{
|
||||
val l = p.asInstanceOf[IRedstonePart].strongPowerLevel(side)
|
||||
if(l > max) max = l
|
||||
}
|
||||
)
|
||||
return max
|
||||
}
|
||||
|
||||
def openConnections(side:Int):Int =
|
||||
{
|
||||
if(blocksRedstone(side))
|
||||
return 0
|
||||
|
||||
var m = 0x10
|
||||
var i = 0
|
||||
while(i < 4)
|
||||
{
|
||||
if(!blocksRedstone(edgeBetween(side, rotateSide(side&6, i))))
|
||||
m|=1<<i
|
||||
i+=1
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
def blocksRedstone(i:Int) = partMap(i) != null && partMap(i).blocksRedstone
|
||||
|
||||
override def weakPowerLevel(side:Int):Int =
|
||||
weakPowerLevel(side, otherConnectionMask(worldObj, xCoord, yCoord, zCoord, side, true))
|
||||
|
||||
override def canConnectRedstone(side:Int):Boolean =
|
||||
{
|
||||
val vside = vanillaToSide(side)
|
||||
return (getConnectionMask(vside) & otherConnectionMask(worldObj, xCoord, yCoord, zCoord, vside, false)) > 0
|
||||
}
|
||||
|
||||
def getConnectionMask(side:Int):Int =
|
||||
{
|
||||
val mask = openConnections(side)
|
||||
var res = 0
|
||||
partList.foreach(p =>
|
||||
res|=connectionMask(p, side)&mask)
|
||||
return res
|
||||
}
|
||||
|
||||
def weakPowerLevel(side:Int, mask:Int):Int =
|
||||
{
|
||||
val tmask = openConnections(side)&mask
|
||||
var max = 0
|
||||
partList.foreach(p =>
|
||||
if((connectionMask(p, side)&tmask) > 0)
|
||||
{
|
||||
val l = p.asInstanceOf[IRedstonePart].weakPowerLevel(side)
|
||||
if(l > max) max = l
|
||||
})
|
||||
return max
|
||||
}
|
||||
def openConnections(side:Int):Int
|
||||
def blocksRedstone(i:Int):Boolean
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,6 +43,9 @@ trait IRedstoneConnector
|
||||
def weakPowerLevel(side:Int, mask:Int):Int
|
||||
}
|
||||
|
||||
/**
|
||||
* Block version of IRedstoneConnector
|
||||
*/
|
||||
trait IRedstoneConnectorBlock
|
||||
{
|
||||
def getConnectionMask(world:IBlockAccess, x:Int, y:Int, z:Int, side:Int):Int
|
||||
@@ -118,7 +63,7 @@ object RedstoneInteractions
|
||||
{
|
||||
val tile = p.tile
|
||||
return getWeakPowerTo(tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord, side,
|
||||
tile.asInstanceOf[TRedstoneTile].openConnections(side)&connectionMask(p, side))
|
||||
tile.asInstanceOf[IRedstoneTile].openConnections(side)&connectionMask(p, side))
|
||||
}
|
||||
|
||||
def getWeakPowerTo(world:World, x:Int, y:Int, z:Int, side:Int, mask:Int):Int =
|
||||
|
||||
@@ -11,29 +11,6 @@ trait JPartialOcclusion
|
||||
def allowCompleteOcclusion = false
|
||||
}
|
||||
|
||||
trait TPartialOcclusionTile extends TileMultipart
|
||||
{
|
||||
override def occlusionTest(parts:Seq[TMultiPart], npart:TMultiPart):Boolean =
|
||||
{
|
||||
if(npart.isInstanceOf[JPartialOcclusion] && !partialOcclusionTest(parts:+npart))
|
||||
return false
|
||||
|
||||
return super.occlusionTest(parts, npart)
|
||||
}
|
||||
|
||||
def partialOcclusionTest(parts:Seq[TMultiPart]):Boolean =
|
||||
{
|
||||
val test = new PartialOcclusionTest(parts.length)
|
||||
for(i <- 0 until parts.length)
|
||||
{
|
||||
val part = parts(i)
|
||||
if(part.isInstanceOf[JPartialOcclusion])
|
||||
test.fill(i, part.asInstanceOf[JPartialOcclusion])
|
||||
}
|
||||
return test()
|
||||
}
|
||||
}
|
||||
|
||||
class PartialOcclusionTest(size:Int)
|
||||
{
|
||||
val res = 8
|
||||
|
||||
@@ -41,8 +41,8 @@ import net.minecraft.entity.Entity
|
||||
|
||||
trait TileMultipart extends TileEntity
|
||||
{
|
||||
var partList: ArrayBuffer[TMultiPart] = ArrayBuffer()
|
||||
var partMap: Array[TMultiPart] = new Array(27)
|
||||
var partList = ArrayBuffer[TMultiPart]()
|
||||
var partMap = new Array[TMultiPart](27)
|
||||
|
||||
private var doesTick = false
|
||||
|
||||
|
||||
@@ -35,10 +35,10 @@ class MultipartProxy_serverImpl
|
||||
config = new ConfigFile(new File(cfgdir, "multipart.cfg"))
|
||||
.setComment("Multipart API config file")
|
||||
|
||||
MultipartGenerator.registerTrait("net.minecraftforge.liquids.ITankContainer", "codechicken.multipart.TLiquidTank")
|
||||
MultipartGenerator.registerTrait("codechicken.multipart.JPartialOcclusion", "codechicken.multipart.TPartialOcclusionTile")
|
||||
MultipartGenerator.registerTrait("codechicken.multipart.IRedstonePart", "codechicken.multipart.TRedstoneTile")
|
||||
MultipartGenerator.registerTrait("codechicken.multipart.IRandomDisplayTick", "codechicken.multipart.TRandomDisplayTickTile", null)
|
||||
MultipartGenerator.registerTrait("net.minecraftforge.liquids.ITankContainer", "codechicken.multipart.scalatraits.TTankContainerTile")
|
||||
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)
|
||||
}
|
||||
|
||||
def postInit()
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package codechicken.multipart.scalatraits
|
||||
|
||||
import codechicken.multipart.TileMultipart
|
||||
import codechicken.multipart.TMultiPart
|
||||
import codechicken.multipart.JPartialOcclusion
|
||||
import codechicken.multipart.PartialOcclusionTest
|
||||
|
||||
trait TPartialOcclusionTile extends TileMultipart
|
||||
{
|
||||
override def occlusionTest(parts:Seq[TMultiPart], npart:TMultiPart):Boolean =
|
||||
{
|
||||
if(npart.isInstanceOf[JPartialOcclusion] && !partialOcclusionTest(parts:+npart))
|
||||
return false
|
||||
|
||||
return super.occlusionTest(parts, npart)
|
||||
}
|
||||
|
||||
def partialOcclusionTest(parts:Seq[TMultiPart]):Boolean =
|
||||
{
|
||||
val test = new PartialOcclusionTest(parts.length)
|
||||
for(i <- 0 until parts.length)
|
||||
{
|
||||
val part = parts(i)
|
||||
if(part.isInstanceOf[JPartialOcclusion])
|
||||
test.fill(i, part.asInstanceOf[JPartialOcclusion])
|
||||
}
|
||||
return test()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package codechicken.multipart.scalatraits
|
||||
|
||||
import codechicken.multipart.TileMultipartClient
|
||||
import codechicken.multipart.IRandomDisplayTick
|
||||
import java.util.Random
|
||||
|
||||
/**
|
||||
* Saves processor time looping on tiles that don't need it
|
||||
*/
|
||||
trait TRandomDisplayTickTile extends TileMultipartClient
|
||||
{
|
||||
override def randomDisplayTick(random:Random)
|
||||
{
|
||||
for(p@(_p: IRandomDisplayTick) <- partList.iterator)
|
||||
p.randomDisplayTick(random)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package codechicken.multipart.scalatraits
|
||||
|
||||
import net.minecraftforge.liquids.ITankContainer
|
||||
import scala.collection.mutable.ListBuffer
|
||||
import net.minecraftforge.liquids.LiquidStack
|
||||
import net.minecraftforge.liquids.ILiquidTank
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
import codechicken.multipart.TMultiPart
|
||||
import codechicken.multipart.TileMultipart
|
||||
|
||||
trait TTankContainerTile extends TileMultipart with ITankContainer
|
||||
{
|
||||
var tankList = ListBuffer[ITankContainer]()
|
||||
|
||||
override def partAdded(part:TMultiPart)
|
||||
{
|
||||
super.partAdded(part)
|
||||
if(part.isInstanceOf[ITankContainer])
|
||||
tankList+=part.asInstanceOf[ITankContainer]
|
||||
}
|
||||
|
||||
override def partRemoved(part:TMultiPart, p:Int)
|
||||
{
|
||||
super.partRemoved(part, p)
|
||||
if(part.isInstanceOf[ITankContainer])
|
||||
tankList-=part.asInstanceOf[ITankContainer]
|
||||
}
|
||||
|
||||
override def loadFrom(that:TileMultipart)
|
||||
{
|
||||
super.loadFrom(that)
|
||||
if(that.isInstanceOf[TTankContainerTile])
|
||||
tankList = that.asInstanceOf[TTankContainerTile].tankList
|
||||
}
|
||||
|
||||
override def clearParts()
|
||||
{
|
||||
super.clearParts()
|
||||
tankList.clear
|
||||
}
|
||||
|
||||
override def getTanks(dir:ForgeDirection):Array[ILiquidTank] =
|
||||
{
|
||||
var tankCount:Int = 0
|
||||
tankList.foreach(t => tankCount += t.getTanks(dir).length)
|
||||
val tanks = new Array[ILiquidTank](tankCount)
|
||||
var i = 0
|
||||
tankList.foreach(p => p.getTanks(dir).foreach{t =>
|
||||
tanks(i) = t
|
||||
i+=1
|
||||
})
|
||||
return tanks
|
||||
}
|
||||
|
||||
override def getTank(dir:ForgeDirection, liquid:LiquidStack):ILiquidTank =
|
||||
{
|
||||
tankList.foreach{p =>
|
||||
val t = p.getTank(dir, liquid)
|
||||
if(t != null)
|
||||
return t//TODO: bad, slow
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
override def fill(dir:ForgeDirection, liquid:LiquidStack, doFill:Boolean):Int =
|
||||
{
|
||||
var filled = 0
|
||||
var initial = liquid.amount
|
||||
tankList.foreach(p =>
|
||||
filled+=p.fill(dir, copy(liquid, initial-filled), doFill)
|
||||
)
|
||||
return filled
|
||||
}
|
||||
|
||||
def copy(liquid:LiquidStack, quantity:Int):LiquidStack =
|
||||
{
|
||||
val copy = liquid.copy
|
||||
copy.amount = quantity
|
||||
return copy
|
||||
}
|
||||
|
||||
override def drain(dir:ForgeDirection, amount:Int, doDrain:Boolean):LiquidStack =
|
||||
{
|
||||
var drained:LiquidStack = null
|
||||
tankList.foreach{p =>
|
||||
val ret = p.drain(dir, amount-drained.amount, false)
|
||||
if(ret != null && ret.amount > 0 && (drained == null || drained.isLiquidEqual(ret)))
|
||||
{
|
||||
if(doDrain)
|
||||
p.drain(dir, amount-drained.amount, true)
|
||||
|
||||
if(drained == null)
|
||||
drained = ret
|
||||
else
|
||||
drained.amount+=ret.amount
|
||||
}
|
||||
}
|
||||
return drained
|
||||
}
|
||||
|
||||
override def fill(tankIndex:Int, liquid:LiquidStack, doFill:Boolean):Int =
|
||||
throw new UnsupportedOperationException("Index based tank filling")
|
||||
|
||||
override def drain(tankIndex:Int, maxDrain:Int, doDrain:Boolean):LiquidStack =
|
||||
throw new UnsupportedOperationException("Index based tank draining")
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package codechicken.multipart.scalatraits
|
||||
|
||||
import codechicken.multipart.IRedstoneConnector
|
||||
import codechicken.multipart.TileMultipart
|
||||
import codechicken.multipart.IRedstonePart
|
||||
import codechicken.multipart.RedstoneInteractions._
|
||||
import codechicken.multipart.PartMap._
|
||||
import codechicken.core.vec.Rotation._
|
||||
import codechicken.multipart.IRedstoneTile
|
||||
|
||||
trait TRedstoneTile extends TileMultipart with IRedstoneTile
|
||||
{
|
||||
override def strongPowerLevel(side:Int):Int =
|
||||
{
|
||||
var max = 0
|
||||
partList.foreach(p =>
|
||||
if(p.isInstanceOf[IRedstonePart])
|
||||
{
|
||||
val l = p.asInstanceOf[IRedstonePart].strongPowerLevel(side)
|
||||
if(l > max) max = l
|
||||
}
|
||||
)
|
||||
return max
|
||||
}
|
||||
|
||||
def openConnections(side:Int):Int =
|
||||
{
|
||||
if(blocksRedstone(side))
|
||||
return 0
|
||||
|
||||
var m = 0x10
|
||||
var i = 0
|
||||
while(i < 4)
|
||||
{
|
||||
if(!blocksRedstone(edgeBetween(side, rotateSide(side&6, i))))
|
||||
m|=1<<i
|
||||
i+=1
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
def blocksRedstone(i:Int) = partMap(i) != null && partMap(i).blocksRedstone
|
||||
|
||||
override def weakPowerLevel(side:Int):Int =
|
||||
weakPowerLevel(side, otherConnectionMask(worldObj, xCoord, yCoord, zCoord, side, true))
|
||||
|
||||
override def canConnectRedstone(side:Int):Boolean =
|
||||
{
|
||||
val vside = vanillaToSide(side)
|
||||
return (getConnectionMask(vside) & otherConnectionMask(worldObj, xCoord, yCoord, zCoord, vside, false)) > 0
|
||||
}
|
||||
|
||||
def getConnectionMask(side:Int):Int =
|
||||
{
|
||||
val mask = openConnections(side)
|
||||
var res = 0
|
||||
partList.foreach(p =>
|
||||
res|=connectionMask(p, side)&mask)
|
||||
return res
|
||||
}
|
||||
|
||||
def weakPowerLevel(side:Int, mask:Int):Int =
|
||||
{
|
||||
val tmask = openConnections(side)&mask
|
||||
var max = 0
|
||||
partList.foreach(p =>
|
||||
if((connectionMask(p, side)&tmask) > 0)
|
||||
{
|
||||
val l = p.asInstanceOf[IRedstonePart].weakPowerLevel(side)
|
||||
if(l > max) max = l
|
||||
})
|
||||
return max
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user