Search in sources :

Example 21 with Vect

use of forestry.core.vect.Vect in project ForestryMC by ForestryMC.

the class FarmLogicArboreal method processHarvestBlock.

private ArrayList<Vect> processHarvestBlock(IFarmable germling, Stack<ICrop> crops, Set<Vect> seen, Vect start, Vect position) {
    World world = getWorld();
    ArrayList<Vect> candidates = new ArrayList<Vect>();
    // Get additional candidates to return
    for (int i = -1; i < 2; i++) {
        for (int j = yOffset; j < 2; j++) {
            for (int k = -1; k < 2; k++) {
                Vect candidate = new Vect(position.x + i, position.y + j, position.z + k);
                if (candidate.equals(position)) {
                    continue;
                }
                if (Math.abs(candidate.x - start.x) > 5) {
                    continue;
                }
                if (Math.abs(candidate.z - start.z) > 5) {
                    continue;
                }
                // See whether the given position has already been processed
                if (seen.contains(candidate)) {
                    continue;
                }
                ICrop crop = germling.getCropAt(world, candidate.x, candidate.y, candidate.z);
                if (crop != null) {
                    crops.push(crop);
                    candidates.add(candidate);
                    seen.add(candidate);
                }
            }
        }
    }
    return candidates;
}
Also used : Vect(forestry.core.vect.Vect) ArrayList(java.util.ArrayList) World(net.minecraft.world.World) ICrop(forestry.api.farming.ICrop)

Example 22 with Vect

use of forestry.core.vect.Vect in project ForestryMC by ForestryMC.

the class FarmLogicArboreal method harvest.

@Override
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
    Vect start = new Vect(x, y, z);
    if (!lastExtentsHarvest.containsKey(start)) {
        lastExtentsHarvest.put(start, 0);
    }
    int lastExtent = lastExtentsHarvest.get(start);
    if (lastExtent > extent) {
        lastExtent = 0;
    }
    Vect position = translateWithOffset(x, y + 1, z, direction, lastExtent);
    Collection<ICrop> crops = getHarvestBlocks(position);
    lastExtent++;
    lastExtentsHarvest.put(start, lastExtent);
    return crops;
}
Also used : Vect(forestry.core.vect.Vect) ICrop(forestry.api.farming.ICrop)

Example 23 with Vect

use of forestry.core.vect.Vect in project ForestryMC by ForestryMC.

the class FarmLogicCocoa method processHarvestBlock.

private ArrayList<Vect> processHarvestBlock(Stack<ICrop> crops, Set<Vect> seen, Vect start, Vect position) {
    World world = getWorld();
    ArrayList<Vect> candidates = new ArrayList<Vect>();
    // Get additional candidates to return
    for (int i = -1; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = -1; k < 2; k++) {
                Vect candidate = new Vect(position.x + i, position.y + j, position.z + k);
                if (candidate.equals(position)) {
                    continue;
                }
                if (Math.abs(candidate.x - start.x) > 5) {
                    continue;
                }
                if (Math.abs(candidate.z - start.z) > 5) {
                    continue;
                }
                // See whether the given position has already been processed
                if (seen.contains(candidate)) {
                    continue;
                }
                ICrop crop = cocoa.getCropAt(world, candidate.x, candidate.y, candidate.z);
                if (crop != null) {
                    crops.push(crop);
                    candidates.add(candidate);
                    seen.add(candidate);
                } else if (VectUtil.isWoodBlock(world, candidate)) {
                    candidates.add(candidate);
                    seen.add(candidate);
                }
            }
        }
    }
    return candidates;
}
Also used : Vect(forestry.core.vect.Vect) MutableVect(forestry.core.vect.MutableVect) ArrayList(java.util.ArrayList) World(net.minecraft.world.World) ICrop(forestry.api.farming.ICrop)

Example 24 with Vect

use of forestry.core.vect.Vect in project ForestryMC by ForestryMC.

the class FarmLogicCocoa method tryPlantingCocoa.

private boolean tryPlantingCocoa(Vect position) {
    World world = getWorld();
    MutableVect current = new MutableVect(position);
    while (VectUtil.isWoodBlock(world, current) && BlockLog.func_150165_c(VectUtil.getBlockMeta(world, current)) == 3) {
        for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
            if (direction == ForgeDirection.UP || direction == ForgeDirection.DOWN) {
                continue;
            }
            Vect candidate = new Vect(current.x + direction.offsetX, current.y, current.z + direction.offsetZ);
            if (VectUtil.isAirBlock(world, candidate)) {
                return housing.plantGermling(cocoa, world, candidate.x, candidate.y, candidate.z);
            }
        }
        current.y++;
        if (current.y - position.y > 1) {
            break;
        }
    }
    return false;
}
Also used : MutableVect(forestry.core.vect.MutableVect) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Vect(forestry.core.vect.Vect) MutableVect(forestry.core.vect.MutableVect) World(net.minecraft.world.World)

Example 25 with Vect

use of forestry.core.vect.Vect in project ForestryMC by ForestryMC.

the class FarmLogicCocoa method harvest.

@Override
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
    Vect start = new Vect(x, y, z);
    if (!lastExtentsHarvest.containsKey(start)) {
        lastExtentsHarvest.put(start, 0);
    }
    int lastExtent = lastExtentsHarvest.get(start);
    if (lastExtent > extent) {
        lastExtent = 0;
    }
    Vect position = translateWithOffset(x, y + 1, z, direction, lastExtent);
    Collection<ICrop> crops = getHarvestBlocks(position);
    lastExtent++;
    lastExtentsHarvest.put(start, lastExtent);
    return crops;
}
Also used : Vect(forestry.core.vect.Vect) MutableVect(forestry.core.vect.MutableVect) ICrop(forestry.api.farming.ICrop)

Aggregations

Vect (forestry.core.vect.Vect)59 World (net.minecraft.world.World)28 ItemStack (net.minecraft.item.ItemStack)19 ICrop (forestry.api.farming.ICrop)18 MutableVect (forestry.core.vect.MutableVect)15 Block (net.minecraft.block.Block)15 Stack (java.util.Stack)11 ArrayList (java.util.ArrayList)10 TileEntity (net.minecraft.tileentity.TileEntity)9 IFarmable (forestry.api.farming.IFarmable)7 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)7 ITileStructure (forestry.api.core.ITileStructure)4 HashSet (java.util.HashSet)4 Random (java.util.Random)4 IFarmComponent (forestry.api.farming.IFarmComponent)3 EnumStructureBlock (forestry.core.utils.Schemata.EnumStructureBlock)3 IVect (forestry.core.vect.IVect)3 List (java.util.List)3 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)3 EnumTemperature (forestry.api.core.EnumTemperature)2