Search in sources :

Example 6 with IErrorState

use of forestry.api.core.IErrorState 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 7 with IErrorState

use of forestry.api.core.IErrorState in project ForestryMC by ForestryMC.

the class Butterfly method getCanSpawn.

@Override
public Set<IErrorState> getCanSpawn(IButterflyNursery nursery, @Nullable IButterflyCocoon cocoon) {
    World world = nursery.getWorldObj();
    Set<IErrorState> errorStates = new HashSet<>();
    // / Night or darkness requires nocturnal species
    boolean isDaytime = world.isDaytime();
    if (!isActiveThisTime(isDaytime)) {
        if (isDaytime) {
            errorStates.add(EnumErrorCode.NOT_NIGHT);
        } else {
            errorStates.add(EnumErrorCode.NOT_DAY);
        }
    }
    // / And finally climate check
    IAlleleButterflySpecies species = genome.getPrimary();
    EnumTemperature actualTemperature = nursery.getTemperature();
    EnumTemperature baseTemperature = species.getTemperature();
    EnumTolerance toleranceTemperature = genome.getToleranceTemp();
    EnumHumidity actualHumidity = nursery.getHumidity();
    EnumHumidity baseHumidity = species.getHumidity();
    EnumTolerance toleranceHumidity = genome.getToleranceHumid();
    ClimateUtil.addClimateErrorStates(actualTemperature, actualHumidity, baseTemperature, toleranceTemperature, baseHumidity, toleranceHumidity, errorStates);
    return errorStates;
}
Also used : IErrorState(forestry.api.core.IErrorState) EnumTolerance(forestry.api.genetics.EnumTolerance) EnumHumidity(forestry.api.core.EnumHumidity) World(net.minecraft.world.World) HashSet(java.util.HashSet) IAlleleButterflySpecies(forestry.api.lepidopterology.IAlleleButterflySpecies) EnumTemperature(forestry.api.core.EnumTemperature)

Example 8 with IErrorState

use of forestry.api.core.IErrorState in project ForestryMC by ForestryMC.

the class ContainerEntity method detectAndSendChanges.

@Override
public void detectAndSendChanges() {
    super.detectAndSendChanges();
    if (entity instanceof IErrorLogicSource) {
        IErrorLogicSource errorLogicSource = (IErrorLogicSource) entity;
        ImmutableSet<IErrorState> errorStates = errorLogicSource.getErrorLogic().getErrorStates();
        if (previousErrorStates == null || !errorStates.equals(previousErrorStates)) {
            PacketErrorUpdateEntity packet = new PacketErrorUpdateEntity(entity, errorLogicSource);
            sendPacketToListeners(packet);
        }
        previousErrorStates = errorStates;
    }
}
Also used : PacketErrorUpdateEntity(forestry.core.network.packets.PacketErrorUpdateEntity) IErrorState(forestry.api.core.IErrorState) IErrorLogicSource(forestry.api.core.IErrorLogicSource)

Example 9 with IErrorState

use of forestry.api.core.IErrorState in project ForestryMC by ForestryMC.

the class GreenhouseProviderServer method checkBlocks.

/**
 * Check all internal blocks.
 */
