Search in sources :

Example 1 with LocalizedParticleEffectMessage

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

the class EntityAIWorkCrusher method crush.

/**
 * The crushing process.
 *
 * @return the next AiState to go to.
 */
protected IAIState crush() {
    if (walkToBuilding()) {
        return getState();
    }
    worker.getCitizenData().setVisibleStatus(CRUSHING);
    job.setProgress(job.getProgress() + TICK_DELAY);
    final BuildingCrusher crusherBuilding = getOwnBuilding();
    WorkerUtil.faceBlock(crusherBuilding.getPosition(), worker);
    if (currentRecipeStorage == null) {
        currentRecipeStorage = crusherBuilding.getCurrentRecipe();
    }
    if ((getState() != CRAFT && crusherBuilding.getCurrentDailyQuantity() >= crusherBuilding.getCrusherMode().getB()) || currentRecipeStorage == null) {
        return START_WORKING;
    }
    final IAIState check = checkForItems(currentRecipeStorage);
    if (job.getProgress() > MAX_LEVEL - Math.min((getSecondarySkillLevel() / 2) + 1, MAX_LEVEL)) {
        job.setProgress(0);
        if (check == CRAFT) {
            if (getState() != CRAFT) {
                crusherBuilding.setCurrentDailyQuantity(crusherBuilding.getCurrentDailyQuantity() + 1);
                if (crusherBuilding.getCurrentDailyQuantity() >= crusherBuilding.getCrusherMode().getB()) {
                    incrementActionsDoneAndDecSaturation();
                }
            }
            if (currentRequest != null) {
                currentRequest.addDelivery(currentRecipeStorage.getPrimaryOutput());
            }
            worker.swing(Hand.MAIN_HAND);
            job.setCraftCounter(job.getCraftCounter() + 1);
            currentRecipeStorage.fullfillRecipe(getLootContext(), ImmutableList.of(worker.getItemHandlerCitizen()));
            worker.decreaseSaturationForContinuousAction();
            worker.getCitizenExperienceHandler().addExperience(0.1);
        } else if (getState() != CRAFT) {
            currentRecipeStorage = crusherBuilding.getCurrentRecipe();
            final int requestQty = Math.min((crusherBuilding.getCrusherMode().getB() - crusherBuilding.getCurrentDailyQuantity()) * 2, STACKSIZE);
            if (requestQty <= 0) {
                return START_WORKING;
            }
            final ItemStack stack = currentRecipeStorage.getInput().get(0).getItemStack().copy();
            stack.setCount(requestQty);
            checkIfRequestForItemExistOrCreateAsynch(stack);
            return START_WORKING;
        } else {
            return check;
        }
    }
    if (check == CRAFT) {
        Network.getNetwork().sendToTrackingEntity(new LocalizedParticleEffectMessage(currentRecipeStorage.getInput().get(0).getItemStack().copy(), crusherBuilding.getID()), worker);
        Network.getNetwork().sendToTrackingEntity(new LocalizedParticleEffectMessage(currentRecipeStorage.getPrimaryOutput().copy(), crusherBuilding.getID().below()), worker);
        SoundUtils.playSoundAtCitizen(world, getOwnBuilding().getID(), SoundEvents.STONE_BREAK);
    }
    return getState();
}
Also used : BuildingCrusher(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingCrusher) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) LocalizedParticleEffectMessage(com.minecolonies.coremod.network.messages.client.LocalizedParticleEffectMessage) ItemStack(net.minecraft.item.ItemStack)

Example 2 with LocalizedParticleEffectMessage

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

the class EntityAIWorkSifter method sift.

/**
 * The sifting process.
 *
 * @return the next AiState to go to.
 */
