Search in sources :

Example 1 with IClimateState

use of forestry.api.climate.IClimateState 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 IClimateState

use of forestry.api.climate.IClimateState 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 IClimateState

use of forestry.api.climate.IClimateState 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 IClimateState

use of forestry.api.climate.IClimateState in project ForestryMC by ForestryMC.

the class GreenhouseController method onMachineAssembled.

/* MultiblockControllerForestry */
@Override
protected void onMachineAssembled() {
    super.onMachineAssembled();
    BlockPos centerTop = getTopCenterCoord();
    centerPos = centerTop.up(CENTER_HEIGHT);
    createDefaultState();
    limits = createLimits();
    if (!climateContainer.getTargetedState().isPresent()) {
        IClimateState defaultClimate = getDefaultClimate();
        climateContainer.setState(defaultClimate.copy());
        climateContainer.setTargetedState(defaultClimate);
    }
    provider.init(centerPos, limits);
    assembleTickCount = getTickCount();
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) IClimateState(forestry.api.climate.IClimateState)

Example 5 with IClimateState

use of forestry.api.climate.IClimateState 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)

Aggregations

IClimateState (forestry.api.climate.IClimateState)16 IClimateContainer (forestry.greenhouse.api.climate.IClimateContainer)4 BlockPos (net.minecraft.util.math.BlockPos)4 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)3 IGreenhouseBlock (forestry.greenhouse.api.greenhouse.IGreenhouseBlock)2 IGreenhouseControllerInternal (forestry.greenhouse.multiblock.IGreenhouseControllerInternal)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 IGreenhouseComponent (forestry.api.multiblock.IGreenhouseComponent)1 IColoredBlock (forestry.core.blocks.IColoredBlock)1 PacketUpdateClimate (forestry.core.network.packets.PacketUpdateClimate)1 IClimateModifier (forestry.greenhouse.api.climate.IClimateModifier)1 IClimateSource (forestry.greenhouse.api.climate.IClimateSource)1 IGreenhouseClimateManager (forestry.greenhouse.api.climate.IGreenhouseClimateManager)1 IGreenhouseProvider (forestry.greenhouse.api.greenhouse.IGreenhouseProvider)1 GuiGreenhouse (forestry.greenhouse.gui.GuiGreenhouse)1 PacketSelectClimateTargeted (forestry.greenhouse.network.packets.PacketSelectClimateTargeted)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