blob: 1d799797f85e9f5678a3b5d7e6df1647ba1f8e6a [file] [log] [blame] [raw]
package li.cil.oc.common.block
import cpw.mods.fml.relauncher.Side
import cpw.mods.fml.relauncher.SideOnly
import li.cil.oc.OpenComputers
import li.cil.oc.client.Textures
import li.cil.oc.common.GuiType
import li.cil.oc.common.tileentity
import net.minecraft.client.renderer.texture.IIconRegister
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.world.IBlockAccess
import net.minecraft.world.World
import net.minecraftforge.common.util.ForgeDirection
class ServerRack extends RedstoneAware with traits.SpecialBlock with traits.PowerAcceptor {
override protected def customTextures = Array(
None,
None,
Some("ServerRackSide"),
Some("ServerRackFront"),
Some("ServerRackSide"),
Some("ServerRackSide")
)
override def registerBlockIcons(iconRegister: IIconRegister) = {
super.registerBlockIcons(iconRegister)
System.arraycopy(icons, 0, Textures.ServerRack.icons, 0, icons.length)
}
@SideOnly(Side.CLIENT)
override def getMixedBrightnessForBlock(world: IBlockAccess, x: Int, y: Int, z: Int) = {
world.getTileEntity(x, y, z) match {
case rack: tileentity.ServerRack =>
def brightness(x: Int, y: Int, z: Int) = world.getLightBrightnessForSkyBlocks(x, y, z, getLightValue(world, x, y, z))
val value = brightness(x + rack.facing.offsetX, y + rack.facing.offsetY, z + rack.facing.offsetZ)
val skyBrightness = (value >> 20) & 15
val blockBrightness = (value >> 4) & 15
((skyBrightness * 3 / 4) << 20) | ((blockBrightness * 3 / 4) << 4)
case _ => super.getMixedBrightnessForBlock(world, x, y, z)
}
}
override def isBlockSolid(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) = side == ForgeDirection.SOUTH
// ----------------------------------------------------------------------- //
override def hasTileEntity(metadata: Int) = true
override def createTileEntity(world: World, metadata: Int) = new tileentity.ServerRack()
// ----------------------------------------------------------------------- //
override def onBlockActivated(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.Rack.id, world, x, y, z)
}
true
}
else false
}
}