Search in sources :

Example 1 with IFarmable

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

the class FarmLogicInfernal method harvest.

@Override
public Collection<ICrop> harvest(World world, BlockPos pos, FarmDirection direction, int extent) {
    Stack<ICrop> crops = new Stack<>();
    for (int i = 0; i < extent; i++) {
        BlockPos position = translateWithOffset(pos.up(), direction, i);
        if (!world.isBlockLoaded(position)) {
            break;
        }
        if (world.isAirBlock(pos)) {
            continue;
        }
        IBlockState blockState = world.getBlockState(position);
        for (IFarmable farmable : getFarmables()) {
            ICrop crop = farmable.getCropAt(world, position, blockState);
            if (crop != null) {
                crops.push(crop);
                break;
            }
        }
    }
    return crops;
}
Also used : IFarmable(forestry.api.farming.IFarmable) IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) ICrop(forestry.api.farming.ICrop) Stack(java.util.Stack) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IFarmable

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

the class FarmLogicArboreal method harvestBlocks.

private Collection<ICrop> harvestBlocks(World world, BlockPos position) {
    // Determine what type we want to harvest.
    IFarmable farmable = getFarmableForBlock(world, position, getFarmables());
    if (farmable == null) {
        return Collections.emptyList();
    }
    // get all crops of the same type that are connected to the first one
    Stack<BlockPos> knownCropPositions = new Stack<>();
    knownCropPositions.add(position);
    Set<BlockPos> checkedBlocks = new HashSet<>();
    Stack<ICrop> crops = new Stack<>();
    while (!knownCropPositions.empty()) {
        BlockPos knownCropPos = knownCropPositions.pop();
        for (BlockPos candidate : BlockPos.getAllInBox(knownCropPos.add(-1, -1, -1), knownCropPos.add(1, 1, 1))) {
            if (!world.isBlockLoaded(candidate)) {
                return crops;
            }
            if (!checkedBlocks.contains(candidate)) {
                checkedBlocks.add(candidate);
                IBlockState blockState = world.getBlockState(candidate);
                ICrop crop = farmable.getCropAt(world, candidate, blockState);
                if (crop != null) {
                    crops.push(crop);
                    knownCropPositions.push(candidate);
                }
            }
        }
    }
    return crops;
}
Also used : IFarmable(forestry.api.farming.IFarmable) IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) ICrop(forestry.api.farming.ICrop) Stack(java.util.Stack) ItemStack(net.minecraft.item.ItemStack) HashSet(java.util.HashSet)

Example 3 with IFarmable

use of forestry.api.farming.IFarmable in project Binnie by ForestryMC.

the class GardenLogic method trySetCrop.

private boolean trySetCrop(World world, BlockPos position, FarmDirection direction, IFarmHousing housing) {
    for (IFarmable farmable : farmables) {
        if (!housing.plantGermling(farmable, world, position, direction)) {
            continue;
        }
        if (housing instanceof IOwnedTile) {
            TileEntity tile = world.getTileEntity(position);
            if (tile instanceof TileEntityFlower) {
                TileEntityFlower flower = (TileEntityFlower) tile;
                IOwnedTile owned = (IOwnedTile) housing;
                flower.setOwner(owned.getOwnerHandler().getOwner());
            }
        }
        return true;
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IFarmable(forestry.api.farming.IFarmable) IOwnedTile(forestry.core.owner.IOwnedTile) TileEntityFlower(binnie.botany.tile.TileEntityFlower)

Example 4 with IFarmable

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

Aggregations

IFarmable (forestry.api.farming.IFarmable)4 ICrop (forestry.api.farming.ICrop)2 Stack (java.util.Stack)2 IBlockState (net.minecraft.block.state.IBlockState)2 ItemStack (net.minecraft.item.ItemStack)2 BlockPos (net.minecraft.util.math.BlockPos)2 TileEntityFlower (binnie.botany.tile.TileEntityFlower)1 IFarmHousing (forestry.api.farming.IFarmHousing)1 IFarmLogic (forestry.api.farming.IFarmLogic)1 IOwnedTile (forestry.core.owner.IOwnedTile)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 TileEntity (net.minecraft.tileentity.TileEntity)1