Search in sources :

Example 11 with IClimateState

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

the class ClimateSource method work.

@Override
public final IClimateState work(IClimateState previousState, IClimateState targetState, IClimateState currentState, final double sizeModifier, final boolean canWork) {
    IClimateState state = ClimateStates.INSTANCE.create(getState(), ClimateStateType.EXTENDED);
    IClimateState change = ClimateStates.extendedZero();
    IClimateState defaultState = container.getParent().getDefaultClimate();
    ClimateSourceType validType = getWorkType(currentState, targetState);
    ClimateSourceType oppositeType = getOppositeWorkType(currentState, defaultState);
    beforeWork();
    boolean work = canWork(state, oppositeType);
    // Test if the source can work and test if the owner has enough resources to work.
    if (!canWork || !work && oppositeType != null) {
        isActive = false;
        isNotValid();
        if (ClimateStates.isZero(state)) {
            return change;
        } else if (ClimateStates.isNearZero(state)) {
            setState(change);
            return change;
        } else if (ClimateStates.isNearTarget(currentState, targetState)) {
            return change;
        }
        if (oppositeType != null) {
            // If the state is not already zero, remove one change state from the state.
            change = getChange(oppositeType, defaultState, currentState);
            change = ClimateStates.INSTANCE.create(-change.getTemperature(), -change.getHumidity(), ClimateStateType.EXTENDED);
        }
    } else if (validType == null && oppositeType != null) {
        // Remove the resources if the owner has enough resources and the state is not the default state.
        removeResources(state, oppositeType);
    } else if (validType != null) {
        change = getChange(validType, targetState, previousState);
        IClimateState changedState = state.add(change.scale(1 / sizeModifier));
        boolean couldWork = canWork(changedState, oppositeType);
        // Test if the owner could work with the changed state. If he can remove the resources for the changed state, if not only remove the resources for the old state.
        removeResources(couldWork ? changedState : state, oppositeType);
        if (!couldWork) {
            change = ClimateStates.extendedZero();
        }
    }
    state = state.add(change.scale(1 / sizeModifier));
    if (ClimateStates.isZero(state) || ClimateStates.isNearZero(state)) {
        state = ClimateStates.extendedZero();
    }
    if (false) {
        state = ClimateStates.extendedZero();
    }
    setState(state);
    return change;
}
Also used : IClimateState(forestry.api.climate.IClimateState)

Example 12 with IClimateState

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

the class ItemGreenhouseScreen method addInformation.

@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack stack, @Nullable World world, List<String> tooltip, ITooltipFlag flag) {
    super.addInformation(stack, world, tooltip, flag);
    boolean previewModeActive = isPreviewModeActive(stack);
    String previewMode = Translator.translateToLocal(previewModeActive ? "for.greenhouse_screen.mode.active" : "for.greenhouse_screen.mode.inactive");
    tooltip.add(Translator.translateToLocal(Translator.translateToLocalFormatted("for.greenhouse_screen.mode", previewMode)));
    boolean isValid = isValid(stack, world);
    BlockPos pos = getGreenhousePos(stack);
    String state = isValid ? Translator.translateToLocalFormatted("for.greenhouse_screen.state.linked", pos.getX(), pos.getY(), pos.getZ()) : Translator.translateToLocal("for.greenhouse_screen.state.fail");
    tooltip.add(Translator.translateToLocalFormatted("for.greenhouse_screen.state", state));
    if (!isValid) {
        return;
    }
    IGreenhouseControllerInternal controller = MultiblockUtil.getController(world, pos, IGreenhouseComponent.class);
    IClimateState climateState = controller.getClimateContainer().getState();
    tooltip.add(Translator.translateToLocalFormatted("for.greenhouse_screen.temperature", TextFormatting.GOLD + StringUtil.floatAsPercent(climateState.getTemperature())));
    tooltip.add(Translator.translateToLocalFormatted("for.greenhouse_screen.humidity", TextFormatting.BLUE + StringUtil.floatAsPercent(climateState.getHumidity())));
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) IGreenhouseControllerInternal(forestry.greenhouse.multiblock.IGreenhouseControllerInternal) IClimateState(forestry.api.climate.IClimateState) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 13 with IClimateState

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

the class WidgetClimateBar method handleMouseClick.

