Search in sources :

Example 1 with IBeeModifier

use of forestry.api.apiculture.IBeeModifier in project ForestryMC by ForestryMC.

the class AlleleEffect method getModifiedArea.

public static Vec3i getModifiedArea(IBeeGenome genome, IBeeHousing housing) {
    IBeeModifier beeModifier = BeeManager.beeRoot.createBeeHousingModifier(housing);
    float territoryModifier = beeModifier.getTerritoryModifier(genome, 1f);
    Vec3i area = VectUtil.scale(genome.getTerritory(), territoryModifier);
    int x = area.getX();
    int y = area.getY();
    int z = area.getZ();
    if (x < 1) {
        x = 1;
    }
    if (y < 1) {
        y = 1;
    }
    if (z < 1) {
        z = 1;
    }
    return new Vec3i(x, y, z);
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) IBeeModifier(forestry.api.apiculture.IBeeModifier)

Example 2 with IBeeModifier

use of forestry.api.apiculture.IBeeModifier in project ForestryMC by ForestryMC.

the class AlvearyController method onBlockRemoved.

@Override
protected void onBlockRemoved(IMultiblockComponent oldPart) {
    if (oldPart instanceof IAlvearyComponent) {
        if (oldPart instanceof IAlvearyComponent.BeeModifier) {
            IAlvearyComponent.BeeModifier alvearyBeeModifier = (IAlvearyComponent.BeeModifier) oldPart;
            IBeeModifier beeModifier = alvearyBeeModifier.getBeeModifier();
            beeModifiers.remove(beeModifier);
        }
        if (oldPart instanceof IAlvearyComponent.BeeListener) {
            IAlvearyComponent.BeeListener beeListenerSource = (IAlvearyComponent.BeeListener) oldPart;
            IBeeListener beeListener = beeListenerSource.getBeeListener();
            beeListeners.remove(beeListener);
        }
        if (oldPart instanceof IAlvearyComponent.Climatiser) {
            climatisers.remove(oldPart);
        }
        if (oldPart instanceof IAlvearyComponent.Active) {
            activeComponents.remove(oldPart);
        }
    }
}
Also used : AlvearyBeeModifier(forestry.apiculture.AlvearyBeeModifier) IBeeModifier(forestry.api.apiculture.IBeeModifier) IBeeListener(forestry.api.apiculture.IBeeListener) IBeeModifier(forestry.api.apiculture.IBeeModifier) IBeeListener(forestry.api.apiculture.IBeeListener) IAlvearyComponent(forestry.api.multiblock.IAlvearyComponent)

Example 3 with IBeeModifier

use of forestry.api.apiculture.IBeeModifier in project ForestryMC by ForestryMC.

the class AlvearyController method onBlockAdded.

@Override
protected void onBlockAdded(IMultiblockComponent newPart) {
    if (newPart instanceof IAlvearyComponent) {
        if (newPart instanceof IAlvearyComponent.BeeModifier) {
            IAlvearyComponent.BeeModifier alvearyBeeModifier = (IAlvearyComponent.BeeModifier) newPart;
            IBeeModifier beeModifier = alvearyBeeModifier.getBeeModifier();
            beeModifiers.add(beeModifier);
        }
        if (newPart instanceof IAlvearyComponent.BeeListener) {
            IAlvearyComponent.BeeListener beeListenerSource = (IAlvearyComponent.BeeListener) newPart;
            IBeeListener beeListener = beeListenerSource.getBeeListener();
            beeListeners.add(beeListener);
        }
        if (newPart instanceof IAlvearyComponent.Climatiser) {
            climatisers.add((IAlvearyComponent.Climatiser) newPart);
        }
        if (newPart instanceof IAlvearyComponent.Active) {
            activeComponents.add((IAlvearyComponent.Active) newPart);
        }
    }
}
Also used : AlvearyBeeModifier(forestry.apiculture.AlvearyBeeModifier) IBeeModifier(forestry.api.apiculture.IBeeModifier) IBeeListener(forestry.api.apiculture.IBeeListener) IBeeModifier(forestry.api.apiculture.IBeeModifier) IBeeListener(forestry.api.apiculture.IBeeListener) IAlvearyComponent(forestry.api.multiblock.IAlvearyComponent)

Example 4 with IBeeModifier

use of forestry.api.apiculture.IBeeModifier in project ForestryMC by ForestryMC.

the class Bee method getCanWork.

