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

38 lines
1.2 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia.item;
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));
}
if (user instanceof PlayerEntity && !((PlayerEntity)user).abilities.creativeMode) {
stack.decrement(1);
}
return stack.isEmpty() ? new ItemStack(getRecipeRemainder()) : stack;
}
@Override
public UseAction getUseAction(ItemStack stack) {
return UseAction.DRINK;
}
}