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