Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.github.sham1.fluidcraft.machine.block
- import com.github.sham1.fluidcraft.Fluidcraft
- import com.google.common.base.Predicate
- import net.minecraft.block.Block
- import net.minecraft.block.material.Material
- import net.minecraft.block.properties.{IProperty, PropertyBool, PropertyInteger, PropertyDirection}
- import net.minecraft.block.state.{BlockState, IBlockState}
- import net.minecraft.entity.EntityLivingBase
- import net.minecraft.entity.player.EntityPlayer
- import net.minecraft.item.ItemStack
- import net.minecraft.tileentity.TileEntity
- import net.minecraft.util.{BlockPos, EnumFacing}
- import net.minecraft.world.{World, IBlockAccess}
- object FCraftThermalGenBlock extends {
- setCreativeTab(Fluidcraft.fcraftCreativeTab)
- final val PROPERTYFACING: PropertyDirection = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL.asInstanceOf[Predicate[_]])
- final val PROPERTYPOWERED: PropertyBool = PropertyBool.create("powered")
- override def getStateFromMeta(meta: Int): IBlockState ={
- val facing:EnumFacing = EnumFacing.getHorizontal(meta)
- val poweredBits:Int = (meta & 0x0c) >> 2
- val powered:Boolean = getBooleanFromInt(poweredBits)
- this.getDefaultState.withProperty(PROPERTYFACING, facing).withProperty(PROPERTYPOWERED, powered)
- }
- override def getMetaFromState(state: IBlockState): Int ={
- val facing:EnumFacing = state.getValue(PROPERTYFACING).asInstanceOf[EnumFacing]
- val powered:Boolean = state.getValue(PROPERTYPOWERED).asInstanceOf[Boolean]
- val facingBits = facing.getHorizontalIndex
- val poweredBits = getIntFromBoolean(powered)
- facingBits | poweredBits
- }
- override def getActualState(state: IBlockState, worldIn: IBlockAccess, pos: BlockPos): IBlockState = state
- override def createBlockState(): BlockState = new BlockState(this, PROPERTYFACING.asInstanceOf[IProperty], PROPERTYPOWERED.asInstanceOf[IProperty])
- override def onBlockPlacedBy(worldIn: World, pos: BlockPos, state: IBlockState, placer: EntityLivingBase, stack: ItemStack): Unit ={
- var facing:EnumFacing = EnumFacing.NORTH
- if(placer != null)
- facing = EnumFacing.fromAngle(placer.rotationYaw)
- if (facing == EnumFacing.NORTH)
- facing = EnumFacing.SOUTH
- else if (facing == EnumFacing.SOUTH)
- facing = EnumFacing.NORTH
- else if (facing == EnumFacing.WEST)
- facing = EnumFacing.EAST
- else if (facing == EnumFacing.EAST)
- facing = EnumFacing.WEST
- this.getDefaultState.withProperty(PROPERTYFACING, facing).withProperty(PROPERTYPOWERED, false)
- }
- def getIntFromBoolean(value: Boolean): Int = {
- if (!value) {
- return 0
- }
- 1
- }
- def getBooleanFromInt(value: Int): Boolean = {
- if (value == 0){
- return false
- }
- true
- }
- override def hasTileEntity(state: IBlockState): Boolean = true
- override def createTileEntity(world: World, state: IBlockState): TileEntity = super.createTileEntity(world, state)
- override def onBlockActivated(worldIn: World, pos: BlockPos, state: IBlockState, playerIn: EntityPlayer, side: EnumFacing, hitX: Float, hitY: Float, hitZ: Float): Boolean = {
- val tileEntity:TileEntity = worldIn.getTileEntity(pos)
- if(tileEntity == null || playerIn.isSneaking)
- return false
- playerIn.openGui(Fluidcraft, 0, worldIn, pos.getX, pos.getY, pos.getZ)
- true
- }
- }with Block(Material.iron)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement