Search in sources :

Example 56 with Player

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

the class FluidUtil method interactWithFluidHandler.

/**
 * Used to handle the common case of a player holding a fluid item and right-clicking on a fluid handler.
 * First it tries to fill the item from the handler,
 * if that action fails then it tries to drain the item into the handler.
 * Automatically updates the item in the player's hand and stashes any extra items created.
 *
 * @param player  The player doing the interaction between the item and fluid handler.
 * @param hand    The player's hand that is holding an item that should interact with the fluid handler.
 * @param handler The fluid handler.
 * @return true if the interaction succeeded and updated the item held by the player, false otherwise.
 */
public static boolean interactWithFluidHandler(@Nonnull Player player, @Nonnull InteractionHand hand, @Nonnull IFluidHandler handler) {
    Preconditions.checkNotNull(player);
    Preconditions.checkNotNull(hand);
    Preconditions.checkNotNull(handler);
    ItemStack heldItem = player.getItemInHand(hand);
    if (!heldItem.isEmpty()) {
        return player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).map(playerInventory -> {
            FluidActionResult fluidActionResult = tryFillContainerAndStow(heldItem, handler, playerInventory, Integer.MAX_VALUE, player, true);
            if (!fluidActionResult.isSuccess()) {
                fluidActionResult = tryEmptyContainerAndStow(heldItem, handler, playerInventory, Integer.MAX_VALUE, player, true);
            }
            if (fluidActionResult.isSuccess()) {
                player.setItemInHand(hand, fluidActionResult.getResult());
                return true;
            }
            return false;
        }).orElse(false);
    }
    return false;
}
Also used : SoundSource(net.minecraft.sounds.SoundSource) IItemHandler(net.minecraftforge.items.IItemHandler) Items(net.minecraft.world.item.Items) FluidBlockWrapper(net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper) BucketPickup(net.minecraft.world.level.block.BucketPickup) LiquidBlockContainer(net.minecraft.world.level.block.LiquidBlockContainer) Direction(net.minecraft.core.Direction) BlockState(net.minecraft.world.level.block.state.BlockState) BlockWrapper(net.minecraftforge.fluids.capability.wrappers.BlockWrapper) LazyOptional(net.minecraftforge.common.util.LazyOptional) ItemHandlerHelper(net.minecraftforge.items.ItemHandlerHelper) Fluid(net.minecraft.world.level.material.Fluid) Fluids(net.minecraft.world.level.material.Fluids) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) CapabilityFluidHandler(net.minecraftforge.fluids.capability.CapabilityFluidHandler) BlockHitResult(net.minecraft.world.phys.BlockHitResult) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) BucketPickupHandlerWrapper(net.minecraftforge.fluids.capability.wrappers.BucketPickupHandlerWrapper) Material(net.minecraft.world.level.material.Material) Player(net.minecraft.world.entity.player.Player) BlockPos(net.minecraft.core.BlockPos) Vec3(net.minecraft.world.phys.Vec3) SoundEvent(net.minecraft.sounds.SoundEvent) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) BlockPlaceContext(net.minecraft.world.item.context.BlockPlaceContext) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Block(net.minecraft.world.level.block.Block) BucketItem(net.minecraft.world.item.BucketItem) ItemStack(net.minecraft.world.item.ItemStack) InteractionHand(net.minecraft.world.InteractionHand) Level(net.minecraft.world.level.Level) ItemStack(net.minecraft.world.item.ItemStack)

Example 57 with Player

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

the class EntityMyWitherSkeleton method handlePlayerInteraction.

