Search in sources :

Example 1 with SmartWrenchSelector

use of mcjty.lib.api.smartwrench.SmartWrenchSelector in project RFTools by McJty.

the class SmartWrenchItem method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = player.getHeldItem(hand);
    if (!world.isRemote) {
        if (player.isSneaking()) {
            // Make sure the block get activated if it is a GenericBlock
            IBlockState state = world.getBlockState(pos);
            Block block = state.getBlock();
            if (block instanceof GenericBlock) {
                if (DimensionalShardBlock.activateBlock(block, world, pos, state, player, hand, facing, hitX, hitY, hitZ)) {
                    return EnumActionResult.SUCCESS;
                }
            }
        }
        SmartWrenchMode mode = getCurrentMode(stack);
        if (mode == SmartWrenchMode.MODE_SELECT) {
            GlobalCoordinate b = getCurrentBlock(stack);
            if (b != null) {
                if (b.getDimension() != world.provider.getDimension()) {
                    Logging.message(player, TextFormatting.RED + "The selected block is in another dimension!");
                    return EnumActionResult.FAIL;
                }
                TileEntity te = world.getTileEntity(b.getCoordinate());
                if (te instanceof SmartWrenchSelector) {
                    SmartWrenchSelector smartWrenchSelector = (SmartWrenchSelector) te;
                    smartWrenchSelector.selectBlock(player, pos);
                }
            }
        }
    }
    return EnumActionResult.SUCCESS;
}
Also used : GenericBlock(mcjty.lib.container.GenericBlock) SmartWrenchMode(mcjty.lib.api.smartwrench.SmartWrenchMode) TileEntity(net.minecraft.tileentity.TileEntity) SmartWrenchSelector(mcjty.lib.api.smartwrench.SmartWrenchSelector) IBlockState(net.minecraft.block.state.IBlockState) DimensionalShardBlock(mcjty.rftools.blocks.ores.DimensionalShardBlock) GenericBlock(mcjty.lib.container.GenericBlock) Block(net.minecraft.block.Block) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) ItemStack(net.minecraft.item.ItemStack)

Aggregations

SmartWrenchMode (mcjty.lib.api.smartwrench.SmartWrenchMode)1 SmartWrenchSelector (mcjty.lib.api.smartwrench.SmartWrenchSelector)1 GenericBlock (mcjty.lib.container.GenericBlock)1 GlobalCoordinate (mcjty.lib.varia.GlobalCoordinate)1 DimensionalShardBlock (mcjty.rftools.blocks.ores.DimensionalShardBlock)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1