Search in sources :

Example 1 with FarmDirection

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

the class GuiSolderingIron method drawGuiContainerBackgroundLayer.

@Override
protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) {
    super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
    ICircuitLayout layout = ((ContainerSolderingIron) inventorySlots).getLayout();
    String title = layout.getName();
    fontRenderer.drawString(title, guiLeft + 8 + textLayout.getCenteredOffset(title, 138), guiTop + 16, ColourProperties.INSTANCE.get("gui.screen"));
    for (int i = 0; i < 4; i++) {
        String description;
        ItemStack tube = itemInventory.getStackInSlot(i + 2);
        CircuitRecipe recipe = SolderManager.getMatchingRecipe(layout, tube);
        if (recipe == null) {
            description = "(" + Translator.translateToLocal("for.gui.noeffect") + ")";
        } else {
            description = recipe.getCircuit().getLocalizedName();
        }
        int row = i * 20;
        fontRenderer.drawString(description, guiLeft + 32, guiTop + 36 + row, ColourProperties.INSTANCE.get("gui.screen"));
        if (tube.isEmpty()) {
            ICircuitSocketType socketType = layout.getSocketType();
            if (CircuitSocketType.FARM.equals(socketType)) {
                FarmDirection farmDirection = FarmDirection.values()[i];
                String farmDirectionString = farmDirection.toString().toLowerCase(Locale.ENGLISH);
                String localizedDirection = Translator.translateToLocal("for.gui.solder." + farmDirectionString);
                fontRenderer.drawString(localizedDirection, guiLeft + 17, guiTop + 36 + row, ColourProperties.INSTANCE.get("gui.screen"));
            }
        }
    }
}
Also used : ICircuitLayout(forestry.api.circuits.ICircuitLayout) ICircuitSocketType(forestry.api.circuits.ICircuitSocketType) FarmDirection(forestry.api.farming.FarmDirection) ItemStack(net.minecraft.item.ItemStack)

Example 2 with FarmDirection

use of forestry.api.farming.FarmDirection 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 3 with FarmDirection

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

the class FarmHelper method createTargets.

public static void createTargets(World world, IFarmHousing farmHousing, Map<FarmDirection, List<FarmTarget>> targets, BlockPos targetStart, final int allowedExtent, final int farmSizeNorthSouth, final int farmSizeEastWest, BlockPos minFarmCoord, BlockPos maxFarmCoord) {
    for (FarmDirection farmSide : FarmDirection.values()) {
        final int farmWidth;
        if (farmSide == FarmDirection.NORTH || farmSide == FarmDirection.SOUTH) {
            farmWidth = farmSizeEastWest;
        } else {
            farmWidth = farmSizeNorthSouth;
        }
        // targets extend sideways in a pinwheel pattern around the farm, so they need to go a little extra distance
        final int targetMaxLimit = allowedExtent + farmWidth;
        FarmDirection layoutDirection = getLayoutDirection(farmSide);
        List<FarmTarget> farmSideTargets = new ArrayList<>();
        targets.put(farmSide, farmSideTargets);
        BlockPos targetLocation = FarmHelper.getFarmMultiblockCorner(targetStart, farmSide, layoutDirection, minFarmCoord, maxFarmCoord);
        BlockPos firstLocation = targetLocation.offset(farmSide.getFacing());
        BlockPos firstGroundPosition = getGroundPosition(world, farmHousing, firstLocation);
        if (firstGroundPosition != null) {
            int groundHeight = firstGroundPosition.getY();
            for (int i = 0; i < allowedExtent; i++) {
                targetLocation = targetLocation.offset(farmSide.getFacing());
                BlockPos groundLocation = new BlockPos(targetLocation.getX(), groundHeight, targetLocation.getZ());
                if (!world.isBlockLoaded(groundLocation) || !farmHousing.isValidPlatform(world, groundLocation)) {
                    break;
                }
                int targetLimit = targetMaxLimit;
                if (!farmHousing.isSquare()) {
                    targetLimit = targetMaxLimit - i - 1;
                }
                FarmTarget target = new FarmTarget(targetLocation, layoutDirection, targetLimit);
                farmSideTargets.add(target);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) FarmDirection(forestry.api.farming.FarmDirection)

Example 4 with FarmDirection

use of forestry.api.farming.FarmDirection 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)

Example 5 with FarmDirection

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

the class GhostItemStackWidget method getDirectionString.

private String getDirectionString() {
    if (slot.getSlotIndex() >= InventoryPlanter.SLOT_PRODUCTION_1 || slot.getSlotIndex() < InventoryPlanter.SLOT_RESOURCES_1 + InventoryPlanter.SLOT_RESOURCES_COUNT) {
        return "";
    }
    int index = slot.getSlotIndex() % 4;
    FarmDirection direction = FarmDirection.values()[index];
    String directionString = direction.toString().toLowerCase(Locale.ENGLISH);
    return Translator.translateToLocal("for.gui.planter." + directionString);
}
Also used : FarmDirection(forestry.api.farming.FarmDirection)

Aggregations

FarmDirection (forestry.api.farming.FarmDirection)6 IErrorLogic (forestry.api.core.IErrorLogic)2 ICrop (forestry.api.farming.ICrop)2 IFarmLogic (forestry.api.farming.IFarmLogic)2 FarmWorkStatus (forestry.farming.FarmHelper.FarmWorkStatus)2 FarmTarget (forestry.farming.FarmTarget)2 ItemStack (net.minecraft.item.ItemStack)2 BlockPos (net.minecraft.util.math.BlockPos)2 EnumAcidity (binnie.botany.api.gardening.EnumAcidity)1 IBlockSoil (binnie.botany.api.gardening.IBlockSoil)1 IGardeningManager (binnie.botany.api.gardening.IGardeningManager)1 ICircuitLayout (forestry.api.circuits.ICircuitLayout)1 ICircuitSocketType (forestry.api.circuits.ICircuitSocketType)1 ArrayList (java.util.ArrayList)1 IBlockState (net.minecraft.block.state.IBlockState)1