@Override
public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) {
    if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) {
        return InteractionResult.CONSUME;
    }
    if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) {
        if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) {
            boolean hadEquipment = false;
            for (EquipmentSlot slot : EquipmentSlot.values()) {
                ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
                if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) {
                    ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot);
                    entityitem.pickupDelay = 10;
                    entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0));
                    this.level.addFreshEntity(entityitem);
                    getMyPet().setEquipment(slot, null);
                    hadEquipment = true;
                }
            }
            if (hadEquipment) {
                if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
                    try {
                        itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand));
                    } catch (Error e) {
                        // TODO REMOVE
                        itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> {
                            try {
                                CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
                            } catch (IllegalAccessException | InvocationTargetException ex) {
                                ex.printStackTrace();
                            }
                        });
                    }
                }
            }
            return InteractionResult.CONSUME;
        } else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) {
            EquipmentSlot slot = EquipmentSlot.getSlotById(Mob.getEquipmentSlotForItem(itemStack).getFilterFlag());
            ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
            if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
                ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot);
                entityitem.pickupDelay = 10;
                entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0));
                this.level.addFreshEntity(entityitem);
            }
            getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack));
            if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
                itemStack.shrink(1);
                if (itemStack.getCount() <= 0) {
                    entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY);
                }
            }
            return InteractionResult.CONSUME;
        }
    }
    return InteractionResult.PASS;
}
Also used : MyPet(de.Keyle.MyPet.api.entity.MyPet) Arrays(java.util.Arrays) Util(de.Keyle.MyPet.api.Util) PetState(de.Keyle.MyPet.api.entity.MyPet.PetState) Items(net.minecraft.world.item.Items) EntitySize(de.Keyle.MyPet.api.entity.EntitySize) MyPetApi(de.Keyle.MyPet.MyPetApi) InteractionResult(net.minecraft.world.InteractionResult) EquipmentSlot(de.Keyle.MyPet.api.entity.EquipmentSlot) ClientboundSetEquipmentPacket(net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket) ServerLevel(net.minecraft.server.level.ServerLevel) Pair(com.mojang.datafixers.util.Pair) InvocationTargetException(java.lang.reflect.InvocationTargetException) EntityMyPet(de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet) Player(net.minecraft.world.entity.player.Player) ItemEntity(net.minecraft.world.entity.item.ItemEntity) MyWitherSkeleton(de.Keyle.MyPet.api.entity.types.MyWitherSkeleton) InteractionHand(net.minecraft.world.InteractionHand) ItemStack(net.minecraft.world.item.ItemStack) Mob(net.minecraft.world.entity.Mob) Level(net.minecraft.world.level.Level) CompatManager(de.Keyle.MyPet.compat.v1_17_R1.CompatManager) Bukkit(org.bukkit.Bukkit) CraftItemStack(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack) ItemEntity(net.minecraft.world.entity.item.ItemEntity) EquipmentSlot(de.Keyle.MyPet.api.entity.EquipmentSlot) ItemStack(net.minecraft.world.item.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack)

Example 58 with Player

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

the class EntityMyZombifiedPiglin method handlePlayerInteraction.

@Override
public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) {
    if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack) == InteractionResult.CONSUME) {
        return InteractionResult.CONSUME;
    }
    if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) {
        if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) {
            boolean hadEquipment = false;
            for (EquipmentSlot slot : EquipmentSlot.values()) {
                ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
                if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) {
                    ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot);
                    entityitem.pickupDelay = 10;
                    entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0));
                    this.level.addFreshEntity(entityitem);
                    getMyPet().setEquipment(slot, null);
                    hadEquipment = true;
                }
            }
            if (hadEquipment) {
                if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
                    try {
                        itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand));
                    } catch (Error e) {
                        // TODO REMOVE
                        itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> {
                            try {
                                CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
                            } catch (IllegalAccessException | InvocationTargetException ex) {
                                ex.printStackTrace();
                            }
                        });
                    }
                }
            }
            return InteractionResult.CONSUME;
        } else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) {
            EquipmentSlot slot = EquipmentSlot.getSlotById(Mob.getEquipmentSlotForItem(itemStack).getFilterFlag());
            ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
            if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
                ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), itemInSlot);
                entityitem.pickupDelay = 10;
                entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0));
                this.level.addFreshEntity(entityitem);
            }
            getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack));
            if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
                itemStack.shrink(1);
                if (itemStack.getCount() <= 0) {
                    entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY);
                }
            }
            return InteractionResult.CONSUME;
        } else if (Configuration.MyPet.ZombifiedPiglin.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) {
            if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
                itemStack.shrink(1);
                if (itemStack.getCount() <= 0) {
                    entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY);
                }
            }
            getMyPet().setBaby(false);
            return InteractionResult.CONSUME;
        }
    }
    return InteractionResult.PASS;
}
Also used : Arrays(java.util.Arrays) Items(net.minecraft.world.item.Items) EntityDataSerializers(net.minecraft.network.syncher.EntityDataSerializers) ServerLevel(net.minecraft.server.level.ServerLevel) Configuration(de.Keyle.MyPet.api.Configuration) CompatManager(de.Keyle.MyPet.compat.v1_17_R1.CompatManager) Bukkit(org.bukkit.Bukkit) MyPet(de.Keyle.MyPet.api.entity.MyPet) Util(de.Keyle.MyPet.api.Util) PetState(de.Keyle.MyPet.api.entity.MyPet.PetState) EntitySize(de.Keyle.MyPet.api.entity.EntitySize) MyPetApi(de.Keyle.MyPet.MyPetApi) MyZombifiedPiglin(de.Keyle.MyPet.api.entity.types.MyZombifiedPiglin) EntityDataAccessor(net.minecraft.network.syncher.EntityDataAccessor) InteractionResult(net.minecraft.world.InteractionResult) EquipmentSlot(de.Keyle.MyPet.api.entity.EquipmentSlot) ClientboundSetEquipmentPacket(net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket) Pair(com.mojang.datafixers.util.Pair) InvocationTargetException(java.lang.reflect.InvocationTargetException) EntityMyPet(de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet) Player(net.minecraft.world.entity.player.Player) SynchedEntityData(net.minecraft.network.syncher.SynchedEntityData) ItemEntity(net.minecraft.world.entity.item.ItemEntity) InteractionHand(net.minecraft.world.InteractionHand) ItemStack(net.minecraft.world.item.ItemStack) Mob(net.minecraft.world.entity.Mob) Level(net.minecraft.world.level.Level) CraftItemStack(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack) ItemEntity(net.minecraft.world.entity.item.ItemEntity) EquipmentSlot(de.Keyle.MyPet.api.entity.EquipmentSlot) ItemStack(net.minecraft.world.item.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack)

