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;
}
Aggregations