@Override
public Set<IErrorState> getCanWork(IBeeHousing housing) {
    World world = housing.getWorldObj();
    Set<IErrorState> errorStates = new HashSet<>();
    IBeeModifier beeModifier = BeeManager.beeRoot.createBeeHousingModifier(housing);
    // / Rain needs tolerant flyers
    if (housing.isRaining() && !canFlyInRain(beeModifier)) {
        errorStates.add(EnumErrorCode.IS_RAINING);
    }
    // / Night or darkness requires nocturnal species
    if (world.isDaytime()) {
        if (!canWorkDuringDay()) {
            errorStates.add(EnumErrorCode.NOT_NIGHT);
        }
    } else {
        if (!canWorkAtNight(beeModifier)) {
            errorStates.add(EnumErrorCode.NOT_DAY);
        }
    }
    if (housing.getBlockLightValue() > Constants.APIARY_MIN_LEVEL_LIGHT) {
        if (!canWorkDuringDay()) {
            errorStates.add(EnumErrorCode.NOT_GLOOMY);
        }
    } else {
        if (!canWorkAtNight(beeModifier)) {
            errorStates.add(EnumErrorCode.NOT_BRIGHT);
        }
    }
    // / Check for the sky, except if in hell
    if (!world.provider.isNether()) {
        if (!housing.canBlockSeeTheSky() && !canWorkUnderground(beeModifier)) {
            errorStates.add(EnumErrorCode.NO_SKY);
        }
    }
    // / And finally climate check
    IAlleleBeeSpecies species = genome.getPrimary();
    {
        EnumTemperature actualTemperature = housing.getTemperature();
        EnumTemperature beeBaseTemperature = species.getTemperature();
        EnumTolerance beeToleranceTemperature = genome.getToleranceTemp();
        if (!AlleleManager.climateHelper.isWithinLimits(actualTemperature, beeBaseTemperature, beeToleranceTemperature)) {
            if (beeBaseTemperature.ordinal() > actualTemperature.ordinal()) {
                errorStates.add(EnumErrorCode.TOO_COLD);
            } else {
                errorStates.add(EnumErrorCode.TOO_HOT);
            }
        }
    }
    {
        EnumHumidity actualHumidity = housing.getHumidity();
        EnumHumidity beeBaseHumidity = species.getHumidity();
        EnumTolerance beeToleranceHumidity = genome.getToleranceHumid();
        if (!AlleleManager.climateHelper.isWithinLimits(actualHumidity, beeBaseHumidity, beeToleranceHumidity)) {
            if (beeBaseHumidity.ordinal() > actualHumidity.ordinal()) {
                errorStates.add(EnumErrorCode.TOO_ARID);
            } else {
                errorStates.add(EnumErrorCode.TOO_HUMID);
            }
        }
    }
    return errorStates;
}
Also used : IAlleleBeeSpecies(forestry.api.apiculture.IAlleleBeeSpecies) IBeeModifier(forestry.api.apiculture.IBeeModifier) IErrorState(forestry.api.core.IErrorState) EnumTolerance(forestry.api.genetics.EnumTolerance) EnumHumidity(forestry.api.core.EnumHumidity) World(net.minecraft.world.World) HashSet(java.util.HashSet) EnumTemperature(forestry.api.core.EnumTemperature)

Example 5 with IBeeModifier

use of forestry.api.apiculture.IBeeModifier in project ForestryMC by ForestryMC.

the class Bee method plantFlowerRandom.

@Override
public BlockPos plantFlowerRandom(IBeeHousing housing, @Nullable List<IBlockState> potentialFlowers) {
    IBeeModifier beeModifier = BeeManager.beeRoot.createBeeHousingModifier(housing);
    int chance = Math.round(genome.getFlowering() * beeModifier.getFloweringModifier(getGenome(), 1f));
    World world = housing.getWorldObj();
    Random random = world.rand;
    // Correct speed
    if (random.nextInt(100) >= chance) {
        return null;
    }
    // Gather required info
    IFlowerProvider provider = genome.getFlowerProvider();
    Vec3i area = getArea(genome, beeModifier);
    Vec3i offset = new Vec3i(-area.getX() / 2, -area.getY() / 4, -area.getZ() / 2);
    BlockPos housingPos = housing.getCoordinates();
    for (int i = 0; i < 10; i++) {
        BlockPos randomPos = VectUtil.getRandomPositionInArea(random, area);
        BlockPos posBlock = VectUtil.add(housingPos, randomPos, offset);
        if (potentialFlowers != null) {
            if (FlowerManager.flowerRegistry.growFlower(provider.getFlowerType(), world, this, posBlock, potentialFlowers)) {
                return posBlock;
            }
        } else {
            // noinspection deprecation
            if (FlowerManager.flowerRegistry.growFlower(provider.getFlowerType(), world, this, posBlock)) {
                return posBlock;
            }
        }
    }
    return null;
}
Also used : IFlowerProvider(forestry.api.genetics.IFlowerProvider) Vec3i(net.minecraft.util.math.Vec3i) IBeeModifier(forestry.api.apiculture.IBeeModifier) Random(java.util.Random) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World)

Aggregations

IBeeModifier (forestry.api.apiculture.IBeeModifier)16 BlockPos (net.minecraft.util.math.BlockPos)7 World (net.minecraft.world.World)7 Vec3i (net.minecraft.util.math.Vec3i)6 Random (java.util.Random)3 ItemStack (net.minecraft.item.ItemStack)3 IAlleleBeeSpecies (forestry.api.apiculture.IAlleleBeeSpecies)2 IBeeListener (forestry.api.apiculture.IBeeListener)2 IBeekeepingMode (forestry.api.apiculture.IBeekeepingMode)2 IHiveFrame (forestry.api.apiculture.IHiveFrame)2 ICheckPollinatable (forestry.api.genetics.ICheckPollinatable)2 IAlvearyComponent (forestry.api.multiblock.IAlvearyComponent)2 AlvearyBeeModifier (forestry.apiculture.AlvearyBeeModifier)2 ArrayList (java.util.ArrayList)2 EnumHumidity (forestry.api.core.EnumHumidity)1 EnumTemperature (forestry.api.core.EnumTemperature)1 IErrorState (forestry.api.core.IErrorState)1 EnumTolerance (forestry.api.genetics.EnumTolerance)1 IFlowerProvider (forestry.api.genetics.IFlowerProvider)1 IIndividual (forestry.api.genetics.IIndividual)1