package eiteam.esteemedinnovation.transport.steam; import net.minecraft.block.BlockDirectional; import net.minecraft.block.BlockPistonBase; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; public class BlockValvePipe extends BlockSteamPipe { public static final PropertyDirection FACING = BlockDirectional.FACING; // The actual states used to determine connection sides. public static final PropertyBool NORTH = PropertyBool.create("north"); public static final PropertyBool EAST = PropertyBool.create("east"); public static final PropertyBool SOUTH = PropertyBool.create("south"); public static final PropertyBool WEST = PropertyBool.create("west"); public static final PropertyBool UP = PropertyBool.create("up"); public static final PropertyBool DOWN = PropertyBool.create("down"); @Override public BlockStateContainer createBlockState() { return new BlockStateContainer(this, FACING, NORTH, EAST, SOUTH, WEST, UP, DOWN); } @Override public int getMetaFromState(IBlockState state) { return state.getValue(FACING).getIndex(); } @Override public IBlockState getStateFromMeta(int meta) { return getDefaultState().withProperty(FACING, EnumFacing.getFront(meta)); } @Override public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase elb, ItemStack stack) { world.setBlockState(pos, state.withProperty(FACING, BlockPistonBase.getFacingFromEntity(pos, elb)), 2); } @Override public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) { TileEntity tileEntity = world.getTileEntity(pos); if (tileEntity != null && tileEntity instanceof TileEntityValvePipe && world.getBlockState(neighbor).canProvidePower()) { TileEntityValvePipe valve = (TileEntityValvePipe) tileEntity; boolean isNotPowered = tileEntity.getWorld().isBlockIndirectlyGettingPowered(pos) <= 0; valve.updateRedstoneState(isNotPowered); } } @Override public TileEntity createTileEntity(World world, IBlockState state) { return new TileEntityValvePipe(); } @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { if (heldItem == null || !(heldItem.getItem() instanceof ItemBlock)) { TileEntityValvePipe tile = (TileEntityValvePipe) world.getTileEntity(pos); if (tile != null && !tile.isTurning()) { tile.setTurning(); } } return true; } }