Search in sources :

Example 6 with IGreenhouseBlock

use of forestry.greenhouse.api.greenhouse.IGreenhouseBlock in project ForestryMC by ForestryMC.

the class GreenhouseBlockStorage method clearBlocks.

public void clearBlocks(boolean chunkUnloading) {
    for (HashMap<Position2D, IGreenhouseBlock> blocks : this.blocks.values()) {
        Iterator<IGreenhouseBlock> blockIterator = blocks.values().iterator();
        while (blockIterator.hasNext()) {
            IGreenhouseBlock block = blockIterator.next();
            if (block != null) {
                removeBlock(block);
                blockIterator.remove();
            }
        }
    }
    blockCount = 0;
}
Also used : Position2D(forestry.greenhouse.api.greenhouse.Position2D) IGreenhouseBlock(forestry.greenhouse.api.greenhouse.IGreenhouseBlock)

Example 7 with IGreenhouseBlock

use of forestry.greenhouse.api.greenhouse.IGreenhouseBlock in project ForestryMC by ForestryMC.

the class GreenhouseBlockStorage method setBlock.

public boolean setBlock(BlockPos pos, @Nullable IGreenhouseBlock newBlock) {
    IGreenhouseChunk chunk = getChunk(pos);
    if (chunk != null) {
        IGreenhouseBlock oldBlock;
        Long chunkPos = ChunkPos.asLong(pos.getX() >> 4, pos.getZ() >> 4);
        HashMap<Position2D, IGreenhouseBlock> chunkBlocks = getChunkBlocks(chunkPos);
        if (newBlock == null) {
            oldBlock = chunkBlocks.remove(new Position2D(pos));
        } else {
            oldBlock = chunkBlocks.put(new Position2D(pos), newBlock);
        }
        // Only count block on the server side
        if (!world.isRemote) {
            if (newBlock == null) {
                if (oldBlock instanceof IBlankBlock) {
                    blockCount--;
                }
            } else if (newBlock != null) {
                cache.add(chunkPos, pos);
                if (newBlock instanceof IBlankBlock) {
                    blockCount++;
                }
            }
        }
        return true;
    }
    return false;
}
Also used : IGreenhouseChunk(forestry.greenhouse.api.greenhouse.IGreenhouseChunk) Position2D(forestry.greenhouse.api.greenhouse.Position2D) IBlankBlock(forestry.greenhouse.api.greenhouse.IBlankBlock) IGreenhouseBlock(forestry.greenhouse.api.greenhouse.IGreenhouseBlock)

Example 8 with IGreenhouseBlock

use of forestry.greenhouse.api.greenhouse.IGreenhouseBlock 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 9 with IGreenhouseBlock

use of forestry.greenhouse.api.greenhouse.IGreenhouseBlock in project ForestryMC by ForestryMC.

the class GreenhouseBlock method equals.

@Override
public boolean equals(Object obj) {
    if (!(obj instanceof IGreenhouseBlock)) {
        return false;
    }
    IGreenhouseBlock logicBlock = (IGreenhouseBlock) obj;
    BlockPos blockPos = logicBlock.getPos();
    return pos.equals(blockPos);
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) IGreenhouseBlock(forestry.greenhouse.api.greenhouse.IGreenhouseBlock)

Example 10 with IGreenhouseBlock

use of forestry.greenhouse.api.greenhouse.IGreenhouseBlock 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

IGreenhouseBlock (forestry.greenhouse.api.greenhouse.IGreenhouseBlock)10 Position2D (forestry.greenhouse.api.greenhouse.Position2D)4 BlockPos (net.minecraft.util.math.BlockPos)3 IClimateState (forestry.api.climate.IClimateState)2 IErrorState (forestry.api.core.IErrorState)2 IClimateContainer (forestry.greenhouse.api.climate.IClimateContainer)2 IBlankBlock (forestry.greenhouse.api.greenhouse.IBlankBlock)2 IGreenhouseBlockHandler (forestry.greenhouse.api.greenhouse.IGreenhouseBlockHandler)2 IGreenhouseChunk (forestry.greenhouse.api.greenhouse.IGreenhouseChunk)2 IGreenhouseProvider (forestry.greenhouse.api.greenhouse.IGreenhouseProvider)2 Nullable (javax.annotation.Nullable)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 IErrorLogic (forestry.api.core.IErrorLogic)1 IGreenhouseController (forestry.api.multiblock.IGreenhouseController)1 MultiblockValidationException (forestry.core.multiblock.MultiblockValidationException)1 GreenhouseLimitsBuilder (forestry.greenhouse.multiblock.GreenhouseLimitsBuilder)1 GreenhouseChunk (forestry.greenhouse.multiblock.blocks.storage.GreenhouseChunk)1 TileGreenhousePlain (forestry.greenhouse.tiles.TileGreenhousePlain)1 LinkedList (java.util.LinkedList)1 Stack (java.util.Stack)1