private GreenhouseState checkBlocks(Collection<IGreenhouseBlock> blocks) {
    IErrorLogic errorLogic = getErrorLogic();
    errorLogic.clearErrors();
    if (minSize == null || maxSize == null || minSize == Position2D.NULL_POSITION || maxSize == Position2D.NULL_POSITION) {
        Position2D maxCoordinates = limits.getMaximumCoordinates();
        maxSize = maxCoordinates.add(1, 1).add(centerPos.getX(), centerPos.getZ());
        Position2D minCoordinates = limits.getMinimumCoordinates();
        minSize = minCoordinates.add(-1, -1).add(centerPos.getX(), centerPos.getZ());
    }
    int greenhouseHeight = centerPos.getY();
    int greenhouseDepth = centerPos.getY();
    int height = 0;
    int depth = 0;
    int maximalHeight = ((IGreenhouseController) container.getParent()).getCenterCoordinates().getY() + limits.getHeight();
    GreenhouseLimitsBuilder builder = new GreenhouseLimitsBuilder();
    Stack<IGreenhouseBlock> blocksToCheck = new Stack();
    blocksToCheck.addAll(blocks);
    while (!blocksToCheck.isEmpty()) {
        IGreenhouseBlock blockToCheck = blocksToCheck.pop();
        if (blockToCheck != null) {
            BlockPos position = blockToCheck.getPos();
            IGreenhouseBlockHandler handler = blockToCheck.getHandler();
            builder.recalculate(position);
            List<IGreenhouseBlock> newBlocksToCheck = new LinkedList<>();
            IErrorState errorState = handler.checkNeighborBlocks(storage, blockToCheck, newBlocksToCheck);
            if (errorState != null) {
                errorLogic.setCondition(true, errorState);
                break;
            }
            blocksToCheck.addAll(newBlocksToCheck);
            if (blockToCheck instanceof IBlankBlock) {
                int positionHeight = getHeight(position, maximalHeight);
                int positionDepth = getDepth(position);
                if (positionHeight == -1) {
                    errorLogic.setCondition(true, EnumErrorCode.NOT_CLOSED);
                    // throw new GreenhouseException(Translator.translateToLocalFormatted("for.multiblock.greenhouse.error.roof.notclosed", position.getX(), position.getY(), position.getZ())).setPos(position);
                    break;
                }
                if (positionHeight > greenhouseHeight) {
                    greenhouseHeight = positionHeight;
                }
                height += positionHeight - centerPos.getY();
                if (positionDepth < greenhouseDepth) {
                    greenhouseDepth = positionDepth;
                }
                depth += centerPos.getY() - positionDepth;
            }
        }
    }
    if (!unloadedChunks.isEmpty()) {
        errorLogic.setCondition(true, EnumErrorCode.NOT_LOADED);
        return GreenhouseState.UNLOADED_CHUNK;
    }
    if (errorLogic.hasErrors()) {
        // Remove the state NOT_CLOSED if the logic has the state TOO_LARGE because the state NOT_CLOSED can be caused by the TOO_LARGE state
        if (errorLogic.getErrorStates().contains(EnumErrorCode.TOO_LARGE)) {
            errorLogic.setCondition(false, EnumErrorCode.NOT_CLOSED);
        }
        return GreenhouseState.OPEN;
    }
    this.size = height + depth + storage.getBlockCount();
    usedLimits = builder.build(greenhouseHeight, greenhouseDepth);
    return GreenhouseState.CLOSED;
}
Also used : GreenhouseLimitsBuilder(forestry.greenhouse.multiblock.GreenhouseLimitsBuilder) IGreenhouseController(forestry.api.multiblock.IGreenhouseController) IGreenhouseBlockHandler(forestry.greenhouse.api.greenhouse.IGreenhouseBlockHandler) IBlankBlock(forestry.greenhouse.api.greenhouse.IBlankBlock) IGreenhouseBlock(forestry.greenhouse.api.greenhouse.IGreenhouseBlock) LinkedList(java.util.LinkedList) Stack(java.util.Stack) IErrorState(forestry.api.core.IErrorState) Position2D(forestry.greenhouse.api.greenhouse.Position2D) BlockPos(net.minecraft.util.math.BlockPos) IErrorLogic(forestry.api.core.IErrorLogic)

Example 10 with IErrorState

use of forestry.api.core.IErrorState in project ForestryMC by ForestryMC.

the class BlankBlockHandler method checkBlockFacing.

private IErrorState checkBlockFacing(IGreenhouseBlockStorage storage, IBlankBlock blockToCheck, BlockPos rootPos, EnumFacing facing, List<IGreenhouseBlock> newBlocksToCheck) {
    if (!blockToCheck.isFaceTested(facing)) {
        BlockPos facingPosition = rootPos.offset(facing);
        IGreenhouseProvider provider = storage.getProvider();
        IErrorState errorState = provider.checkPosition(facingPosition);
        if (errorState != null) {
            return errorState;
        }
        IGreenhouseBlock logicBlock = storage.getBlock(facingPosition);
        for (IGreenhouseBlockHandler handler : provider.getHandlers()) {
            if (handler.onCheckPosition(storage, blockToCheck, facingPosition, facing, logicBlock, newBlocksToCheck)) {
                break;
            }
        }
    }
    return null;
}
Also used : IErrorState(forestry.api.core.IErrorState) BlockPos(net.minecraft.util.math.BlockPos) IGreenhouseProvider(forestry.greenhouse.api.greenhouse.IGreenhouseProvider) IGreenhouseBlockHandler(forestry.greenhouse.api.greenhouse.IGreenhouseBlockHandler) IGreenhouseBlock(forestry.greenhouse.api.greenhouse.IGreenhouseBlock)

Aggregations

IErrorState (forestry.api.core.IErrorState)12 EnumHumidity (forestry.api.core.EnumHumidity)3 EnumTemperature (forestry.api.core.EnumTemperature)3 EnumTolerance (forestry.api.genetics.EnumTolerance)3 HashSet (java.util.HashSet)3 ItemStack (net.minecraft.item.ItemStack)3 World (net.minecraft.world.World)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 IErrorLogic (forestry.api.core.IErrorLogic)2 IErrorLogicSource (forestry.api.core.IErrorLogicSource)2 IAlleleButterflySpecies (forestry.api.lepidopterology.IAlleleButterflySpecies)2 IGreenhouseBlock (forestry.greenhouse.api.greenhouse.IGreenhouseBlock)2 IGreenhouseBlockHandler (forestry.greenhouse.api.greenhouse.IGreenhouseBlockHandler)2 BlockPos (net.minecraft.util.math.BlockPos)2 EnumBeeType (forestry.api.apiculture.EnumBeeType)1 IAlleleBeeSpecies (forestry.api.apiculture.IAlleleBeeSpecies)1 IBee (forestry.api.apiculture.IBee)1 IBeeHousingInventory (forestry.api.apiculture.IBeeHousingInventory)1 IBeeModifier (forestry.api.apiculture.IBeeModifier)1 IGreenhouseController (forestry.api.multiblock.IGreenhouseController)1