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;
}
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;
}
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);
}
Aggregations