Search in sources :

Example 1 with ItemParticleEffectMessage

use of com.minecolonies.coremod.network.messages.client.ItemParticleEffectMessage in project minecolonies by Minecolonies.

the class EntityAIEatTask method eat.

/**
 * Actual action of eating.
 *
 * @return the next state to go to, if successful idle.
 */
private EatingState eat() {
    if (!hasFood()) {
        return CHECK_FOR_FOOD;
    }
    final ICitizenData citizenData = citizen.getCitizenData();
    final ItemStack stack = citizenData.getInventory().getStackInSlot(foodSlot);
    if (!CAN_EAT.test(stack) || !canEat(citizenData, stack)) {
        return CHECK_FOR_FOOD;
    }
    citizen.setItemInHand(Hand.MAIN_HAND, stack);
    citizen.swing(Hand.MAIN_HAND);
    citizen.playSound(SoundEvents.GENERIC_EAT, (float) BASIC_VOLUME, (float) SoundUtils.getRandomPitch(citizen.getRandom()));
    Network.getNetwork().sendToTrackingEntity(new ItemParticleEffectMessage(citizen.getMainHandItem(), citizen.getX(), citizen.getY(), citizen.getZ(), citizen.xRot, citizen.yRot, citizen.getEyeHeight()), citizen);
    waitingTicks++;
    if (waitingTicks < REQUIRED_TIME_TO_EAT) {
        return EAT;
    }
    final Food itemFood = stack.getItem().getFoodProperties();
    Item containerItem = stack.getItem().getCraftingRemainingItem();
    if (containerItem == null && stack.getItem() instanceof SoupItem) {
        containerItem = Items.BOWL;
    }
    final double satIncrease = itemFood.getNutrition() * (1.0 + citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(SATURATION));
    citizenData.increaseSaturation(satIncrease / 2.0);
    citizenData.getInventory().extractItem(foodSlot, 1, false);
    if (containerItem != null && !(containerItem instanceof AirItem)) {
        if (citizenData.getInventory().isFull()) {
            InventoryUtils.spawnItemStack(citizen.level, citizen.getX(), citizen.getY(), citizen.getZ(), new ItemStack(containerItem, 1));
        } else {
            InventoryUtils.addItemStackToItemHandler(citizenData.getInventory(), new ItemStack(containerItem, 1));
        }
    }
    IColony citizenColony = citizen.getCitizenColonyHandler().getColony();
    if (citizenColony != null) {
        AdvancementUtils.TriggerAdvancementPlayersForColony(citizenColony, playerMP -> AdvancementTriggers.CITIZEN_EAT_FOOD.trigger(playerMP, stack));
    }
    citizenData.markDirty();
    citizen.setItemInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
    if (citizenData.getSaturation() < CitizenConstants.FULL_SATURATION && !citizenData.getInventory().getStackInSlot(foodSlot).isEmpty()) {
        waitingTicks = 0;
        return EAT;
    }
    return IDLE;
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData) IColony(com.minecolonies.api.colony.IColony) ItemParticleEffectMessage(com.minecolonies.coremod.network.messages.client.ItemParticleEffectMessage)

Example 2 with ItemParticleEffectMessage

use of com.minecolonies.coremod.network.messages.client.ItemParticleEffectMessage in project minecolonies by Minecolonies.

the class EntityCitizen method eatFoodInteraction.

/**
 * Eats food on right click
 *
 * @param usedStack
 * @param player
 * @param hand
 */
private void eatFoodInteraction(final ItemStack usedStack, final PlayerEntity player, final Hand hand) {
    usedStack.shrink(1);
    player.setItemInHand(hand, usedStack);
    interactionCooldown = 100;
    if (!level.isClientSide()) {
        final double satIncrease = usedStack.getItem().getFoodProperties().getNutrition() * (1.0 + getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(SATURATION));
        citizenData.increaseSaturation(satIncrease / 2.0);
        playSound(SoundEvents.GENERIC_EAT, 1.5f, (float) SoundUtils.getRandomPitch(getRandom()));
        // Position needs to be centered on citizen, Eat AI wrong too?
        Network.getNetwork().sendToTrackingEntity(new ItemParticleEffectMessage(usedStack, getX(), getY(), getZ(), getRotationPitch(), getRotationYaw(), getEyeHeight()), this);
    }
}
Also used : ItemParticleEffectMessage(com.minecolonies.coremod.network.messages.client.ItemParticleEffectMessage)

Example 3 with ItemParticleEffectMessage

use of com.minecolonies.coremod.network.messages.client.ItemParticleEffectMessage in project minecolonies by Minecolonies.

the class EntityCitizen method childFoodInteraction.

/**
 * Interaction with children for offering food
 *
 * @param usedStack
 * @param player
 * @param hand
 */
private void childFoodInteraction(final ItemStack usedStack, final PlayerEntity player, final Hand hand) {
    if (usedStack.getDisplayName().getString().toLowerCase(Locale.ENGLISH).contains("cookie")) {
        usedStack.shrink(1);
        player.setItemInHand(hand, usedStack);
        interactionCooldown = 100;
        if (!level.isClientSide()) {
            final double satIncrease = usedStack.getItem().getFoodProperties().getNutrition() * (1.0 + getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(SATURATION));
            citizenData.increaseSaturation(satIncrease / 2.0);
            addEffect(new EffectInstance(Effects.MOVEMENT_SPEED, 300));
            playSound(SoundEvents.GENERIC_EAT, 1.5f, (float) SoundUtils.getRandomPitch(getRandom()));
            Network.getNetwork().sendToTrackingEntity(new ItemParticleEffectMessage(usedStack, getX(), getY(), getZ(), getRotationPitch(), getRotationYaw(), getEyeHeight()), this);
        }
    } else {
        player.inventory.removeItem(usedStack);
        player.drop(usedStack, true, true);
        if (!level.isClientSide()) {
            playSound(SoundEvents.VILLAGER_NO, 1.0f, (float) SoundUtils.getRandomPitch(getRandom()));
            MessageUtils.format(MESSAGE_INTERACTION_COOKIE, this.getCitizenData().getName()).with(TextFormatting.RED).sendTo(player);
        }
    }
}
Also used : ItemParticleEffectMessage(com.minecolonies.coremod.network.messages.client.ItemParticleEffectMessage) EffectInstance(net.minecraft.potion.EffectInstance)