@Override
public void handleMouseClick(int mouseX, int mouseY, int mouseButton) {
    mouseX -= manager.gui.getGuiLeft();
    mouseY -= manager.gui.getGuiTop();
    for (ClimateButton button : buttons) {
        if (button.isMouseOver(mouseX, mouseY)) {
            IClimateState climateState = button.climate.climateState;
            ((GuiGreenhouse) manager.gui).temperaturePanel.setValue(climateState.getTemperature());
            ((GuiGreenhouse) manager.gui).humidityPanel.setValue(climateState.getHumidity());
            ((GuiGreenhouse) manager.gui).sendNetworkUpdate();
        }
    }
}
Also used : GuiGreenhouse(forestry.greenhouse.gui.GuiGreenhouse) IClimateState(forestry.api.climate.IClimateState)

Example 14 with IClimateState

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

the class ClimateSourceModifier method addInformation.

@Override
@SideOnly(Side.CLIENT)
public void addInformation(IClimateContainer container, NBTTagCompound nbtData, ClimateType type, List<String> lines) {
    IClimateState rangeDown = ClimateStates.INSTANCE.create(nbtData.getCompoundTag("rangeDown"), ClimateStateType.DEFAULT);
    IClimateState rangeUp = ClimateStates.INSTANCE.create(nbtData.getCompoundTag("rangeUp"), ClimateStateType.DEFAULT);
    IClimateState change = ClimateStates.INSTANCE.create(nbtData.getCompoundTag("change"), ClimateStateType.EXTENDED);
    if (type == ClimateType.HUMIDITY) {
        lines.add(Translator.translateToLocalFormatted("for.gui.modifier.sources.range.up", StringUtil.floatAsPercent(rangeUp.getHumidity())));
        lines.add(Translator.translateToLocalFormatted("for.gui.modifier.sources.range.down", StringUtil.floatAsPercent(rangeDown.getHumidity())));
        lines.add(Translator.translateToLocalFormatted("for.gui.modifier.sources.change", StringUtil.floatAsPercent(change.getHumidity())));
    } else {
        lines.add(Translator.translateToLocalFormatted("for.gui.modifier.sources.range.up", StringUtil.floatAsPercent(rangeUp.getTemperature())));
        lines.add(Translator.translateToLocalFormatted("for.gui.modifier.sources.range.down", StringUtil.floatAsPercent(rangeDown.getTemperature())));
        lines.add(Translator.translateToLocalFormatted("for.gui.modifier.sources.change", StringUtil.floatAsPercent(change.getTemperature())));
    }
}
Also used : IClimateState(forestry.api.climate.IClimateState) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 15 with IClimateState

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

the class ClimateSourceModifier method modifyTarget.

@Override
public IClimateState modifyTarget(IClimateContainer container, IClimateState newState, IClimateState previousState, NBTTagCompound data) {
    Collection<IClimateSource> sources = container.getClimateSources();
    if (sources.isEmpty()) {
        data.removeTag("rangeUp");
        data.removeTag("rangeDown");
        data.removeTag("change");
        return newState;
    }
    container.recalculateBoundaries();
    IClimateState boundaryUp = container.getBoundaryUp();
    IClimateState boundaryDown = container.getBoundaryDown();
    // Send the boundaries to the client
    data.setTag("rangeUp", boundaryUp.writeToNBT(new NBTTagCompound()));
    data.setTag("rangeDown", boundaryDown.writeToNBT(new NBTTagCompound()));
    IClimateState targetedState = container.getTargetedState();
    if (!targetedState.isPresent()) {
        return newState;
    }
    IClimateState target = getTargetOrBound(previousState, container.getBoundaryDown(), container.getBoundaryUp(), targetedState);
    IClimateState changeState = ClimateStates.extendedZero();
    for (IClimateSource source : container.getClimateSources()) {
        newState = newState.add(source.getState());
    }
    for (IClimateSource source : container.getClimateSources()) {
        IClimateState state = source.work(previousState, target, newState, container.getSizeModifier(), container.canWork());
        changeState = changeState.add(source.getState());
        newState = newState.add(state);
    }
    data.setTag("change", changeState.writeToNBT(new NBTTagCompound()));
    return newState;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IClimateSource(forestry.greenhouse.api.climate.IClimateSource) IClimateState(forestry.api.climate.IClimateState)

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