From cc53894473a73d9cb9464fa6ba54fa86b7805d6a Mon Sep 17 00:00:00 2001 From: Nedelosk Date: Sun, 12 Jun 2016 20:42:09 +0200 Subject: [PATCH] Finish work --- src/main/java/forestry/Forestry.java | 2 + .../api/core/climate/IClimateManager.java | 7 +++ .../api/core/climate/IClimateRegion.java | 3 ++ .../api/core/climate/IClimateSource.java | 13 +++++ .../api/greenhouse/IGreenhouseListener.java | 8 +-- .../api/multiblock/IGreenhouseComponent.java | 4 +- .../core/climate/ClimateEventHandler.java | 40 +++++++++++++++ .../forestry/core/climate/ClimateManager.java | 4 +- ...atedPosition.java => ClimatePosition.java} | 6 +-- .../forestry/core/climate/ClimateRoom.java | 2 +- .../core/worldgen/WorldGenerator.java | 2 - .../multiblock/FakeGreenhouseController.java | 10 ++++ .../multiblock/GreenhouseController.java | 49 ++++++++++++------- .../IGreenhouseControllerInternal.java | 8 +++ .../proxy/ProxyGreenhouseClient.java | 7 ++- .../tiles/TileGreenhouseClimatiser.java | 17 ++++--- .../tiles/TileGreenhouseSprinkler.java | 19 ++++--- 17 files changed, 156 insertions(+), 45 deletions(-) create mode 100644 src/main/java/forestry/core/climate/ClimateEventHandler.java rename src/main/java/forestry/core/climate/{ClimatedPosition.java => ClimatePosition.java} (89%) diff --git a/src/main/java/forestry/Forestry.java b/src/main/java/forestry/Forestry.java index 6800a00f8..178b7e830 100644 --- a/src/main/java/forestry/Forestry.java +++ b/src/main/java/forestry/Forestry.java @@ -26,6 +26,7 @@ import net.minecraftforge.fml.common.registry.GameRegistry; import forestry.api.core.ForestryAPI; import forestry.core.EventHandlerCore; +import forestry.core.climate.ClimateEventHandler; import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.config.GameMode; @@ -81,6 +82,7 @@ public class Forestry { EventHandlerCore eventHandlerCore = new EventHandlerCore(); MinecraftForge.EVENT_BUS.register(eventHandlerCore); MinecraftForge.EVENT_BUS.register(new MultiblockEventHandler()); + MinecraftForge.EVENT_BUS.register(new ClimateEventHandler()); configFolder = new File(event.getModConfigurationDirectory(), Constants.MOD_ID); Config.load(); diff --git a/src/main/java/forestry/api/core/climate/IClimateManager.java b/src/main/java/forestry/api/core/climate/IClimateManager.java index 7250e31f2..cbc0d5a66 100644 --- a/src/main/java/forestry/api/core/climate/IClimateManager.java +++ b/src/main/java/forestry/api/core/climate/IClimateManager.java @@ -24,10 +24,17 @@ public interface IClimateManager { void removeRegion(IClimateRegion region); + void addSource(IClimateSource source); + + void removeSource(IClimateSource source); + @Nullable IClimateRegion getRegionForPos(World world, BlockPos pos); @Nonnull Map> getRegions(); + @Nonnull + Map> getSources(); + } diff --git a/src/main/java/forestry/api/core/climate/IClimateRegion.java b/src/main/java/forestry/api/core/climate/IClimateRegion.java index 22b01b49f..9f2426c02 100644 --- a/src/main/java/forestry/api/core/climate/IClimateRegion.java +++ b/src/main/java/forestry/api/core/climate/IClimateRegion.java @@ -19,6 +19,9 @@ public interface IClimateRegion extends INbtReadable, INbtWritable { @Nonnull World getWorld(); + /** + * Update the climate in a region, all 20 world ticks. + */ void updateClimate(); @Nonnull diff --git a/src/main/java/forestry/api/core/climate/IClimateSource.java b/src/main/java/forestry/api/core/climate/IClimateSource.java index 0343458c4..de762fadc 100644 --- a/src/main/java/forestry/api/core/climate/IClimateSource.java +++ b/src/main/java/forestry/api/core/climate/IClimateSource.java @@ -5,6 +5,19 @@ ******************************************************************************/ package forestry.api.core.climate; +import net.minecraft.util.math.BlockPos; + +/** + * A climate source is used to change the climate in a region. + */ public interface IClimateSource { + + /** + * @param tickCount The current tick count. + * @param region The climate region, in that the source stands. + */ + void changeClimate(int tickCount, IClimateRegion region); + + BlockPos getPos(); } diff --git a/src/main/java/forestry/api/greenhouse/IGreenhouseListener.java b/src/main/java/forestry/api/greenhouse/IGreenhouseListener.java index d443357f1..c5e41fa2a 100644 --- a/src/main/java/forestry/api/greenhouse/IGreenhouseListener.java +++ b/src/main/java/forestry/api/greenhouse/IGreenhouseListener.java @@ -10,12 +10,12 @@ import forestry.api.multiblock.IGreenhouseController; public interface IGreenhouseListener { /** - * Called before the greenhouse work. + * Called before the greenhouse update the climate system. * - * @param greenhouse The greenhouse multiblock. + * @param greenhouse The greenhouse of the listener. * @param canWork The actual {@link Boolean} value. - * @return True if the greenhouse can work. + * @return True if the greenhouse can update the climate. */ - boolean canWork(G greenhouse, boolean canWork); + boolean canWork(IGreenhouseController greenhouse, boolean canWork); } diff --git a/src/main/java/forestry/api/multiblock/IGreenhouseComponent.java b/src/main/java/forestry/api/multiblock/IGreenhouseComponent.java index 0466f00fc..d7472e67c 100644 --- a/src/main/java/forestry/api/multiblock/IGreenhouseComponent.java +++ b/src/main/java/forestry/api/multiblock/IGreenhouseComponent.java @@ -5,6 +5,7 @@ ******************************************************************************/ package forestry.api.multiblock; +import forestry.api.core.climate.IClimateSource; import forestry.api.greenhouse.IGreenhouseListener; import forestry.api.lepidopterology.IButterflyCocoon; import net.minecraft.item.ItemStack; @@ -20,8 +21,7 @@ public interface IGreenhouseComponent exte interface Door extends IGreenhouseComponent { } - interface Climatiser extends IGreenhouseComponent { - void changeClimate(int tickCount, IGreenhouseController controller); + interface Climatiser extends IGreenhouseComponent, IClimateSource { } interface ButterflyHatch extends IGreenhouseComponent { diff --git a/src/main/java/forestry/core/climate/ClimateEventHandler.java b/src/main/java/forestry/core/climate/ClimateEventHandler.java new file mode 100644 index 000000000..6aaeeb0a6 --- /dev/null +++ b/src/main/java/forestry/core/climate/ClimateEventHandler.java @@ -0,0 +1,40 @@ +package forestry.core.climate; + +import java.util.HashMap; +import java.util.Map; + +import forestry.api.core.ForestryAPI; +import forestry.api.core.climate.IClimateRegion; +import forestry.api.core.climate.IClimateSource; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; + +public class ClimateEventHandler { + + Map serverTicks; + + public ClimateEventHandler() { + serverTicks = new HashMap<>(); + } + + @SubscribeEvent + public void onWorldTick(TickEvent.WorldTickEvent event) { + int dim = event.world.provider.getDimension(); + if (event.phase == TickEvent.Phase.END) { + if(!serverTicks.containsKey(Integer.valueOf(dim))){ + serverTicks.put(Integer.valueOf(dim), 1); + } + int ticks = serverTicks.get(Integer.valueOf(dim)); + if(ticks % 20 == 0){ + for(IClimateRegion region : ForestryAPI.climateManager.getRegions().get(Integer.valueOf(dim))){ + region.updateClimate(); + } + } + for(IClimateSource source : ForestryAPI.climateManager.getSources().get(Integer.valueOf(dim))){ + source.changeClimate(ticks, ForestryAPI.climateManager.getRegionForPos(event.world, source.getPos())); + } + serverTicks.put(Integer.valueOf(dim), ticks+1); + } + } + +} diff --git a/src/main/java/forestry/core/climate/ClimateManager.java b/src/main/java/forestry/core/climate/ClimateManager.java index b9b9cba63..5cfd4629d 100644 --- a/src/main/java/forestry/core/climate/ClimateManager.java +++ b/src/main/java/forestry/core/climate/ClimateManager.java @@ -18,6 +18,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; + import forestry.api.core.climate.IClimateManager; import forestry.api.core.climate.IClimatePosition; import forestry.api.core.climate.IClimateRegion; @@ -36,7 +38,7 @@ public class ClimateManager implements IClimateManager{ return; } List regions = getOrCreateRegions(region.getWorld()); - List positions = (List) region.getPositions().keySet(); + Set positions = region.getPositions().keySet(); for(IClimateRegion otherRegion : regions){ for(BlockPos pos : otherRegion.getPositions().keySet()){ if(positions.contains(pos)){ diff --git a/src/main/java/forestry/core/climate/ClimatedPosition.java b/src/main/java/forestry/core/climate/ClimatePosition.java similarity index 89% rename from src/main/java/forestry/core/climate/ClimatedPosition.java rename to src/main/java/forestry/core/climate/ClimatePosition.java index d0be4cf6c..4107857f4 100644 --- a/src/main/java/forestry/core/climate/ClimatedPosition.java +++ b/src/main/java/forestry/core/climate/ClimatePosition.java @@ -17,7 +17,7 @@ import forestry.api.core.climate.IClimatePosition; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.math.BlockPos; -public class ClimatedPosition implements IClimatePosition { +public class ClimatePosition implements IClimatePosition { @Nonnull protected final IClimateRegion climateRegion; @@ -26,12 +26,12 @@ public class ClimatedPosition implements IClimatePosition { protected float temperature; protected float humidity; - public ClimatedPosition(IClimateRegion climateRegion, BlockPos pos) { + public ClimatePosition(IClimateRegion climateRegion, BlockPos pos) { this.climateRegion = climateRegion; this.pos = pos; } - public ClimatedPosition(@Nonnull IClimateRegion climateRegion, @Nonnull BlockPos pos, float temperature, float humidity) { + public ClimatePosition(@Nonnull IClimateRegion climateRegion, @Nonnull BlockPos pos, float temperature, float humidity) { this.climateRegion = climateRegion; this.pos = pos; this.temperature = temperature; diff --git a/src/main/java/forestry/core/climate/ClimateRoom.java b/src/main/java/forestry/core/climate/ClimateRoom.java index f2affcce4..f43b54c76 100644 --- a/src/main/java/forestry/core/climate/ClimateRoom.java +++ b/src/main/java/forestry/core/climate/ClimateRoom.java @@ -123,7 +123,7 @@ public class ClimateRoom implements IClimateRegion { int yPos = positionTag.getInteger("YPos"); int zPos = positionTag.getInteger("ZPos"); BlockPos pos = new BlockPos(xPos, yPos, zPos); - ClimatedPosition position = new ClimatedPosition(this, pos); + ClimatePosition position = new ClimatePosition(this, pos); position.readFromNBT(positionTag); positions.put(pos, position); } diff --git a/src/main/java/forestry/core/worldgen/WorldGenerator.java b/src/main/java/forestry/core/worldgen/WorldGenerator.java index 3c19f41bb..e3d940f14 100644 --- a/src/main/java/forestry/core/worldgen/WorldGenerator.java +++ b/src/main/java/forestry/core/worldgen/WorldGenerator.java @@ -14,7 +14,6 @@ import java.util.Random; import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.ChunkPos; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkGenerator; import net.minecraft.world.chunk.IChunkProvider; @@ -27,7 +26,6 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import forestry.core.PluginCore; import forestry.core.blocks.BlockResourceOre; import forestry.core.blocks.EnumResourceType; -import forestry.core.climate.ClimateManager; import forestry.core.config.Config; import forestry.plugins.PluginManager; diff --git a/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java b/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java index 99abe2722..4e7e92f0a 100644 --- a/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java +++ b/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java @@ -23,6 +23,7 @@ import forestry.api.core.climate.IClimateRegion; import forestry.api.greenhouse.EnumGreenhouseEventType; import forestry.api.greenhouse.IGreenhouseLogic; import forestry.api.greenhouse.IInternalBlock; +import forestry.api.multiblock.IGreenhouseComponent.Listener; import forestry.core.fluids.FakeTankManager; import forestry.core.fluids.ITankManager; import forestry.core.inventory.FakeInventoryAdapter; @@ -96,4 +97,13 @@ public class FakeGreenhouseController extends FakeMultiblockController implement public IClimateRegion getRegion() { return null; } + + @Override + public void clearRegion() { + } + + @Override + public Set getListenerComponents() { + return Collections.emptySet(); + } } diff --git a/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java b/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java index 919bf9d73..d30f30c54 100644 --- a/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java +++ b/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java @@ -38,6 +38,7 @@ import forestry.api.core.ForestryAPI; import forestry.api.core.ICamouflagedTile; import forestry.api.core.climate.IClimatePosition; import forestry.api.core.climate.IClimateRegion; +import forestry.api.core.climate.IClimateSource; import forestry.api.greenhouse.EnumGreenhouseEventType; import forestry.api.greenhouse.GreenhouseEvents.CamouflageChangeEvent; import forestry.api.greenhouse.GreenhouseEvents.CheckInternalBlockFaceEvent; @@ -52,7 +53,7 @@ import forestry.api.multiblock.IGreenhouseController; import forestry.api.multiblock.IMultiblockComponent; import forestry.core.access.EnumAccess; import forestry.core.climate.ClimateRoom; -import forestry.core.climate.ClimatedPosition; +import forestry.core.climate.ClimatePosition; import forestry.core.config.Constants; import forestry.core.fluids.TankManager; import forestry.core.fluids.tanks.FilteredTank; @@ -81,7 +82,6 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im private final Set internalBlocks = new HashSet<>(); private final Set listenerComponents = new HashSet<>(); - private final Set climatiserComponents = new HashSet<>(); private final Set activeComponents = new HashSet<>(); private final List logics = new ArrayList<>(); @@ -408,15 +408,17 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im Map internalPositions = new HashMap<>(); for(IInternalBlock block : internalBlocks){ if(block != null){ - internalPositions.put(block.getPos(), new ClimatedPosition(region, block.getPos())); + internalPositions.put(block.getPos(), new ClimatePosition(region, block.getPos())); } } + ForestryAPI.climateManager.removeRegion(region); region = new ClimateRoom(region, internalPositions); + ForestryAPI.climateManager.addRegion(region); }else{ Map internalPositions = new HashMap<>(); for(IInternalBlock block : internalBlocks){ if(block != null){ - internalPositions.put(block.getPos(), new ClimatedPosition(region, block.getPos())); + internalPositions.put(block.getPos(), new ClimatePosition(region, block.getPos())); } } region = new ClimateRoom(this, internalPositions); @@ -437,7 +439,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im if (newPart instanceof IGreenhouseComponent.Listener) { listenerComponents.add((IGreenhouseComponent.Listener) newPart); } else if (newPart instanceof IGreenhouseComponent.Climatiser) { - climatiserComponents.add((IGreenhouseComponent.Climatiser) newPart); + ForestryAPI.climateManager.addSource((IClimateSource) newPart); } else if (newPart instanceof IGreenhouseComponent.Active) { activeComponents.add((IGreenhouseComponent.Active) newPart); } @@ -448,7 +450,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im if (oldPart instanceof IGreenhouseComponent.Listener) { listenerComponents.remove(oldPart); } else if (oldPart instanceof IGreenhouseComponent.Climatiser) { - climatiserComponents.remove(oldPart); + ForestryAPI.climateManager.removeSource((IClimateSource) oldPart); } else if (oldPart instanceof IGreenhouseComponent.Active) { activeComponents.remove(oldPart); } @@ -456,10 +458,21 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im @Override protected void onAssimilate(IMultiblockControllerInternal assimilated) { + if(assimilated != null && ((IGreenhouseControllerInternal)assimilated).getRegion() != null){ + IGreenhouseControllerInternal internal = (IGreenhouseControllerInternal) assimilated; + if(region != null){ + ForestryAPI.climateManager.removeRegion(region); + region = new ClimateRoom(region,internal.getRegion().getPositions()); + ForestryAPI.climateManager.addRegion(region); + } + } } @Override public void onAssimilated(IMultiblockControllerInternal assimilator) { + if(region != null){ + ForestryAPI.climateManager.removeRegion(region); + } } @Override @@ -475,20 +488,8 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im for (IGreenhouseComponent.Active activeComponent : activeComponents) { activeComponent.updateServer(tickCount); } - - boolean canWork = true; - for (IGreenhouseComponent.Listener listenerComponent : listenerComponents) { - canWork = listenerComponent.getGreenhouseListener().canWork(this, canWork); - } - - if (canWork) { - for (IGreenhouseComponent.Climatiser climatiser : climatiserComponents) { - climatiser.changeClimate(tickCount, this); - } - } - - return canWork; + return false; } @Override @@ -742,5 +743,15 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im public IClimateRegion getRegion() { return region; } + + @Override + public void clearRegion() { + region = null; + } + + @Override + public Set getListenerComponents() { + return listenerComponents; + } } diff --git a/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java b/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java index 6a3b7bad9..4fcc69903 100644 --- a/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java +++ b/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java @@ -15,6 +15,7 @@ import javax.annotation.Nullable; import java.util.Set; import forestry.api.greenhouse.IInternalBlock; +import forestry.api.multiblock.IGreenhouseComponent; import forestry.api.multiblock.IGreenhouseController; import forestry.core.access.IRestrictedAccess; import forestry.core.fluids.ITankManager; @@ -48,4 +49,11 @@ public interface IGreenhouseControllerInternal extends IGreenhouseController, IM * @return All internal blocks of the greenhouse. */ Set getInternalBlocks(); + + /** + * Set the region to null. + */ + void clearRegion(); + + Set getListenerComponents(); } diff --git a/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouseClient.java b/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouseClient.java index 8bc9651ed..5dca13426 100644 --- a/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouseClient.java +++ b/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouseClient.java @@ -15,13 +15,14 @@ import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraftforge.client.model.animation.AnimationTESR; import net.minecraftforge.fml.client.registry.ClientRegistry; - +import forestry.api.core.ForestryAPI; import forestry.core.models.BlockModelIndex; import forestry.core.proxy.Proxies; import forestry.greenhouse.PluginGreenhouse; import forestry.greenhouse.blocks.BlockGreenhouseType; import forestry.greenhouse.models.ModelGreenhouse; import forestry.greenhouse.tiles.TileGreenhouseSprinkler; +import forestry.plugins.ForestryPluginUids; public class ProxyGreenhouseClient extends ProxyGreenhouse { @@ -33,6 +34,10 @@ public class ProxyGreenhouseClient extends ProxyGreenhouse { } else if (greenhouseType == BlockGreenhouseType.SPRINKLER) { ClientRegistry.bindTileEntitySpecialRenderer(TileGreenhouseSprinkler.class, new AnimationTESR<>()); continue; + }else if(greenhouseType == BlockGreenhouseType.BUTTERFLY_HATCH){ + if(!ForestryAPI.enabledPlugins.contains(ForestryPluginUids.LEPIDOPTEROLOGY)){ + continue; + } } Proxies.render.registerBlockModel(new BlockModelIndex(new ModelResourceLocation("forestry:greenhouse." + greenhouseType), new ModelResourceLocation("forestry:greenhouse", "inventory"), new ModelGreenhouse(), diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseClimatiser.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseClimatiser.java index 566e09673..585e6925b 100644 --- a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseClimatiser.java +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseClimatiser.java @@ -18,7 +18,6 @@ import net.minecraft.util.math.BlockPos; import forestry.api.core.climate.IClimatePosition; import forestry.api.core.climate.IClimateRegion; import forestry.api.multiblock.IGreenhouseComponent; -import forestry.api.multiblock.IGreenhouseController; import forestry.api.multiblock.IMultiblockController; import forestry.apiculture.network.packets.PacketActiveUpdate; import forestry.core.proxy.Proxies; @@ -81,12 +80,18 @@ public class TileGreenhouseClimatiser extends TileGreenhouse implements IActivat } @Override - public void changeClimate(int tick, IGreenhouseController greenhouse) { - if(minPos != null && maxPos != null){ - IGreenhouseControllerInternal greenhouseInternal = (IGreenhouseControllerInternal) greenhouse; - if (workingTime == 0 && greenhouseInternal.getEnergyManager().consumeEnergyToDoWork(WORK_CYCLES, ENERGY_PER_OPERATION)) { + public void changeClimate(int tick, IClimateRegion region) { + IMultiblockController controller = getMultiblockLogic().getController(); + if(getMultiblockLogic().isConnected() && controller != null && controller.isAssembled() && minPos != null && maxPos != null && region != null){ + IGreenhouseControllerInternal greenhouseInternal = (IGreenhouseControllerInternal) controller; + boolean canWork = true; + for (IGreenhouseComponent.Listener listenerComponent : greenhouseInternal.getListenerComponents()) { + if(canWork){ + canWork = listenerComponent.getGreenhouseListener().canWork(greenhouseInternal, canWork); + } + } + if (canWork && workingTime == 0 && greenhouseInternal.getEnergyManager().consumeEnergyToDoWork(WORK_CYCLES, ENERGY_PER_OPERATION)) { int dimensionID = worldObj.provider.getDimension(); - IClimateRegion region = greenhouse.getRegion(); for(BlockPos pos : BlockPos.getAllInBox(maxPos, minPos)){ IClimatePosition position = region.getPositions().get(pos); diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseSprinkler.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseSprinkler.java index a673af106..993100a1a 100644 --- a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseSprinkler.java +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseSprinkler.java @@ -22,7 +22,8 @@ import net.minecraftforge.common.model.animation.CapabilityAnimation; import net.minecraftforge.common.model.animation.IAnimationStateMachine; import forestry.api.core.climate.IClimatePosition; import forestry.api.core.climate.IClimateRegion; -import forestry.api.multiblock.IGreenhouseController; +import forestry.api.multiblock.IGreenhouseComponent; +import forestry.api.multiblock.IMultiblockController; import forestry.core.config.Constants; import forestry.core.fluids.tanks.StandardTank; import forestry.core.proxy.Proxies; @@ -51,12 +52,18 @@ public class TileGreenhouseSprinkler extends TileGreenhouseClimatiser { } @Override - public void changeClimate(int tick, IGreenhouseController greenhouse) { - if(minPos != null && maxPos != null){ - IGreenhouseControllerInternal greenhouseInternal = (IGreenhouseControllerInternal) greenhouse; - if (workingTime == 0 && consumeWaterToDoWork(WORK_CYCLES, WATER_PER_OPERATION, (StandardTank) greenhouseInternal.getTankManager().getTank(0))) { + public void changeClimate(int tick, IClimateRegion region) { + IMultiblockController controller = getMultiblockLogic().getController(); + if(getMultiblockLogic().isConnected() && controller != null && controller.isAssembled() && minPos != null && maxPos != null && region != null){ + IGreenhouseControllerInternal greenhouseInternal = (IGreenhouseControllerInternal) controller; + boolean canWork = true; + for (IGreenhouseComponent.Listener listenerComponent : greenhouseInternal.getListenerComponents()) { + if(canWork){ + canWork = listenerComponent.getGreenhouseListener().canWork(greenhouseInternal, canWork); + } + } + if (canWork && workingTime == 0 && consumeWaterToDoWork(WORK_CYCLES, WATER_PER_OPERATION, (StandardTank) greenhouseInternal.getTankManager().getTank(0))) { int dimensionID = worldObj.provider.getDimension(); - IClimateRegion region = greenhouse.getRegion(); for(BlockPos pos : BlockPos.getAllInBox(maxPos, minPos)){ IClimatePosition position = region.getPositions().get(pos);