- 16
- 1
- 0
При ломании блока кликнув левой клавишей выдается хил, и колдаун на 320 тиков, колдаун выдается но хил и ломания блоков все еще происходит при нажатии левой клавиши.
Код:
public class HealthGadget extends Item {
public HealthGadget(Item.Properties properties) {
super(properties);
}
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
World world = context.getWorld();
if (!world.isRemote) {
PlayerEntity playerEntity = (PlayerEntity)Objects.requireNonNull(context.getPlayer());
BlockState clickedBlock = world.getBlockState(context.getPos());
//playerEntity.getCooldownTracker().setCooldown(getItem(), 320);
this.rightClickOnCertainBlockState(clickedBlock, context, playerEntity);
stack.damageItem(1, playerEntity, (player) -> {
player.sendBreakAnimation(context.getHand());
});
}
return super.onItemUseFirst(stack, context);
}
private void rightClickOnCertainBlockState(BlockState clickedBlock, ItemUseContext context, PlayerEntity playerEntity) {
//playerEntity.getCooldownTracker().setCooldown(getItem(), 320);
boolean playerIsNotOnFire = !playerEntity.isBurning();
if (!(random.nextFloat() > 1.0F) && playerIsNotOnFire && this.blockIsValidForResistance(clickedBlock)) {
//playerEntity.getCooldownTracker().setCooldown(getItem(), 320);
this.gainFireResistanceAndDestroyBlock(playerEntity, context.getWorld(), context.getPos());
}
}
private boolean blockIsValidForResistance(BlockState clickedBlock) {
return clickedBlock.getBlock() == Blocks.TALL_GRASS;
}
private void gainFireResistanceAndDestroyBlock(PlayerEntity playerEntity, World world, BlockPos pos) {
//playerEntity.getCooldownTracker().setCooldown(getItem(), 320);
gainFireResistance(playerEntity);
world.destroyBlock(pos, false);
}
public static void gainFireResistance(PlayerEntity playerEntity) {
playerEntity.addPotionEffect(new EffectInstance(Effects.INSTANT_HEALTH, 1, 1));
}
}