use of forestry.core.vect.Vect in project ForestryMC by ForestryMC.
the class ItemHabitatLocator method findNearestBiome.
private ChunkCoordinates findNearestBiome(Entity player, Collection<BiomeGenBase> biomesToSearch) {
final int maxChecksPerTick = 100;
final int maxSearchRadiusIterations = 500;
final int spacing = 20;
Vect playerPos = new Vect((int) player.posX, (int) player.posY, (int) player.posZ);
// If we are in a valid spot, we point to ourselves.
ChunkCoordinates coordinates = getChunkCoordinates(playerPos, player.worldObj, biomesToSearch);
if (coordinates != null) {
searchAngleIteration = 0;
searchRadiusIteration = 0;
return new ChunkCoordinates(playerPos.x, playerPos.y, playerPos.z);
}
// check in a circular pattern, starting at the center and increasing radius each step
final int radius = spacing * (searchRadiusIteration + 1);
double angleSpacing = 2.0f * Math.asin(spacing / (2.0 * radius));
// round to nearest divisible angle, for an even distribution
angleSpacing = 2.0 * Math.PI / Math.round(2.0 * Math.PI / angleSpacing);
// do a limited number of checks per tick
for (int i = 0; i < maxChecksPerTick; i++) {
double angle = angleSpacing * searchAngleIteration;
if (angle > 2.0 * Math.PI) {
searchAngleIteration = 0;
searchRadiusIteration++;
if (searchRadiusIteration > maxSearchRadiusIterations) {
searchAngleIteration = 0;
searchRadiusIteration = 0;
searchCenter = playerPos;
}
return null;
} else {
searchAngleIteration++;
}
int xOffset = Math.round((float) (radius * Math.cos(angle)));
int zOffset = Math.round((float) (radius * Math.sin(angle)));
Vect pos = searchCenter.add(xOffset, 0, zOffset);
coordinates = getChunkCoordinates(pos, player.worldObj, biomesToSearch);
if (coordinates != null) {
searchAngleIteration = 0;
searchRadiusIteration = 0;
return coordinates;
}
}
return null;
}
use of forestry.core.vect.Vect in project ForestryMC by ForestryMC.
the class FarmLogicGourd 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;
}
use of forestry.core.vect.Vect in project ForestryMC by ForestryMC.
the class TileControl method hasRedstoneSignal.
private boolean hasRedstoneSignal(ForgeDirection direction) {
Vect side = new Vect(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ);
ForgeDirection opp = direction.getOpposite();
int dir;
if (opp.offsetZ < 0) {
dir = 2;
} else if (opp.offsetZ > 0) {
dir = 3;
} else if (opp.offsetX < 0) {
dir = 4;
} else if (opp.offsetX > 0) {
dir = 5;
} else {
dir = 0;
}
return worldObj.getIndirectPowerLevelTo(side.x, side.y, side.z, dir) > 0 || worldObj.isBlockProvidingPowerTo(side.x, side.y, side.z, dir) > 0;
}
use of forestry.core.vect.Vect in project ForestryMC by ForestryMC.
the class TileFarmPlain method doWork.
@Override
public boolean doWork() {
// System.out.println("Starting doWork()");
if (targets == null || checkTimer.delayPassed(worldObj, 400)) {
Vect targetStart = new Vect(xCoord, yCoord, zCoord);
int sizeNorthSouth = FarmHelper.getFarmSizeNorthSouth(worldObj, targetStart);
int sizeEastWest = FarmHelper.getFarmSizeEastWest(worldObj, targetStart);
// Set the maximum allowed extent.
allowedExtent = Math.max(sizeNorthSouth, sizeEastWest) * 3;
targets = createTargets(worldObj, targetStart, allowedExtent, sizeNorthSouth, sizeEastWest);
setExtents();
}
// System.out.println("Targets set");
if (tryAddPending()) {
return true;
}
// Abort if we still have produce waiting.
if (!pendingProduce.isEmpty()) {
setErrorState(EnumErrorCode.NOSPACE);
return false;
}
// System.out.println("Product queue empty.");
if (storedFertilizer <= BUFFER_FERTILIZER) {
replenishFertilizer();
if (storedFertilizer <= 0) {
setErrorState(EnumErrorCode.NOFERTILIZER);
return false;
}
}
// Cull queued crops.
if (!pendingCrops.isEmpty()) {
if (cullCrop(pendingCrops.peek(), harvestProvider)) {
pendingCrops.pop();
return true;
} else {
return false;
}
}
// Cultivation and collection
FarmWorkStatus farmWorkStatus = new FarmWorkStatus();
for (Map.Entry<ForgeDirection, List<FarmTarget>> entry : targets.entrySet()) {
ForgeDirection farmSide = entry.getKey();
IFarmLogic logic = getFarmLogic(farmSide);
if (logic == null) {
continue;
}
// Allow listeners to cancel this cycle.
if (isCycleCanceledByListeners(logic, farmSide)) {
continue;
}
// Always try to collect windfall first.
if (collectWindfall(logic)) {
farmWorkStatus.didWork = true;
} else {
List<FarmTarget> farmTargets = entry.getValue();
if (stage == Stage.HARVEST) {
farmWorkStatus.didWork = harvestTargets(farmTargets, logic);
} else {
farmWorkStatus = cultivateTargets(farmWorkStatus, farmTargets, logic);
}
}
if (farmWorkStatus.didWork) {
break;
}
}
if (farmWorkStatus.didWork) {
setErrorState(EnumErrorCode.OK);
} else if (stage == Stage.CULTIVATE) {
if (!farmWorkStatus.hasFarmland) {
setErrorState(EnumErrorCode.NOFARMLAND);
} else if (!farmWorkStatus.hasFertilizer) {
setErrorState(EnumErrorCode.NOFERTILIZER);
} else if (!farmWorkStatus.hasLiquid) {
setErrorState(EnumErrorCode.NOLIQUID);
}
}
// Farms alternate between cultivation and harvest.
stage = stage.next();
return farmWorkStatus.didWork;
}
use of forestry.core.vect.Vect in project ForestryMC by ForestryMC.
the class TileFarmPlain method getGroundPosition.
private static Vect getGroundPosition(World world, Vect targetPosition) {
for (int yOffset = 2; yOffset > -4; yOffset--) {
Vect position = targetPosition.add(0, yOffset, 0);
Block ground = VectUtil.getBlock(world, position);
if (StructureLogicFarm.bricks.contains(ground)) {
return position;
}
}
return null;
}
Aggregations