Example 59 with Player

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

the class EntityMyHorse method handlePlayerInteraction.

@Override
public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) {
    if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) {
        return InteractionResult.CONSUME;
    }
    if (itemStack != null && canUseItem()) {
        org.bukkit.inventory.ItemStack is = CraftItemStack.asBukkitCopy(itemStack);
        if (itemStack.getItem() == Items.SADDLE && !getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking() && canEquip()) {
            getMyPet().setSaddle(is);
            if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
                itemStack.shrink(1);
                if (itemStack.getCount() <= 0) {
                    entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY);
                }
            }
            return InteractionResult.CONSUME;
        } else if (!getMyPet().hasArmor() && getOwner().getPlayer().isSneaking() && canEquip() && isArmor(is)) {
            getMyPet().setArmor(is);
            if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
                itemStack.shrink(1);
                if (itemStack.getCount() <= 0) {
                    entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY);
                }
            }
            return InteractionResult.CONSUME;
        } else if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) {
            if (getMyPet().hasArmor()) {
                ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getArmor()));
                entityitem.pickupDelay = 10;
                entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0));
                this.level.addFreshEntity(entityitem);
            }
            if (getMyPet().hasChest()) {
                ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getChest()));
                entityitem.pickupDelay = 10;
                entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0));
                this.level.addFreshEntity(entityitem);
            }
            if (getMyPet().hasSaddle()) {
                ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getSaddle()));
                entityitem.pickupDelay = 10;
                entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0));
                this.level.addFreshEntity(entityitem);
            }
            makeSound("entity.sheep.shear", 1.0F, 1.0F);
            getMyPet().setChest(null);
            getMyPet().setSaddle(null);
            getMyPet().setArmor(null);
            if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
                try {
                    itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand));
                } catch (Error e) {
                    // TODO REMOVE
                    itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> {
                        try {
                            CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
                        } catch (IllegalAccessException | InvocationTargetException ex) {
                            ex.printStackTrace();
                        }
                    });
                }
            }
            return InteractionResult.CONSUME;
        } else if (Configuration.MyPet.Horse.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) {
            if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
                itemStack.shrink(1);
                if (itemStack.getCount() <= 0) {
                    entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY);
                }
            }
            getMyPet().setBaby(false);
            return InteractionResult.CONSUME;
        }
    }
    return InteractionResult.PASS;
}
Also used : Arrays(java.util.Arrays) Items(net.minecraft.world.item.Items) EntityDataSerializers(net.minecraft.network.syncher.EntityDataSerializers) BlockState(net.minecraft.world.level.block.state.BlockState) ServerLevel(net.minecraft.server.level.ServerLevel) Configuration(de.Keyle.MyPet.api.Configuration) SoundEvents(net.minecraft.sounds.SoundEvents) CompatManager(de.Keyle.MyPet.compat.v1_17_R1.CompatManager) Bukkit(org.bukkit.Bukkit) MyPet(de.Keyle.MyPet.api.entity.MyPet) Util(de.Keyle.MyPet.api.Util) EntitySize(de.Keyle.MyPet.api.entity.EntitySize) MyPetApi(de.Keyle.MyPet.MyPetApi) MyHorse(de.Keyle.MyPet.api.entity.types.MyHorse) EntityDataAccessor(net.minecraft.network.syncher.EntityDataAccessor) InteractionResult(net.minecraft.world.InteractionResult) UUID(java.util.UUID) EquipmentSlot(de.Keyle.MyPet.api.entity.EquipmentSlot) ClientboundSetEquipmentPacket(net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket) Pair(com.mojang.datafixers.util.Pair) SoundType(net.minecraft.world.level.block.SoundType) InvocationTargetException(java.lang.reflect.InvocationTargetException) EntityMyPet(de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet) Player(net.minecraft.world.entity.player.Player) Blocks(net.minecraft.world.level.block.Blocks) SynchedEntityData(net.minecraft.network.syncher.SynchedEntityData) Entity(net.minecraft.world.entity.Entity) BlockPos(net.minecraft.core.BlockPos) ItemEntity(net.minecraft.world.entity.item.ItemEntity) Optional(java.util.Optional) InteractionHand(net.minecraft.world.InteractionHand) ItemStack(net.minecraft.world.item.ItemStack) Level(net.minecraft.world.level.Level) CraftItemStack(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack) ItemEntity(net.minecraft.world.entity.item.ItemEntity)