protected IAIState sift() {
    final BuildingSifter sifterBuilding = getOwnBuilding();
    // Go idle if we can't do any more today
    if (sifterBuilding.getCurrentDailyQuantity() >= sifterBuilding.getMaxDailyQuantity()) {
        return IDLE;
    }
    if (walkToBuilding()) {
        return getState();
    }
    if (InventoryUtils.isItemHandlerFull(worker.getInventoryCitizen())) {
        return INVENTORY_FULL;
    }
    if (currentRecipeStorage == null) {
        final ICraftingBuildingModule module = getOwnBuilding().getFirstModuleOccurance(BuildingSifter.CraftingModule.class);
        currentRecipeStorage = module.getFirstFulfillableRecipe(ItemStackUtils::isEmpty, 1, false);
    }
    if (currentRecipeStorage == null) {
        if (InventoryUtils.getCountFromBuilding(sifterBuilding, i -> ModTags.meshes.contains(i.getItem())) == 0) {
            if (InventoryUtils.getItemCountInProvider(worker, i -> ModTags.meshes.contains(i.getItem())) > 0) {
                // We don't want the mesh in our inventory, we 'craft' out of the building
                incrementActionsDone();
                return INVENTORY_FULL;
            }
            if (worker.getCitizenData() != null) {
                worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(SIFTER_NO_MESH), ChatPriority.IMPORTANT));
                setDelay(NO_MESH_DELAY);
            }
        }
        if (!ItemStackUtils.isEmpty(worker.getMainHandItem())) {
            worker.setItemInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
        }
        if (!ItemStackUtils.isEmpty(worker.getOffhandItem())) {
            worker.setItemInHand(Hand.OFF_HAND, ItemStack.EMPTY);
        }
        progress = 0;
        return START_WORKING;
    }
    final ItemStack meshItem = currentRecipeStorage.getCraftingTools().get(0);
    final ItemStack inputItem = currentRecipeStorage.getCleanedInput().stream().map(ItemStorage::getItemStack).filter(item -> !ItemStackUtils.compareItemStacksIgnoreStackSize(item, meshItem, false, true)).findFirst().orElse(ItemStack.EMPTY);
    if (meshItem.isEmpty() || inputItem.isEmpty()) {
        currentRecipeStorage = null;
        return getState();
    }
    if (!inputItem.isEmpty() && (ItemStackUtils.isEmpty(worker.getMainHandItem()) || ItemStackUtils.compareItemStacksIgnoreStackSize(worker.getMainHandItem(), inputItem))) {
        worker.setItemInHand(Hand.MAIN_HAND, inputItem);
    }
    if (!meshItem.isEmpty() && (ItemStackUtils.isEmpty(worker.getOffhandItem()) || ItemStackUtils.compareItemStacksIgnoreStackSize(worker.getOffhandItem(), meshItem, false, true))) {
        worker.setItemInHand(Hand.OFF_HAND, meshItem);
    }
    WorkerUtil.faceBlock(getOwnBuilding().getPosition(), worker);
    progress++;
    if (progress > MAX_LEVEL - (getEffectiveSkillLevel(getSecondarySkillLevel()) / 2)) {
        progress = 0;
        sifterBuilding.setCurrentDailyQuantity(sifterBuilding.getCurrentDailyQuantity() + 1);
        if (sifterBuilding.getCurrentDailyQuantity() >= sifterBuilding.getMaxDailyQuantity() || worker.getRandom().nextInt(ONE_HUNDRED_PERCENT) < CHANCE_TO_DUMP_INV) {
            incrementActionsDoneAndDecSaturation();
        }
        if (!currentRecipeStorage.fullfillRecipe(getLootContext(), sifterBuilding.getHandlers())) {
            currentRecipeStorage = null;
            return getState();
        }
        worker.decreaseSaturationForContinuousAction();
        worker.getCitizenExperienceHandler().addExperience(0.2);
    }
    Network.getNetwork().sendToTrackingEntity(new LocalizedParticleEffectMessage(meshItem, sifterBuilding.getID()), worker);
    Network.getNetwork().sendToTrackingEntity(new LocalizedParticleEffectMessage(inputItem, sifterBuilding.getID().below()), worker);
    worker.swing(Hand.MAIN_HAND);
    SoundUtils.playSoundAtCitizen(world, getOwnBuilding().getID(), SoundEvents.LEASH_KNOT_BREAK);
    return getState();
}
Also used : ModTags(com.minecolonies.api.items.ModTags) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) ICraftingBuildingModule(com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) BuildingSifter(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingSifter) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) SIFTER_NO_MESH(com.minecolonies.api.util.constant.TranslationConstants.SIFTER_NO_MESH) SoundUtils(com.minecolonies.api.util.SoundUtils) LocalizedParticleEffectMessage(com.minecolonies.coremod.network.messages.client.LocalizedParticleEffectMessage) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) SoundEvents(net.minecraft.util.SoundEvents) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) WorkerUtil(com.minecolonies.coremod.util.WorkerUtil) InventoryUtils(com.minecolonies.api.util.InventoryUtils) AbstractEntityAICrafting(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAICrafting) ONE_HUNDRED_PERCENT(com.minecolonies.api.util.constant.Constants.ONE_HUNDRED_PERCENT) Hand(net.minecraft.util.Hand) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) Network(com.minecolonies.coremod.Network) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) JobSifter(com.minecolonies.coremod.colony.jobs.JobSifter) BuildingSifter(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingSifter) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) LocalizedParticleEffectMessage(com.minecolonies.coremod.network.messages.client.LocalizedParticleEffectMessage) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ICraftingBuildingModule(com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule) ItemStack(net.minecraft.item.ItemStack)