Example 4 with ItemParticleEffectMessage

use of com.minecolonies.coremod.network.messages.client.ItemParticleEffectMessage in project minecolonies by Minecolonies.

the class VisitorCitizen method directPlayerInteraction.

/**
 * Direct interaction on right click
 *
 * @param player
 * @param hand
 * @return
 */
private ActionResultType directPlayerInteraction(final PlayerEntity player, final Hand hand) {
    final ItemStack usedStack = player.getItemInHand(hand);
    if (ISFOOD.test(usedStack)) {
        usedStack.setCount(usedStack.getCount() - 1);
        player.setItemInHand(hand, usedStack);
        if (!level.isClientSide()) {
            getCitizenData().increaseSaturation(usedStack.getItem().getFoodProperties().getNutrition());
            playSound(SoundEvents.GENERIC_EAT, 1.5f, (float) SoundUtils.getRandomPitch(getRandom()));
            // Position needs to be centered on citizen, Eat AI wrong too?
            Network.getNetwork().sendToTrackingEntity(new ItemParticleEffectMessage(usedStack, getX(), getY(), getZ(), getRotationPitch(), getRotationYaw(), getEyeHeight()), this);
            citizenChatHandler.sendLocalizedChat(MESSAGE_INTERACTION_VISITOR_FOOD);
        }
        return ActionResultType.CONSUME;
    }
    return null;
}
Also used : ItemStack(net.minecraft.item.ItemStack) ItemParticleEffectMessage(com.minecolonies.coremod.network.messages.client.ItemParticleEffectMessage)

Example 5 with ItemParticleEffectMessage

use of com.minecolonies.coremod.network.messages.client.ItemParticleEffectMessage in project minecolonies by ldtteam.

the class EntityAIEatTask method eat.

/**
 * Actual action of eating.
 *
 * @return the next state to go to, if successful idle.
 */
private EatingState eat() {
    if (!hasFood()) {
        return CHECK_FOR_FOOD;
    }
    final ICitizenData citizenData = citizen.getCitizenData();
    final ItemStack stack = citizenData.getInventory().getStackInSlot(foodSlot);
    if (!CAN_EAT.test(stack) || !canEat(citizenData, stack)) {
        return CHECK_FOR_FOOD;
    }
    citizen.setItemInHand(Hand.MAIN_HAND, stack);
    citizen.swing(Hand.MAIN_HAND);
    citizen.playSound(SoundEvents.GENERIC_EAT, (float) BASIC_VOLUME, (float) SoundUtils.getRandomPitch(citizen.getRandom()));
    Network.getNetwork().sendToTrackingEntity(new ItemParticleEffectMessage(citizen.getMainHandItem(), citizen.getX(), citizen.getY(), citizen.getZ(), citizen.xRot, citizen.yRot, citizen.getEyeHeight()), citizen);
    waitingTicks++;
    if (waitingTicks < REQUIRED_TIME_TO_EAT) {
        return EAT;
    }
    final Food itemFood = stack.getItem().getFoodProperties();
    Item containerItem = stack.getItem().getCraftingRemainingItem();
    if (containerItem == null && stack.getItem() instanceof SoupItem) {
        containerItem = Items.BOWL;
    }
    final double satIncrease = itemFood.getNutrition() * (1.0 + citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(SATURATION));
    citizenData.increaseSaturation(satIncrease / 2.0);
    citizenData.getInventory().extractItem(foodSlot, 1, false);
    if (containerItem != null && !(containerItem instanceof AirItem)) {
        if (citizenData.getInventory().isFull()) {
            InventoryUtils.spawnItemStack(citizen.level, citizen.getX(), citizen.getY(), citizen.getZ(), new ItemStack(containerItem, 1));
        } else {
            InventoryUtils.addItemStackToItemHandler(citizenData.getInventory(), new ItemStack(containerItem, 1));
        }
    }
    IColony citizenColony = citizen.getCitizenColonyHandler().getColony();
    if (citizenColony != null) {
        AdvancementUtils.TriggerAdvancementPlayersForColony(citizenColony, playerMP -> AdvancementTriggers.CITIZEN_EAT_FOOD.trigger(playerMP, stack));
    }
    citizenData.markDirty();
    citizen.setItemInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
    if (citizenData.getSaturation() < CitizenConstants.FULL_SATURATION && !citizenData.getInventory().getStackInSlot(foodSlot).isEmpty()) {
        waitingTicks = 0;
        return EAT;
    }
    return IDLE;
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData) IColony(com.minecolonies.api.colony.IColony) ItemParticleEffectMessage(com.minecolonies.coremod.network.messages.client.ItemParticleEffectMessage)

Aggregations

ItemParticleEffectMessage (com.minecolonies.coremod.network.messages.client.ItemParticleEffectMessage)5 ICitizenData (com.minecolonies.api.colony.ICitizenData)2 IColony (com.minecolonies.api.colony.IColony)2 ItemStack (net.minecraft.item.ItemStack)1 EffectInstance (net.minecraft.potion.EffectInstance)1