Unicopia/src/main/java/com/minelittlepony/unicopia/item/DrinkableItem.java

42 lines
1.4 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia.item;
2021-08-19 13:15:59 +02:00
import com.minelittlepony.unicopia.item.toxin.ToxicHolder;
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));
}
((ToxicHolder)this).getToxic(stack).finishUsing(stack, world, user);
2021-08-04 15:38:03 +02:00
if (user instanceof PlayerEntity && !((PlayerEntity)user).getAbilities().creativeMode) {
stack.decrement(1);
}
return stack.isEmpty() ? new ItemStack(getRecipeRemainder()) : stack;
}
@Override
public UseAction getUseAction(ItemStack stack) {
return UseAction.DRINK;
}
}