Search in sources :

Example 1 with IFarmLogic

use of forestry.api.farming.IFarmLogic in project ForestryMC by ForestryMC.

the class FarmController method doWork.

@Override
public boolean doWork() {
    farmWorkTicks++;
    if (targets.isEmpty() || farmWorkTicks % 20 == 0) {
        setUpFarmlandTargets();
    }
    IErrorLogic errorLogic = getErrorLogic();
    if (!pendingProduce.isEmpty()) {
        boolean added = inventory.tryAddPendingProduce(pendingProduce);
        errorLogic.setCondition(!added, EnumErrorCode.NO_SPACE_INVENTORY);
        return added;
    }
    boolean hasFertilizer = fertilizerManager.maintainFertilizer(inventory);
    if (errorLogic.setCondition(!hasFertilizer, EnumErrorCode.NO_FERTILIZER)) {
        return false;
    }
    // Cull queued crops.
    if (!pendingCrops.isEmpty() && harvestProvider != null) {
        ICrop first = pendingCrops.get(0);
        if (cullCrop(first, harvestProvider)) {
            pendingCrops.remove(0);
            return true;
        } else {
            return false;
        }
    }
    // Cultivation and collection
    FarmWorkStatus farmWorkStatus = new FarmWorkStatus();
    List<FarmDirection> farmDirections = Arrays.asList(FarmDirection.values());
    Collections.shuffle(farmDirections, world.rand);
    for (FarmDirection farmSide : farmDirections) {
        IFarmLogic logic = getFarmLogic(farmSide);
        // Always try to collect windfall.
        if (collectWindfall(logic)) {
            farmWorkStatus.didWork = true;
        }
        List<FarmTarget> farmTargets = targets.get(farmSide);
        if (stage == Stage.HARVEST) {
            Collection<ICrop> harvested = FarmHelper.harvestTargets(world, farmTargets, logic, farmListeners);
            farmWorkStatus.didWork = !harvested.isEmpty();
            if (!harvested.isEmpty()) {
                pendingCrops.addAll(harvested);
                pendingCrops.sort(FarmHelper.TopDownICropComparator.INSTANCE);
                harvestProvider = logic;
            }
        } else if (stage == Stage.CULTIVATE) {
            farmWorkStatus = cultivateTargets(farmWorkStatus, farmTargets, logic, farmSide);
        }
        if (farmWorkStatus.didWork) {
            break;
        }
    }
    if (stage == Stage.CULTIVATE) {
        errorLogic.setCondition(!farmWorkStatus.hasFarmland, EnumErrorCode.NO_FARMLAND);
        errorLogic.setCondition(!farmWorkStatus.hasFertilizer, EnumErrorCode.NO_FERTILIZER);
        errorLogic.setCondition(!farmWorkStatus.hasLiquid, EnumErrorCode.NO_LIQUID_FARM);
    }
    // alternate between cultivation and harvest.
    stage = stage.next();
    return farmWorkStatus.didWork;
}
Also used : FarmWorkStatus(forestry.farming.FarmHelper.FarmWorkStatus) FarmTarget(forestry.farming.FarmTarget) FarmDirection(forestry.api.farming.FarmDirection) IFarmLogic(forestry.api.farming.IFarmLogic) ICrop(forestry.api.farming.ICrop) IErrorLogic(forestry.api.core.IErrorLogic)

Example 2 with IFarmLogic

use of forestry.api.farming.IFarmLogic in project PneumaticCraft by MineMaarten.

the class FarmLogicPlasticCustomEarth method getFarmLogic.

@Override
protected IFarmLogic getFarmLogic(IFarmHousing housing) throws Throwable {
    ItemStack[] resources = new ItemStack[] { getEarth() };
    Constructor c = getLogicClass("FarmLogicArboreal").getConstructor(IFarmHousing.class, ItemStack[].class, ItemStack.class, Iterable.class);
    return (IFarmLogic) c.newInstance(housing, resources, resources[0], Arrays.asList(new FarmablePlastic(getBlock())));
}
Also used : Constructor(java.lang.reflect.Constructor) ItemStack(net.minecraft.item.ItemStack) IFarmLogic(forestry.api.farming.IFarmLogic)

Example 3 with IFarmLogic

use of forestry.api.farming.IFarmLogic in project PneumaticCraft by MineMaarten.

the class FarmLogicPlasticNormal method getFarmLogic.

