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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations