cleaned up block delegate a bit, since its probably here to stay after all (mostly naming stuff and sorting)

This commit is contained in:
Florian Nücke 2013-11-30 01:51:17 +01:00
parent dddf238a3b
commit b2b56419c9
16 changed files with 331 additions and 326 deletions

View File

@ -18,7 +18,7 @@ class Adapter(val parent: SimpleDelegator) extends SimpleDelegate {
// ----------------------------------------------------------------------- //
override def addInformation(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
override def tooltipLines(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
tooltip.addAll(Tooltip.get(unlocalizedName))
}
@ -42,7 +42,7 @@ class Adapter(val parent: SimpleDelegator) extends SimpleDelegate {
// ----------------------------------------------------------------------- //
override def onNeighborBlockChange(world: World, x: Int, y: Int, z: Int, blockId: Int) =
override def neighborBlockChanged(world: World, x: Int, y: Int, z: Int, blockId: Int) =
world.getBlockTileEntity(x, y, z) match {
case adapter: tileentity.Adapter => adapter.neighborChanged()
case _ => // Ignore.

View File

@ -16,7 +16,7 @@ class Cable(val parent: SpecialDelegator) extends SpecialDelegate {
// ----------------------------------------------------------------------- //
override def addInformation(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
override def tooltipLines(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
tooltip.addAll(Tooltip.get(unlocalizedName))
}
@ -34,22 +34,22 @@ class Cable(val parent: SpecialDelegator) extends SpecialDelegate {
// ----------------------------------------------------------------------- //
override def isBlockNormalCube(world: World, x: Int, y: Int, z: Int) = false
override def isNormalCube(world: World, x: Int, y: Int, z: Int) = false
override def isBlockSolid(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) = false
override def isSolid(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) = false
override def getLightOpacity(world: World, x: Int, y: Int, z: Int) = 0
override def opacity(world: World, x: Int, y: Int, z: Int) = 0
override def shouldSideBeRendered(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) = false
// ----------------------------------------------------------------------- //
override def onNeighborBlockChange(world: World, x: Int, y: Int, z: Int, blockId: Int) {
override def neighborBlockChanged(world: World, x: Int, y: Int, z: Int, blockId: Int) {
world.markBlockForRenderUpdate(x, y, z)
super.onNeighborBlockChange(world, x, y, z, blockId)
super.neighborBlockChanged(world, x, y, z, blockId)
}
override def setBlockBoundsBasedOnState(world: IBlockAccess, x: Int, y: Int, z: Int) {
override def updateBounds(world: IBlockAccess, x: Int, y: Int, z: Int) {
parent.setBlockBounds(Cable.bounds(world, x, y, z))
}
}

View File

@ -18,7 +18,7 @@ class Capacitor(val parent: SimpleDelegator) extends SimpleDelegate {
// ----------------------------------------------------------------------- //
override def addInformation(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
override def tooltipLines(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
tooltip.addAll(Tooltip.get(unlocalizedName))
}
@ -34,7 +34,7 @@ class Capacitor(val parent: SimpleDelegator) extends SimpleDelegate {
icons(ForgeDirection.EAST.ordinal) = icons(ForgeDirection.NORTH.ordinal)
}
override def getLightValue(world: IBlockAccess, x: Int, y: Int, z: Int) = 5
override def luminance(world: IBlockAccess, x: Int, y: Int, z: Int) = 5
// ----------------------------------------------------------------------- //
@ -52,7 +52,7 @@ class Capacitor(val parent: SimpleDelegator) extends SimpleDelegate {
case _ =>
}
override def onNeighborBlockChange(world: World, x: Int, y: Int, z: Int, blockId: Int) =
override def neighborBlockChanged(world: World, x: Int, y: Int, z: Int, blockId: Int) =
world.getBlockTileEntity(x, y, z) match {
case capacitor: tileentity.Capacitor => capacitor.recomputeCapacity()
case _ =>

View File

@ -16,7 +16,7 @@ abstract class Case(val parent: SimpleDelegator) extends Computer with SimpleDel
def tier: Int
override def addInformation(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
override def tooltipLines(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
val slots = tier match {
case 0 => "2/1/1"
case 1 => "2/2/2"
@ -30,7 +30,7 @@ abstract class Case(val parent: SimpleDelegator) extends Computer with SimpleDel
val off = Array.fill[Icon](6)(null)
}
override def getBlockTextureFromSide(world: IBlockAccess, x: Int, y: Int, z: Int, worldSide: ForgeDirection, localSide: ForgeDirection) = {
override def icon(world: IBlockAccess, x: Int, y: Int, z: Int, worldSide: ForgeDirection, localSide: ForgeDirection) = {
getIcon(localSide, world.getBlockTileEntity(x, y, z) match {
case computer: tileentity.Case => computer.isRunning
case _ => false
@ -66,8 +66,8 @@ abstract class Case(val parent: SimpleDelegator) extends Computer with SimpleDel
// ----------------------------------------------------------------------- //
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer,
side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = {
override def rightClick(world: World, x: Int, y: Int, z: Int, player: EntityPlayer,
side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = {
if (!player.isSneaking) {
if (!world.isRemote) {
player.openGui(OpenComputers, GuiType.Case.id, world, x, y, z)
@ -78,11 +78,11 @@ abstract class Case(val parent: SimpleDelegator) extends Computer with SimpleDel
}
// TODO do we have to manually sync the client since we can only check this on the server side?
override def onBlockRemovedBy(world: World, x: Int, y: Int, z: Int, player: EntityPlayer) =
override def removedByEntity(world: World, x: Int, y: Int, z: Int, player: EntityPlayer) =
world.getBlockTileEntity(x, y, z) match {
case c: tileentity.Case if !world.isRemote =>
c.computer.canInteract(player.getCommandSenderName)
case _ => super.onBlockRemovedBy(world, x, y, z, player)
case _ => super.removedByEntity(world, x, y, z, player)
}
}
@ -93,7 +93,7 @@ object Case {
def tier = 0
override def getRenderColor = 0x7F7F7F
override def color = 0x7F7F7F
}
class Tier2(parent: SimpleDelegator) extends Case(parent) {
@ -101,7 +101,7 @@ object Case {
def tier = 1
override def getRenderColor = 0xFFFF66
override def color = 0xFFFF66
}
class Tier3(parent: SimpleDelegator) extends Case(parent) {
@ -109,7 +109,7 @@ object Case {
def tier = 2
override def getRenderColor = 0x66FFFF
override def color = 0x66FFFF
}
}

View File

@ -16,7 +16,7 @@ class Charger(val parent: SimpleDelegator) extends SimpleDelegate {
private val icons = Array.fill[Icon](6)(null)
override def addInformation(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
override def tooltipLines(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
tooltip.addAll(Tooltip.get(unlocalizedName))
}
@ -36,9 +36,9 @@ class Charger(val parent: SimpleDelegator) extends SimpleDelegate {
override def createTileEntity(world: World) = Some(new tileentity.Charger())
override def canConnectRedstone(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) = true
override def canConnectToRedstone(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) = true
override def onNeighborBlockChange(world: World, x: Int, y: Int, z: Int, blockId: Int) =
override def neighborBlockChanged(world: World, x: Int, y: Int, z: Int, blockId: Int) =
world.getBlockTileEntity(x, y, z) match {
case charger: tileentity.Charger => charger.onNeighborChanged()
case _ =>

View File

@ -7,7 +7,7 @@ import net.minecraftforge.common.ForgeDirection
abstract class Computer extends Delegate {
override def hasTileEntity = true
override def canConnectRedstone(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) =
override def canConnectToRedstone(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) =
world.getBlockTileEntity(x, y, z) match {
case computer: tileentity.Computer => computer.isOutputEnabled
case _ => false
@ -22,7 +22,7 @@ abstract class Computer extends Delegate {
case _ => super.isProvidingWeakPower(world, x, y, z, side)
}
override def onNeighborBlockChange(world: World, x: Int, y: Int, z: Int, blockId: Int) =
override def neighborBlockChanged(world: World, x: Int, y: Int, z: Int, blockId: Int) =
world.getBlockTileEntity(x, y, z) match {
case computer: tileentity.Computer => computer.checkRedstoneInputChanged()
case _ => // Ignore.

View File

@ -11,7 +11,6 @@ import net.minecraft.world.IBlockAccess
import net.minecraft.world.World
import net.minecraftforge.common.ForgeDirection
/** The base class on which all our blocks are built. */
trait Delegate {
val unlocalizedName: String
@ -25,89 +24,96 @@ trait Delegate {
world.setBlock(x, y, z, parent.blockID, blockId, flags)
}
def createItemStack(amount: Int = 1) = new ItemStack(parent, amount, damageDropped)
def createItemStack(amount: Int = 1) = new ItemStack(parent, amount, itemDamage)
// ----------------------------------------------------------------------- //
// Block
// ----------------------------------------------------------------------- //
def addInformation(stack: ItemStack, player: EntityPlayer, tooltip: java.util.List[String], advanced: Boolean) {}
def itemDamage = blockId
def breakBlock(world: World, x: Int, y: Int, z: Int, blockId: Int) {}
def pick(target: MovingObjectPosition, world: World, x: Int, y: Int, z: Int): ItemStack = createItemStack()
def canConnectRedstone(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) = false
def drop(world: World, x: Int, y: Int, z: Int, chance: Float, fortune: Int) = false
def isNormalCube(world: World, x: Int, y: Int, z: Int) = true
def validRotations(world: World, x: Int, y: Int, z: Int) = validRotations_
def canPlaceBlockOnSide(world: World, x: Int, y: Int, z: Int, side: ForgeDirection) = true
def colorMultiplier(world: IBlockAccess, x: Int, y: Int, z: Int) = getRenderColor
def collisionRayTrace(world: World, x: Int, y: Int, z: Int, origin: Vec3, direction: Vec3) =
parent.superCollisionRayTrace(world, x, y, z, origin, direction)
def createTileEntity(world: World): Option[TileEntity] = None
def getBlockTextureFromSide(world: IBlockAccess, x: Int, y: Int, z: Int,
worldSide: ForgeDirection, localSide: ForgeDirection): Option[Icon] = icon(localSide)
def getCollisionBoundingBoxFromPool(world: World, x: Int, y: Int, z: Int) =
def bounds(world: World, x: Int, y: Int, z: Int) =
AxisAlignedBB.getAABBPool.getAABB(0, 0, 0, 1, 1, 1)
def damageDropped = blockId
def updateBounds(world: IBlockAccess, x: Int, y: Int, z: Int) =
parent.setBlockBounds(0, 0, 0, 1, 1, 1)
def dropBlockAsItemWithChance(world: World, x: Int, y: Int, z: Int, chance: Float, fortune: Int) = false
def intersect(world: World, x: Int, y: Int, z: Int, origin: Vec3, direction: Vec3) =
parent.superCollisionRayTrace(world, x, y, z, origin, direction)
def pickBlock(target: MovingObjectPosition, world: World, x: Int, y: Int, z: Int): ItemStack = createItemStack()
// ----------------------------------------------------------------------- //
def getRenderColor = 0xFFFFFF
def getLightOpacity(world: World, x: Int, y: Int, z: Int) = 255
def getLightValue(world: IBlockAccess, x: Int, y: Int, z: Int) = 0
def getValidRotations(world: World, x: Int, y: Int, z: Int) = validRotations
def hasTileEntity = false
def icon(side: ForgeDirection): Option[Icon] = None
def isBlockNormalCube(world: World, x: Int, y: Int, z: Int) = true
def canConnectToRedstone(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) = false
def isProvidingStrongPower(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) = 0
def isProvidingWeakPower(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) = 0
def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = false
// ----------------------------------------------------------------------- //
def onBlockAdded(world: World, x: Int, y: Int, z: Int) {}
def hasTileEntity = false
def onBlockPlacedBy(world: World, x: Int, y: Int, z: Int, player: EntityLivingBase, stack: ItemStack) {}
def createTileEntity(world: World): Option[TileEntity] = None
def onBlockPreDestroy(world: World, x: Int, y: Int, z: Int) =
// ----------------------------------------------------------------------- //
def update(world: World, x: Int, y: Int, z: Int) = {}
def addedToWorld(world: World, x: Int, y: Int, z: Int) {}
def addedByEntity(world: World, x: Int, y: Int, z: Int, player: EntityLivingBase, stack: ItemStack) {}
def aboutToBeRemoved(world: World, x: Int, y: Int, z: Int) =
if (!world.isRemote) world.getBlockTileEntity(x, y, z) match {
case inventory: tileentity.Inventory => inventory.dropAllSlots()
case _ => // Ignore.
}
def onBlockRemovedBy(world: World, x: Int, y: Int, z: Int, player: EntityPlayer) = true
def removedFromWorld(world: World, x: Int, y: Int, z: Int, blockId: Int) {}
def onNeighborBlockChange(world: World, x: Int, y: Int, z: Int, blockId: Int) {}
def removedByEntity(world: World, x: Int, y: Int, z: Int, player: EntityPlayer) = true
def registerIcons(iconRegister: IconRegister) {}
def neighborBlockChanged(world: World, x: Int, y: Int, z: Int, blockId: Int) {}
def setBlockBoundsBasedOnState(world: IBlockAccess, x: Int, y: Int, z: Int) =
parent.setBlockBounds(0, 0, 0, 1, 1, 1)
def leftClick(world: World, x: Int, y: Int, z: Int, player: EntityPlayer) {}
def setBlockBoundsForItemRender(): Unit = parent.setBlockBoundsForItemRender()
def rightClick(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = false
// ----------------------------------------------------------------------- //
def tooltipLines(stack: ItemStack, player: EntityPlayer, tooltip: java.util.List[String], advanced: Boolean) {}
def opacity(world: World, x: Int, y: Int, z: Int) = 255
def luminance(world: IBlockAccess, x: Int, y: Int, z: Int) = 0
def color = 0xFFFFFF
def color(world: IBlockAccess, x: Int, y: Int, z: Int): Int = color
def icon(side: ForgeDirection): Option[Icon] = None
def icon(world: IBlockAccess, x: Int, y: Int, z: Int, worldSide: ForgeDirection, localSide: ForgeDirection): Option[Icon] = icon(localSide)
def itemBounds(): Unit = parent.setBlockBoundsForItemRender()
def preItemRender() {}
def postItemRender() {}
def update(world: World, x: Int, y: Int, z: Int) = {}
def registerIcons(iconRegister: IconRegister) {}
// ----------------------------------------------------------------------- //
protected val validRotations = Array(
protected val validRotations_ = Array(
ForgeDirection.SOUTH,
ForgeDirection.WEST,
ForgeDirection.NORTH,
@ -127,7 +133,7 @@ trait SpecialDelegate extends Delegate {
// ----------------------------------------------------------------------- //
def isBlockSolid(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) = true
def isSolid(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) = true
def shouldSideBeRendered(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) =
!world.isBlockOpaqueCube(x, y, z)

View File

@ -20,21 +20,6 @@ import net.minecraftforge.common.ForgeDirection
import powercrystals.minefactoryreloaded.api.rednet.{IRedNetNetworkContainer, RedNetConnectionType, IConnectableRedNet}
import scala.collection.mutable
/**
* Block proxy for all real block implementations.
*
* All of our blocks are implemented as "sub-blocks" of this block, i.e. they
* are instances of this block with differing metadata. This way we only need a
* single block ID to represent 15 blocks.
*
* This means this block contains barely any logic, it only forwards calls to
* the underlying sub block, based on the metadata. The only actual logic done
* in here is:
* - block rotation, if the block has a rotatable tile entity. In that case all
* sides are also translated into local coordinate space for the sub block
* (i.e. "up" will always be up relative to the block itself. So if it's
* rotated up may actually be west).
*/
class Delegator[Child <: Delegate](id: Int) extends Block(id, Material.iron) {
setHardness(2f)
setCreativeTab(CreativeTab)
@ -68,6 +53,13 @@ class Delegator[Child <: Delegate](id: Int) extends Block(id, Material.iron) {
case _ => None
}
override def getSubBlocks(itemId: Int, creativeTab: CreativeTabs, list: util.List[_]) = {
// Workaround for MC's untyped lists...
def add[T](list: util.List[T], value: Any) = list.add(value.asInstanceOf[T])
(0 until subBlocks.length).filter(id => subBlocks(id).showInItemList).
foreach(id => add(list, new ItemStack(this, 1, id)))
}
// ----------------------------------------------------------------------- //
// Rotation
// ----------------------------------------------------------------------- //
@ -102,162 +94,105 @@ class Delegator[Child <: Delegate](id: Int) extends Block(id, Material.iron) {
// Block
// ----------------------------------------------------------------------- //
def addInformation(metadata: Int, stack: ItemStack, player: EntityPlayer, tooltip: java.util.List[String], advanced: Boolean) {
subBlock(metadata) match {
case Some(subBlock) => subBlock.addInformation(stack, player, tooltip, advanced)
case _ =>
}
}
override def breakBlock(world: World, x: Int, y: Int, z: Int, blockId: Int, metadata: Int) = {
subBlock(metadata) match {
case Some(subBlock) => subBlock.breakBlock(world, x, y, z, blockId)
case _ => // Invalid but avoid match error.
}
super.breakBlock(world, x, y, z, blockId, metadata)
}
override def canPlaceBlockOnSide(world: World, x: Int, y: Int, z: Int, side: Int, stack: ItemStack) =
subBlock(stack) match {
case Some(subBlock) => subBlock.canPlaceBlockOnSide(world, x, y, z, ForgeDirection.getOrientation(side).getOpposite)
case _ => super.canPlaceBlockOnSide(world, x, y, z, side, stack)
}
override def canBeReplacedByLeaves(world: World, x: Int, y: Int, z: Int) = false
override def canCreatureSpawn(creature: EnumCreatureType, world: World, x: Int, y: Int, z: Int) = false
override def damageDropped(metadata: Int) =
subBlock(metadata) match {
case Some(subBlock) => subBlock.damageDropped
case _ => super.damageDropped(metadata)
}
override def dropBlockAsItemWithChance(world: World, x: Int, y: Int, z: Int, metadata: Int, chance: Float, fortune: Int) =
subBlock(metadata) match {
case Some(subBlock) if subBlock.dropBlockAsItemWithChance(world, x, y, z, chance, fortune) => // Delegate took care of it.
case _ => super.dropBlockAsItemWithChance(world, x, y, z, metadata, chance, fortune)
}
def dropBlockAsItem(world: World, x: Int, y: Int, z: Int, stack: ItemStack) {
dropBlockAsItem_do(world, x, y, z, stack)
}
override def getPickBlock(target: MovingObjectPosition, world: World, x: Int, y: Int, z: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.pickBlock(target, world, x, y, z)
case _ => super.getPickBlock(target, world, x, y, z)
}
override def getRenderColor(metadata: Int) =
subBlock(metadata) match {
case Some(subBlock) => subBlock.getRenderColor
case _ => super.getRenderColor(metadata)
}
override def colorMultiplier(world: IBlockAccess, x: Int, y: Int, z: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.colorMultiplier(world, x, y, z)
case _ => super.colorMultiplier(world, x, y, z)
}
override def getDamageValue(world: World, x: Int, y: Int, z: Int) = world.getBlockMetadata(x, y, z)
override def canConnectRedstone(world: IBlockAccess, x: Int, y: Int, z: Int, side: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.canConnectRedstone(
world, x, y, z, side match {
case -1 => ForgeDirection.UP
case 0 => ForgeDirection.NORTH
case 1 => ForgeDirection.EAST
case 2 => ForgeDirection.SOUTH
case 3 => ForgeDirection.WEST
})
case _ => false
}
override def collisionRayTrace(world: World, x: Int, y: Int, z: Int, origin: Vec3, direction: Vec3) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.collisionRayTrace(world, x, y, z, origin, direction)
case _ => super.collisionRayTrace(world, x, y, z, origin, direction)
}
// Allow delegates to fall back to the default implementation.
def superCollisionRayTrace(world: World, x: Int, y: Int, z: Int, origin: Vec3, direction: Vec3) =
super.collisionRayTrace(world, x, y, z, origin, direction)
override def createTileEntity(world: World, metadata: Int): TileEntity =
subBlock(metadata) match {
case Some(subBlock) => subBlock.createTileEntity(world).orNull
case _ => null
}
override def getCollisionBoundingBoxFromPool(world: World, x: Int, y: Int, z: Int) = {
setBlockBoundsBasedOnState(world, x, y, z)
super.getCollisionBoundingBoxFromPool(world, x, y, z)
}
override def getBlockTexture(world: IBlockAccess, x: Int, y: Int, z: Int, side: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) =>
val orientation = ForgeDirection.getOrientation(side)
subBlock.getBlockTextureFromSide(world, x, y, z, orientation, toLocal(world, x, y, z, orientation)) match {
case Some(icon) => icon
case _ => super.getBlockTexture(world, x, y, z, side)
}
case _ => super.getBlockTexture(world, x, y, z, side)
}
override def getLightValue(world: IBlockAccess, x: Int, y: Int, z: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.getLightValue(world, x, y, z)
case _ => 0
}
override def getIcon(side: Int, metadata: Int) =
subBlock(metadata) match {
case Some(subBlock) => subBlock.icon(ForgeDirection.getOrientation(side)) match {
case Some(icon) => icon
case _ => super.getIcon(side, metadata)
}
case _ => super.getIcon(side, metadata)
}
override def getLightOpacity(world: World, x: Int, y: Int, z: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.getLightOpacity(world, x, y, z)
case _ => 255
}
override def getSubBlocks(itemId: Int, creativeTab: CreativeTabs, list: util.List[_]) = {
// Workaround for MC's untyped lists...
def add[T](list: util.List[T], value: Any) = list.add(value.asInstanceOf[T])
(0 until subBlocks.length).filter(id => subBlocks(id).showInItemList).
foreach(id => add(list, new ItemStack(this, 1, id)))
}
override def getRenderType = BlockRenderer.getRenderId
def getUnlocalizedName(metadata: Int) =
subBlock(metadata) match {
case Some(subBlock) => subBlock.unlocalizedName
case _ => Settings.namespace + "block"
}
override def getValidRotations(world: World, x: Int, y: Int, z: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.getValidRotations(world, x, y, z)
case _ => super.getValidRotations(world, x, y, z)
override def damageDropped(metadata: Int) =
subBlock(metadata) match {
case Some(subBlock) => subBlock.itemDamage
case _ => super.damageDropped(metadata)
}
override def hasTileEntity(metadata: Int) = subBlock(metadata) match {
case Some(subBlock) => subBlock.hasTileEntity
case _ => false
override def getDamageValue(world: World, x: Int, y: Int, z: Int) = world.getBlockMetadata(x, y, z)
override def getPickBlock(target: MovingObjectPosition, world: World, x: Int, y: Int, z: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.pick(target, world, x, y, z)
case _ => super.getPickBlock(target, world, x, y, z)
}
override def dropBlockAsItemWithChance(world: World, x: Int, y: Int, z: Int, metadata: Int, chance: Float, fortune: Int) =
subBlock(metadata) match {
case Some(subBlock) if subBlock.drop(world, x, y, z, chance, fortune) => // Delegate took care of it.
case _ => super.dropBlockAsItemWithChance(world, x, y, z, metadata, chance, fortune)
}
def dropBlockAsItem(world: World, x: Int, y: Int, z: Int, stack: ItemStack) {
dropBlockAsItem_do(world, x, y, z, stack)
}
override def isBlockNormalCube(world: World, x: Int, y: Int, z: Int) =
subBlock(world.getBlockMetadata(x, y, z)) match {
case Some(subBlock) => subBlock.isBlockNormalCube(world, x, y, z)
case Some(subBlock) => subBlock.isNormalCube(world, x, y, z)
case _ => false
}
override def getValidRotations(world: World, x: Int, y: Int, z: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.validRotations(world, x, y, z)
case _ => super.getValidRotations(world, x, y, z)
}
override def canPlaceBlockOnSide(world: World, x: Int, y: Int, z: Int, side: Int, stack: ItemStack) =
subBlock(stack) match {
case Some(subBlock) => subBlock.canPlaceBlockOnSide(world, x, y, z, ForgeDirection.getOrientation(side).getOpposite)
case _ => super.canPlaceBlockOnSide(world, x, y, z, side, stack)
}
override def getCollisionBoundingBoxFromPool(world: World, x: Int, y: Int, z: Int) = {
setBlockBoundsBasedOnState(world, x, y, z)
super.getCollisionBoundingBoxFromPool(world, x, y, z)
}
override def setBlockBoundsBasedOnState(world: IBlockAccess, x: Int, y: Int, z: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.updateBounds(world, x, y, z)
case _ =>
}
def setBlockBounds(bounds: AxisAlignedBB) {
setBlockBounds(
bounds.minX.toFloat, bounds.minY.toFloat, bounds.minZ.toFloat,
bounds.maxX.toFloat, bounds.maxY.toFloat, bounds.maxZ.toFloat)
}
override def collisionRayTrace(world: World, x: Int, y: Int, z: Int, origin: Vec3, direction: Vec3) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.intersect(world, x, y, z, origin, direction)
case _ => super.collisionRayTrace(world, x, y, z, origin, direction)
}
// Allow delegates to fall back to the default implementation.
def superCollisionRayTrace(world: World, x: Int, y: Int, z: Int, origin: Vec3, direction: Vec3) =
super.collisionRayTrace(world, x, y, z, origin, direction)
override def rotateBlock(world: World, x: Int, y: Int, z: Int, axis: ForgeDirection) =
world.getBlockTileEntity(x, y, z) match {
case rotatable: tileentity.Rotatable if rotatable.rotate(axis) =>
world.markBlockForRenderUpdate(x, y, z)
true
case _ => false
}
// ----------------------------------------------------------------------- //
override def canConnectRedstone(world: IBlockAccess, x: Int, y: Int, z: Int, side: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.canConnectToRedstone(
world, x, y, z, side match {
case -1 => ForgeDirection.UP
case 0 => ForgeDirection.NORTH
case 1 => ForgeDirection.EAST
case 2 => ForgeDirection.SOUTH
case 3 => ForgeDirection.WEST
})
case _ => false
}
@ -273,68 +208,133 @@ class Delegator[Child <: Delegate](id: Int) extends Block(id, Material.iron) {
case _ => 0
}
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, side: Int, hitX: Float, hitY: Float, hitZ: Float): Boolean = {
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.onBlockActivated(
world, x, y, z, player, ForgeDirection.getOrientation(side), hitX, hitY, hitZ)
case _ => false
}
// ----------------------------------------------------------------------- //
override def hasTileEntity(metadata: Int) = subBlock(metadata) match {
case Some(subBlock) => subBlock.hasTileEntity
case _ => false
}
override def createTileEntity(world: World, metadata: Int): TileEntity =
subBlock(metadata) match {
case Some(subBlock) => subBlock.createTileEntity(world).orNull
case _ => null
}
// ----------------------------------------------------------------------- //
override def updateTick(world: World, x: Int, y: Int, z: Int, rng: Random) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.update(world, x, y, z)
case _ =>
}
override def onBlockAdded(world: World, x: Int, y: Int, z: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.onBlockAdded(world, x, y, z)
case Some(subBlock) => subBlock.addedToWorld(world, x, y, z)
case _ => // Invalid but avoid match error.
}
override def onBlockPlacedBy(world: World, x: Int, y: Int, z: Int, player: EntityLivingBase, stack: ItemStack) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.onBlockPlacedBy(world, x, y, z, player, stack)
case Some(subBlock) => subBlock.addedByEntity(world, x, y, z, player, stack)
case _ => // Invalid but avoid match error.
}
override def onBlockPreDestroy(world: World, x: Int, y: Int, z: Int, metadata: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.onBlockPreDestroy(world, x, y, z)
case Some(subBlock) => subBlock.aboutToBeRemoved(world, x, y, z)
case _ => // Invalid but avoid match error.
}
override def onNeighborBlockChange(world: World, x: Int, y: Int, z: Int, blockId: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.onNeighborBlockChange(world, x, y, z, blockId)
override def breakBlock(world: World, x: Int, y: Int, z: Int, blockId: Int, metadata: Int) = {
subBlock(metadata) match {
case Some(subBlock) => subBlock.removedFromWorld(world, x, y, z, blockId)
case _ => // Invalid but avoid match error.
}
override def registerIcons(iconRegister: IconRegister) = {
super.registerIcons(iconRegister)
subBlocks.foreach(_.registerIcons(iconRegister))
super.breakBlock(world, x, y, z, blockId, metadata)
}
override def removeBlockByPlayer(world: World, player: EntityPlayer, x: Int, y: Int, z: Int) =
(subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.onBlockRemovedBy(world, x, y, z, player)
case Some(subBlock) => subBlock.removedByEntity(world, x, y, z, player)
case _ => true
}) && super.removeBlockByPlayer(world, player, x, y, z)
override def rotateBlock(world: World, x: Int, y: Int, z: Int, axis: ForgeDirection) =
world.getBlockTileEntity(x, y, z) match {
case rotatable: tileentity.Rotatable if rotatable.rotate(axis) =>
world.markBlockForRenderUpdate(x, y, z)
true
case _ => false
override def onNeighborBlockChange(world: World, x: Int, y: Int, z: Int, blockId: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.neighborBlockChanged(world, x, y, z, blockId)
case _ => // Invalid but avoid match error.
}
def setBlockBounds(bounds: AxisAlignedBB) {
setBlockBounds(
bounds.minX.toFloat, bounds.minY.toFloat, bounds.minZ.toFloat,
bounds.maxX.toFloat, bounds.maxY.toFloat, bounds.maxZ.toFloat)
override def onBlockClicked(world: World, x: Int, y: Int, z: Int, player: EntityPlayer) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.leftClick(world, x, y, z, player)
case _ =>
}
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, side: Int, hitX: Float, hitY: Float, hitZ: Float): Boolean = {
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.rightClick(
world, x, y, z, player, ForgeDirection.getOrientation(side), hitX, hitY, hitZ)
case _ => false
}
}
override def setBlockBoundsBasedOnState(world: IBlockAccess, x: Int, y: Int, z: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.setBlockBoundsBasedOnState(world, x, y, z)
// ----------------------------------------------------------------------- //
def addInformation(metadata: Int, stack: ItemStack, player: EntityPlayer, tooltip: java.util.List[String], advanced: Boolean) {
subBlock(metadata) match {
case Some(subBlock) => subBlock.tooltipLines(stack, player, tooltip, advanced)
case _ =>
}
}
override def getRenderType = BlockRenderer.getRenderId
override def getLightOpacity(world: World, x: Int, y: Int, z: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.opacity(world, x, y, z)
case _ => 255
}
override def getLightValue(world: IBlockAccess, x: Int, y: Int, z: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.luminance(world, x, y, z)
case _ => 0
}
override def getRenderColor(metadata: Int) =
subBlock(metadata) match {
case Some(subBlock) => subBlock.color
case _ => super.getRenderColor(metadata)
}
override def colorMultiplier(world: IBlockAccess, x: Int, y: Int, z: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.color(world, x, y, z)
case _ => super.colorMultiplier(world, x, y, z)
}
override def getIcon(side: Int, metadata: Int) =
subBlock(metadata) match {
case Some(subBlock) => subBlock.icon(ForgeDirection.getOrientation(side)) match {
case Some(icon) => icon
case _ => super.getIcon(side, metadata)
}
case _ => super.getIcon(side, metadata)
}
override def getBlockTexture(world: IBlockAccess, x: Int, y: Int, z: Int, side: Int) =
subBlock(world, x, y, z) match {
case Some(subBlock) =>
val orientation = ForgeDirection.getOrientation(side)
subBlock.icon(world, x, y, z, orientation, toLocal(world, x, y, z, orientation)) match {
case Some(icon) => icon
case _ => super.getBlockTexture(world, x, y, z, side)
}
case _ => super.getBlockTexture(world, x, y, z, side)
}
override def setBlockBoundsForItemRender() {
setBlockBounds(0, 0, 0, 1, 1, 1)
@ -342,7 +342,7 @@ class Delegator[Child <: Delegate](id: Int) extends Block(id, Material.iron) {
def setBlockBoundsForItemRender(metadata: Int): Unit =
subBlock(metadata) match {
case Some(subBlock) => subBlock.setBlockBoundsForItemRender()
case Some(subBlock) => subBlock.itemBounds()
case _ => setBlockBoundsForItemRender()
}
@ -352,11 +352,10 @@ class Delegator[Child <: Delegate](id: Int) extends Block(id, Material.iron) {
case _ =>
}
override def updateTick(world: World, x: Int, y: Int, z: Int, rng: Random) =
subBlock(world, x, y, z) match {
case Some(subBlock) => subBlock.update(world, x, y, z)
case _ =>
}
override def registerIcons(iconRegister: IconRegister) = {
super.registerIcons(iconRegister)
subBlocks.foreach(_.registerIcons(iconRegister))
}
}
object Delegator {
@ -384,16 +383,16 @@ object Delegator {
class SimpleDelegator(id: Int) extends Delegator[SimpleDelegate](id)
class SpecialDelegator(id: Int) extends Delegator[SpecialDelegate](id) {
override def isBlockSolid(world: IBlockAccess, x: Int, y: Int, z: Int, side: Int) =
subBlock(world.getBlockMetadata(x, y, z)) match {
case Some(subBlock) => subBlock.isBlockSolid(world, x, y, z, ForgeDirection.getOrientation(side))
case _ => true
}
override def isOpaqueCube = false
override def renderAsNormalBlock = false
override def isBlockSolid(world: IBlockAccess, x: Int, y: Int, z: Int, side: Int) =
subBlock(world.getBlockMetadata(x, y, z)) match {
case Some(subBlock) => subBlock.isSolid(world, x, y, z, ForgeDirection.getOrientation(side))
case _ => true
}
override def shouldSideBeRendered(world: IBlockAccess, x: Int, y: Int, z: Int, side: Int) = {
val direction = ForgeDirection.getOrientation(side)
subBlock(world.getBlockMetadata(x - direction.offsetX, y - direction.offsetY, z - direction.offsetZ)) match {

View File

@ -19,7 +19,7 @@ class DiskDrive(val parent: SimpleDelegator) extends SimpleDelegate {
// ----------------------------------------------------------------------- //
override def addInformation(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
override def tooltipLines(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
tooltip.addAll(Tooltip.get(unlocalizedName))
if (Loader.isModLoaded("ComputerCraft")) {
tooltip.addAll(Tooltip.get(unlocalizedName + ".CC"))
@ -52,8 +52,8 @@ class DiskDrive(val parent: SimpleDelegator) extends SimpleDelegate {
// ----------------------------------------------------------------------- //
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer,
side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = {
override def rightClick(world: World, x: Int, y: Int, z: Int, player: EntityPlayer,
side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = {
if (!player.isSneaking) {
if (!world.isRemote) {
player.openGui(OpenComputers, GuiType.DiskDrive.id, world, x, y, z)

View File

@ -18,7 +18,7 @@ class Keyboard(val parent: SpecialDelegator) extends SpecialDelegate {
var icon: Icon = null
override def addInformation(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
override def tooltipLines(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
tooltip.addAll(Tooltip.get(unlocalizedName))
}
@ -46,17 +46,17 @@ class Keyboard(val parent: SpecialDelegator) extends SpecialDelegate {
case _ => false
}
override def isBlockNormalCube(world: World, x: Int, y: Int, z: Int) = false
override def isNormalCube(world: World, x: Int, y: Int, z: Int) = false
override def getLightOpacity(world: World, x: Int, y: Int, z: Int) = 0
override def opacity(world: World, x: Int, y: Int, z: Int) = 0
override def setBlockBoundsBasedOnState(world: IBlockAccess, x: Int, y: Int, z: Int) =
override def updateBounds(world: IBlockAccess, x: Int, y: Int, z: Int) =
world.getBlockTileEntity(x, y, z) match {
case keyboard: tileentity.Keyboard => parent.setBlockBounds(computeBounds(keyboard.pitch, keyboard.yaw))
case _ => super.setBlockBoundsBasedOnState(world, x, y, z)
case _ => super.updateBounds(world, x, y, z)
}
override def setBlockBoundsForItemRender() {
override def itemBounds() {
parent.setBlockBounds(computeBounds(ForgeDirection.NORTH, ForgeDirection.WEST))
}
@ -83,7 +83,7 @@ class Keyboard(val parent: SpecialDelegator) extends SpecialDelegate {
(x0 max x1) + 0.5f, (y0 max y1) + 0.5f, (z0 max z1) + 0.5f)
}
override def onNeighborBlockChange(world: World, x: Int, y: Int, z: Int, blockId: Int) =
override def neighborBlockChanged(world: World, x: Int, y: Int, z: Int, blockId: Int) =
world.getBlockTileEntity(x, y, z) match {
case keyboard: tileentity.Keyboard if canPlaceBlockOnSide(world, x, y, z, keyboard.facing.getOpposite) => // Can stay.
case _ =>
@ -91,7 +91,7 @@ class Keyboard(val parent: SpecialDelegator) extends SpecialDelegate {
world.setBlockToAir(x, y, z)
}
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) =
override def rightClick(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) =
world.getBlockTileEntity(x, y, z) match {
case keyboard: tileentity.Keyboard =>
val (sx, sy, sz) = (
@ -99,11 +99,11 @@ class Keyboard(val parent: SpecialDelegator) extends SpecialDelegate {
y + keyboard.facing.getOpposite.offsetY,
z + keyboard.facing.getOpposite.offsetZ)
Delegator.subBlock(world, sx, sy, sz) match {
case Some(screen: Screen) => screen.onBlockActivated(world, sx, sy, sz, player, keyboard.facing.getOpposite, 0, 0, 0)
case _ => super.onBlockActivated(world, x, y, z, player, side, hitX, hitY, hitZ)
case Some(screen: Screen) => screen.rightClick(world, sx, sy, sz, player, keyboard.facing.getOpposite, 0, 0, 0)
case _ => super.rightClick(world, x, y, z, player, side, hitX, hitY, hitZ)
}
case _ => super.onBlockActivated(world, x, y, z, player, side, hitX, hitY, hitZ)
case _ => super.rightClick(world, x, y, z, player, side, hitX, hitY, hitZ)
}
override protected val validRotations = ForgeDirection.VALID_DIRECTIONS
override protected val validRotations_ = ForgeDirection.VALID_DIRECTIONS
}

View File

@ -19,7 +19,7 @@ class PowerConverter(val parent: SimpleDelegator) extends SimpleDelegate {
// ----------------------------------------------------------------------- //
override def addInformation(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
override def tooltipLines(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
tooltip.addAll(Tooltip.get(unlocalizedName))
if (Loader.isModLoaded("IC2")) {
val ratio = Settings.get.ratioIndustrialCraft2

View File

@ -18,7 +18,7 @@ class PowerDistributor(val parent: SimpleDelegator) extends SimpleDelegate {
// ----------------------------------------------------------------------- //
override def addInformation(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
override def tooltipLines(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
tooltip.addAll(Tooltip.get(unlocalizedName))
}
@ -34,7 +34,7 @@ class PowerDistributor(val parent: SimpleDelegator) extends SimpleDelegate {
icons(ForgeDirection.EAST.ordinal) = icons(ForgeDirection.NORTH.ordinal)
}
override def getLightValue(world: IBlockAccess, x: Int, y: Int, z: Int) = 5
override def luminance(world: IBlockAccess, x: Int, y: Int, z: Int) = 5
// ----------------------------------------------------------------------- //

View File

@ -3,40 +3,40 @@ package li.cil.oc.common.block
import li.cil.oc.Blocks
import li.cil.oc.common.tileentity
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.util.MovingObjectPosition
import net.minecraft.world.{IBlockAccess, World}
import net.minecraftforge.common.ForgeDirection
import net.minecraft.util.MovingObjectPosition
class RobotAfterimage(val parent: SpecialDelegator) extends SpecialDelegate {
val unlocalizedName = "RobotAfterimage"
override val showInItemList = false
override def pickBlock(target: MovingObjectPosition, world: World, x: Int, y: Int, z: Int) =
override def pick(target: MovingObjectPosition, world: World, x: Int, y: Int, z: Int) =
findMovingRobot(world, x, y, z) match {
case Some(robot) => robot.createItemStack()
case _ => null
}
override def breakBlock(world: World, x: Int, y: Int, z: Int, blockId: Int) = {
super.breakBlock(world, x, y, z, blockId)
override def removedFromWorld(world: World, x: Int, y: Int, z: Int, blockId: Int) = {
super.removedFromWorld(world, x, y, z, blockId)
findMovingRobot(world, x, y, z) match {
case Some(robot) if robot.isAnimatingMove => world.setBlockToAir(robot.x, robot.y, robot.z)
case _ => // Probably broken by the robot we represent.
}
}
override def damageDropped = Blocks.robotProxy.blockId
override def itemDamage = Blocks.robotProxy.blockId
override def getLightOpacity(world: World, x: Int, y: Int, z: Int) = 0
override def opacity(world: World, x: Int, y: Int, z: Int) = 0
override def isBlockNormalCube(world: World, x: Int, y: Int, z: Int) = false
override def isNormalCube(world: World, x: Int, y: Int, z: Int) = false
override def isBlockSolid(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) = false
override def isSolid(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) = false
override def shouldSideBeRendered(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) = false
override def setBlockBoundsBasedOnState(world: IBlockAccess, x: Int, y: Int, z: Int) = {
override def updateBounds(world: IBlockAccess, x: Int, y: Int, z: Int) = {
findMovingRobot(world, x, y, z) match {
case Some(robot) =>
val block = robot.getBlockType
@ -52,7 +52,7 @@ class RobotAfterimage(val parent: SpecialDelegator) extends SpecialDelegate {
}
}
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = {
override def rightClick(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = {
findMovingRobot(world, x, y, z) match {
case Some(robot) => robot.getBlockType.onBlockActivated(world, robot.x, robot.y, robot.z, player, side.ordinal, hitX, hitY, hitZ)
case _ => world.setBlockToAir(x, y, z)

View File

@ -21,14 +21,14 @@ class RobotProxy(val parent: SpecialDelegator) extends Computer with SpecialDele
// ----------------------------------------------------------------------- //
override def addInformation(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
override def tooltipLines(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
if (stack.hasTagCompound && stack.getTagCompound.hasKey(Settings.namespace + "storedEnergy")) {
tooltip.addAll(Tooltip.get(unlocalizedName + "_StoredEnergy", stack.getTagCompound.getInteger(Settings.namespace + "storedEnergy")))
}
tooltip.addAll(Tooltip.get(unlocalizedName))
}
override def pickBlock(target: MovingObjectPosition, world: World, x: Int, y: Int, z: Int) =
override def pick(target: MovingObjectPosition, world: World, x: Int, y: Int, z: Int) =
world.getBlockTileEntity(x, y, z) match {
case proxy: tileentity.RobotProxy => proxy.robot.createItemStack()
case _ => null
@ -45,25 +45,25 @@ class RobotProxy(val parent: SpecialDelegator) extends Computer with SpecialDele
// ----------------------------------------------------------------------- //
override def isBlockNormalCube(world: World, x: Int, y: Int, z: Int) = false
override def isNormalCube(world: World, x: Int, y: Int, z: Int) = false
override def isBlockSolid(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) = false
override def isSolid(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) = false
override def getLightOpacity(world: World, x: Int, y: Int, z: Int) = 0
override def opacity(world: World, x: Int, y: Int, z: Int) = 0
override def shouldSideBeRendered(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) = false
// ----------------------------------------------------------------------- //
override def dropBlockAsItemWithChance(world: World, x: Int, y: Int, z: Int, chance: Float, fortune: Int) = true
override def drop(world: World, x: Int, y: Int, z: Int, chance: Float, fortune: Int) = true
override def collisionRayTrace(world: World, x: Int, y: Int, z: Int, origin: Vec3, direction: Vec3) = {
override def intersect(world: World, x: Int, y: Int, z: Int, origin: Vec3, direction: Vec3) = {
val bounds = parent.getCollisionBoundingBoxFromPool(world, x, y, z)
if (bounds.isVecInside(origin)) null
else super.collisionRayTrace(world, x, y, z, origin, direction)
else super.intersect(world, x, y, z, origin, direction)
}
override def setBlockBoundsBasedOnState(world: IBlockAccess, x: Int, y: Int, z: Int) {
override def updateBounds(world: IBlockAccess, x: Int, y: Int, z: Int) {
world.getBlockTileEntity(x, y, z) match {
case proxy: tileentity.RobotProxy =>
val robot = proxy.robot
@ -76,12 +76,12 @@ class RobotProxy(val parent: SpecialDelegator) extends Computer with SpecialDele
-robot.moveDirection.offsetZ * remaining)
}
parent.setBlockBounds(bounds)
case _ => super.setBlockBoundsBasedOnState(world, x, y, z)
case _ => super.updateBounds(world, x, y, z)
}
}
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer,
side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = {
override def rightClick(world: World, x: Int, y: Int, z: Int, player: EntityPlayer,
side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = {
if (!player.isSneaking) {
if (!world.isRemote) {
player.openGui(OpenComputers, GuiType.Robot.id, world, x, y, z)
@ -91,8 +91,8 @@ class RobotProxy(val parent: SpecialDelegator) extends Computer with SpecialDele
else false
}
override def onBlockPlacedBy(world: World, x: Int, y: Int, z: Int, entity: EntityLivingBase, stack: ItemStack) {
super.onBlockPlacedBy(world, x, y, z, entity, stack)
override def addedByEntity(world: World, x: Int, y: Int, z: Int, entity: EntityLivingBase, stack: ItemStack) {
super.addedByEntity(world, x, y, z, entity, stack)
if (!world.isRemote) ((entity, world.getBlockTileEntity(x, y, z)) match {
case (player: robot.Player, proxy: tileentity.RobotProxy) =>
Some((proxy.robot, player.robot.owner))
@ -107,18 +107,18 @@ class RobotProxy(val parent: SpecialDelegator) extends Computer with SpecialDele
}
}
override def onBlockRemovedBy(world: World, x: Int, y: Int, z: Int, player: EntityPlayer) = {
override def removedByEntity(world: World, x: Int, y: Int, z: Int, player: EntityPlayer) = {
if (!world.isRemote) world.getBlockTileEntity(x, y, z) match {
case proxy: tileentity.RobotProxy if !player.capabilities.isCreativeMode || proxy.globalBuffer > 1 =>
parent.dropBlockAsItem(world, x, y, z, proxy.robot.createItemStack())
case _ =>
}
super.onBlockRemovedBy(world, x, y, z, player)
super.removedByEntity(world, x, y, z, player)
}
override def onBlockPreDestroy(world: World, x: Int, y: Int, z: Int) {
override def aboutToBeRemoved(world: World, x: Int, y: Int, z: Int) {
if (moving.get.isEmpty) {
super.onBlockPreDestroy(world, x, y, z)
super.aboutToBeRemoved(world, x, y, z)
}
}
}

View File

@ -19,7 +19,7 @@ class Router(val parent: SimpleDelegator) extends SimpleDelegate {
// ----------------------------------------------------------------------- //
override def addInformation(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
override def tooltipLines(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
tooltip.addAll(Tooltip.get(unlocalizedName))
}

View File

@ -18,7 +18,7 @@ abstract class Screen(val parent: SimpleDelegator) extends SimpleDelegate {
def tier: Int
override def addInformation(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
override def tooltipLines(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
val (w, h) = Settings.screenResolutionsByTier(tier)
val depth = PackedColor.Depth.bits(Settings.screenDepthsByTier(tier))
tooltip.addAll(Tooltip.get("Screen", w, h, depth))
@ -71,7 +71,7 @@ abstract class Screen(val parent: SimpleDelegator) extends SimpleDelegate {
// This an ugly monstrosity, but it's still better than having to manually
// compute ambient occlusion in a custom block renderer to keep the lighting
// pretty... which would be even more grotesque.
override def getBlockTextureFromSide(world: IBlockAccess, x: Int, y: Int, z: Int, worldSide: ForgeDirection, localSide: ForgeDirection) =
override def icon(world: IBlockAccess, x: Int, y: Int, z: Int, worldSide: ForgeDirection, localSide: ForgeDirection) =
world.getBlockTileEntity(x, y, z) match {
case screen: tileentity.Screen if screen.width > 1 || screen.height > 1 =>
val (w, h) = (screen.width, screen.height)
@ -273,7 +273,7 @@ abstract class Screen(val parent: SimpleDelegator) extends SimpleDelegate {
Icons.fvt = iconRegister.registerIcon(Settings.resourceDomain + ":screen/fvt")
}
override def getLightValue(world: IBlockAccess, x: Int, y: Int, z: Int) = 5
override def luminance(world: IBlockAccess, x: Int, y: Int, z: Int) = 5
// ----------------------------------------------------------------------- //
@ -283,8 +283,8 @@ abstract class Screen(val parent: SimpleDelegator) extends SimpleDelegate {
// ----------------------------------------------------------------------- //
override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer,
side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) =
override def rightClick(world: World, x: Int, y: Int, z: Int, player: EntityPlayer,
side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) =
if (!player.isSneaking) {
world.getBlockTileEntity(x, y, z) match {
case screen: tileentity.Screen if screen.hasKeyboard =>
@ -297,7 +297,7 @@ abstract class Screen(val parent: SimpleDelegator) extends SimpleDelegate {
// ----------------------------------------------------------------------- //
override protected val validRotations = ForgeDirection.VALID_DIRECTIONS
override protected val validRotations_ = ForgeDirection.VALID_DIRECTIONS
}
object Screen {
@ -307,7 +307,7 @@ object Screen {
def tier = 0
override def getRenderColor = 0x7F7F7F
override def color = 0x7F7F7F
}
class Tier2(parent: SimpleDelegator) extends Screen(parent) {
@ -315,7 +315,7 @@ object Screen {
def tier = 1
override def getRenderColor = 0xFFFF66
override def color = 0xFFFF66
}
class Tier3(parent: SimpleDelegator) extends Screen(parent) {
@ -323,7 +323,7 @@ object Screen {
def tier = 2
override def getRenderColor = 0x66FFFF
override def color = 0x66FFFF
}
}