diff --git a/src/main/java/forestry/api/greenhouse/GreenhouseEvents.java b/src/main/java/forestry/api/greenhouse/GreenhouseEvents.java index 61d33d274..07e8339bd 100644 --- a/src/main/java/forestry/api/greenhouse/GreenhouseEvents.java +++ b/src/main/java/forestry/api/greenhouse/GreenhouseEvents.java @@ -18,14 +18,15 @@ import net.minecraftforge.fml.common.eventhandler.Event; import forestry.api.core.EnumCamouflageType; import forestry.api.core.ICamouflageHandler; import forestry.api.core.ICamouflagedTile; +import forestry.api.multiblock.IGreenhouseController; public class GreenhouseEvents extends Event { @Nullable - public final IGreenhouseState state; + public final IGreenhouseController controller; - public GreenhouseEvents(@Nullable IGreenhouseState state) { - this.state = state; + public GreenhouseEvents(@Nullable IGreenhouseController state) { + this.controller = state; } public static class CamouflageChangeEvent extends GreenhouseEvents{ @@ -37,8 +38,8 @@ public class GreenhouseEvents extends Event { @Nonnull public final EnumCamouflageType camouflageType; - public CamouflageChangeEvent(IGreenhouseState state, @Nullable ICamouflagedTile camouflagedBlock, @Nonnull ICamouflageHandler camouflageHandler, @Nonnull EnumCamouflageType camouflageType) { - super(state); + public CamouflageChangeEvent(IGreenhouseController controller, @Nullable ICamouflagedTile camouflagedBlock, @Nonnull ICamouflageHandler camouflageHandler, @Nonnull EnumCamouflageType camouflageType) { + super(controller); this.camouflagedBlock = camouflagedBlock; this.camouflageHandler = camouflageHandler; @@ -51,8 +52,8 @@ public class GreenhouseEvents extends Event { @Nonnull public IInternalBlock internalBlock; - public InternalBlockEvent(IGreenhouseState state, @Nonnull IInternalBlock internalBlock) { - super(state); + public InternalBlockEvent(IGreenhouseController controller, @Nonnull IInternalBlock internalBlock) { + super(controller); this.internalBlock = internalBlock; } @@ -60,8 +61,8 @@ public class GreenhouseEvents extends Event { public static class CreateInternalBlockEvent extends InternalBlockEvent{ - public CreateInternalBlockEvent(IGreenhouseState state, IInternalBlock internalBlock) { - super(state, internalBlock); + public CreateInternalBlockEvent(IGreenhouseController controller, IInternalBlock internalBlock) { + super(controller, internalBlock); } } @@ -70,8 +71,8 @@ public class GreenhouseEvents extends Event { @Nonnull public final IInternalBlockFace face; - public CheckInternalBlockFaceEvent(IGreenhouseState state, IInternalBlock internalBlock, @Nonnull IInternalBlockFace face) { - super(state, internalBlock); + public CheckInternalBlockFaceEvent(IGreenhouseController controller, IInternalBlock internalBlock, @Nonnull IInternalBlockFace face) { + super(controller, internalBlock); this.face = face; } diff --git a/src/main/java/forestry/api/greenhouse/IGreenhouseHelper.java b/src/main/java/forestry/api/greenhouse/IGreenhouseHelper.java index ed55ac0ff..b1fd26ae1 100644 --- a/src/main/java/forestry/api/greenhouse/IGreenhouseHelper.java +++ b/src/main/java/forestry/api/greenhouse/IGreenhouseHelper.java @@ -5,14 +5,15 @@ ******************************************************************************/ package forestry.api.greenhouse; +import forestry.api.multiblock.IGreenhouseController; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public interface IGreenhouseHelper { /** - * @return A {@link IGreenhouseState} of a greenhouse, when the pos is a greenhouse + * @return A {@link IGreenhouseController} of a greenhouse, when the pos is a greenhouse */ - IGreenhouseState getGreenhouseState(World world, BlockPos pos); + IGreenhouseController getGreenhouseController(World world, BlockPos pos); } diff --git a/src/main/java/forestry/api/greenhouse/IGreenhouseState.java b/src/main/java/forestry/api/greenhouse/IGreenhouseState.java deleted file mode 100644 index 773d0b798..000000000 --- a/src/main/java/forestry/api/greenhouse/IGreenhouseState.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright 2011-2014 SirSengir - * - * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. - ******************************************************************************/ -package forestry.api.greenhouse; - -import java.util.Collection; -import java.util.Set; - -import javax.annotation.Nonnull; -import forestry.api.core.EnumHumidity; -import forestry.api.core.EnumTemperature; -import forestry.api.multiblock.IMultiblockComponent; - -public interface IGreenhouseState { - - @Nonnull - EnumTemperature getTemperature(); - - @Nonnull - EnumHumidity getHumidity(); - - float getExactTemperature(); - - float getExactHumidity(); - - Set getInternalBlocks(); - - Collection getGreenhouseComponents(); - -} diff --git a/src/main/java/forestry/api/multiblock/IGreenhouseController.java b/src/main/java/forestry/api/multiblock/IGreenhouseController.java index c89c3a56c..4c2ca6f0d 100644 --- a/src/main/java/forestry/api/multiblock/IGreenhouseController.java +++ b/src/main/java/forestry/api/multiblock/IGreenhouseController.java @@ -11,8 +11,9 @@ import forestry.api.core.ICamouflageHandler; import forestry.api.greenhouse.EnumGreenhouseEventType; import forestry.api.greenhouse.IGreenhouseHousing; import forestry.api.greenhouse.IGreenhouseLogic; +import forestry.core.climate.IClimateHandler; -public interface IGreenhouseController extends IMultiblockController, IGreenhouseHousing, ICamouflageHandler { +public interface IGreenhouseController extends IMultiblockController, IGreenhouseHousing, ICamouflageHandler, IClimateHandler { /** * Handle change events. diff --git a/src/main/java/forestry/apiculture/worldgen/VillageApiaristHouse.java b/src/main/java/forestry/apiculture/worldgen/VillageApiaristHouse.java index dc5985af3..c5639ff85 100644 --- a/src/main/java/forestry/apiculture/worldgen/VillageApiaristHouse.java +++ b/src/main/java/forestry/apiculture/worldgen/VillageApiaristHouse.java @@ -17,7 +17,6 @@ import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.BlockDoor; -import net.minecraft.block.BlockFenceGate; import net.minecraft.block.BlockHorizontal; import net.minecraft.block.BlockLog; import net.minecraft.block.BlockSlab; @@ -58,10 +57,8 @@ import forestry.apiculture.flowers.Flower; import forestry.apiculture.flowers.FlowerRegistry; import forestry.apiculture.tiles.TileBeeHouse; import forestry.arboriculture.PluginArboriculture; -import forestry.arboriculture.blocks.log.BlockArbLog; import forestry.core.PluginCore; import forestry.core.blocks.BlockBase; -import forestry.core.blocks.BlockCore; import forestry.core.config.Constants; import forestry.core.tiles.TileUtil; import forestry.plugins.ForestryPluginUids; diff --git a/src/main/java/forestry/core/climate/ClimateEventHandler.java b/src/main/java/forestry/core/climate/ClimateEventHandler.java index 40c49bea2..58982659d 100644 --- a/src/main/java/forestry/core/climate/ClimateEventHandler.java +++ b/src/main/java/forestry/core/climate/ClimateEventHandler.java @@ -22,7 +22,7 @@ public class ClimateEventHandler { int dimensionID = event.getWorld().provider.getDimension(); World world = event.getWorld(); Chunk chunk = event.getChunk(); - IClimateWorld climateWorld = ForestryAPI.climateManager.getClimateWorlds().get(Integer.valueOf(dimensionID)); + IClimateWorld climateWorld = ClimateManager.getOrCreateWorld(world); if(climateWorld != null){ ClimateChunk climateChunk = climateWorld.getClimateChunks().get(new ChunkPos(event.getChunk().xPosition, event.getChunk().zPosition)); @@ -55,12 +55,7 @@ public class ClimateEventHandler { World world = event.getWorld(); Chunk chunk = event.getChunk(); - IClimateWorld climateWorld = ForestryAPI.climateManager.getClimateWorlds().get(Integer.valueOf(dimensionID)); - - if(climateWorld == null){ - climateWorld = new ClimateWorld(); - ForestryAPI.climateManager.getClimateWorlds().put(Integer.valueOf(dimensionID), climateWorld); - } + IClimateWorld climateWorld = ClimateManager.getOrCreateWorld(world); ChunkPos chunkPos = new ChunkPos(event.getChunk().xPosition, event.getChunk().zPosition); NBTTagCompound chunkTag = event.getData(); diff --git a/src/main/java/forestry/core/climate/ClimateManager.java b/src/main/java/forestry/core/climate/ClimateManager.java index 4e0955de7..bb5f22dfd 100644 --- a/src/main/java/forestry/core/climate/ClimateManager.java +++ b/src/main/java/forestry/core/climate/ClimateManager.java @@ -21,7 +21,7 @@ import forestry.api.core.ForestryAPI; import forestry.api.core.climate.IClimateManager; import forestry.api.core.climate.IClimateWorld; import forestry.api.greenhouse.GreenhouseManager; -import forestry.api.greenhouse.IGreenhouseState; +import forestry.api.multiblock.IGreenhouseController; import forestry.plugins.ForestryPluginUids; public class ClimateManager implements IClimateManager{ @@ -34,27 +34,25 @@ public class ClimateManager implements IClimateManager{ @Override public float getTemperature(World world, BlockPos pos) { - if(ForestryAPI.enabledPlugins.contains(ForestryPluginUids.GREENHOUSE)){ - IGreenhouseState state = GreenhouseManager.greenhouseHelper.getGreenhouseState(world, pos); - - if(state != null){ - return state.getExactTemperature(); - } - } + IClimateWorld climateWorld = getOrCreateWorld(world); Biome biome = world.getBiome(pos); + + if(climateWorld.getPosition(pos) != null){ + return climateWorld.getPosition(pos).getTemperature(); + } + return biome.getTemperature(); } @Override public float getHumidity(World world, BlockPos pos) { - if(ForestryAPI.enabledPlugins.contains(ForestryPluginUids.GREENHOUSE)){ - IGreenhouseState state = GreenhouseManager.greenhouseHelper.getGreenhouseState(world, pos); - - if(state != null){ - return state.getExactHumidity(); - } - } + IClimateWorld climateWorld = getOrCreateWorld(world); Biome biome = world.getBiome(pos); + + if(climateWorld.getPosition(pos) != null){ + return climateWorld.getPosition(pos).getHumidity(); + } + return biome.getRainfall(); } @@ -65,6 +63,17 @@ public class ClimateManager implements IClimateManager{ } } + public static IClimateWorld getOrCreateWorld(World world){ + IClimateWorld climateWorld = ForestryAPI.climateManager.getClimateWorlds().get(Integer.valueOf(world.provider.getDimension())); + + if(climateWorld == null){ + climateWorld = new ClimateWorld(); + ForestryAPI.climateManager.registerWorld(climateWorld); + } + return climateWorld; + } + + @Override public Map getClimateWorlds() { return climateWorlds; diff --git a/src/main/java/forestry/core/climate/ClimateWorld.java b/src/main/java/forestry/core/climate/ClimateWorld.java index f689e15c8..02db07998 100644 --- a/src/main/java/forestry/core/climate/ClimateWorld.java +++ b/src/main/java/forestry/core/climate/ClimateWorld.java @@ -73,7 +73,7 @@ public class ClimateWorld implements IClimateWorld{ } @Override - public void setChunk(ClimateChunk climateChunk) { + public void addChunk(ClimateChunk climateChunk) { if(climateChunk == null){ return; } diff --git a/src/main/java/forestry/core/climate/ClimatedPosition.java b/src/main/java/forestry/core/climate/ClimatedPosition.java index 19c513b9a..f06a0ce09 100644 --- a/src/main/java/forestry/core/climate/ClimatedPosition.java +++ b/src/main/java/forestry/core/climate/ClimatedPosition.java @@ -15,8 +15,12 @@ import java.util.List; import javax.annotation.Nonnull; +import forestry.api.core.ForestryAPI; import forestry.api.core.climate.IClimateWorld; import forestry.api.core.climate.IClimatedPosition; +import forestry.api.greenhouse.GreenhouseManager; +import forestry.api.greenhouse.IGreenhouseState; +import forestry.api.multiblock.IGreenhouseController; import forestry.api.multiblock.IMultiblockComponent; import forestry.api.multiblock.IMultiblockLogic; import net.minecraft.nbt.NBTTagCompound; @@ -161,6 +165,10 @@ public class ClimatedPosition implements IClimatedPosition { handlers.add((IClimateHandler) logic.getController()); } } + IGreenhouseController greenhouse = GreenhouseManager.greenhouseHelper.getGreenhouseController(climateWorld.getWorld(), pos); + if(greenhouse != null){ + handlers.add(greenhouse); + } } return handlers; } diff --git a/src/main/java/forestry/core/climate/IClimateHandler.java b/src/main/java/forestry/core/climate/IClimateHandler.java index 05a3722fb..43214c060 100644 --- a/src/main/java/forestry/core/climate/IClimateHandler.java +++ b/src/main/java/forestry/core/climate/IClimateHandler.java @@ -10,6 +10,8 @@ public interface IClimateHandler { IClimateWorld getWorld(); + boolean canHandle(IClimatedPosition position); + boolean canHoldClimate(IClimatedPosition position); } diff --git a/src/main/java/forestry/greenhouse/FakeGreenhouseState.java b/src/main/java/forestry/greenhouse/FakeGreenhouseState.java deleted file mode 100644 index 83a962d06..000000000 --- a/src/main/java/forestry/greenhouse/FakeGreenhouseState.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.greenhouse; - -import java.util.Collection; -import java.util.Collections; -import java.util.Set; - -import forestry.api.core.EnumHumidity; -import forestry.api.core.EnumTemperature; -import forestry.api.greenhouse.IGreenhouseState; -import forestry.api.greenhouse.IInternalBlock; -import forestry.api.multiblock.IMultiblockComponent; - -public class FakeGreenhouseState implements IGreenhouseState { - - public static final FakeGreenhouseState instance = new FakeGreenhouseState(); - - @Override - public EnumTemperature getTemperature() { - return null; - } - - @Override - public EnumHumidity getHumidity() { - return null; - } - - @Override - public float getExactTemperature() { - return 0; - } - - @Override - public float getExactHumidity() { - return 0; - } - - @Override - public Set getInternalBlocks() { - return Collections.emptySet(); - } - - @Override - public Collection getGreenhouseComponents() { - return Collections.emptyList(); - } - -} diff --git a/src/main/java/forestry/greenhouse/GreenhouseHelper.java b/src/main/java/forestry/greenhouse/GreenhouseHelper.java index 21c96c6b6..209ffed6d 100644 --- a/src/main/java/forestry/greenhouse/GreenhouseHelper.java +++ b/src/main/java/forestry/greenhouse/GreenhouseHelper.java @@ -14,8 +14,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import forestry.api.greenhouse.IGreenhouseHelper; -import forestry.api.greenhouse.IGreenhouseState; import forestry.api.greenhouse.IInternalBlock; +import forestry.api.multiblock.IGreenhouseController; import forestry.core.multiblock.IMultiblockControllerInternal; import forestry.core.multiblock.MultiblockRegistry; import forestry.greenhouse.multiblock.IGreenhouseControllerInternal; @@ -24,13 +24,13 @@ import forestry.greenhouse.multiblock.InternalBlockCheck; public class GreenhouseHelper implements IGreenhouseHelper { @Override - public IGreenhouseState getGreenhouseState(World world, BlockPos pos) { + public IGreenhouseController getGreenhouseController(World world, BlockPos pos) { if (MultiblockRegistry.getControllersFromWorld(world) != null) { for (IMultiblockControllerInternal controllerInternal : MultiblockRegistry.getControllersFromWorld(world)) { if (controllerInternal instanceof IGreenhouseControllerInternal) { if (controllerInternal.isAssembled()) { if (isPositionInGreenhouse((IGreenhouseControllerInternal) controllerInternal, pos)) { - return ((IGreenhouseControllerInternal) controllerInternal).createState(); + return (IGreenhouseController) controllerInternal; } } } diff --git a/src/main/java/forestry/greenhouse/GreenhouseState.java b/src/main/java/forestry/greenhouse/GreenhouseState.java deleted file mode 100644 index 9b481a77d..000000000 --- a/src/main/java/forestry/greenhouse/GreenhouseState.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.greenhouse; - -import java.util.Collection; -import java.util.Set; - -import forestry.api.core.EnumHumidity; -import forestry.api.core.EnumTemperature; -import forestry.api.greenhouse.IGreenhouseState; -import forestry.api.greenhouse.IInternalBlock; -import forestry.api.multiblock.IMultiblockComponent; -import forestry.greenhouse.multiblock.GreenhouseController; - -public final class GreenhouseState implements IGreenhouseState { - - private final float humidity; - private final float temperature; - private final Set internalBlocks; - private final Collection greenhouseComponents; - - public GreenhouseState(float humidity, float temperature, Set internalBlocks, Collection greenhouseComponents) { - this.humidity = humidity; - this.temperature = temperature; - this.internalBlocks = internalBlocks; - this.greenhouseComponents = greenhouseComponents; - } - - public GreenhouseState(GreenhouseController controller) { - this(controller.getExactHumidity(), controller.getExactTemperature(), controller.getInternalBlocks(), controller.getComponents()); - } - - @Override - public EnumTemperature getTemperature() { - return EnumTemperature.getFromValue(temperature); - } - - @Override - public EnumHumidity getHumidity() { - return EnumHumidity.getFromValue(humidity); - } - - @Override - public float getExactTemperature() { - return temperature; - } - - @Override - public float getExactHumidity() { - return humidity; - } - - @Override - public Set getInternalBlocks() { - return internalBlocks; - } - - @Override - public Collection getGreenhouseComponents() { - return greenhouseComponents; - } - -} diff --git a/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java b/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java index 29a2ba211..16a277009 100644 --- a/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java +++ b/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java @@ -19,9 +19,10 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import forestry.api.core.EnumCamouflageType; +import forestry.api.core.climate.IClimateWorld; +import forestry.api.core.climate.IClimatedPosition; import forestry.api.greenhouse.EnumGreenhouseEventType; import forestry.api.greenhouse.IGreenhouseLogic; -import forestry.api.greenhouse.IGreenhouseState; import forestry.api.greenhouse.IInternalBlock; import forestry.core.fluids.FakeTankManager; import forestry.core.fluids.ITankManager; @@ -29,7 +30,6 @@ import forestry.core.inventory.FakeInventoryAdapter; import forestry.core.inventory.IInventoryAdapter; import forestry.core.multiblock.FakeMultiblockController; import forestry.energy.EnergyManager; -import forestry.greenhouse.FakeGreenhouseState; public class FakeGreenhouseController extends FakeMultiblockController implements IGreenhouseControllerInternal { public static final FakeGreenhouseController instance = new FakeGreenhouseController(); @@ -82,12 +82,6 @@ public class FakeGreenhouseController extends FakeMultiblockController implement @Override public void onChange(EnumGreenhouseEventType type, Object event) { } - - @Nonnull - @Override - public IGreenhouseState createState() { - return FakeGreenhouseState.instance; - } @Override public Set getInternalBlocks() { @@ -98,4 +92,24 @@ public class FakeGreenhouseController extends FakeMultiblockController implement public String getUnlocalizedType() { return "for.multiblock.greenhouse.type"; } + + @Override + public BlockPos getPos() { + return null; + } + + @Override + public IClimateWorld getWorld() { + return null; + } + + @Override + public boolean canHandle(IClimatedPosition position) { + return false; + } + + @Override + public boolean canHoldClimate(IClimatedPosition position) { + return false; + } } diff --git a/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java b/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java index 942134dbf..a1d1a626f 100644 --- a/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java +++ b/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java @@ -43,7 +43,6 @@ import forestry.api.greenhouse.GreenhouseEvents.CheckInternalBlockFaceEvent; import forestry.api.greenhouse.GreenhouseEvents.CreateInternalBlockEvent; import forestry.api.greenhouse.GreenhouseManager; import forestry.api.greenhouse.IGreenhouseLogic; -import forestry.api.greenhouse.IGreenhouseState; import forestry.api.greenhouse.IInternalBlock; import forestry.api.greenhouse.IInternalBlockFace; import forestry.api.multiblock.IGreenhouseComponent; @@ -51,6 +50,7 @@ import forestry.api.multiblock.IGreenhouseComponent.ButterflyHatch; import forestry.api.multiblock.IGreenhouseController; import forestry.api.multiblock.IMultiblockComponent; import forestry.core.access.EnumAccess; +import forestry.core.climate.ClimateManager; import forestry.core.climate.ClimateWorld; import forestry.core.config.Constants; import forestry.core.fluids.TankManager; @@ -70,7 +70,6 @@ import forestry.core.utils.ItemStackUtil; import forestry.core.utils.Log; import forestry.core.utils.Translator; import forestry.energy.EnergyManager; -import forestry.greenhouse.GreenhouseState; import forestry.greenhouse.blocks.BlockGreenhouse; import forestry.greenhouse.blocks.BlockGreenhouseType; import forestry.greenhouse.inventory.InventoryGreenhouse; @@ -123,11 +122,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im @Override public float getExactTemperature() { int dimensionID = worldObj.provider.getDimension(); - IClimateWorld climateWorld = ForestryAPI.climateManager.getClimateWorlds().get(Integer.valueOf(dimensionID)); - if(climateWorld == null){ - climateWorld = new ClimateWorld(); - ForestryAPI.climateManager.getClimateWorlds().put(Integer.valueOf(dimensionID), climateWorld); - } + IClimateWorld climateWorld = ClimateManager.getOrCreateWorld(worldObj); float temperature = 0.0F; @@ -143,11 +138,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im @Override public float getExactHumidity() { int dimensionID = worldObj.provider.getDimension(); - IClimateWorld climateWorld = ForestryAPI.climateManager.getClimateWorlds().get(Integer.valueOf(dimensionID)); - if(climateWorld == null){ - climateWorld = new ClimateWorld(); - ForestryAPI.climateManager.getClimateWorlds().put(Integer.valueOf(dimensionID), climateWorld); - } + IClimateWorld climateWorld = ClimateManager.getOrCreateWorld(worldObj); float humidity = 0.0F; @@ -311,7 +302,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im } } - MinecraftForge.EVENT_BUS.post(new CamouflageChangeEvent(createState(), null, this, type)); + MinecraftForge.EVENT_BUS.post(new CamouflageChangeEvent(this, null, this, type)); } } @@ -344,12 +335,6 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im } /* GREENHOUSE */ - @Nonnull - @Override - public IGreenhouseState createState() { - return new GreenhouseState(this); - } - @Override public void onChange(EnumGreenhouseEventType type, Object event) { for (IGreenhouseLogic logic : logics) { @@ -412,11 +397,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im createLogics(); int dimensionID = worldObj.provider.getDimension(); - IClimateWorld climateWorld = ForestryAPI.climateManager.getClimateWorlds().get(Integer.valueOf(dimensionID)); - if(climateWorld == null){ - climateWorld = new ClimateWorld(); - ForestryAPI.climateManager.getClimateWorlds().put(Integer.valueOf(dimensionID), climateWorld); - } + IClimateWorld climateWorld = ClimateManager.getOrCreateWorld(worldObj); for(IInternalBlock internalBlock : internalBlocks){ if(climateWorld.getPosition(internalBlock.getPos()) != null){ @@ -661,7 +642,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im isBlockGoodForInterior(worldObj, posRoot); for (IInternalBlockFace faceToCheck : blockToCheck.getFaces()) { - CheckInternalBlockFaceEvent checkEvent = new CheckInternalBlockFaceEvent(createState(), blockToCheck, faceToCheck); + CheckInternalBlockFaceEvent checkEvent = new CheckInternalBlockFaceEvent(this, blockToCheck, faceToCheck); MinecraftForge.EVENT_BUS.post(checkEvent); if (!faceToCheck.isTested()) { @@ -699,7 +680,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im } private IInternalBlock createInternalBlock(IInternalBlock internalBlock) { - CreateInternalBlockEvent createEvent = new CreateInternalBlockEvent(createState(), internalBlock); + CreateInternalBlockEvent createEvent = new CreateInternalBlockEvent(this, internalBlock); MinecraftForge.EVENT_BUS.post(createEvent); @@ -713,11 +694,11 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im } public static ButterflyHatch getGreenhouseButterflyHatch(World world, BlockPos pos) { - if (GreenhouseManager.greenhouseHelper.getGreenhouseState(world, pos) == null) { + if (GreenhouseManager.greenhouseHelper.getGreenhouseController(world, pos) == null) { return null; } - IGreenhouseState state = GreenhouseManager.greenhouseHelper.getGreenhouseState(world, pos); - for (IMultiblockComponent greenhouse : state.getGreenhouseComponents()) { + IGreenhouseController controller = GreenhouseManager.greenhouseHelper.getGreenhouseController(world, pos); + for (IMultiblockComponent greenhouse : controller.getComponents()) { if (greenhouse instanceof ButterflyHatch) { return (ButterflyHatch) greenhouse; } diff --git a/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java b/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java index 65cb117b9..6a3b7bad9 100644 --- a/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java +++ b/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java @@ -14,7 +14,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.Set; -import forestry.api.greenhouse.IGreenhouseState; import forestry.api.greenhouse.IInternalBlock; import forestry.api.multiblock.IGreenhouseController; import forestry.core.access.IRestrictedAccess; @@ -45,13 +44,6 @@ public interface IGreenhouseControllerInternal extends IGreenhouseController, IM @Nullable EnergyManager getEnergyManager(); - - /** - * @return The current state of the greenhouse controller. - */ - @Nonnull - IGreenhouseState createState(); - /** * @return All internal blocks of the greenhouse. */ diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseClimatiser.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseClimatiser.java index 173958184..e2bef221b 100644 --- a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseClimatiser.java +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseClimatiser.java @@ -15,14 +15,13 @@ import javax.annotation.Nonnull; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; -import forestry.api.core.ForestryAPI; import forestry.api.core.climate.IClimateWorld; import forestry.api.core.climate.IClimatedPosition; import forestry.api.multiblock.IGreenhouseComponent; import forestry.api.multiblock.IGreenhouseController; import forestry.api.multiblock.IMultiblockController; import forestry.apiculture.network.packets.PacketActiveUpdate; -import forestry.core.climate.ClimateWorld; +import forestry.core.climate.ClimateManager; import forestry.core.proxy.Proxies; import forestry.core.tiles.IActivatable; import forestry.greenhouse.multiblock.IGreenhouseControllerInternal; @@ -96,11 +95,7 @@ public class TileGreenhouseClimatiser extends TileGreenhouse implements IActivat IGreenhouseControllerInternal greenhouseInternal = (IGreenhouseControllerInternal) greenhouse; if (workingTime == 0 && greenhouseInternal.getEnergyManager().consumeEnergyToDoWork(WORK_CYCLES, ENERGY_PER_OPERATION)) { int dimensionID = worldObj.provider.getDimension(); - IClimateWorld climateWorld = ForestryAPI.climateManager.getClimateWorlds().get(Integer.valueOf(dimensionID)); - if(climateWorld == null){ - climateWorld = new ClimateWorld(); - ForestryAPI.climateManager.getClimateWorlds().put(Integer.valueOf(dimensionID), climateWorld); - } + IClimateWorld climateWorld = ClimateManager.getOrCreateWorld(worldObj); for(BlockPos pos : BlockPos.getAllInBox(maxPos, minPos)){ IClimatedPosition position = climateWorld.getPosition(pos);