Search in sources :

Example 41 with Vect

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;
}
Also used : Vect(forestry.core.vect.Vect) ChunkCoordinates(net.minecraft.util.ChunkCoordinates)

Example 42 with Vect

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;
}
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 43 with Vect

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;
}
Also used : Vect(forestry.core.vect.Vect) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 44 with Vect

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;
}
Also used : FarmTarget(forestry.farming.FarmTarget) Vect(forestry.core.vect.Vect) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) List(java.util.List) ArrayList(java.util.ArrayList) IFarmLogic(forestry.api.farming.IFarmLogic) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 45 with Vect

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;
}
Also used : Vect(forestry.core.vect.Vect) Block(net.minecraft.block.Block)

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