68 lines
2.6 KiB
Java
68 lines
2.6 KiB
Java
package net.minecraft.world.item;
|
|
|
|
import java.util.List;
|
|
import net.minecraft.advancements.CriteriaTriggers;
|
|
import net.minecraft.core.component.DataComponents;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
import net.minecraft.sounds.SoundEvents;
|
|
import net.minecraft.stats.Stats;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.InteractionResultHolder;
|
|
import net.minecraft.world.effect.MobEffectInstance;
|
|
import net.minecraft.world.effect.MobEffects;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.item.alchemy.PotionContents;
|
|
import net.minecraft.world.level.Level;
|
|
|
|
public class OminousBottleItem extends Item {
|
|
private static final int DRINK_DURATION = 32;
|
|
public static final int EFFECT_DURATION = 120000;
|
|
public static final int MIN_AMPLIFIER = 0;
|
|
public static final int MAX_AMPLIFIER = 4;
|
|
|
|
public OminousBottleItem(Item.Properties properties) {
|
|
super(properties);
|
|
}
|
|
|
|
@Override
|
|
public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity livingEntity) {
|
|
if (livingEntity instanceof ServerPlayer serverPlayer) {
|
|
CriteriaTriggers.CONSUME_ITEM.trigger(serverPlayer, stack);
|
|
serverPlayer.awardStat(Stats.ITEM_USED.get(this));
|
|
}
|
|
|
|
if (!level.isClientSide) {
|
|
level.playSound(null, livingEntity.blockPosition(), SoundEvents.OMINOUS_BOTTLE_DISPOSE, livingEntity.getSoundSource(), 1.0F, 1.0F);
|
|
Integer integer = stack.getOrDefault(DataComponents.OMINOUS_BOTTLE_AMPLIFIER, 0);
|
|
livingEntity.addEffect(new MobEffectInstance(MobEffects.BAD_OMEN, 120000, integer, false, false, true));
|
|
}
|
|
|
|
stack.consume(1, livingEntity);
|
|
return stack;
|
|
}
|
|
|
|
@Override
|
|
public int getUseDuration(ItemStack stack, LivingEntity entity) {
|
|
return 32;
|
|
}
|
|
|
|
@Override
|
|
public UseAnim getUseAnimation(ItemStack stack) {
|
|
return UseAnim.DRINK;
|
|
}
|
|
|
|
@Override
|
|
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand usedHand) {
|
|
return ItemUtils.startUsingInstantly(level, player, usedHand);
|
|
}
|
|
|
|
@Override
|
|
public void appendHoverText(ItemStack stack, Item.TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
|
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
|
|
Integer integer = stack.getOrDefault(DataComponents.OMINOUS_BOTTLE_AMPLIFIER, 0);
|
|
List<MobEffectInstance> list = List.of(new MobEffectInstance(MobEffects.BAD_OMEN, 120000, integer, false, false, true));
|
|
PotionContents.addPotionTooltip(list, tooltipComponents::add, 1.0F, context.tickRate());
|
|
}
|
|
}
|