Search in sources :

Example 1 with MultiblockTileEntityForestry

use of forestry.core.multiblock.MultiblockTileEntityForestry in project ForestryMC by ForestryMC.

the class BlockStructure method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (playerIn.isSneaking()) {
        return false;
    }
    MultiblockTileEntityForestry part = TileUtil.getTile(worldIn, pos, MultiblockTileEntityForestry.class);
    if (part == null) {
        return false;
    }
    IMultiblockController controller = part.getMultiblockLogic().getController();
    ItemStack heldItem = playerIn.getHeldItem(hand);
    // multiblock-debugging message if the machine is not assembled.
    if (heldItem.isEmpty()) {
        if (controller != null) {
            if (!controller.isAssembled()) {
                String validationError = controller.getLastValidationError();
                if (validationError != null) {
                    long tick = worldIn.getTotalWorldTime();
                    if (tick > previousMessageTick + 20) {
                        playerIn.sendMessage(new TextComponentString(validationError));
                        previousMessageTick = tick;
                    }
                    return true;
                }
            }
        } else {
            playerIn.sendMessage(new TextComponentTranslation("for.multiblock.error.notConnected"));
            return true;
        }
    }
    // Don't open the GUI if the multiblock isn't assembled
    if (controller == null || !controller.isAssembled()) {
        return false;
    }
    if (!worldIn.isRemote) {
        part.openGui(playerIn);
    }
    return true;
}
Also used : IMultiblockController(forestry.api.multiblock.IMultiblockController) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) MultiblockTileEntityForestry(forestry.core.multiblock.MultiblockTileEntityForestry) TextComponentString(net.minecraft.util.text.TextComponentString) ItemStack(net.minecraft.item.ItemStack) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 2 with MultiblockTileEntityForestry

use of forestry.core.multiblock.MultiblockTileEntityForestry in project ForestryMC by ForestryMC.

the class BlockGreenhouse method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (playerIn.isSneaking()) {
        return false;
    }
    MultiblockTileEntityForestry part = TileUtil.getTile(worldIn, pos, MultiblockTileEntityForestry.class);
    if (part == null) {
        return false;
    }
    IMultiblockController controller = part.getMultiblockLogic().getController();
    ItemStack mainHand = playerIn.getHeldItemMainhand();
    if (mainHand.isEmpty()) {
        if (playerIn.getHeldItemOffhand().isEmpty()) {
            // multiblock-debugging message if the machine is not assembled.
            if (!controller.isAssembled()) {
                String validationError = controller.getLastValidationError();
                if (validationError != null) {
                    long tick = worldIn.getTotalWorldTime();
                    if (tick > previousMessageTick + 20) {
                        playerIn.sendMessage(new TextComponentString(validationError));
                        previousMessageTick = tick;
                    }
                    return true;
                }
            }
        }
    }
    // Don't open the GUI if the multiblock isn't assembled
    if (!controller.isAssembled()) {
        return false;
    }
    if (!worldIn.isRemote) {
        part.openGui(playerIn);
    }
    return true;
}
Also used : IMultiblockController(forestry.api.multiblock.IMultiblockController) MultiblockTileEntityForestry(forestry.core.multiblock.MultiblockTileEntityForestry) TextComponentString(net.minecraft.util.text.TextComponentString) ItemStack(net.minecraft.item.ItemStack) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

IMultiblockController (forestry.api.multiblock.IMultiblockController)2 MultiblockTileEntityForestry (forestry.core.multiblock.MultiblockTileEntityForestry)2 ItemStack (net.minecraft.item.ItemStack)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1