Example 3 with LocalizedParticleEffectMessage

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

the class EntityAIWorkSifter method sift.

/**
 * The sifting process.
 *
 * @return the next AiState to go to.
 */
protected IAIState sift() {
    final BuildingSifter sifterBuilding = building;
    // Go idle if we can't do any more today
    if (sifterBuilding.getCurrentDailyQuantity() >= sifterBuilding.getMaxDailyQuantity()) {
        return IDLE;
    }
    if (walkToBuilding()) {
        return getState();
    }
    if (InventoryUtils.isItemHandlerFull(worker.getInventoryCitizen())) {
        return INVENTORY_FULL;
    }
    if (currentRecipeStorage == null) {
        final ICraftingBuildingModule module = building.getFirstModuleOccurance(BuildingSifter.CraftingModule.class);
        currentRecipeStorage = module.getFirstFulfillableRecipe(ItemStackUtils::isEmpty, 1, false);
    }
    if (currentRecipeStorage == null) {
        if (InventoryUtils.hasBuildingEnoughElseCount(sifterBuilding, i -> ModTags.meshes.contains(i.getItem()), 1) == 0) {
            if (InventoryUtils.getItemCountInProvider(worker, i -> ModTags.meshes.contains(i.getItem())) > 0) {
                // We don't want the mesh in our inventory, we 'craft' out of the building
                incrementActionsDone();
                return INVENTORY_FULL;
            }
            if (worker.getCitizenData() != null) {
                worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(SIFTER_NO_MESH), ChatPriority.IMPORTANT));
                setDelay(NO_MESH_DELAY);
            }
        }
        if (!ItemStackUtils.isEmpty(worker.getMainHandItem())) {
            worker.setItemInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
        }
        if (!ItemStackUtils.isEmpty(worker.getOffhandItem())) {
            worker.setItemInHand(Hand.OFF_HAND, ItemStack.EMPTY);
        }
        progress = 0;
        return START_WORKING;
    }
    final ItemStack meshItem = currentRecipeStorage.getCraftingTools().get(0);
    final ItemStack inputItem = currentRecipeStorage.getCleanedInput().stream().map(ItemStorage::getItemStack).filter(item -> !ItemStackUtils.compareItemStacksIgnoreStackSize(item, meshItem, false, true)).findFirst().orElse(ItemStack.EMPTY);
    if (meshItem.isEmpty() || inputItem.isEmpty()) {
        currentRecipeStorage = null;
        return getState();
    }
    if (!inputItem.isEmpty() && (ItemStackUtils.isEmpty(worker.getMainHandItem()) || ItemStackUtils.compareItemStacksIgnoreStackSize(worker.getMainHandItem(), inputItem))) {
        worker.setItemInHand(Hand.MAIN_HAND, inputItem);
    }
    if (!meshItem.isEmpty() && (ItemStackUtils.isEmpty(worker.getOffhandItem()) || ItemStackUtils.compareItemStacksIgnoreStackSize(worker.getOffhandItem(), meshItem, false, true))) {
        worker.setItemInHand(Hand.OFF_HAND, meshItem);
    }
    WorkerUtil.faceBlock(building.getPosition(), worker);
    progress++;
    if (progress > MAX_LEVEL - (getEffectiveSkillLevel(getSecondarySkillLevel()) / 2)) {
        progress = 0;
        sifterBuilding.setCurrentDailyQuantity(sifterBuilding.getCurrentDailyQuantity() + 1);
        if (sifterBuilding.getCurrentDailyQuantity() >= sifterBuilding.getMaxDailyQuantity() || worker.getRandom().nextInt(ONE_HUNDRED_PERCENT) < CHANCE_TO_DUMP_INV) {
            incrementActionsDoneAndDecSaturation();
        }
        if (!currentRecipeStorage.fullfillRecipe(getLootContext(), sifterBuilding.getHandlers())) {
            currentRecipeStorage = null;
            return getState();
        }
        worker.decreaseSaturationForContinuousAction();
        worker.getCitizenExperienceHandler().addExperience(0.2);
    }
    Network.getNetwork().sendToTrackingEntity(new LocalizedParticleEffectMessage(meshItem, sifterBuilding.getID()), worker);
    Network.getNetwork().sendToTrackingEntity(new LocalizedParticleEffectMessage(inputItem, sifterBuilding.getID().below()), worker);
    worker.swing(Hand.MAIN_HAND);
    SoundUtils.playSoundAtCitizen(world, building.getID(), SoundEvents.LEASH_KNOT_BREAK);
    return getState();
}
Also used : ModTags(com.minecolonies.api.items.ModTags) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) ICraftingBuildingModule(com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) BuildingSifter(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingSifter) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) SIFTER_NO_MESH(com.minecolonies.api.util.constant.TranslationConstants.SIFTER_NO_MESH) SoundUtils(com.minecolonies.api.util.SoundUtils) LocalizedParticleEffectMessage(com.minecolonies.coremod.network.messages.client.LocalizedParticleEffectMessage) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) SoundEvents(net.minecraft.util.SoundEvents) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) WorkerUtil(com.minecolonies.coremod.util.WorkerUtil) InventoryUtils(com.minecolonies.api.util.InventoryUtils) AbstractEntityAICrafting(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAICrafting) ONE_HUNDRED_PERCENT(com.minecolonies.api.util.constant.Constants.ONE_HUNDRED_PERCENT) Hand(net.minecraft.util.Hand) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) Network(com.minecolonies.coremod.Network) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) JobSifter(com.minecolonies.coremod.colony.jobs.JobSifter) BuildingSifter(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingSifter) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) LocalizedParticleEffectMessage(com.minecolonies.coremod.network.messages.client.LocalizedParticleEffectMessage) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ICraftingBuildingModule(com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule) ItemStack(net.minecraft.item.ItemStack)

