ПКМ по блоку используя предмет: как получить координаты блока?

Версия Minecraft
1.14.4
Необходим следующий функционал: при нажатии ПКМ по блоку с определённым (кастомным) предметом в руке, после валидации этого блока, изменить одно из значений CompoundNBT для предмета. С CompoundNBT вроде разобрался (но буду благодарен, если подскажете более элегантный способ изменения существующего значения), но возник вопрос, как вычислить блок, на который нацелен игрок.


public class LightCollectorItem extends ToolItem:
    @Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
        BlockPos blockPosUnderAim = new BlockPos(0, 0, 0); //todo get correct block
        ItemStack heldItem = playerIn.getHeldItem(handIn);
      
        if (isLightValueValid(worldIn, blockPosUnderAim)) {
            CompoundNBT compoundNBT = heldItem.getTag();

            int lightCounter;
            if (compoundNBT == null) {
                compoundNBT = new CompoundNBT();
                lightCounter = 0;
            } else {
                lightCounter = compoundNBT.getInt(LIGHT_COUNTER_KEY);
            }

            compoundNBT.putInt(LIGHT_COUNTER_KEY, ++lightCounter);
            heldItem.setTag(compoundNBT);
        }
      
        return new ActionResult<>(ActionResultType.SUCCESS, heldItem);
    }
 
201
6
32
Смотри, если ты хочешь получить блок(координаты, свойства и т.д), на который игрок нажал предметом ПКМ, то onItemUse, а если хочешь тот блок, на который он смотрит, то onItemRightClick
 
3,005
192
592
CompoundNBT compoundNBT = heldItem.getTag();

int lightCounter;
if (compoundNBT == null) {
compoundNBT = new CompoundNBT();
lightCounter = 0;
} else {
lightCounter = compoundNBT.getInt(LIGHT_COUNTER_KEY);
}

compoundNBT.putInt(LIGHT_COUNTER_KEY, ++lightCounter);
heldItem.setTag(compoundNBT);
Код:
CompoundNBT tag = heldItem.getOrCreateTag();
tag.putInt(LIGHT_COUNTER_KEY, tag.getInt(LIGHT_COUNTER_KEY)++);
Как-то так вроде лучше?
 
Сверху