Search in sources :

Example 1 with IClimateContainer

use of forestry.greenhouse.api.climate.IClimateContainer in project ForestryMC by ForestryMC.

the class ClimateWorldManager method getClimateState.

public IClimateState getClimateState(World world, BlockPos pos) {
    IClimateState cacheState = stateCache.getIfPresent(pos);
    if (cacheState == null) {
        IGreenhouseClimateManager climateSourceManager = GreenhouseManager.climateManager;
        if (climateSourceManager != null) {
            IClimateContainer container = climateSourceManager.getContainer(world, pos);
            if (container != null) {
                cacheState = container.getState();
            }
        }
        if (cacheState == null) {
            cacheState = parent.getBiomeState(world, pos);
        }
        stateCache.put(pos, cacheState);
    }
    return cacheState;
}
Also used : IClimateContainer(forestry.greenhouse.api.climate.IClimateContainer) IClimateState(forestry.api.climate.IClimateState) IGreenhouseClimateManager(forestry.greenhouse.api.climate.IGreenhouseClimateManager)

Example 2 with IClimateContainer

use of forestry.greenhouse.api.climate.IClimateContainer in project ForestryMC by ForestryMC.

the class ProxyGreenhouseClient method getFoliageColor.

@SubscribeEvent
public void getFoliageColor(BiomeEvent.GetFoliageColor event) {
    if (COLOR_BLOCK_POSITION != null) {
        IGreenhouseBlock logicBlock = GreenhouseBlockManager.getInstance().getBlock(Minecraft.getMinecraft().world, COLOR_BLOCK_POSITION);
        if (logicBlock != null && logicBlock.getProvider().isClosed()) {
            IClimateContainer container = logicBlock.getProvider().getClimateContainer();
            IClimateState climateState = container.getState();
            double temperature = MathHelper.clamp(climateState.getTemperature(), 0.0F, 1.0F);
            double humidity = MathHelper.clamp(climateState.getHumidity(), 0.0F, 1.0F);
            event.setNewColor(ColorizerGrass.getGrassColor(temperature, humidity));
        }
    }
}
Also used : IClimateContainer(forestry.greenhouse.api.climate.IClimateContainer) IClimateState(forestry.api.climate.IClimateState) IGreenhouseBlock(forestry.greenhouse.api.greenhouse.IGreenhouseBlock) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with IClimateContainer

use of forestry.greenhouse.api.climate.IClimateContainer in project ForestryMC by ForestryMC.

the class ProxyGreenhouseClient method getGrassColor.

@SubscribeEvent
public void getGrassColor(BiomeEvent.GetGrassColor event) {
    if (COLOR_BLOCK_POSITION != null) {
        IGreenhouseBlock logicBlock = GreenhouseBlockManager.getInstance().getBlock(Minecraft.getMinecraft().world, COLOR_BLOCK_POSITION);
        if (logicBlock != null && logicBlock.getProvider().isClosed()) {
            IClimateContainer container = logicBlock.getProvider().getClimateContainer();
            IClimateState climateState = container.getState();
            double temperature = MathHelper.clamp(climateState.getTemperature(), 0.0F, 1.0F);
            double humidity = MathHelper.clamp(climateState.getHumidity(), 0.0F, 1.0F);
            event.setNewColor(ColorizerGrass.getGrassColor(temperature, humidity));
        }
    }
}
Also used : IClimateContainer(forestry.greenhouse.api.climate.IClimateContainer) IClimateState(forestry.api.climate.IClimateState) IGreenhouseBlock(forestry.greenhouse.api.greenhouse.IGreenhouseBlock) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with IClimateContainer

use of forestry.greenhouse.api.climate.IClimateContainer 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 5 with IClimateContainer

use of forestry.greenhouse.api.climate.IClimateContainer in project ForestryMC by ForestryMC.

the class ClimateContainer method equals.

@Override
public boolean equals(Object obj) {
    if (!(obj instanceof IClimateContainer)) {
        return false;
    }
    IClimateContainer container = (IClimateContainer) obj;
    IClimateHousing parent = container.getParent();
    if (parent.getCoordinates() == null || this.parent.getCoordinates() == null) {
        return false;
    }
    return this.parent.getCoordinates().equals(parent.getCoordinates());
}
Also used : IClimateContainer(forestry.greenhouse.api.climate.IClimateContainer) IClimateHousing(forestry.api.greenhouse.IClimateHousing)

Aggregations

IClimateContainer (forestry.greenhouse.api.climate.IClimateContainer)7 IClimateState (forestry.api.climate.IClimateState)4 IClimateSource (forestry.greenhouse.api.climate.IClimateSource)2 IGreenhouseBlock (forestry.greenhouse.api.greenhouse.IGreenhouseBlock)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 IClimateHousing (forestry.api.greenhouse.IClimateHousing)1 IGreenhouseComponent (forestry.api.multiblock.IGreenhouseComponent)1 IColoredBlock (forestry.core.blocks.IColoredBlock)1 IClimateSourceOwner (forestry.greenhouse.api.climate.IClimateSourceOwner)1 IGreenhouseClimateManager (forestry.greenhouse.api.climate.IGreenhouseClimateManager)1 IGreenhouseProvider (forestry.greenhouse.api.greenhouse.IGreenhouseProvider)1 Position2D (forestry.greenhouse.api.greenhouse.Position2D)1 IGreenhouseControllerInternal (forestry.greenhouse.multiblock.IGreenhouseControllerInternal)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 BlockColors (net.minecraft.client.renderer.color.BlockColors)1 ItemStack (net.minecraft.item.ItemStack)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1