Search in sources :

Example 6 with IClimateSource

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

IClimateSource (forestry.greenhouse.api.climate.IClimateSource)6 IClimateSourceOwner (forestry.greenhouse.api.climate.IClimateSourceOwner)3 IClimateContainer (forestry.greenhouse.api.climate.IClimateContainer)2 IClimateSourceCircuitable (forestry.greenhouse.api.climate.IClimateSourceCircuitable)2 IClimateState (forestry.api.climate.IClimateState)1 Position2D (forestry.greenhouse.api.greenhouse.Position2D)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1