2021-06-21 23:49:55 +02:00
|
|
|
package com.minelittlepony.unicopia.item;
|
|
|
|
|
2021-08-19 13:15:59 +02:00
|
|
|
import com.minelittlepony.unicopia.item.toxin.ToxicHolder;
|
|
|
|
|
2021-06-21 23:49:55 +02:00
|
|
|
import net.minecraft.advancement.criterion.Criteria;
|
|
|
|
import net.minecraft.entity.LivingEntity;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
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) {
|
|
|
|
if (user instanceof ServerPlayerEntity) {
|
|
|
|
ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity)user;
|
|
|
|
Criteria.CONSUME_ITEM.trigger(serverPlayerEntity, stack);
|
|
|
|
serverPlayerEntity.incrementStat(Stats.USED.getOrCreateStat(this));
|
|
|
|
}
|
|
|
|
|
2021-08-04 15:38:03 +02:00
|
|
|
if (user instanceof PlayerEntity && !((PlayerEntity)user).getAbilities().creativeMode) {
|
2021-06-21 23:49:55 +02:00
|
|
|
stack.decrement(1);
|
|
|
|
}
|
|
|
|
|
2022-09-30 12:43:07 +02:00
|
|
|
((ToxicHolder)this).getToxic(stack).finishUsing(stack, world, user);
|
2021-08-19 13:15:59 +02:00
|
|
|
|
2021-06-21 23:49:55 +02:00
|
|
|
return stack.isEmpty() ? new ItemStack(getRecipeRemainder()) : stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public UseAction getUseAction(ItemStack stack) {
|
|
|
|
return UseAction.DRINK;
|
|
|
|
}
|
|
|
|
}
|