Search in sources :

Example 26 with Vect

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

the class FarmLogicCrops 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 + 1, z, direction, i);
        for (IFarmable seed : seeds) {
            ICrop crop = seed.getCropAt(world, position.x, position.y, position.z);
            if (crop != null) {
                crops.push(crop);
            }
        }
    }
    return crops;
}
Also used : IFarmable(forestry.api.farming.IFarmable) Vect(forestry.core.vect.Vect) IVect(forestry.core.vect.IVect) World(net.minecraft.world.World) ICrop(forestry.api.farming.ICrop) Stack(java.util.Stack) ItemStack(net.minecraft.item.ItemStack)

Example 27 with Vect

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

the class FarmLogicCrops 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, max.y, max.z);
    List<Entity> list = housing.getWorld().getEntitiesWithinAABB(Entity.class, harvestBox);
    int i;
    for (i = 0; i < list.size(); i++) {
        Entity entity = list.get(i);
        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) IVect(forestry.core.vect.IVect) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 28 with Vect

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

the class FarmLogicOrchard method processHarvestBlock.

private List<Vect> processHarvestBlock(Stack<ICrop> crops, Set<Vect> seen, Vect start, Vect position) {
    World world = getWorld();
    List<Vect> candidates = new ArrayList<Vect>();
    // Get additional candidates to return
    for (int i = -2; i < 3; 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 (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;
                }
                if (VectUtil.isWoodBlock(world, candidate)) {
                    candidates.add(candidate);
                    seen.add(candidate);
                } else if (isFruitBearer(world, candidate)) {
                    candidates.add(candidate);
                    seen.add(candidate);
                    ICrop crop = getCrop(world, candidate);
                    if (crop != null) {
                        crops.push(crop);
                    }
                }
            }
        }
    }
    return candidates;
}
Also used : Vect(forestry.core.vect.Vect) ArrayList(java.util.ArrayList) World(net.minecraft.world.World) ICrop(forestry.api.farming.ICrop)

Example 29 with Vect

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

the class FarmableFarmCraftory method getCropAt.

@Override
public ICrop getCropAt(World world, int x, int y, int z) {
    Block block = world.getBlock(x, y, z);
    if (block != PluginFarmCraftory.blockSingle && block != PluginFarmCraftory.blockMulti) {
        return null;
    }
    TileEntity tile = world.getTileEntity(x, y, z);
    if (tile == null) {
        return null;
    }
    if (PluginFarmCraftory.getGrowthStage(tile) < 2) {
        return null;
    }
    return new CropBlock(world, block, world.getBlockMetadata(x, y, z), new Vect(x, y, z));
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Vect(forestry.core.vect.Vect) Block(net.minecraft.block.Block)

Example 30 with Vect

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

the class StructureLogic method resetStructureBlocks.

protected void resetStructureBlocks(Schemata schemata) {
    Vect dimensions = schemata.getDimensions(isRotated);
    int offsetX = schemata.getxOffset();
    int offsetZ = schemata.getzOffset();
    if (isRotated) {
        offsetX = schemata.getzOffset();
        offsetZ = schemata.getxOffset();
    }
    for (int i = 0; i < dimensions.x; i++) {
        for (int j = 0; j < schemata.getHeight(); j++) {
            for (int k = 0; k < dimensions.z; k++) {
                int x = structureTile.xCoord + i + offsetX;
                int y = structureTile.yCoord + j + schemata.getyOffset();
                int z = structureTile.zCoord + k + offsetZ;
                TileEntity tile = structureTile.getWorldObj().getTileEntity(x, y, z);
                if (!(tile instanceof ITileStructure)) {
                    continue;
                }
                ITileStructure part = (ITileStructure) tile;
                if (!part.getTypeUID().equals(getTypeUID())) {
                    continue;
                }
                part.onStructureReset();
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITileStructure(forestry.api.core.ITileStructure) Vect(forestry.core.vect.Vect)

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