Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 3.36 KB | None | 0 0
  1. package com.github.sham1.fluidcraft.machine.block
  2.  
  3. import com.github.sham1.fluidcraft.Fluidcraft
  4. import com.google.common.base.Predicate
  5. import net.minecraft.block.Block
  6. import net.minecraft.block.material.Material
  7. import net.minecraft.block.properties.{IProperty, PropertyBool, PropertyInteger, PropertyDirection}
  8. import net.minecraft.block.state.{BlockState, IBlockState}
  9. import net.minecraft.entity.EntityLivingBase
  10. import net.minecraft.entity.player.EntityPlayer
  11. import net.minecraft.item.ItemStack
  12. import net.minecraft.tileentity.TileEntity
  13. import net.minecraft.util.{BlockPos, EnumFacing}
  14. import net.minecraft.world.{World, IBlockAccess}
  15.  
  16. object FCraftThermalGenBlock extends {
  17.   setCreativeTab(Fluidcraft.fcraftCreativeTab)
  18.  
  19.   final val PROPERTYFACING: PropertyDirection = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL.asInstanceOf[Predicate[_]])
  20.   final val PROPERTYPOWERED: PropertyBool = PropertyBool.create("powered")
  21.  
  22.   override def getStateFromMeta(meta: Int): IBlockState ={
  23.     val facing:EnumFacing = EnumFacing.getHorizontal(meta)
  24.     val poweredBits:Int = (meta & 0x0c) >> 2
  25.     val powered:Boolean = getBooleanFromInt(poweredBits)
  26.  
  27.     this.getDefaultState.withProperty(PROPERTYFACING, facing).withProperty(PROPERTYPOWERED, powered)
  28.   }
  29.  
  30.   override def getMetaFromState(state: IBlockState): Int ={
  31.     val facing:EnumFacing = state.getValue(PROPERTYFACING).asInstanceOf[EnumFacing]
  32.     val powered:Boolean = state.getValue(PROPERTYPOWERED).asInstanceOf[Boolean]
  33.  
  34.     val facingBits = facing.getHorizontalIndex
  35.     val poweredBits = getIntFromBoolean(powered)
  36.  
  37.     facingBits | poweredBits
  38.   }
  39.  
  40.   override def getActualState(state: IBlockState, worldIn: IBlockAccess, pos: BlockPos): IBlockState = state
  41.  
  42.   override def createBlockState(): BlockState = new BlockState(this, PROPERTYFACING.asInstanceOf[IProperty], PROPERTYPOWERED.asInstanceOf[IProperty])
  43.  
  44.   override def onBlockPlacedBy(worldIn: World, pos: BlockPos, state: IBlockState, placer: EntityLivingBase, stack: ItemStack): Unit ={
  45.     var facing:EnumFacing = EnumFacing.NORTH
  46.     if(placer != null)
  47.       facing = EnumFacing.fromAngle(placer.rotationYaw)
  48.  
  49.     if (facing == EnumFacing.NORTH)
  50.       facing = EnumFacing.SOUTH
  51.     else if (facing == EnumFacing.SOUTH)
  52.       facing = EnumFacing.NORTH
  53.     else if (facing == EnumFacing.WEST)
  54.       facing = EnumFacing.EAST
  55.     else if (facing == EnumFacing.EAST)
  56.       facing = EnumFacing.WEST
  57.  
  58.     this.getDefaultState.withProperty(PROPERTYFACING, facing).withProperty(PROPERTYPOWERED, false)
  59.   }
  60.  
  61.   def getIntFromBoolean(value: Boolean): Int = {
  62.     if (!value) {
  63.       return 0
  64.     }
  65.     1
  66.   }
  67.  
  68.   def getBooleanFromInt(value: Int): Boolean = {
  69.     if (value == 0){
  70.       return false
  71.     }
  72.     true
  73.   }
  74.  
  75.   override def hasTileEntity(state: IBlockState): Boolean = true
  76.  
  77.   override def createTileEntity(world: World, state: IBlockState): TileEntity = super.createTileEntity(world, state)
  78.  
  79.   override def onBlockActivated(worldIn: World, pos: BlockPos, state: IBlockState, playerIn: EntityPlayer, side: EnumFacing, hitX: Float, hitY: Float, hitZ: Float): Boolean = {
  80.     val tileEntity:TileEntity = worldIn.getTileEntity(pos)
  81.     if(tileEntity == null || playerIn.isSneaking)
  82.       return false
  83.  
  84.     playerIn.openGui(Fluidcraft, 0, worldIn, pos.getX, pos.getY, pos.getZ)
  85.     true
  86.   }
  87. }with Block(Material.iron)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement