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