Example 60 with Player

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

the class EntityMyLlama method handlePlayerInteraction.

@Override
public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) {
    if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) {
        return InteractionResult.CONSUME;
    }
    if (itemStack != null && canUseItem()) {
        if (ItemTags.CARPETS.contains(itemStack.getItem()) && !getMyPet().hasDecor() && getOwner().getPlayer().isSneaking() && canEquip()) {
            getMyPet().setDecor(CraftItemStack.asBukkitCopy(itemStack));
            if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
                itemStack.shrink(1);
                if (itemStack.getCount() <= 0) {
                    entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY);
                }
            }
            return InteractionResult.CONSUME;
        } else if (itemStack.getItem() == Blocks.CHEST.asItem() && getOwner().getPlayer().isSneaking() && !getMyPet().hasChest() && !getMyPet().isBaby() && canEquip()) {
            getMyPet().setChest(CraftItemStack.asBukkitCopy(itemStack));
            if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
                itemStack.shrink(1);
                if (itemStack.getCount() <= 0) {
                    entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY);
                }
            }
            return InteractionResult.CONSUME;
        } else if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) {
            if (getMyPet().hasChest()) {
                ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getChest()));
                entityitem.pickupDelay = 10;
                entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0));
                this.level.addFreshEntity(entityitem);
            }
            if (getMyPet().hasDecor()) {
                ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getDecor()));
                entityitem.pickupDelay = 10;
                entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0));
                this.level.addFreshEntity(entityitem);
            }
            makeSound("entity.sheep.shear", 1.0F, 1.0F);
            getMyPet().setChest(null);
            getMyPet().setDecor(null);
            if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
                try {
                    itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand));
                } catch (Error e) {
                    // TODO REMOVE
                    itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> {
                        try {
                            CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
                        } catch (IllegalAccessException | InvocationTargetException ex) {
                            ex.printStackTrace();
                        }
                    });
                }
            }
            return InteractionResult.CONSUME;
        } else if (Configuration.MyPet.Llama.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) {
            if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
                itemStack.shrink(1);
                if (itemStack.getCount() <= 0) {
                    entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY);
                }
            }
            getMyPet().setBaby(false);
            return InteractionResult.CONSUME;
        }
    }
    return InteractionResult.PASS;
}
Also used : MyPet(de.Keyle.MyPet.api.entity.MyPet) Items(net.minecraft.world.item.Items) EntitySize(de.Keyle.MyPet.api.entity.EntitySize) ItemTags(net.minecraft.tags.ItemTags) WoolCarpetBlock(net.minecraft.world.level.block.WoolCarpetBlock) EntityDataSerializers(net.minecraft.network.syncher.EntityDataSerializers) EntityDataAccessor(net.minecraft.network.syncher.EntityDataAccessor) InteractionResult(net.minecraft.world.InteractionResult) UUID(java.util.UUID) InvocationTargetException(java.lang.reflect.InvocationTargetException) EntityMyPet(de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet) Player(net.minecraft.world.entity.player.Player) Blocks(net.minecraft.world.level.block.Blocks) SynchedEntityData(net.minecraft.network.syncher.SynchedEntityData) Configuration(de.Keyle.MyPet.api.Configuration) ItemEntity(net.minecraft.world.entity.item.ItemEntity) Optional(java.util.Optional) MyLlama(de.Keyle.MyPet.api.entity.types.MyLlama) Block(net.minecraft.world.level.block.Block) InteractionHand(net.minecraft.world.InteractionHand) ItemStack(net.minecraft.world.item.ItemStack) Level(net.minecraft.world.level.Level) CompatManager(de.Keyle.MyPet.compat.v1_17_R1.CompatManager) CraftItemStack(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack) ItemEntity(net.minecraft.world.entity.item.ItemEntity)

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