Search in sources :

Example 1 with IScannableBlock

use of gregtech.api.items.toolitem.IScannableBlock in project GregTech by GregTechCE.

the class ScannerBehavior method onItemUseFinish.

@Override
public ItemStack onItemUseFinish(ItemStack stack, EntityPlayer player) {
    if (!player.world.isRemote) {
        Pair<BlockPos, IBlockState> hitBlock = getHitBlock(player);
        if (hitBlock != null && checkCanUseScanner(stack, player, false).getLeft() == null) {
            ITextComponent component = new TextComponentTranslation("behavior.scanner.analyzing_complete");
            component.getStyle().setColor(TextFormatting.GOLD);
            player.sendStatusMessage(component, true);
            IScannableBlock magnifiableBlock = ((IScannableBlock) hitBlock.getRight().getBlock());
            List<ITextComponent> text = magnifiableBlock.getMagnifyResults(player.world, hitBlock.getLeft(), hitBlock.getRight(), player);
            text.forEach(player::sendMessage);
        }
    }
    return stack;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IBlockState(net.minecraft.block.state.IBlockState) IScannableBlock(gregtech.api.items.toolitem.IScannableBlock) ITextComponent(net.minecraft.util.text.ITextComponent) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with IScannableBlock

use of gregtech.api.items.toolitem.IScannableBlock in project GregTech by GregTechCE.

the class ScannerBehavior method getHitBlock.

private Pair<BlockPos, IBlockState> getHitBlock(EntityPlayer entityPlayer) {
    RayTraceResult result = RayTracer.retrace(entityPlayer);
    if (result.typeOfHit == Type.BLOCK) {
        BlockPos blockPos = result.getBlockPos();
        IBlockState blockState = entityPlayer.world.getBlockState(blockPos);
        if (blockState.getBlock() instanceof IScannableBlock) {
            return Pair.of(blockPos, blockState);
        }
    }
    return null;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IScannableBlock(gregtech.api.items.toolitem.IScannableBlock) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with IScannableBlock

use of gregtech.api.items.toolitem.IScannableBlock in project GregTech by GregTechCE.

the class ScannerBehavior method checkCanUseScanner.

private Pair<String, Integer> checkCanUseScanner(ItemStack itemStack, EntityPlayer player, boolean simulate) {
    Pair<BlockPos, IBlockState> hitBlock = getHitBlock(player);
    if (hitBlock == null) {
        return Pair.of("behavior.scanner.analyzing_failed", 0);
    }
    IBlockState state = hitBlock.getRight();
    long amount = ((IScannableBlock) state.getBlock()).getScanDuration(player.world, hitBlock.getLeft(), state, player);
    if (!dischargeItem(itemStack, amount, simulate)) {
        return Pair.of("metaitem.scanner.not_enough_energy", 0);
    }
    int maxHitUse = ((IScannableBlock) state.getBlock()).getScanDuration(player.world, hitBlock.getLeft(), state, player);
    return Pair.of(null, maxHitUse);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IScannableBlock(gregtech.api.items.toolitem.IScannableBlock) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

IScannableBlock (gregtech.api.items.toolitem.IScannableBlock)3 IBlockState (net.minecraft.block.state.IBlockState)3 BlockPos (net.minecraft.util.math.BlockPos)3 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1