Search in sources :

Example 46 with Vect

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

the class TileFarmPlain method createTargets.

private static TreeMap<ForgeDirection, List<FarmTarget>> createTargets(World world, Vect targetStart, final int allowedExtent, final int farmSizeNorthSouth, final int farmSizeEastWest) {
    TreeMap<ForgeDirection, List<FarmTarget>> targets = new TreeMap<ForgeDirection, List<FarmTarget>>();
    for (ForgeDirection farmSide : CARDINAL_DIRECTIONS) {
        int farmSize;
        if (farmSide == ForgeDirection.NORTH || farmSide == ForgeDirection.SOUTH) {
            farmSize = farmSizeNorthSouth;
        } else {
            farmSize = farmSizeEastWest;
        }
        // targets extend sideways in a pinwheel pattern around the farm, so they need to go a little extra distance
        final int targetMaxLimit = allowedExtent + farmSize;
        ForgeDirection layoutDirection = getLayoutDirection(farmSide);
        Vect targetLocation = FarmHelper.getFarmMultiblockCorner(world, targetStart, farmSide, layoutDirection.getOpposite());
        Vect firstLocation = targetLocation.add(farmSide);
        Vect firstGroundPosition = getGroundPosition(world, firstLocation);
        if (firstGroundPosition == null) {
            break;
        }
        int groundHeight = firstGroundPosition.getY();
        List<FarmTarget> farmSideTargets = new ArrayList<FarmTarget>();
        for (int i = 0; i < allowedExtent; i++) {
            targetLocation = targetLocation.add(farmSide);
            Vect groundLocation = new Vect(targetLocation.getX(), groundHeight, targetLocation.getZ());
            int targetLimit = targetMaxLimit;
            if (!Config.squareFarms) {
                targetLimit = targetMaxLimit - i - 1;
            }
            Block platform = VectUtil.getBlock(world, groundLocation);
            Vect soilPosition = new Vect(groundLocation.x, groundLocation.y + 1, groundLocation.z);
            if (!StructureLogicFarm.bricks.contains(platform) || !FarmLogic.canBreakSoil(world, soilPosition)) {
                break;
            }
            FarmTarget target = new FarmTarget(targetLocation, layoutDirection, targetLimit);
            farmSideTargets.add(target);
        }
        targets.put(farmSide, farmSideTargets);
    }
    return targets;
}
Also used : FarmTarget(forestry.farming.FarmTarget) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Vect(forestry.core.vect.Vect) ArrayList(java.util.ArrayList) Block(net.minecraft.block.Block) List(java.util.List) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap)

Example 47 with Vect

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

the class FarmLogicArboreal method collect.

@SuppressWarnings("unchecked")
@Override
public Collection<ItemStack> collect() {
    Collection<ItemStack> products = produce;
    produce = new ArrayList<ItemStack>();
    Vect coords = new Vect(housing.getCoords());
    Vect area = new Vect(housing.getArea());
    Vect offset = new Vect(housing.getOffset());
    Vect min = coords.add(offset);
    Vect max = min.add(area);
    AxisAlignedBB harvestBox = AxisAlignedBB.getBoundingBox(min.x, min.y, min.z, max.x, getWorld().getHeight(), max.z);
    List<Entity> list = getWorld().getEntitiesWithinAABB(Entity.class, harvestBox);
    for (Entity entity : list) {
        if (entity instanceof EntityItem) {
            EntityItem item = (EntityItem) entity;
            if (!item.isDead) {
                ItemStack contained = item.getEntityItem();
                if (isAcceptedGermling(contained) || isWindfall(contained)) {
                    produce.add(contained.copy());
                    item.setDead();
                }
            }
        }
    }
    return products;
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) Vect(forestry.core.vect.Vect) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 48 with Vect

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

the class FarmLogicArboreal method getHarvestBlocks.

private Collection<ICrop> getHarvestBlocks(Vect position) {
    World world = getWorld();
    Set<Vect> seen = new HashSet<Vect>();
    Stack<ICrop> crops = new Stack<ICrop>();
    // Determine what type we want to harvest.
    IFarmable germling = null;
    for (IFarmable germl : germlings) {
        ICrop crop = germl.getCropAt(world, position.x, position.y, position.z);
        if (crop == null) {
            continue;
        }
        crops.push(crop);
        seen.add(position);
        germling = germl;
        break;
    }
    if (germling == null) {
        return crops;
    }
    ArrayList<Vect> candidates = processHarvestBlock(germling, crops, seen, position, position);
    ArrayList<Vect> temp = new ArrayList<Vect>();
    while (!candidates.isEmpty()) {
        for (Vect candidate : candidates) {
            temp.addAll(processHarvestBlock(germling, crops, seen, position, candidate));
        }
        candidates.clear();
        candidates.addAll(temp);
        temp.clear();
    }
    return crops;
}
Also used : IFarmable(forestry.api.farming.IFarmable) Vect(forestry.core.vect.Vect) ArrayList(java.util.ArrayList) World(net.minecraft.world.World) ICrop(forestry.api.farming.ICrop) HashSet(java.util.HashSet) Stack(java.util.Stack) ItemStack(net.minecraft.item.ItemStack)

Example 49 with Vect

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

the class FarmLogicCocoa method cultivate.

@Override
public boolean cultivate(int x, int y, int z, ForgeDirection direction, int extent) {
    Vect start = new Vect(x, y, z);
    if (!lastExtentsCultivation.containsKey(start)) {
        lastExtentsCultivation.put(start, 0);
    }
    int lastExtent = lastExtentsCultivation.get(start);
    if (lastExtent > extent) {
        lastExtent = 0;
    }
    Vect position = translateWithOffset(x, y + 1, z, direction, lastExtent);
    boolean result = tryPlantingCocoa(position);
    lastExtent++;
    lastExtentsCultivation.put(start, lastExtent);
    return result;
}
Also used : Vect(forestry.core.vect.Vect) MutableVect(forestry.core.vect.MutableVect)

Example 50 with Vect

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

the class FarmLogicCocoa method getHarvestBlocks.

private Collection<ICrop> getHarvestBlocks(Vect position) {
    Set<Vect> seen = new HashSet<Vect>();
    Stack<ICrop> crops = new Stack<ICrop>();
    // Determine what type we want to harvest.
    Block block = VectUtil.getBlock(getWorld(), position);
    ICrop crop = null;
    if (!block.isWood(getWorld(), position.x, position.y, position.z)) {
        crop = cocoa.getCropAt(getWorld(), position.x, position.y, position.z);
        if (crop == null) {
            return crops;
        }
    }
    if (crop != null) {
        crops.add(crop);
    }
    ArrayList<Vect> candidates = processHarvestBlock(crops, seen, position, position);
    ArrayList<Vect> temp = new ArrayList<Vect>();
    while (!candidates.isEmpty() && crops.size() < 20) {
        for (Vect candidate : candidates) {
            temp.addAll(processHarvestBlock(crops, seen, position, candidate));
        }
        candidates.clear();
        candidates.addAll(temp);
        temp.clear();
    }
    return crops;
}
Also used : Vect(forestry.core.vect.Vect) MutableVect(forestry.core.vect.MutableVect) ArrayList(java.util.ArrayList) Block(net.minecraft.block.Block) ICrop(forestry.api.farming.ICrop) HashSet(java.util.HashSet) Stack(java.util.Stack) ItemStack(net.minecraft.item.ItemStack)

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