Search in sources :

Example 1 with IGreenhouseControllerInternal

use of forestry.greenhouse.multiblock.IGreenhouseControllerInternal in project ForestryMC by ForestryMC.

the class BlockGreenhouse method colorMultiplier.

@Override
@SideOnly(Side.CLIENT)
@SuppressWarnings("deprecation")
public int colorMultiplier(IBlockState blockState, @Nullable IBlockAccess world, @Nullable BlockPos pos, int tintIndex) {
    if (pos == null || world == null) {
        return 16777215;
    }
    ItemStack camouflageStack = getCamouflageBlock(world, pos);
    if (tintIndex == ModelCamouflaged.OVERLAY_COLOR_INDEX + 1) {
        BlockGreenhouseType type = getGreenhouseType(blockState);
        if (type == BlockGreenhouseType.SCREEN) {
            IGreenhouseControllerInternal controller = MultiblockUtil.getController(world, pos, IGreenhouseComponent.class);
            if (controller == null || !controller.isAssembled()) {
                return 16777215;
            }
            IClimateContainer container = controller.getClimateContainer();
            IClimateState state = container.getState();
            return ClimateUtil.getColor(EnumTemperature.getFromValue(state.getTemperature()));
        } else if (type == BlockGreenhouseType.BORDER_CENTER) {
            boolean isClosed = true;
            IGreenhouseControllerInternal controller = MultiblockUtil.getController(world, pos, IGreenhouseComponent.class);
            if (controller == null || !controller.isAssembled()) {
                isClosed = false;
            } else {
                IGreenhouseProvider manager = controller.getProvider();
                isClosed = manager.isClosed();
            }
            return isClosed ? 1356406 : 12197655;
        }
    } else if (tintIndex < ModelCamouflaged.OVERLAY_COLOR_INDEX && !camouflageStack.isEmpty()) {
        Block block = Block.getBlockFromItem(camouflageStack.getItem());
        if (block != Blocks.AIR) {
            IBlockState camouflageState = block.getStateFromMeta(camouflageStack.getItemDamage());
            BlockColors blockColors = Minecraft.getMinecraft().getBlockColors();
            int color = blockColors.colorMultiplier(camouflageState, world, pos, tintIndex);
            if (color != -1) {
                return color;
            }
        }
    }
    return 16777215;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IClimateContainer(forestry.greenhouse.api.climate.IClimateContainer) Block(net.minecraft.block.Block) IColoredBlock(forestry.core.blocks.IColoredBlock) IGreenhouseControllerInternal(forestry.greenhouse.multiblock.IGreenhouseControllerInternal) IClimateState(forestry.api.climate.IClimateState) IGreenhouseProvider(forestry.greenhouse.api.greenhouse.IGreenhouseProvider) ItemStack(net.minecraft.item.ItemStack) BlockColors(net.minecraft.client.renderer.color.BlockColors) IGreenhouseComponent(forestry.api.multiblock.IGreenhouseComponent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with IGreenhouseControllerInternal

use of forestry.greenhouse.multiblock.IGreenhouseControllerInternal in project ForestryMC by ForestryMC.

the class ClimateSourceClimatiser method canWork.

@Override
public boolean canWork(IClimateState currentState, ClimateSourceType oppositeType) {
    IClimateHousing region = container.getParent();
    if (region instanceof IGreenhouseControllerInternal) {
        IGreenhouseControllerInternal controller = (IGreenhouseControllerInternal) region;
        IErrorLogic errorLogic = owner.getErrorLogic();
        EnergyManager energyManager = controller.getEnergyManager();
        if (energyManager.extractEnergy((int) (ENERGY_PER_OPERATION * getEnergyModifier(currentState, oppositeType)), true) > 0) {
            owner.setActive(true);
            errorLogic.setCondition(false, EnumErrorCode.NO_POWER);
            return true;
        } else {
            owner.setActive(false);
            errorLogic.setCondition(true, EnumErrorCode.NO_POWER);
            return false;
        }
    }
    if (owner.isActive()) {
        owner.setActive(false);
    }
    return false;
}
Also used : EnergyManager(forestry.energy.EnergyManager) IGreenhouseControllerInternal(forestry.greenhouse.multiblock.IGreenhouseControllerInternal) IErrorLogic(forestry.api.core.IErrorLogic) IClimateHousing(forestry.api.greenhouse.IClimateHousing)

Example 3 with IGreenhouseControllerInternal

use of forestry.greenhouse.multiblock.IGreenhouseControllerInternal in project ForestryMC by ForestryMC.

the class GreenhouseEventHandler method onWorldRenderLast.

@SubscribeEvent
public void onWorldRenderLast(RenderWorldLastEvent event) {
    try {
        float partialTicks = event.getPartialTicks();
        EntityPlayer player = Minecraft.getMinecraft().player;
        World world = player.world;
        long tick = world.getTotalWorldTime();
        if (tick > previousCheckTick + 50) {
            greenhousePositions.clear();
            for (ItemStack itemStack : getClimateScreen(player.inventory)) {
                if (!itemStack.isEmpty()) {
                    BlockPos position = ItemGreenhouseScreen.getGreenhousePos(itemStack);
                    IGreenhouseControllerInternal controller = MultiblockUtil.getController(world, position, IGreenhouseComponent.class);
                    if (controller == null || !controller.isAssembled()) {
                        return;
                    }
                    position = controller.getCenterCoordinates();
                    double distance = MathHelper.sqrt(player.getDistanceSqToCenter(position));
                    if (distance > 64F) {
                        return;
                    }
                    greenhousePositions.add(position);
                }
            }
            previousCheckTick = tick;
        }
        for (BlockPos position : greenhousePositions) {
            IGreenhouseControllerInternal controller = MultiblockUtil.getController(world, position, IGreenhouseComponent.class);
            if (controller == null || !controller.isAssembled()) {
                continue;
            }
            IGreenhouseProvider provider = controller.getProvider();
            position = controller.getCenterCoordinates();
            double distance = MathHelper.sqrt(player.getDistanceSqToCenter(position));
            if (distance > 64F) {
                return;
            }
            double playerX = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
            double playerY = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
            double playerZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
            GlStateManager.pushMatrix();
            GlStateManager.translate(-playerX, -playerY, -playerZ);
            GlStateManager.enableBlend();
            GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
            GlStateManager.disableTexture2D();
            GlStateManager.glLineWidth(2.5F);
            // Draw center position
            BlockPos offset = provider.getCenterPos();
            AxisAlignedBB testBlockBB = Block.FULL_BLOCK_AABB.offset(offset);
            RenderGlobal.drawSelectionBoundingBox(testBlockBB, 0.0F, 0.0F, 0.0F, 0.5F);
            IGreenhouseLimits limits = provider.getUsedLimits();
            if (limits != null) {
                Position2D minEdge = limits.getMinimumCoordinates();
                Position2D maxEdge = limits.getMaximumCoordinates();
                AxisAlignedBB greenhouseBB = new AxisAlignedBB(minEdge.getX(), limits.getDepth(), minEdge.getZ(), maxEdge.getX() + 1, limits.getHeight() + 1, maxEdge.getZ() + 1);
                RenderGlobal.drawSelectionBoundingBox(greenhouseBB, 0.0F, 0.0F, 0.0F, 0.5F);
            }
            GlStateManager.enableTexture2D();
            GlStateManager.disableBlend();
            GlStateManager.popMatrix();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IGreenhouseProvider(forestry.greenhouse.api.greenhouse.IGreenhouseProvider) World(net.minecraft.world.World) IGreenhouseLimits(forestry.greenhouse.api.greenhouse.IGreenhouseLimits) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Position2D(forestry.greenhouse.api.greenhouse.Position2D) BlockPos(net.minecraft.util.math.BlockPos) IGreenhouseControllerInternal(forestry.greenhouse.multiblock.IGreenhouseControllerInternal) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with IGreenhouseControllerInternal

use of forestry.greenhouse.multiblock.IGreenhouseControllerInternal in project ForestryMC by ForestryMC.

the class ClimateSourceClimatiser method removeResources.

@Override
protected void removeResources(IClimateState currentState, ClimateSourceType oppositeType) {
    IClimateHousing region = container.getParent();
    if (region instanceof IGreenhouseControllerInternal) {
        IGreenhouseControllerInternal controller = (IGreenhouseControllerInternal) region;
        EnergyManager energyManager = controller.getEnergyManager();
        energyManager.extractEnergy((int) (ENERGY_PER_OPERATION * getEnergyModifier(currentState, oppositeType)), false);
    }
}
Also used : EnergyManager(forestry.energy.EnergyManager) IGreenhouseControllerInternal(forestry.greenhouse.multiblock.IGreenhouseControllerInternal) IClimateHousing(forestry.api.greenhouse.IClimateHousing)

Example 5 with IGreenhouseControllerInternal

use of forestry.greenhouse.multiblock.IGreenhouseControllerInternal in project ForestryMC by ForestryMC.

the class ItemGreenhouseScreen method isValid.

public static boolean isValid(ItemStack stack, World world) {
    BlockPos pos = getGreenhousePos(stack);
    boolean isValid = true;
    if (pos == null || world == null || !world.isBlockLoaded(pos)) {
        isValid = false;
    } else {
        IGreenhouseControllerInternal controller = MultiblockUtil.getController(world, pos, IGreenhouseComponent.class);
        if (controller == null || !controller.isAssembled()) {
            isValid = false;
        }
    }
    return isValid;
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) IGreenhouseControllerInternal(forestry.greenhouse.multiblock.IGreenhouseControllerInternal)

Aggregations

IGreenhouseControllerInternal (forestry.greenhouse.multiblock.IGreenhouseControllerInternal)6 BlockPos (net.minecraft.util.math.BlockPos)3 IClimateState (forestry.api.climate.IClimateState)2 IClimateHousing (forestry.api.greenhouse.IClimateHousing)2 EnergyManager (forestry.energy.EnergyManager)2 IGreenhouseProvider (forestry.greenhouse.api.greenhouse.IGreenhouseProvider)2 ItemStack (net.minecraft.item.ItemStack)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 IErrorLogic (forestry.api.core.IErrorLogic)1 IGreenhouseComponent (forestry.api.multiblock.IGreenhouseComponent)1 IColoredBlock (forestry.core.blocks.IColoredBlock)1 IClimateContainer (forestry.greenhouse.api.climate.IClimateContainer)1 IGreenhouseLimits (forestry.greenhouse.api.greenhouse.IGreenhouseLimits)1 Position2D (forestry.greenhouse.api.greenhouse.Position2D)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 BlockColors (net.minecraft.client.renderer.color.BlockColors)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 World (net.minecraft.world.World)1