Search in sources :

Example 1 with TileEntityBarrel

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

the class EntityAIWorkComposter method harvestBarrels.

/**
 * The AI will harvest the finished barrels they found in their hut.
 *
 * @return the next IAIState after doing this
 */
private IAIState harvestBarrels() {
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_STATUS_COMPOSTER_HARVESTING));
    if (walkToBlock(currentTarget)) {
        setDelay(2);
        return getState();
    }
    if (world.getBlockEntity(currentTarget) instanceof TileEntityBarrel) {
        worker.getCitizenItemHandler().hitBlockWithToolInHand(currentTarget);
        final TileEntityBarrel te = (TileEntityBarrel) world.getBlockEntity(currentTarget);
        final ItemStack compost = te.retrieveCompost(getLootMultiplier(worker.getRandom()));
        if (getOwnBuilding().getSetting(BuildingComposter.PRODUCE_DIRT).getValue()) {
            /**
             * Podzol or dirt?
             * 5% chance (by default) for podzol, else dirt.
             * Two researches to increase it to 10% and 15%, respectively.
             */
            if (((worker.getRandom().nextInt(100)) + 1) <= (5 * (1 + worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(PODZOL_CHANCE)))) {
                InventoryUtils.addItemStackToItemHandler(worker.getInventoryCitizen(), new ItemStack(Blocks.PODZOL, MineColonies.getConfig().getServer().dirtFromCompost.get()));
            } else {
                InventoryUtils.addItemStackToItemHandler(worker.getInventoryCitizen(), new ItemStack(Blocks.DIRT, MineColonies.getConfig().getServer().dirtFromCompost.get()));
            }
        } else {
            InventoryUtils.addItemStackToItemHandler(worker.getInventoryCitizen(), compost);
        }
        worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN);
        this.incrementActionsDoneAndDecSaturation();
    }
    setDelay(AFTER_TASK_DELAY);
    return START_WORKING;
}
Also used : TileEntityBarrel(com.minecolonies.coremod.tileentities.TileEntityBarrel) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack)

Example 2 with TileEntityBarrel

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

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.getOwnBuilding();
    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 3 with TileEntityBarrel

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

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 4 with TileEntityBarrel

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

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 = building.getColony().getWorld();
    for (final BlockPos pos : building.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 5 with TileEntityBarrel

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

the class EntityAIWorkComposter method harvestBarrels.

/**
 * The AI will harvest the finished barrels they found in their hut.
 *
 * @return the next IAIState after doing this
 */
private IAIState harvestBarrels() {
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_STATUS_COMPOSTER_HARVESTING));
    if (walkToBlock(currentTarget)) {
        setDelay(2);
        return getState();
    }
    if (world.getBlockEntity(currentTarget) instanceof TileEntityBarrel) {
        worker.getCitizenItemHandler().hitBlockWithToolInHand(currentTarget);
        final TileEntityBarrel te = (TileEntityBarrel) world.getBlockEntity(currentTarget);
        final ItemStack compost = te.retrieveCompost(getLootMultiplier(worker.getRandom()));
        if (building.getSetting(BuildingComposter.PRODUCE_DIRT).getValue()) {
            /**
             * Podzol or dirt?
             * 5% chance (by default) for podzol, else dirt.
             * Two researches to increase it to 10% and 15%, respectively.
             */
            if (((worker.getRandom().nextInt(100)) + 1) <= (5 * (1 + worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(PODZOL_CHANCE)))) {
                InventoryUtils.addItemStackToItemHandler(worker.getInventoryCitizen(), new ItemStack(Blocks.PODZOL, MineColonies.getConfig().getServer().dirtFromCompost.get()));
            } else {
                InventoryUtils.addItemStackToItemHandler(worker.getInventoryCitizen(), new ItemStack(Blocks.DIRT, MineColonies.getConfig().getServer().dirtFromCompost.get()));
            }
        } else {
            InventoryUtils.addItemStackToItemHandler(worker.getInventoryCitizen(), compost);
        }
        worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN);
        this.incrementActionsDoneAndDecSaturation();
    }
    setDelay(AFTER_TASK_DELAY);
    return START_WORKING;
}
Also used : TileEntityBarrel(com.minecolonies.coremod.tileentities.TileEntityBarrel) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack)

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