Example 4 with LocalizedParticleEffectMessage

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

the class EntityAIWorkCrusher method crush.

/**
 * The crushing process.
 *
 * @return the next AiState to go to.
 */
protected IAIState crush() {
    if (walkToBuilding()) {
        return getState();
    }
    worker.getCitizenData().setVisibleStatus(CRUSHING);
    job.setProgress(job.getProgress() + TICK_DELAY);
    final BuildingCrusher crusherBuilding = building;
    WorkerUtil.faceBlock(crusherBuilding.getPosition(), worker);
    final IRecipeStorage recipeMode = crusherBuilding.getSetting(BuildingCrusher.MODE).getValue(crusherBuilding);
    final int dailyLimit = crusherBuilding.getSetting(BuildingCrusher.DAILY_LIMIT).getValue();
    if (currentRecipeStorage == null) {
        currentRecipeStorage = recipeMode;
    }
    if ((getState() != CRAFT && crusherBuilding.getCurrentDailyQuantity() >= dailyLimit) || currentRecipeStorage == null) {
        return START_WORKING;
    }
    final IAIState check = checkForItems(currentRecipeStorage);
    if (job.getProgress() > MAX_LEVEL - Math.min((getSecondarySkillLevel() / 2) + 1, MAX_LEVEL)) {
        job.setProgress(0);
        if (check == CRAFT) {
            if (getState() != CRAFT) {
                crusherBuilding.setCurrentDailyQuantity(crusherBuilding.getCurrentDailyQuantity() + 1);
                if (crusherBuilding.getCurrentDailyQuantity() >= dailyLimit) {
                    incrementActionsDoneAndDecSaturation();
                }
            }
            if (currentRequest != null) {
                currentRequest.addDelivery(currentRecipeStorage.getPrimaryOutput());
            }
            worker.swing(Hand.MAIN_HAND);
            job.setCraftCounter(job.getCraftCounter() + 1);
            currentRecipeStorage.fullfillRecipe(getLootContext(), ImmutableList.of(worker.getItemHandlerCitizen()));
            worker.decreaseSaturationForContinuousAction();
            worker.getCitizenExperienceHandler().addExperience(0.1);
        } else if (getState() != CRAFT) {
            currentRecipeStorage = recipeMode;
            final int requestQty = Math.min((dailyLimit - crusherBuilding.getCurrentDailyQuantity()) * 2, STACKSIZE);
            if (requestQty <= 0) {
                return START_WORKING;
            }
            final ItemStack stack = currentRecipeStorage.getInput().get(0).getItemStack().copy();
            stack.setCount(requestQty);
            checkIfRequestForItemExistOrCreateAsync(stack);
            return START_WORKING;
        } else {
            return check;
        }
    }
    if (check == CRAFT) {
        Network.getNetwork().sendToTrackingEntity(new LocalizedParticleEffectMessage(currentRecipeStorage.getInput().get(0).getItemStack().copy(), crusherBuilding.getID()), worker);
        Network.getNetwork().sendToTrackingEntity(new LocalizedParticleEffectMessage(currentRecipeStorage.getPrimaryOutput().copy(), crusherBuilding.getID().below()), worker);
        SoundUtils.playSoundAtCitizen(world, building.getID(), SoundEvents.STONE_BREAK);
    }
    return getState();
}
Also used : BuildingCrusher(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingCrusher) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) LocalizedParticleEffectMessage(com.minecolonies.coremod.network.messages.client.LocalizedParticleEffectMessage) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)4 LocalizedParticleEffectMessage (com.minecolonies.coremod.network.messages.client.LocalizedParticleEffectMessage)4 ItemStack (net.minecraft.item.ItemStack)4 ICraftingBuildingModule (com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule)2 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)2 ItemStorage (com.minecolonies.api.crafting.ItemStorage)2 AITarget (com.minecolonies.api.entity.ai.statemachine.AITarget)2 AIWorkerState (com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState)2 ModTags (com.minecolonies.api.items.ModTags)2 InventoryUtils (com.minecolonies.api.util.InventoryUtils)2 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)2 SoundUtils (com.minecolonies.api.util.SoundUtils)2 ONE_HUNDRED_PERCENT (com.minecolonies.api.util.constant.Constants.ONE_HUNDRED_PERCENT)2 SIFTER_NO_MESH (com.minecolonies.api.util.constant.TranslationConstants.SIFTER_NO_MESH)2 Network (com.minecolonies.coremod.Network)2 BuildingCrusher (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingCrusher)2 BuildingSifter (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingSifter)2 StandardInteraction (com.minecolonies.coremod.colony.interactionhandling.StandardInteraction)2 JobSifter (com.minecolonies.coremod.colony.jobs.JobSifter)2 AbstractEntityAICrafting (com.minecolonies.coremod.entity.ai.basic.AbstractEntityAICrafting)2