Search in sources :

Example 31 with Vect

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

the class FarmLogicPoale 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 : germlings) {
            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) World(net.minecraft.world.World) ICrop(forestry.api.farming.ICrop) Stack(java.util.Stack) ItemStack(net.minecraft.item.ItemStack)

Example 32 with Vect

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

the class StructureLogicAlveary method determineMasterState.

@Override
protected EnumStructureState determineMasterState(Schemata schemata, boolean rotate) {
    Vect dimensions = schemata.getDimensions(rotate);
    int offsetX = schemata.getxOffset();
    int offsetZ = schemata.getzOffset();
    if (rotate) {
        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;
                if (!structureTile.getWorldObj().blockExists(x, y, z)) {
                    return EnumStructureState.INDETERMINATE;
                }
                EnumStructureBlock required = schemata.getAt(i, j, k, rotate);
                if (required == EnumStructureBlock.ANY) {
                    continue;
                }
                TileEntity tile = structureTile.getWorldObj().getTileEntity(x, y, z);
                Block block = structureTile.getWorldObj().getBlock(x, y, z);
                switch(required) {
                    case AIR:
                        if (!block.isAir(structureTile.getWorldObj(), x, y, z)) {
                            return EnumStructureState.INVALID;
                        }
                        break;
                    case BLOCK_A:
                        if (tile == null || !(tile instanceof IAlvearyComponent)) {
                            return EnumStructureState.INVALID;
                        }
                        if (!((ITileStructure) tile).getTypeUID().equals(UID_ALVEARY)) {
                            return EnumStructureState.INVALID;
                        }
                        break;
                    case MASTER:
                    case BLOCK_B:
                        if (tile == null || !(tile instanceof TileAlvearyPlain)) {
                            return EnumStructureState.INVALID;
                        }
                        break;
                    case BLOCK_C:
                        if (!slabBlocks.contains(block)) {
                            return EnumStructureState.INVALID;
                        }
                        if ((structureTile.getWorldObj().getBlockMetadata(x, y, z) & 8) != 0) {
                            return EnumStructureState.INVALID;
                        }
                        break;
                    case BLOCK_D:
                        if (block != Blocks.spruce_stairs) {
                            return EnumStructureState.INVALID;
                        }
                        break;
                    case FOREIGN:
                        if (tile instanceof ITileStructure) {
                            return EnumStructureState.INVALID;
                        }
                        break;
                    default:
                        return EnumStructureState.INDETERMINATE;
                }
            }
        }
    }
    return EnumStructureState.VALID;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITileStructure(forestry.api.core.ITileStructure) Vect(forestry.core.vect.Vect) Block(net.minecraft.block.Block) ForestryBlock(forestry.core.config.ForestryBlock) EnumStructureBlock(forestry.core.utils.Schemata.EnumStructureBlock) IAlvearyComponent(forestry.api.apiculture.IAlvearyComponent) EnumStructureBlock(forestry.core.utils.Schemata.EnumStructureBlock)

Example 33 with Vect

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

the class Bee method hasFlower.

@Override
public boolean hasFlower(IBeeHousing housing) {
    IFlowerProvider provider = genome.getFlowerProvider();
    Vect housingPos = new Vect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord());
    Vect area = getArea(genome, housing);
    Vect offset = new Vect(-area.x / 2, -area.y / 2, -area.z / 2);
    boolean hasFlower = false;
    MutableVect posCurrent = new MutableVect(0, 0, 0);
    while (posCurrent.advancePositionInArea(area)) {
        Vect posBlock = Vect.add(housingPos, posCurrent, offset);
        if (provider.isAcceptedFlower(housing.getWorld(), this, posBlock.x, posBlock.y, posBlock.z)) {
            hasFlower = true;
            break;
        }
    }
    return hasFlower;
}
Also used : IFlowerProvider(forestry.api.genetics.IFlowerProvider) MutableVect(forestry.core.vect.MutableVect) Vect(forestry.core.vect.Vect) MutableVect(forestry.core.vect.MutableVect)

Example 34 with Vect

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

the class Bee method pollinateRandom.

@Override
public boolean pollinateRandom(IBeeHousing housing, IIndividual pollen) {
    int chance = (int) (genome.getFlowering() * housing.getFloweringModifier(getGenome(), 1f));
    World world = housing.getWorld();
    Random random = world.rand;
    // Correct speed
    if (random.nextInt(100) >= chance) {
        return false;
    }
    Vect area = getArea(genome, housing);
    Vect offset = new Vect(-area.x / 2, -area.y / 4, -area.z / 2);
    Vect housingPos = new Vect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord());
    for (int i = 0; i < 30; i++) {
        Vect randomPos = Vect.getRandomPositionInArea(random, area);
        Vect posBlock = Vect.add(housingPos, randomPos, offset);
        ICheckPollinatable checkPollinatable = GeneticsUtil.getCheckPollinatable(world, posBlock.x, posBlock.y, posBlock.z);
        if (checkPollinatable == null) {
            continue;
        }
        if (!genome.getFlowerProvider().isAcceptedPollinatable(world, new FakePollinatable(checkPollinatable))) {
            continue;
        }
        if (!checkPollinatable.canMateWith(pollen)) {
            continue;
        }
        IPollinatable realPollinatable = GeneticsUtil.getOrCreatePollinatable(housing.getOwnerName(), world, posBlock.x, posBlock.y, posBlock.z);
        if (realPollinatable != null) {
            realPollinatable.mateWith(pollen);
            return true;
        }
    }
    return false;
}
Also used : ICheckPollinatable(forestry.arboriculture.genetics.ICheckPollinatable) Random(java.util.Random) FakePollinatable(forestry.arboriculture.genetics.FakePollinatable) Vect(forestry.core.vect.Vect) MutableVect(forestry.core.vect.MutableVect) IPollinatable(forestry.api.genetics.IPollinatable) World(net.minecraft.world.World)

Example 35 with Vect

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

the class Bee method retrievePollen.

/* FLOWERS */
@Override
public IIndividual retrievePollen(IBeeHousing housing) {
    int chance = Math.round(genome.getFlowering() * housing.getFloweringModifier(getGenome(), 1f));
    World world = housing.getWorld();
    Random random = world.rand;
    // Correct speed
    if (random.nextInt(100) >= chance) {
        return null;
    }
    Vect area = getArea(genome, housing);
    Vect offset = new Vect(-area.x / 2, -area.y / 4, -area.z / 2);
    Vect housingPos = new Vect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord());
    IIndividual pollen = null;
    for (int i = 0; i < 20; i++) {
        Vect randomPos = Vect.getRandomPositionInArea(random, area);
        Vect blockPos = Vect.add(housingPos, randomPos, offset);
        TileEntity tile = world.getTileEntity(blockPos.x, blockPos.y, blockPos.z);
        if (tile instanceof IPollinatable) {
            IPollinatable pitcher = (IPollinatable) tile;
            if (genome.getFlowerProvider().isAcceptedPollinatable(world, pitcher)) {
                pollen = pitcher.getPollen();
            }
        } else {
            pollen = GeneticsUtil.getErsatzPollen(world, blockPos.x, blockPos.y, blockPos.z);
        }
        if (pollen != null) {
            return pollen;
        }
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Random(java.util.Random) IIndividual(forestry.api.genetics.IIndividual) Vect(forestry.core.vect.Vect) MutableVect(forestry.core.vect.MutableVect) IPollinatable(forestry.api.genetics.IPollinatable) 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