Search in sources :

Example 1 with IGreenhouseController

use of forestry.api.multiblock.IGreenhouseController in project ForestryMC by ForestryMC.

the class ItemGreenhouseScreen method handleSneaking.

private EnumActionResult handleSneaking(World world, BlockPos pos, EntityPlayer player, ItemStack itemStack, BlockPos itemPos) {
    IGreenhouseComponent component = MultiblockUtil.getComponent(world, pos, IGreenhouseComponent.class);
    if (component != null) {
        IGreenhouseController controller = component.getMultiblockLogic().getController();
        if (!controller.isAssembled()) {
            if (!world.isRemote) {
                player.sendStatusMessage(new TextComponentTranslation("for.message.greenhouse_screen.notassembled"), true);
            }
            return EnumActionResult.PASS;
        }
        itemStack.setTagInfo(GREENHOUSE_KEY, NBTUtil.createPosTag(pos));
        if (!world.isRemote) {
            player.sendStatusMessage(new TextComponentTranslation("for.message.greenhouse_screen.position"), true);
        }
    } else {
        if (itemPos == null) {
            if (!world.isRemote) {
                player.sendStatusMessage(new TextComponentTranslation("for.message.greenhouse_screen.fail"), true);
            }
            return EnumActionResult.PASS;
        }
        if (!world.isBlockLoaded(pos)) {
            if (!world.isRemote) {
                player.sendStatusMessage(new TextComponentTranslation("for.message.greenhouse_screen.away"), true);
            }
            return EnumActionResult.PASS;
        }
        IGreenhouseController controller = MultiblockUtil.getController(world, itemPos, IGreenhouseComponent.class);
        if (controller == null || !controller.isAssembled()) {
            return EnumActionResult.PASS;
        }
        controller.setCenterCoordinates(pos);
        if (!world.isRemote) {
            player.sendStatusMessage(new TextComponentTranslation("for.message.greenhouse_screen.center", pos), true);
        }
    }
    return EnumActionResult.PASS;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IGreenhouseController(forestry.api.multiblock.IGreenhouseController) IGreenhouseComponent(forestry.api.multiblock.IGreenhouseComponent)

Example 2 with IGreenhouseController

use of forestry.api.multiblock.IGreenhouseController in project ForestryMC by ForestryMC.

the class GreenhouseProviderClient method markBlockForRenderUpdate.

public void markBlockForRenderUpdate() {
    IClimateHousing housing = container.getParent();
    if (housing instanceof IGreenhouseController) {
        IGreenhouseController controller = (IGreenhouseController) housing;
        if (!controller.isAssembled()) {
            return;
        }
        BlockPos position = controller.getCenterCoordinates();
        Position2D minEdge = limits.getMinimumCoordinates();
        Position2D maxEdge = limits.getMaximumCoordinates();
        BlockPos minPos = new BlockPos(minEdge.getX(), -limits.getDepth(), minEdge.getZ());
        BlockPos maxPos = new BlockPos(maxEdge.getX() + 1, limits.getHeight(), maxEdge.getZ() + 1);
        minPos = minPos.add(position);
        maxPos = maxPos.add(position);
        world.markBlockRangeForRenderUpdate(minPos, maxPos);
    }
}
Also used : IGreenhouseController(forestry.api.multiblock.IGreenhouseController) Position2D(forestry.greenhouse.api.greenhouse.Position2D) BlockPos(net.minecraft.util.math.BlockPos) IClimateHousing(forestry.api.greenhouse.IClimateHousing)

Example 3 with IGreenhouseController

use of forestry.api.multiblock.IGreenhouseController 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 4 with IGreenhouseController

use of forestry.api.multiblock.IGreenhouseController in project ForestryMC by ForestryMC.

the class TileGreenhousePlain method onMachineAssembled.

@Override
public void onMachineAssembled(IMultiblockController multiblockController, BlockPos minCoord, BlockPos maxCoord) {
    super.onMachineAssembled(multiblockController, minCoord, maxCoord);
    IGreenhouseController greenhouseController = (IGreenhouseController) multiblockController;
    // set border block state
    int bandY = maxCoord.getY();
    if (getPos().getY() == bandY) {
        BlockGreenhouseType type = BlockGreenhouseType.BORDER;
        if (getPos().equals(greenhouseController.getCenterCoordinates())) {
            type = BlockGreenhouseType.BORDER_CENTER;
        }
        this.world.setBlockState(getPos(), ModuleGreenhouse.getBlocks().greenhouseBlock.getDefaultState().withProperty(BlockGreenhouse.TYPE, type), 2);
    }
}
Also used : BlockGreenhouseType(forestry.greenhouse.blocks.BlockGreenhouseType) IGreenhouseController(forestry.api.multiblock.IGreenhouseController)

Aggregations

IGreenhouseController (forestry.api.multiblock.IGreenhouseController)4 Position2D (forestry.greenhouse.api.greenhouse.Position2D)2 BlockPos (net.minecraft.util.math.BlockPos)2 IErrorLogic (forestry.api.core.IErrorLogic)1 IErrorState (forestry.api.core.IErrorState)1 IClimateHousing (forestry.api.greenhouse.IClimateHousing)1 IGreenhouseComponent (forestry.api.multiblock.IGreenhouseComponent)1 IBlankBlock (forestry.greenhouse.api.greenhouse.IBlankBlock)1 IGreenhouseBlock (forestry.greenhouse.api.greenhouse.IGreenhouseBlock)1 IGreenhouseBlockHandler (forestry.greenhouse.api.greenhouse.IGreenhouseBlockHandler)1 BlockGreenhouseType (forestry.greenhouse.blocks.BlockGreenhouseType)1 GreenhouseLimitsBuilder (forestry.greenhouse.multiblock.GreenhouseLimitsBuilder)1 LinkedList (java.util.LinkedList)1 Stack (java.util.Stack)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1