2021-06-21 23:49:55 +02:00
|
|
|
package com.minelittlepony.unicopia.item;
|
|
|
|
|
2023-08-14 23:13:29 +02:00
|
|
|
import java.util.Optional;
|
|
|
|
|
2021-06-21 23:49:55 +02:00
|
|
|
import net.minecraft.advancement.criterion.Criteria;
|
|
|
|
import net.minecraft.entity.LivingEntity;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.server.network.ServerPlayerEntity;
|
|
|
|
import net.minecraft.stat.Stats;
|
|
|
|
import net.minecraft.util.UseAction;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
public class DrinkableItem extends Item {
|
|
|
|
public DrinkableItem(Item.Settings settings) {
|
|
|
|
super(settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) {
|
2023-11-10 15:11:53 +01:00
|
|
|
super.finishUsing(stack, world, user);
|
2021-06-21 23:49:55 +02:00
|
|
|
if (user instanceof ServerPlayerEntity) {
|
|
|
|
ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity)user;
|
|
|
|
Criteria.CONSUME_ITEM.trigger(serverPlayerEntity, stack);
|
|
|
|
serverPlayerEntity.incrementStat(Stats.USED.getOrCreateStat(this));
|
|
|
|
}
|
|
|
|
|
2023-08-14 23:13:29 +02:00
|
|
|
return stack.isEmpty() ? Optional.ofNullable(getRecipeRemainder()).map(Item::getDefaultStack).orElse(ItemStack.EMPTY) : stack;
|
2021-06-21 23:49:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public UseAction getUseAction(ItemStack stack) {
|
|
|
|
return UseAction.DRINK;
|
|
|
|
}
|
|
|
|
}
|