From e07f10d981a788a7a6b4228c1ca5599b715eb56a Mon Sep 17 00:00:00 2001 From: Nedelosk Date: Wed, 6 Sep 2017 17:38:00 +0200 Subject: [PATCH] Clean Up Greenhouse Climate --- .../api/greenhouse/IGreenhouseListener.java | 2 +- .../forestry/core/climate/ClimateFactory.java | 3 +- .../multiblock/MultiblockControllerBase.java | 1 + .../network/packets/PacketUpdateClimate.java | 2 +- .../forestry/greenhouse/GreenhouseHelper.java | 4 +- .../api/climate/IClimateContainer.java | 17 --- .../climate/IClimateContainerListener.java | 15 --- .../api/climate/IClimateSourceContainer.java | 7 +- .../api/greenhouse/IGreenhouseHelper.java | 2 - .../api/greenhouse/IGreenhouseLogic.java | 2 +- .../greenhouse/IGreenhouseLogicFactory.java | 2 +- .../climate/ClimateContainer.java | 109 ++++-------------- .../modifiers/ClimateSourceModifier.java | 96 +++++++++------ .../multiblock/GreenhouseController.java | 23 ++-- .../GreenhouseMultiblockSizeLimits.java | 3 +- 15 files changed, 104 insertions(+), 184 deletions(-) delete mode 100644 src/main/java/forestry/greenhouse/api/climate/IClimateContainerListener.java rename src/main/java/forestry/{ => greenhouse}/api/greenhouse/IGreenhouseLogic.java (91%) rename src/main/java/forestry/{ => greenhouse}/api/greenhouse/IGreenhouseLogicFactory.java (91%) rename src/main/java/forestry/{core => greenhouse}/climate/ClimateContainer.java (69%) diff --git a/src/main/java/forestry/api/greenhouse/IGreenhouseListener.java b/src/main/java/forestry/api/greenhouse/IGreenhouseListener.java index add3a804c..186733790 100644 --- a/src/main/java/forestry/api/greenhouse/IGreenhouseListener.java +++ b/src/main/java/forestry/api/greenhouse/IGreenhouseListener.java @@ -10,7 +10,7 @@ import forestry.api.multiblock.IGreenhouseController; public interface IGreenhouseListener { /** - * Called before the greenhouse update the climate system. + * Called before the greenhouse updates the climate system. * * @param greenhouse The greenhouse of the listener. * @param canWork The actual {@link Boolean} value. diff --git a/src/main/java/forestry/core/climate/ClimateFactory.java b/src/main/java/forestry/core/climate/ClimateFactory.java index 5e2165922..c1432ca46 100644 --- a/src/main/java/forestry/core/climate/ClimateFactory.java +++ b/src/main/java/forestry/core/climate/ClimateFactory.java @@ -1,8 +1,9 @@ package forestry.core.climate; +import forestry.api.greenhouse.IClimateHousing; import forestry.greenhouse.api.climate.IClimateContainer; import forestry.greenhouse.api.climate.IClimateFactory; -import forestry.api.greenhouse.IClimateHousing; +import forestry.greenhouse.climate.ClimateContainer; public class ClimateFactory implements IClimateFactory{ diff --git a/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java b/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java index ea1468af7..769820d3a 100755 --- a/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java +++ b/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java @@ -37,6 +37,7 @@ public abstract class MultiblockControllerBase implements IMultiblockControllerI // Ticks private static final Random rand = new Random(); + //TODO: Use TickHelper private int tickCount = rand.nextInt(256); // Disassembled -> Assembled; Assembled -> Disassembled OR Paused; Paused -> Assembled diff --git a/src/main/java/forestry/core/network/packets/PacketUpdateClimate.java b/src/main/java/forestry/core/network/packets/PacketUpdateClimate.java index bfb52d89a..c6f9d2793 100644 --- a/src/main/java/forestry/core/network/packets/PacketUpdateClimate.java +++ b/src/main/java/forestry/core/network/packets/PacketUpdateClimate.java @@ -17,7 +17,6 @@ import net.minecraft.util.math.BlockPos; import forestry.api.greenhouse.IClimateHousing; import forestry.api.multiblock.IGreenhouseComponent; -import forestry.core.climate.ClimateContainer; import forestry.core.multiblock.MultiblockUtil; import forestry.core.network.ForestryPacket; import forestry.core.network.IForestryPacketClient; @@ -26,6 +25,7 @@ import forestry.core.network.IStreamable; import forestry.core.network.PacketBufferForestry; import forestry.core.network.PacketIdClient; import forestry.greenhouse.api.climate.IClimateContainer; +import forestry.greenhouse.climate.ClimateContainer; import forestry.greenhouse.multiblock.IGreenhouseControllerInternal; public class PacketUpdateClimate extends ForestryPacket implements IForestryPacketClient { diff --git a/src/main/java/forestry/greenhouse/GreenhouseHelper.java b/src/main/java/forestry/greenhouse/GreenhouseHelper.java index f9fcbfa96..7bd153c2e 100644 --- a/src/main/java/forestry/greenhouse/GreenhouseHelper.java +++ b/src/main/java/forestry/greenhouse/GreenhouseHelper.java @@ -18,10 +18,10 @@ import java.util.Map; import net.minecraft.item.ItemStack; -import forestry.api.greenhouse.IGreenhouseLogic; -import forestry.api.greenhouse.IGreenhouseLogicFactory; import forestry.api.multiblock.IGreenhouseController; import forestry.greenhouse.api.greenhouse.IGreenhouseHelper; +import forestry.greenhouse.api.greenhouse.IGreenhouseLogic; +import forestry.greenhouse.api.greenhouse.IGreenhouseLogicFactory; public class GreenhouseHelper implements IGreenhouseHelper { diff --git a/src/main/java/forestry/greenhouse/api/climate/IClimateContainer.java b/src/main/java/forestry/greenhouse/api/climate/IClimateContainer.java index ac6bd6581..507bd4573 100644 --- a/src/main/java/forestry/greenhouse/api/climate/IClimateContainer.java +++ b/src/main/java/forestry/greenhouse/api/climate/IClimateContainer.java @@ -5,8 +5,6 @@ ******************************************************************************/ package forestry.greenhouse.api.climate; -import java.util.Collection; - import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; @@ -36,21 +34,6 @@ public interface IClimateContainer extends INbtReadable, INbtWritable, IClimateS */ void updateClimate(int ticks); - /** - * Add a listener to this container. - */ - void addListener(IClimateContainerListener listener); - - /** - * Remove a listener to this container. - */ - void removeListener(IClimateContainerListener listener); - - /** - * All listeners of this container. - */ - Collection getListeners(); - /** * @return only not present if the controller never was assembled. */ diff --git a/src/main/java/forestry/greenhouse/api/climate/IClimateContainerListener.java b/src/main/java/forestry/greenhouse/api/climate/IClimateContainerListener.java deleted file mode 100644 index aa0e62d26..000000000 --- a/src/main/java/forestry/greenhouse/api/climate/IClimateContainerListener.java +++ /dev/null @@ -1,15 +0,0 @@ -/******************************************************************************* - * Copyright 2011-2014 SirSengir - * - * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. - ******************************************************************************/ -package forestry.greenhouse.api.climate; - -public interface IClimateContainerListener { - - /** - * Test if the container is closed. - */ - boolean isClosed(IClimateContainer container); - -} diff --git a/src/main/java/forestry/greenhouse/api/climate/IClimateSourceContainer.java b/src/main/java/forestry/greenhouse/api/climate/IClimateSourceContainer.java index 10aa5b1e2..5fc0c10c6 100644 --- a/src/main/java/forestry/greenhouse/api/climate/IClimateSourceContainer.java +++ b/src/main/java/forestry/greenhouse/api/climate/IClimateSourceContainer.java @@ -40,8 +40,13 @@ public interface IClimateSourceContainer { IClimateState getBoundaryDown(); /** - * Has to be called if any range of a {@link IClimateSource} changes. It calculates the range of all {@link IClimateSource}s together. + * Calculates the range of all {@link IClimateSource}s together. */ void recalculateBoundaries(double sizeModifier); + /** + * @return True if the container allows the {@link IClimateSource}s to work. + */ + boolean canWork(); + } diff --git a/src/main/java/forestry/greenhouse/api/greenhouse/IGreenhouseHelper.java b/src/main/java/forestry/greenhouse/api/greenhouse/IGreenhouseHelper.java index fb5456cdc..7fb07ddf7 100644 --- a/src/main/java/forestry/greenhouse/api/greenhouse/IGreenhouseHelper.java +++ b/src/main/java/forestry/greenhouse/api/greenhouse/IGreenhouseHelper.java @@ -9,8 +9,6 @@ import java.util.Collection; import net.minecraft.item.ItemStack; -import forestry.api.greenhouse.IGreenhouseLogic; -import forestry.api.greenhouse.IGreenhouseLogicFactory; import forestry.api.multiblock.IGreenhouseController; public interface IGreenhouseHelper { diff --git a/src/main/java/forestry/api/greenhouse/IGreenhouseLogic.java b/src/main/java/forestry/greenhouse/api/greenhouse/IGreenhouseLogic.java similarity index 91% rename from src/main/java/forestry/api/greenhouse/IGreenhouseLogic.java rename to src/main/java/forestry/greenhouse/api/greenhouse/IGreenhouseLogic.java index d8d2d0699..08d0a36b7 100644 --- a/src/main/java/forestry/api/greenhouse/IGreenhouseLogic.java +++ b/src/main/java/forestry/greenhouse/api/greenhouse/IGreenhouseLogic.java @@ -3,7 +3,7 @@ * * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. ******************************************************************************/ -package forestry.api.greenhouse; +package forestry.greenhouse.api.greenhouse; import forestry.api.core.INbtReadable; import forestry.api.core.INbtWritable; diff --git a/src/main/java/forestry/api/greenhouse/IGreenhouseLogicFactory.java b/src/main/java/forestry/greenhouse/api/greenhouse/IGreenhouseLogicFactory.java similarity index 91% rename from src/main/java/forestry/api/greenhouse/IGreenhouseLogicFactory.java rename to src/main/java/forestry/greenhouse/api/greenhouse/IGreenhouseLogicFactory.java index e9c4ee5b1..7ee7f1045 100644 --- a/src/main/java/forestry/api/greenhouse/IGreenhouseLogicFactory.java +++ b/src/main/java/forestry/greenhouse/api/greenhouse/IGreenhouseLogicFactory.java @@ -3,7 +3,7 @@ * * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. ******************************************************************************/ -package forestry.api.greenhouse; +package forestry.greenhouse.api.greenhouse; import forestry.api.multiblock.IGreenhouseController; diff --git a/src/main/java/forestry/core/climate/ClimateContainer.java b/src/main/java/forestry/greenhouse/climate/ClimateContainer.java similarity index 69% rename from src/main/java/forestry/core/climate/ClimateContainer.java rename to src/main/java/forestry/greenhouse/climate/ClimateContainer.java index 3120bdba9..bdf2150fe 100644 --- a/src/main/java/forestry/core/climate/ClimateContainer.java +++ b/src/main/java/forestry/greenhouse/climate/ClimateContainer.java @@ -8,14 +8,13 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.core.climate; +package forestry.greenhouse.climate; import java.io.IOException; import java.util.Collection; import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; import java.util.Set; +import java.util.function.Supplier; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.math.BlockPos; @@ -29,23 +28,23 @@ import forestry.api.climate.ClimateType; import forestry.api.climate.IClimateState; import forestry.api.core.ForestryAPI; import forestry.api.greenhouse.IClimateHousing; +import forestry.core.climate.AbsentClimateState; +import forestry.core.climate.ClimateData; +import forestry.core.climate.ClimateState; import forestry.core.network.IStreamable; import forestry.core.network.PacketBufferForestry; import forestry.core.network.packets.PacketUpdateClimate; import forestry.core.utils.NetworkUtil; import forestry.greenhouse.api.climate.IClimateContainer; -import forestry.greenhouse.api.climate.IClimateContainerListener; import forestry.greenhouse.api.climate.IClimateData; import forestry.greenhouse.api.climate.IClimateModifier; import forestry.greenhouse.api.climate.IClimateSource; -import forestry.greenhouse.climate.GreenhouseClimateManager; public class ClimateContainer implements IClimateContainer, IStreamable { - public static final float CLIMATE_CHANGE = 0.01F; protected final IClimateHousing parent; - protected final ClimateContainerListeners listeners; protected final Set sources; + protected final Supplier canWork; private int delay; protected IClimateState state; protected IClimateState targetedState; @@ -57,8 +56,11 @@ public class ClimateContainer implements IClimateContainer, IStreamable { * Creates an empty region. */ public ClimateContainer(IClimateHousing parent) { + this(parent, () -> true); + } + + public ClimateContainer(IClimateHousing parent, Supplier canWork) { this.parent = parent; - this.listeners = new ClimateContainerListeners(); this.sources = new HashSet<>(); this.delay = 20; this.state = parent.getDefaultClimate().toState(ClimateStateType.MUTABLE); @@ -66,11 +68,7 @@ public class ClimateContainer implements IClimateContainer, IStreamable { this.boundaryUp = ClimateState.MIN; this.boundaryDown = ClimateState.MIN; this.targetedState = AbsentClimateState.INSTANCE; - } - - public ClimateContainer(IClimateHousing parent, NBTTagCompound nbtTag) { - this(parent); - readFromNBT(nbtTag); + this.canWork = canWork; } @Override @@ -81,41 +79,15 @@ public class ClimateContainer implements IClimateContainer, IStreamable { @Override public void updateClimate(int ticks) { if (ticks % getTickDelay() == 0) { - if(!listeners.isClosed(this)) { - returnClimateToDefault(); - }else{ - 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).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()); - } + 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).toState(ClimateStateType.CHANGE); } - } - } - - protected void returnClimateToDefault(){ - IClimateState defaultState = parent.getDefaultClimate(); - float biomeTemperature = defaultState.getTemperature(); - float biomeHumidity = defaultState.getHumidity(); - float temperature = state.getTemperature(); - float humidity = state.getHumidity(); - if (temperature != biomeTemperature) { - if (temperature > biomeTemperature) { - state.addTemperature(-Math.min(CLIMATE_CHANGE, temperature - biomeTemperature)); - } else { - state.addTemperature(Math.min(CLIMATE_CHANGE, biomeTemperature - temperature)); - } - } - if (humidity != biomeHumidity) { - if (humidity > biomeHumidity) { - state.addHumidity(-Math.min(CLIMATE_CHANGE, humidity - biomeHumidity)); - } else { - state.addHumidity(Math.min(CLIMATE_CHANGE, biomeHumidity - humidity)); + state = state.toState(ClimateStateType.MUTABLE); + if (!state.equals(oldState)) { + BlockPos coordinates = parent.getCoordinates(); + NetworkUtil.sendNetworkPacket(new PacketUpdateClimate(coordinates, this), coordinates, parent.getWorldObj()); } } } @@ -249,21 +221,6 @@ public class ClimateContainer implements IClimateContainer, IStreamable { return state; } - @Override - public void addListener(IClimateContainerListener listener) { - listeners.addListaner(listener); - } - - @Override - public void removeListener(IClimateContainerListener listener) { - listeners.removeListener(listener); - } - - @Override - public Collection getListeners() { - return listeners.getListeners(); - } - @Override public boolean equals(Object obj) { if(!(obj instanceof IClimateContainer)){ @@ -291,32 +248,10 @@ public class ClimateContainer implements IClimateContainer, IStreamable { } return data; } - - private static final class ClimateContainerListeners implements IClimateContainerListener{ - private List listeners = new LinkedList<>(); - @Override - public boolean isClosed(IClimateContainer container) { - for(IClimateContainerListener listener : listeners){ - if(!listener.isClosed(container)){ - return false; - } - } - return true; - } - - public void addListaner(IClimateContainerListener listener) { - listeners.add(listener); - } - - public void removeListener(IClimateContainerListener listener) { - listeners.remove(listener); - } - - public Collection getListeners() { - return listeners; - } - + @Override + public boolean canWork() { + return canWork.get(); } } diff --git a/src/main/java/forestry/greenhouse/climate/modifiers/ClimateSourceModifier.java b/src/main/java/forestry/greenhouse/climate/modifiers/ClimateSourceModifier.java index 965a78e91..29fdf2178 100644 --- a/src/main/java/forestry/greenhouse/climate/modifiers/ClimateSourceModifier.java +++ b/src/main/java/forestry/greenhouse/climate/modifiers/ClimateSourceModifier.java @@ -30,6 +30,7 @@ import forestry.greenhouse.api.climate.IClimateModifier; import forestry.greenhouse.api.climate.IClimateSource; public class ClimateSourceModifier implements IClimateModifier { + public static final float CLIMATE_CHANGE = 0.01F; @Override public IClimateState modifyTarget(IClimateContainer container, IClimateState newState, IClimateState oldState, NBTTagCompound data) { @@ -42,48 +43,69 @@ public class ClimateSourceModifier implements IClimateModifier { } IClimateHousing housing = container.getParent(); double sizeModifier = housing.getSize() / Config.climateSourceRange; - double size = sizeModifier * 0.2D; sizeModifier = Math.max(sizeModifier, 1.0D); - container.recalculateBoundaries(sizeModifier); - - IClimateState boundaryUp = container.getBoundaryUp(); - IClimateState boundaryDown = container.getBoundaryDown(); - - data.setTag("rangeUp", boundaryUp.writeToNBT(new NBTTagCompound())); - data.setTag("rangeDown", boundaryDown.writeToNBT(new NBTTagCompound())); - - IClimateState targetedState = container.getTargetedState(); - if (!targetedState.isPresent()) { - return newState; - } - int workedSources = 0; - IClimateState target = getTargetOrBound(oldState, container.getBoundaryDown(), container.getBoundaryUp(), targetedState); IClimateState changeState = new ClimateState(data.getCompoundTag("change"), ClimateStateType.CHANGE); - - for (IClimateSource source : container.getClimateSources()) { - IClimateState state = source.work(oldState, target); - if (state.isPresent()) { - boolean hasChange = false; - double temperatureChange = state.getTemperature(); - double humidityChange = state.getHumidity(); - if (temperatureChange != 0) { - temperatureChange /= sizeModifier; - hasChange = true; - } - if (humidityChange != 0) { - humidityChange /= sizeModifier; - hasChange = true; - } - if (hasChange) { - changeState = changeState.addTemperature((float) temperatureChange); - changeState = changeState.addHumidity((float) humidityChange); - workedSources++; + if (!container.canWork()) { + IClimateState defaultState = container.getParent().getDefaultClimate(); + float defaultTemperature = defaultState.getTemperature(); + float defaultHumidity = defaultState.getHumidity(); + float temperature = changeState.getTemperature(); + float humidity = changeState.getHumidity(); + if (temperature != defaultTemperature) { + if (temperature > defaultTemperature) { + changeState = changeState.addTemperature((float) -Math.min(CLIMATE_CHANGE / sizeModifier, temperature - defaultTemperature)); + } else { + changeState = changeState.addTemperature((float) Math.min(CLIMATE_CHANGE / sizeModifier, defaultTemperature - temperature)); } } - } - if (workedSources == 0) { - return newState.add(changeState); + if (humidity != defaultHumidity) { + if (humidity > defaultHumidity) { + changeState = changeState.addHumidity((float) -Math.min(CLIMATE_CHANGE / sizeModifier, humidity - defaultHumidity)); + } else { + changeState = changeState.addHumidity((float) Math.min(CLIMATE_CHANGE / sizeModifier, defaultHumidity - humidity)); + } + } + } else { + container.recalculateBoundaries(sizeModifier); + + IClimateState boundaryUp = container.getBoundaryUp(); + IClimateState boundaryDown = container.getBoundaryDown(); + + data.setTag("rangeUp", boundaryUp.writeToNBT(new NBTTagCompound())); + data.setTag("rangeDown", boundaryDown.writeToNBT(new NBTTagCompound())); + + IClimateState targetedState = container.getTargetedState(); + if (!targetedState.isPresent()) { + return newState; + } + int workedSources = 0; + IClimateState target = getTargetOrBound(oldState, container.getBoundaryDown(), container.getBoundaryUp(), targetedState); + + for (IClimateSource source : container.getClimateSources()) { + IClimateState state = source.work(oldState, target); + if (state.isPresent()) { + boolean hasChange = false; + double temperatureChange = state.getTemperature(); + double humidityChange = state.getHumidity(); + if (temperatureChange != 0) { + temperatureChange /= sizeModifier; + hasChange = true; + } + if (humidityChange != 0) { + humidityChange /= sizeModifier; + hasChange = true; + } + if (hasChange) { + changeState = changeState.addTemperature((float) temperatureChange); + changeState = changeState.addHumidity((float) humidityChange); + workedSources++; + } + } + } + if (workedSources == 0) { + return newState.add(changeState); + } } data.setTag("change", changeState.writeToNBT(new NBTTagCompound())); return newState.add(changeState); diff --git a/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java b/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java index 87f429cee..d81c5b188 100644 --- a/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java +++ b/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java @@ -33,13 +33,11 @@ import forestry.api.core.EnumTemperature; import forestry.api.core.ICamouflagedTile; import forestry.api.core.IErrorLogic; import forestry.api.greenhouse.IGreenhouseListener; -import forestry.api.greenhouse.IGreenhouseLogic; import forestry.api.multiblock.IGreenhouseComponent; import forestry.api.multiblock.IGreenhouseComponent.Active; import forestry.api.multiblock.IGreenhouseComponent.Listener; import forestry.api.multiblock.IMultiblockComponent; import forestry.core.PluginCore; -import forestry.core.climate.ClimateContainer; import forestry.core.climate.ClimateState; import forestry.core.config.Config; import forestry.core.multiblock.IMultiblockControllerInternal; @@ -52,14 +50,15 @@ import forestry.core.utils.Translator; import forestry.energy.EnergyManager; import forestry.greenhouse.api.climate.GreenhouseState; import forestry.greenhouse.api.climate.IClimateContainer; -import forestry.greenhouse.api.climate.IClimateContainerListener; import forestry.greenhouse.api.greenhouse.GreenhouseManager; import forestry.greenhouse.api.greenhouse.IGreenhouseBlock; import forestry.greenhouse.api.greenhouse.IGreenhouseLimits; +import forestry.greenhouse.api.greenhouse.IGreenhouseLogic; import forestry.greenhouse.api.greenhouse.IGreenhouseProvider; import forestry.greenhouse.api.greenhouse.IGreenhouseProviderListener; import forestry.greenhouse.api.greenhouse.Position2D; import forestry.greenhouse.camouflage.CamouflageHandlerType; +import forestry.greenhouse.climate.ClimateContainer; import forestry.greenhouse.multiblock.blocks.storage.GreenhouseProvider; import forestry.greenhouse.multiblock.blocks.storage.GreenhouseProviderClient; import forestry.greenhouse.multiblock.blocks.storage.GreenhouseProviderServer; @@ -68,7 +67,7 @@ import forestry.greenhouse.network.packets.PacketCamouflageSelectionServer; import forestry.greenhouse.network.packets.PacketGreenhouseDataRequest; import forestry.greenhouse.tiles.TileGreenhousePlain; -public class GreenhouseController extends RectangularMultiblockControllerBase implements IGreenhouseControllerInternal, IClimateContainerListener, IGreenhouseProviderListener { +public class GreenhouseController extends RectangularMultiblockControllerBase implements IGreenhouseControllerInternal, IGreenhouseProviderListener { public static final String TYPE = "for.multiblock.greenhouse.type"; public static final int CENTER_HEIGHT = 3; @@ -95,13 +94,12 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im private boolean requestedData; public GreenhouseController(World world) { - super(world, GreenhouseMultiblockSizeLimits.instance); + super(world, GreenhouseMultiblockSizeLimits.INSTANCE); this.energyManager = new EnergyManager(200, 100000); this.camouflage = getDefaultCamouflageBlock(); - this.climateContainer = new ClimateContainer(this); - this.climateContainer.addListener(this); + this.climateContainer = new ClimateContainer(this, this::canWork); this.centerPos = BlockPos.ORIGIN; if (world.isRemote) { provider = new GreenhouseProviderClient(world, climateContainer); @@ -189,11 +187,6 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im return limits; } - @Override - public boolean isClosed(IClimateContainer container) { - return provider.isClosed(); - } - /* IMultiblockControllerInternal */ @Override public void formatDescriptionPacket(NBTTagCompound data) { @@ -281,9 +274,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im provider.create(); } } else { - if (canWork()) { - climateContainer.updateClimate(tickCount); - } + climateContainer.updateClimate(tickCount); for (Active activeComponent : activeComponents) { activeComponent.updateServer(tickCount); @@ -364,7 +355,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im IGreenhouseListener listener = listenerComponent.getGreenhouseListener(); canWork = listener.canWork(this, canWork); } - return canWork; + return canWork && provider.isClosed(); } @Override diff --git a/src/main/java/forestry/greenhouse/multiblock/GreenhouseMultiblockSizeLimits.java b/src/main/java/forestry/greenhouse/multiblock/GreenhouseMultiblockSizeLimits.java index 8efaf89a8..e1d2328df 100644 --- a/src/main/java/forestry/greenhouse/multiblock/GreenhouseMultiblockSizeLimits.java +++ b/src/main/java/forestry/greenhouse/multiblock/GreenhouseMultiblockSizeLimits.java @@ -13,10 +13,9 @@ package forestry.greenhouse.multiblock; import forestry.core.multiblock.IMultiblockSizeLimits; class GreenhouseMultiblockSizeLimits implements IMultiblockSizeLimits { - public static final GreenhouseMultiblockSizeLimits instance = new GreenhouseMultiblockSizeLimits(); + public static final GreenhouseMultiblockSizeLimits INSTANCE = new GreenhouseMultiblockSizeLimits(); private GreenhouseMultiblockSizeLimits() { - } @Override