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;
}
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;
}
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;
}
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;
}
Aggregations