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