Search in sources :

Example 6 with TileEntityBarrel

use of com.minecolonies.coremod.tileentities.TileEntityBarrel in project minecolonies by Minecolonies.

the class EntityAIWorkComposter method decideWhatToDo.

/**
 * Method for the AI to decide what to do. Possible actions: harvest barrels, fill barrels or idle
 *
 * @return the decision it made
 */
private IAIState decideWhatToDo() {
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_STATUS_IDLING));
    worker.getCitizenData().setVisibleStatus(VisibleCitizenStatus.WORKING);
    if (walkToBuilding()) {
        setDelay(2);
        return getState();
    }
    final BuildingComposter building = this.building;
    for (final BlockPos barrel : building.getBarrels()) {
        final TileEntity te = world.getBlockEntity(barrel);
        if (te instanceof TileEntityBarrel) {
            this.currentTarget = barrel;
            if (((TileEntityBarrel) te).isDone()) {
                setDelay(DECIDE_DELAY);
                worker.getCitizenData().setVisibleStatus(COMPOST);
                return COMPOSTER_HARVEST;
            }
        }
    }
    for (final BlockPos barrel : building.getBarrels()) {
        final TileEntity te = world.getBlockEntity(barrel);
        if (te instanceof TileEntityBarrel && !((TileEntityBarrel) te).checkIfWorking()) {
            this.currentTarget = barrel;
            setDelay(DECIDE_DELAY);
            worker.getCitizenData().setVisibleStatus(COMPOST);
            return COMPOSTER_FILL;
        }
    }
    setDelay(DECIDE_DELAY);
    return START_WORKING;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityBarrel(com.minecolonies.coremod.tileentities.TileEntityBarrel) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) BuildingComposter(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingComposter)

Example 7 with TileEntityBarrel

use of com.minecolonies.coremod.tileentities.TileEntityBarrel in project minecolonies by Minecolonies.

the class EntityAIWorkComposter method fillBarrels.

/**
 * The AI will now fill the barrel that he found empty on his building
 *
 * @return the nex IAIState after doing this
 */
private IAIState fillBarrels() {
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_STATUS_COMPOSTER_FILLING));
    if (worker.getItemInHand(Hand.MAIN_HAND) == ItemStack.EMPTY) {
        final int slot = InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), stack -> building.getModuleMatching(ItemListModule.class, m -> m.getId().equals(COMPOSTABLE_LIST)).isItemInList(new ItemStorage(stack)));
        if (slot >= 0) {
            worker.setItemInHand(Hand.MAIN_HAND, worker.getInventoryCitizen().getStackInSlot(slot));
        } else {
            return GET_MATERIALS;
        }
    }
    if (walkToBlock(currentTarget)) {
        setDelay(2);
        return getState();
    }
    if (world.getBlockEntity(currentTarget) instanceof TileEntityBarrel) {
        final TileEntityBarrel barrel = (TileEntityBarrel) world.getBlockEntity(currentTarget);
        worker.getCitizenItemHandler().hitBlockWithToolInHand(currentTarget);
        barrel.addItem(worker.getItemInHand(Hand.MAIN_HAND));
        worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN);
        this.incrementActionsDoneAndDecSaturation();
        worker.setItemInHand(Hand.MAIN_HAND, ItemStackUtils.EMPTY);
        incrementActionsDone();
    }
    setDelay(AFTER_TASK_DELAY);
    return START_WORKING;
}
Also used : TileEntityBarrel(com.minecolonies.coremod.tileentities.TileEntityBarrel) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 8 with TileEntityBarrel

use of com.minecolonies.coremod.tileentities.TileEntityBarrel in project minecolonies by ldtteam.

the class BlockBarrel method use.

@NotNull
@Override
public ActionResultType use(final BlockState state, final World worldIn, final BlockPos pos, final PlayerEntity player, final Hand hand, final BlockRayTraceResult ray) {
    final ItemStack itemstack = player.inventory.getSelected();
    final TileEntity te = worldIn.getBlockEntity(pos);
    if (te instanceof TileEntityBarrel && !worldIn.isClientSide) {
        ((TileEntityBarrel) te).useBarrel(player, itemstack, ray.getDirection());
        ((TileEntityBarrel) te).updateBlock(worldIn);
    }
    return ActionResultType.SUCCESS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityBarrel(com.minecolonies.coremod.tileentities.TileEntityBarrel) ItemStack(net.minecraft.item.ItemStack) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with TileEntityBarrel

use of com.minecolonies.coremod.tileentities.TileEntityBarrel in project minecolonies by ldtteam.

the class EntityAIWorkComposter method accelerateBarrels.

/**
 * Actually accelerate the Barrels
 */
private IAIState accelerateBarrels() {
    final int accelerationTicks = (worker.getCitizenData().getCitizenSkillHandler().getLevel(getModuleForJob().getPrimarySkill()) / 10) * 2;
    final World world = getOwnBuilding().getColony().getWorld();
    for (final BlockPos pos : getOwnBuilding().getBarrels()) {
        if (WorldUtil.isBlockLoaded(world, pos)) {
            final TileEntity entity = world.getBlockEntity(pos);
            if (entity instanceof TileEntityBarrel) {
                final TileEntityBarrel barrel = (TileEntityBarrel) entity;
                for (int i = 0; i < accelerationTicks; i++) {
                    if (barrel.checkIfWorking() && !barrel.isDone()) {
                        barrel.tick();
                    }
                }
            }
        }
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityBarrel(com.minecolonies.coremod.tileentities.TileEntityBarrel) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World)

Example 10 with TileEntityBarrel

use of com.minecolonies.coremod.tileentities.TileEntityBarrel in project minecolonies by ldtteam.

the class EntityAIWorkComposter method fillBarrels.

/**
 * The AI will now fill the barrel that he found empty on his building
 *
 * @return the nex IAIState after doing this
 */
private IAIState fillBarrels() {
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_STATUS_COMPOSTER_FILLING));
    if (worker.getItemInHand(Hand.MAIN_HAND) == ItemStack.EMPTY) {
        final int slot = InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), stack -> getOwnBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(COMPOSTABLE_LIST)).isItemInList(new ItemStorage(stack)));
        if (slot >= 0) {
            worker.setItemInHand(Hand.MAIN_HAND, worker.getInventoryCitizen().getStackInSlot(slot));
        } else {
            return GET_MATERIALS;
        }
    }
    if (walkToBlock(currentTarget)) {
        setDelay(2);
        return getState();
    }
    if (world.getBlockEntity(currentTarget) instanceof TileEntityBarrel) {
        final TileEntityBarrel barrel = (TileEntityBarrel) world.getBlockEntity(currentTarget);
        worker.getCitizenItemHandler().hitBlockWithToolInHand(currentTarget);
        barrel.addItem(worker.getItemInHand(Hand.MAIN_HAND));
        worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN);
        this.incrementActionsDoneAndDecSaturation();
        worker.setItemInHand(Hand.MAIN_HAND, ItemStackUtils.EMPTY);
        incrementActionsDone();
    }
    setDelay(AFTER_TASK_DELAY);
    return START_WORKING;
}
Also used : TileEntityBarrel(com.minecolonies.coremod.tileentities.TileEntityBarrel) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Aggregations

TileEntityBarrel (com.minecolonies.coremod.tileentities.TileEntityBarrel)10 TileEntity (net.minecraft.tileentity.TileEntity)6 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)6 ItemStack (net.minecraft.item.ItemStack)4 BlockPos (net.minecraft.util.math.BlockPos)4 ItemStorage (com.minecolonies.api.crafting.ItemStorage)2 BuildingComposter (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingComposter)2 World (net.minecraft.world.World)2 NotNull (org.jetbrains.annotations.NotNull)2