@Override
protected IFarmLogic getFarmLogic(IFarmHousing housing) throws Throwable {
    ArrayList<IFarmable> origList = (ArrayList<IFarmable>) Farmables.farmables.get("farmVegetables");
    ArrayList<IFarmable> backup = new ArrayList<IFarmable>(origList);
    origList.clear();
    origList.add(new FarmablePlastic(getBlock()));
    IFarmLogic logic = getLogicClass("FarmLogicVegetable").getConstructor(IFarmHousing.class).newInstance(housing);
    origList.clear();
    origList.addAll(backup);
    return logic;
}
Also used : IFarmable(forestry.api.farming.IFarmable) IFarmHousing(forestry.api.farming.IFarmHousing) ArrayList(java.util.ArrayList) IFarmLogic(forestry.api.farming.IFarmLogic)

Example 4 with IFarmLogic

use of forestry.api.farming.IFarmLogic in project ForestryMC by ForestryMC.

the class TilePlanter method workCycle.

@Override
protected boolean workCycle() {
    if (targets.isEmpty() || updateOnInterval(10)) {
        setUpFarmlandTargets();
    }
    IErrorLogic errorLogic = getErrorLogic();
    boolean hasFertilizer = fertilizerManager.maintainFertilizer(inventory);
    if (errorLogic.setCondition(!hasFertilizer, EnumErrorCode.NO_FERTILIZER)) {
        return false;
    }
    if (!pendingProduce.isEmpty()) {
        boolean added = inventory.tryAddPendingProduce(pendingProduce);
        errorLogic.setCondition(!added, EnumErrorCode.NO_SPACE_INVENTORY);
        return added;
    }
    // Cull queued crops.
    if (!pendingCrops.isEmpty()) {
        ICrop first = pendingCrops.get(0);
        if (cullCrop(first)) {
            pendingCrops.remove(0);
            return true;
        } else {
            return false;
        }
    }
    // Cultivation and collection
    FarmWorkStatus farmWorkStatus = new FarmWorkStatus();
    List<FarmDirection> farmDirections = Arrays.asList(FarmDirection.values());
    Collections.shuffle(farmDirections, world.rand);
    for (FarmDirection farmSide : farmDirections) {
        IFarmLogic logic = getFarmLogic(farmSide);
        // Always try to collect windfall.
        if (collectWindfall()) {
            farmWorkStatus.didWork = true;
        }
        List<FarmTarget> farmTargets = targets.get(farmSide);
        if (stage == Stage.HARVEST) {
            Collection<ICrop> harvested = FarmHelper.harvestTargets(world, farmTargets, logic, Collections.emptySet());
            farmWorkStatus.didWork = !harvested.isEmpty();
            if (!harvested.isEmpty()) {
                pendingCrops.addAll(harvested);
                pendingCrops.sort(FarmHelper.TopDownICropComparator.INSTANCE);
            }
        } else if (stage == Stage.CULTIVATE) {
            farmWorkStatus = cultivateTargets(farmWorkStatus, farmTargets, farmSide);
        }
        if (farmWorkStatus.didWork) {
            break;
        }
    }
    if (stage == Stage.CULTIVATE) {
        errorLogic.setCondition(!farmWorkStatus.hasFarmland, EnumErrorCode.NO_FARMLAND);
        errorLogic.setCondition(!farmWorkStatus.hasFertilizer, EnumErrorCode.NO_FERTILIZER);
        errorLogic.setCondition(!farmWorkStatus.hasLiquid, EnumErrorCode.NO_LIQUID_FARM);
    }
    // alternate between cultivation and harvest.
    stage = stage.next();
    return false;
}
Also used : FarmWorkStatus(forestry.farming.FarmHelper.FarmWorkStatus) FarmTarget(forestry.farming.FarmTarget) FarmDirection(forestry.api.farming.FarmDirection) IFarmLogic(forestry.api.farming.IFarmLogic) ICrop(forestry.api.farming.ICrop) IErrorLogic(forestry.api.core.IErrorLogic)

Aggregations

IFarmLogic (forestry.api.farming.IFarmLogic)4 IErrorLogic (forestry.api.core.IErrorLogic)2 FarmDirection (forestry.api.farming.FarmDirection)2 ICrop (forestry.api.farming.ICrop)2 FarmWorkStatus (forestry.farming.FarmHelper.FarmWorkStatus)2 FarmTarget (forestry.farming.FarmTarget)2 IFarmHousing (forestry.api.farming.IFarmHousing)1 IFarmable (forestry.api.farming.IFarmable)1 Constructor (java.lang.reflect.Constructor)1 ArrayList (java.util.ArrayList)1 ItemStack (net.minecraft.item.ItemStack)1