diff --git a/lang b/lang index 52791479e..d22e48bca 160000 --- a/lang +++ b/lang @@ -1 +1 @@ -Subproject commit 52791479e340f8c8c699cd865f66a6a5215dcf63 +Subproject commit d22e48bca0de6a15f9a0ee4877c16deea6ed2c0a diff --git a/src/main/java/forestry/api/climate/ClimateStateType.java b/src/main/java/forestry/api/climate/ClimateStateType.java index 0195d37b0..3cb95b388 100644 --- a/src/main/java/forestry/api/climate/ClimateStateType.java +++ b/src/main/java/forestry/api/climate/ClimateStateType.java @@ -7,7 +7,7 @@ import net.minecraft.util.math.MathHelper; public enum ClimateStateType { IMMUTABLE(0.0F, 2.0F), MUTABLE(0.0F, 2.0F), - CHANGE(-2.0F, 2.0F); + CHANGE(-3.0F, 3.0F); public final Function bounds; diff --git a/src/main/java/forestry/api/climate/IClimateState.java b/src/main/java/forestry/api/climate/IClimateState.java index a5fd5efc5..d532a549c 100644 --- a/src/main/java/forestry/api/climate/IClimateState.java +++ b/src/main/java/forestry/api/climate/IClimateState.java @@ -32,11 +32,7 @@ public interface IClimateState extends INbtWritable { return type == ClimateType.HUMIDITY ? getHumidity() : getTemperature(); } - IClimateState toImmutable(); - - IClimateState toMutable(); - - IClimateState toChange(); + IClimateState toState(ClimateStateType type); IClimateState setTemperature(float temperature); diff --git a/src/main/java/forestry/core/climate/AbsentClimateState.java b/src/main/java/forestry/core/climate/AbsentClimateState.java index 5d799e010..34589fbd1 100644 --- a/src/main/java/forestry/core/climate/AbsentClimateState.java +++ b/src/main/java/forestry/core/climate/AbsentClimateState.java @@ -21,17 +21,7 @@ public final class AbsentClimateState implements IClimateState { } @Override - public IClimateState toImmutable() { - return this; - } - - @Override - public IClimateState toMutable() { - return this; - } - - @Override - public IClimateState toChange() { + public IClimateState toState(ClimateStateType type) { return this; } diff --git a/src/main/java/forestry/core/climate/ClimateContainer.java b/src/main/java/forestry/core/climate/ClimateContainer.java index bc1c816f1..3120bdba9 100644 --- a/src/main/java/forestry/core/climate/ClimateContainer.java +++ b/src/main/java/forestry/core/climate/ClimateContainer.java @@ -61,7 +61,7 @@ public class ClimateContainer implements IClimateContainer, IStreamable { this.listeners = new ClimateContainerListeners(); this.sources = new HashSet<>(); this.delay = 20; - this.state = parent.getDefaultClimate().toMutable(); + this.state = parent.getDefaultClimate().toState(ClimateStateType.MUTABLE); this.modifierData = new NBTTagCompound(); this.boundaryUp = ClimateState.MIN; this.boundaryDown = ClimateState.MIN; @@ -84,11 +84,12 @@ public class ClimateContainer implements IClimateContainer, IStreamable { if(!listeners.isClosed(this)) { returnClimateToDefault(); }else{ - IClimateState oldState = state.toImmutable(); - state = parent.getDefaultClimate().toMutable(); + IClimateState oldState = state.toState(ClimateStateType.IMMUTABLE); + state = parent.getDefaultClimate().toState(ClimateStateType.CHANGE); for(IClimateModifier modifier : GreenhouseClimateManager.getInstance().getModifiers()){ - state = modifier.modifyTarget(this, state, oldState, modifierData).toMutable(); + state = modifier.modifyTarget(this, state, oldState, modifierData).toState(ClimateStateType.CHANGE); } + state = state.toState(ClimateStateType.MUTABLE); if(!state.equals(oldState)) { BlockPos coordinates = parent.getCoordinates(); NetworkUtil.sendNetworkPacket(new PacketUpdateClimate(coordinates, this), coordinates, parent.getWorldObj()); diff --git a/src/main/java/forestry/core/climate/ClimateState.java b/src/main/java/forestry/core/climate/ClimateState.java index b66063eb4..e71892d59 100644 --- a/src/main/java/forestry/core/climate/ClimateState.java +++ b/src/main/java/forestry/core/climate/ClimateState.java @@ -37,10 +37,10 @@ public class ClimateState implements IClimateState, IClimateInfo { } public ClimateState(float temperature, float humidity, ClimateStateType type) { - addTemperature(temperature); - addHumidity(humidity); this.type = type; this.bounds = type.bounds; + addTemperature(temperature); + addHumidity(humidity); } public ClimateState(NBTTagCompound compound, ClimateStateType type) { @@ -94,23 +94,13 @@ public class ClimateState implements IClimateState, IClimateInfo { } @Override - public IClimateState toImmutable() { - return new ClimateState(this, ClimateStateType.IMMUTABLE); - } - - @Override - public IClimateState toMutable() { - return new ClimateState(this, ClimateStateType.MUTABLE); - } - - @Override - public IClimateState toChange() { - return new ClimateState(this, ClimateStateType.CHANGE); + public IClimateState toState(ClimateStateType type) { + return new ClimateState(this, type); } @Override public IClimateState addTemperature(float temperature){ - this.temperature=+ temperature; + this.temperature= bounds.apply(this.temperature + temperature); if(!isPresent()){ return AbsentClimateState.INSTANCE; } @@ -119,7 +109,7 @@ public class ClimateState implements IClimateState, IClimateInfo { @Override public IClimateState addHumidity(float humidity){ - this.humidity=+ humidity; + this.humidity= bounds.apply(this.humidity + humidity); if(!isPresent()){ return AbsentClimateState.INSTANCE; } diff --git a/src/main/java/forestry/core/gui/tables/Table.java b/src/main/java/forestry/core/gui/tables/Table.java index c9c29f18e..756842730 100644 --- a/src/main/java/forestry/core/gui/tables/Table.java +++ b/src/main/java/forestry/core/gui/tables/Table.java @@ -27,6 +27,11 @@ public class Table { lines.add(new TableTitle(title)); } + public Table clear(){ + lines.clear(); + return this; + } + public Table addValueEntry(String textKey, String value) { lines.add(new TableValueText(textKey + ": ", value)); return this; diff --git a/src/main/java/forestry/greenhouse/api/climate/IClimateData.java b/src/main/java/forestry/greenhouse/api/climate/IClimateData.java index 08a9066c3..706465197 100644 --- a/src/main/java/forestry/greenhouse/api/climate/IClimateData.java +++ b/src/main/java/forestry/greenhouse/api/climate/IClimateData.java @@ -13,5 +13,8 @@ public interface IClimateData { IClimateData addData(ClimateType type, String displayName, float value); + /** + * @return A map with all data that this object contains. + */ Map getData(ClimateType type); } diff --git a/src/main/java/forestry/greenhouse/climate/modifiers/TimeModifier.java b/src/main/java/forestry/greenhouse/climate/modifiers/TimeModifier.java index a4869fbcc..47bffff9c 100644 --- a/src/main/java/forestry/greenhouse/climate/modifiers/TimeModifier.java +++ b/src/main/java/forestry/greenhouse/climate/modifiers/TimeModifier.java @@ -27,7 +27,7 @@ import forestry.greenhouse.api.climate.IClimateModifier; public class TimeModifier implements IClimateModifier { - private static final float TEMPERATURE_CHANGE = 0.01F; + private static final float TEMPERATURE_CHANGE = 0.1F; public static float calculateLightRatio(World world) { int lightValue = EnumSkyBlock.SKY.defaultLightValue - world.getSkylightSubtracted(); diff --git a/src/main/java/forestry/greenhouse/gui/GuiGreenhouse.java b/src/main/java/forestry/greenhouse/gui/GuiGreenhouse.java index 5a62ba62f..f4419d11e 100755 --- a/src/main/java/forestry/greenhouse/gui/GuiGreenhouse.java +++ b/src/main/java/forestry/greenhouse/gui/GuiGreenhouse.java @@ -24,7 +24,6 @@ import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.TextLayoutHelper; import forestry.core.utils.NetworkUtil; import forestry.greenhouse.api.climate.IClimateContainer; -import forestry.greenhouse.api.climate.IClimateData; import forestry.greenhouse.gui.widgets.WidgetCamouflageTab; import forestry.greenhouse.gui.widgets.WidgetClimateBar; import forestry.greenhouse.gui.widgets.WidgetClimatePanel; @@ -51,15 +50,13 @@ public class GuiGreenhouse extends GuiForestryTitled { this.xSize = 196; this.ySize = 202; - IClimateData data = container.getData(); - //Add the camouflage tab widgetManager.add(new WidgetCamouflageTab(widgetManager, xSize / 4 - WidgetCamouflageTab.WIDTH / 2, -WidgetCamouflageTab.HEIGHT, controller, tile)); if(container.getTargetedState().isPresent()) { widgetManager.add(new WidgetClimateBar(widgetManager, xSize / 3 + WidgetClimateBar.WIDTH / 3, -WidgetClimateBar.HEIGHT)); } - widgetManager.add(temperaturePanel = new WidgetClimatePanel(widgetManager, this, 9, 18, ClimateType.TEMPERATURE, data)); - widgetManager.add(humidityPanel = new WidgetClimatePanel(widgetManager, this, 102, 18, ClimateType.HUMIDITY, data)); + widgetManager.add(temperaturePanel = new WidgetClimatePanel(widgetManager, this, 9, 18, ClimateType.TEMPERATURE)); + widgetManager.add(humidityPanel = new WidgetClimatePanel(widgetManager, this, 102, 18, ClimateType.HUMIDITY)); } public void sendNetworkUpdate() { diff --git a/src/main/java/forestry/greenhouse/gui/widgets/WidgetClimateBar.java b/src/main/java/forestry/greenhouse/gui/widgets/WidgetClimateBar.java index 320e23c07..a784c3509 100644 --- a/src/main/java/forestry/greenhouse/gui/widgets/WidgetClimateBar.java +++ b/src/main/java/forestry/greenhouse/gui/widgets/WidgetClimateBar.java @@ -17,12 +17,16 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.init.Biomes; +import net.minecraft.world.biome.Biome; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import forestry.api.core.EnumTemperature; -import forestry.api.genetics.AlleleManager; +import forestry.api.climate.ClimateStateType; +import forestry.api.climate.IClimateState; +import forestry.api.core.ForestryAPI; +import forestry.core.climate.ClimateState; import forestry.core.gui.tooltips.ToolTip; import forestry.core.gui.widgets.Widget; import forestry.core.gui.widgets.WidgetManager; @@ -40,27 +44,8 @@ public class WidgetClimateBar extends Widget { super(manager, xPos, yPos); this.width = WIDTH; this.height = HEIGHT; - for (int i = 1; i < 6; i++) { - EnumTemperature temp = EnumTemperature.VALUES[i]; - float value; - switch (temp) { - case ICY: - value = 0.0F; - break; - case COLD: - value = 0.2F; - break; - case WARM: - value = 0.9F; - break; - case HOT: - value = 1.2F; - break; - default: - value = 0.5F; - break; - } - buttons.add(new ClimateButton(this, temp, value, xPos + 5 + (i - 1) * 16, yPos + 5)); + for(EnumClimate climate : EnumClimate.values()){ + buttons.add(new ClimateButton(this, climate, xPos + 5 + climate.ordinal() * 16, yPos + 5)); } } @@ -90,7 +75,9 @@ public class WidgetClimateBar extends Widget { mouseY -= manager.gui.getGuiTop(); for (ClimateButton button : buttons) { if (button.isMouseOver(mouseX, mouseY)) { - ((GuiGreenhouse) manager.gui).temperaturePanel.setValue(button.value); + IClimateState climateState = button.climate.climateState; + ((GuiGreenhouse) manager.gui).temperaturePanel.setValue(climateState.getTemperature()); + ((GuiGreenhouse) manager.gui).humidityPanel.setValue(climateState.getHumidity()); } } } @@ -108,31 +95,49 @@ public class WidgetClimateBar extends Widget { manager.gui.drawTexturedModalRect(x, y, sprite, 16, 16); } - private static class ClimateButton { + private enum EnumClimate { + ICY("habitats/snow", Biomes.ICE_PLAINS), + COLD("habitats/taiga", Biomes.TAIGA), + NORMAL("habitats/plains", Biomes.PLAINS), + WARM("habitats/jungle", Biomes.JUNGLE), + HOT("habitats/desert", Biomes.DESERT); + IClimateState climateState; + String spriteName; + + EnumClimate(String spriteName, Biome biome) { + climateState = new ClimateState(biome.getTemperature(), biome.getRainfall(), ClimateStateType.IMMUTABLE); + this.spriteName = spriteName; + } + + @SideOnly(Side.CLIENT) + public TextureAtlasSprite getSprite() { + return ForestryAPI.textureManager.getDefault(spriteName); + } + } + + private class ClimateButton { final WidgetClimateBar parent; - final EnumTemperature temperature; - final float value; + final EnumClimate climate; protected final ToolTip toolTip = new ToolTip(250) { @Override @SideOnly(Side.CLIENT) public void refresh() { toolTip.clear(); - toolTip.add("T: " + AlleleManager.climateHelper.toDisplay(temperature)); - toolTip.add("V: " + value); + toolTip.add("T: " + climate.climateState.getTemperature()); + toolTip.add("H: " + climate.climateState.getHumidity()); } }; final int xPos, yPos; - public ClimateButton(WidgetClimateBar parent, EnumTemperature temperature, float value, int xPos, int yPos) { + public ClimateButton(WidgetClimateBar parent, EnumClimate climate, int xPos, int yPos) { this.parent = parent; - this.temperature = temperature; - this.value = value; + this.climate = climate; this.xPos = xPos; this.yPos = yPos; } public void draw(int startX, int startY) { - parent.drawSprite(temperature.getSprite(), startX + xPos, startY + yPos); + parent.drawSprite(climate.getSprite(), startX + xPos, startY + yPos); } public ToolTip getToolTip() { diff --git a/src/main/java/forestry/greenhouse/gui/widgets/WidgetClimatePanel.java b/src/main/java/forestry/greenhouse/gui/widgets/WidgetClimatePanel.java index b9b4d1ac0..492d70192 100644 --- a/src/main/java/forestry/greenhouse/gui/widgets/WidgetClimatePanel.java +++ b/src/main/java/forestry/greenhouse/gui/widgets/WidgetClimatePanel.java @@ -28,13 +28,13 @@ import forestry.core.gui.tables.Table; import forestry.core.gui.widgets.Widget; import forestry.core.gui.widgets.WidgetManager; import forestry.core.render.ColourProperties; -import forestry.core.utils.StringUtil; import forestry.core.utils.Translator; import forestry.greenhouse.api.climate.IClimateData; import forestry.greenhouse.gui.GuiGreenhouse; public class WidgetClimatePanel extends Widget { + protected static final int TEXT_FIELD_LENGTH = 50; protected static final Predicate NUMBER_FILTER = text -> { if (text == null) { return false; @@ -58,14 +58,13 @@ public class WidgetClimatePanel extends Widget { private final Table table; private final GuiTextField textField; - public WidgetClimatePanel(WidgetManager manager, GuiGreenhouse gui, int xPos, int yPos, ClimateType type, IClimateData data) { + public WidgetClimatePanel(WidgetManager manager, GuiGreenhouse gui, int xPos, int yPos, ClimateType type) { super(manager, xPos, yPos); this.width = 85; this.height = 98; this.type = type; this.gui = gui; - int textFieldLength = 50; - textField = new GuiTextField(0, Minecraft.getMinecraft().fontRenderer, xPos + width / 2 - textFieldLength / 2, yPos + 14, textFieldLength, 10); + textField = new GuiTextField(0, Minecraft.getMinecraft().fontRenderer, xPos + width / 2 - TEXT_FIELD_LENGTH / 2, yPos + 14, TEXT_FIELD_LENGTH, 10); textField.setValidator(NUMBER_FILTER); textField.setEnableBackgroundDrawing(false); IClimateState climateState = gui.container.getTargetedState(); @@ -76,9 +75,6 @@ public class WidgetClimatePanel extends Widget { textField.setEnabled(false); } table = new Table(); - for (Map.Entry entry : data.getData(type).entrySet()) { - table.addValueEntry(entry.getKey(), StringUtil.floatAsPercent(entry.getValue())); - } } @Override @@ -86,7 +82,7 @@ public class WidgetClimatePanel extends Widget { GlStateManager.color(1.0f, 1.0f, 1.0f); Minecraft mc = Minecraft.getMinecraft(); mc.getTextureManager().bindTexture(gui.textureFile); - gui.drawTexturedModalRect(startX + textField.x - 2, startY + textField.y - 2, 204, 115, 52, 12); + gui.drawTexturedModalRect(startX + textField.x - 2, startY + textField.y - 2, 196, 50, 52, 12); FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer; String title = Translator.translateToLocal("for.gui." + type.getName()); @@ -95,9 +91,29 @@ public class WidgetClimatePanel extends Widget { GlStateManager.color(1.0f, 1.0f, 1.0f); textField.drawTextBox(); + updateData(); table.draw(xPos + startX - 2, yPos + startY + 26, 14737632, false); } + private int updateTimer = 0; + + private void updateData(){ + if(updateTimer > 0){ + updateTimer--; + return; + } + updateTimer = 40; + table.clear(); + IClimateData data = gui.container.getData(); + for (Map.Entry entry : data.getData(type).entrySet()) { + float value = entry.getValue(); + int percent = (int)(value * 100); + if(percent != 0) { + table.addValueEntry(entry.getKey(), percent + " %"); + } + } + } + @Override public void handleMouseClick(int mouseX, int mouseY, int mouseButton) { boolean wasFocused = textField.isFocused(); diff --git a/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java b/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java index 3e03fe14f..186681ef2 100644 --- a/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java +++ b/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java @@ -401,7 +401,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im limits = createLimits(); if(!climateContainer.getTargetedState().isPresent()) { IClimateState defaultClimate = getDefaultClimate(); - climateContainer.setState(defaultClimate.toMutable()); + climateContainer.setState(defaultClimate.toState(ClimateStateType.MUTABLE)); climateContainer.setTargetedState(defaultClimate); } diff --git a/src/main/resources/assets/forestry/textures/gui/greenhouse.png b/src/main/resources/assets/forestry/textures/gui/greenhouse.png index bd7c9a599..50c806365 100644 Binary files a/src/main/resources/assets/forestry/textures/gui/greenhouse.png and b/src/main/resources/assets/forestry/textures/gui/greenhouse.png differ