Search in sources :

Example 51 with Vect

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

the class FarmLogicEnder method maintainGermlings.

@Override
protected boolean maintainGermlings(int x, int y, int z, ForgeDirection direction, int extent) {
    World world = getWorld();
    for (int i = 0; i < extent; i++) {
        Vect position = translateWithOffset(x, y, z, direction, i);
        if (!VectUtil.isAirBlock(world, position) && !Utils.isReplaceableBlock(world, position.x, position.y, position.z)) {
            continue;
        }
        ItemStack below = VectUtil.getAsItemStack(world, position.add(0, -1, 0));
        if (!isAcceptedSoil(below)) {
            continue;
        }
        return trySetCrop(position);
    }
    return false;
}
Also used : Vect(forestry.core.vect.Vect) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack)

Example 52 with Vect

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

the class FarmHelper method getFarmSizeInDirection.

private static int getFarmSizeInDirection(World world, Vect start, ForgeDirection farmSide, ForgeDirection searchDirection) {
    int size = 0;
    ForgeDirection toCenter = farmSide.getOpposite();
    Vect target = start.add(farmSide);
    TileEntity farmTile;
    do {
        size++;
        target = target.add(searchDirection);
        Vect farmTileLocation = target.add(toCenter);
        farmTile = VectUtil.getTile(world, farmTileLocation);
    } while (farmTile instanceof IFarmComponent);
    return size;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IFarmComponent(forestry.api.farming.IFarmComponent) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Vect(forestry.core.vect.Vect) MutableVect(forestry.core.vect.MutableVect)

Example 53 with Vect

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

the class FarmLogicPeat method harvest.

@Override
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
    World world = getWorld();
    Stack<ICrop> crops = new Stack<ICrop>();
    for (int i = 0; i < extent; i++) {
        Vect position = translateWithOffset(x, y, z, direction, i);
        ItemStack occupant = VectUtil.getAsItemStack(world, position);
        if (occupant.getItem() == null) {
            continue;
        }
        Block block = Block.getBlockFromItem(occupant.getItem());
        if (block == null || !(block instanceof BlockSoil)) {
            continue;
        }
        BlockSoil blockSoil = (BlockSoil) block;
        BlockSoil.SoilType soilType = blockSoil.getTypeFromMeta(occupant.getItemDamage());
        if (soilType == BlockSoil.SoilType.PEAT) {
            crops.push(new CropPeat(world, position));
        }
    }
    return crops;
}
Also used : Vect(forestry.core.vect.Vect) Block(net.minecraft.block.Block) ForestryBlock(forestry.core.config.ForestryBlock) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) ICrop(forestry.api.farming.ICrop) BlockSoil(forestry.core.gadgets.BlockSoil) Stack(java.util.Stack) ItemStack(net.minecraft.item.ItemStack)

Example 54 with Vect

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

the class FarmLogicRubber method getHarvestBlocks.

private Collection<ICrop> getHarvestBlocks(Vect position) {
    Set<Vect> seen = new HashSet<Vect>();
    Stack<ICrop> crops = new Stack<ICrop>();
    World world = getWorld();
    // Determine what type we want to harvest.
    Block block = VectUtil.getBlock(world, position);
    if (!StackUtils.equals(block, PluginIC2.rubberwood)) {
        return crops;
    }
    int meta = VectUtil.getBlockMeta(world, position);
    if (meta >= 2 && meta <= 5) {
        crops.push(new CropRubber(getWorld(), block, meta, position));
    }
    ArrayList<Vect> candidates = processHarvestBlock(crops, seen, position);
    ArrayList<Vect> temp = new ArrayList<Vect>();
    while (!candidates.isEmpty() && crops.size() < 100) {
        for (Vect candidate : candidates) {
            temp.addAll(processHarvestBlock(crops, seen, candidate));
        }
        candidates.clear();
        candidates.addAll(temp);
        temp.clear();
    }
    return crops;
}
Also used : Vect(forestry.core.vect.Vect) ArrayList(java.util.ArrayList) Block(net.minecraft.block.Block) World(net.minecraft.world.World) ICrop(forestry.api.farming.ICrop) HashSet(java.util.HashSet) Stack(java.util.Stack) ItemStack(net.minecraft.item.ItemStack)

Example 55 with Vect

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

the class FarmLogicRubber method processHarvestBlock.

private ArrayList<Vect> processHarvestBlock(Stack<ICrop> crops, Set<Vect> seen, Vect position) {
    World world = getWorld();
    ArrayList<Vect> candidates = new ArrayList<Vect>();
    // Get additional candidates to return
    for (int j = 0; j < 2; j++) {
        Vect candidate = new Vect(position.x, position.y + j, position.z);
        if (candidate.equals(position)) {
            continue;
        }
        // See whether the given position has already been processed
        if (seen.contains(candidate)) {
            continue;
        }
        Block block = VectUtil.getBlock(world, candidate);
        if (StackUtils.equals(block, PluginIC2.rubberwood)) {
            int meta = VectUtil.getBlockMeta(world, candidate);
            if (meta >= 2 && meta <= 5) {
                crops.push(new CropRubber(world, block, meta, candidate));
            }
            candidates.add(candidate);
            seen.add(candidate);
        }
    }
    return candidates;
}
Also used : Vect(forestry.core.vect.Vect) ArrayList(java.util.ArrayList) Block(net.minecraft.block.Block) World(net.minecraft.world.World)

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