Search in sources :

Example 96 with Player

use of net.minecraft.world.entity.player.Player in project Tropicraft by Tropicraft.

the class CocktailItem method finishUsingItem.

/**
 * Called when the player finishes using this Item (E.g. finishes eating.). Not called when the player stops using
 * the Item before the action is complete.
 */
@Override
public ItemStack finishUsingItem(@Nonnull ItemStack stack, @Nonnull Level worldIn, @Nonnull LivingEntity entityLiving) {
    if (entityLiving instanceof Player) {
        final Player player = (Player) entityLiving;
        onFoodEaten(stack, worldIn, player);
        Drink drink = getDrink(stack);
        if (worldIn.isRainingAt(player.blockPosition()) && drink == Drink.PINA_COLADA) {
        // TODO 1.17 advancements player.addStat(AchievementRegistry.drinkPinaColada);
        }
        return player.getAbilities().instabuild ? stack : new ItemStack(TropicraftItems.BAMBOO_MUG.get());
    }
    return new ItemStack(TropicraftItems.BAMBOO_MUG.get());
}
Also used : Player(net.minecraft.world.entity.player.Player) Drink(net.tropicraft.core.common.drinks.Drink) ItemStack(net.minecraft.world.item.ItemStack)

Example 97 with Player

use of net.minecraft.world.entity.player.Player in project Tropicraft by Tropicraft.

the class BambooItemFrameItem method useOn.

@Override
public InteractionResult useOn(UseOnContext context) {
    BlockPos blockpos = context.getClickedPos();
    Direction direction = context.getClickedFace();
    BlockPos blockpos1 = blockpos.relative(direction);
    Player playerentity = context.getPlayer();
    ItemStack itemstack = context.getItemInHand();
    if (playerentity != null && !this.mayPlace(playerentity, direction, itemstack, blockpos1)) {
        return InteractionResult.FAIL;
    } else {
        Level world = context.getLevel();
        HangingEntity hangingentity = new BambooItemFrame(world, blockpos1, direction);
        CompoundTag compoundnbt = itemstack.getTag();
        if (compoundnbt != null) {
            EntityType.updateCustomEntityTag(world, playerentity, hangingentity, compoundnbt);
        }
        if (hangingentity.survives()) {
            if (!world.isClientSide) {
                hangingentity.playPlacementSound();
                world.addFreshEntity(hangingentity);
            }
            itemstack.shrink(1);
        }
        return InteractionResult.SUCCESS;
    }
}
Also used : HangingEntity(net.minecraft.world.entity.decoration.HangingEntity) Player(net.minecraft.world.entity.player.Player) BlockPos(net.minecraft.core.BlockPos) Level(net.minecraft.world.level.Level) ItemStack(net.minecraft.world.item.ItemStack) Direction(net.minecraft.core.Direction) BambooItemFrame(net.tropicraft.core.common.entity.BambooItemFrame) CompoundTag(net.minecraft.nbt.CompoundTag)

Aggregations

Player (net.minecraft.world.entity.player.Player)97 ItemStack (net.minecraft.world.item.ItemStack)65 Level (net.minecraft.world.level.Level)56 InteractionHand (net.minecraft.world.InteractionHand)55 InteractionResult (net.minecraft.world.InteractionResult)52 ItemEntity (net.minecraft.world.entity.item.ItemEntity)51 Items (net.minecraft.world.item.Items)51 EntitySize (de.Keyle.MyPet.api.entity.EntitySize)50 MyPet (de.Keyle.MyPet.api.entity.MyPet)50 InvocationTargetException (java.lang.reflect.InvocationTargetException)50 EntityDataAccessor (net.minecraft.network.syncher.EntityDataAccessor)42 EntityDataSerializers (net.minecraft.network.syncher.EntityDataSerializers)42 SynchedEntityData (net.minecraft.network.syncher.SynchedEntityData)42 ServerLevel (net.minecraft.server.level.ServerLevel)40 Bukkit (org.bukkit.Bukkit)39 MyPetApi (de.Keyle.MyPet.MyPetApi)38 Util (de.Keyle.MyPet.api.Util)38 Pair (com.mojang.datafixers.util.Pair)36 EquipmentSlot (de.Keyle.MyPet.api.entity.EquipmentSlot)36 Arrays (java.util.Arrays)36