diff --git a/src/main/java/forestry/api/core/ICamouflageHandler.java b/src/main/java/forestry/api/core/ICamouflageHandler.java index 925b960e9..18ff0fe5c 100644 --- a/src/main/java/forestry/api/core/ICamouflageHandler.java +++ b/src/main/java/forestry/api/core/ICamouflageHandler.java @@ -10,14 +10,29 @@ import net.minecraft.world.World; public interface ICamouflageHandler{ + /** + * @return The item of the block that is the camouflage of this handler for the EnumCamouflageType. + */ ItemStack getCamouflageBlock(EnumCamouflageType type); + /** + * @return The default camouflage block item for the EnumCamouflageType. + */ ItemStack getDefaultCamouflageBlock(EnumCamouflageType type); + /** + * Set the camouflage block item for the EnumCamouflageType. + */ void setCamouflageBlock(EnumCamouflageType type, ItemStack camouflageBlock); + /** + * @return The coordinates of the handler as a BlockPos. + */ BlockPos getCoordinates(); + /** + * @return The world of the handler. + */ World getWorld(); } diff --git a/src/main/java/forestry/api/greenhouse/IGreenhouseHousing.java b/src/main/java/forestry/api/greenhouse/IGreenhouseHousing.java index 6b259da31..a31546912 100644 --- a/src/main/java/forestry/api/greenhouse/IGreenhouseHousing.java +++ b/src/main/java/forestry/api/greenhouse/IGreenhouseHousing.java @@ -21,7 +21,7 @@ public interface IGreenhouseHousing extends IErrorLogicSource { float getExactHumidity(); /** - * @return The world in that the housing is + * @return The world in that the housing is. */ World getWorld(); diff --git a/src/main/java/forestry/api/multiblock/IGreenhouseController.java b/src/main/java/forestry/api/multiblock/IGreenhouseController.java index 988ee4c39..101fcce5b 100644 --- a/src/main/java/forestry/api/multiblock/IGreenhouseController.java +++ b/src/main/java/forestry/api/multiblock/IGreenhouseController.java @@ -16,12 +16,12 @@ import forestry.api.greenhouse.IGreenhouseLogic; public interface IGreenhouseController extends IMultiblockController, IGreenhouseHousing, ICamouflageHandler, IClimateControlled { /** - * Handle change events + * Handle change events. */ void onChange(EnumGreenhouseEventType type, Object event); /** - * @return The logics of the greenhouse + * @return The logics of the greenhouse. */ List getLogics(); diff --git a/src/main/java/forestry/greenhouse/FakeGreenhouseState.java b/src/main/java/forestry/greenhouse/FakeGreenhouseState.java new file mode 100644 index 000000000..6f87154dd --- /dev/null +++ b/src/main/java/forestry/greenhouse/FakeGreenhouseState.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * 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.List; + +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 net.minecraft.world.World; + +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 List getInternalBlocks() { + return Collections.emptyList(); + } + + @Override + public Collection getGreenhouseComponents() { + return Collections.emptyList(); + } + + @Override + public World getWorld() { + return null; + } + +} diff --git a/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java b/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java index 1f9d8d465..0dbac8095 100644 --- a/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java +++ b/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java @@ -24,6 +24,7 @@ import forestry.core.inventory.FakeInventoryAdapter; import forestry.core.inventory.IInventoryAdapter; import forestry.core.multiblock.FakeMultiblockController; import forestry.energy.EnergyManager; +import forestry.greenhouse.FakeGreenhouseState; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockPos; @@ -87,12 +88,11 @@ public class FakeGreenhouseController extends FakeMultiblockController implement @Override public IGreenhouseState createState() { - return null; + return FakeGreenhouseState.instance; } - + @Override public List getInternalBlocks() { return Collections.emptyList(); } - } diff --git a/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java b/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java index 684b8e4b1..396388db5 100644 --- a/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java +++ b/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java @@ -360,17 +360,22 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im private void createLogics() { logics.clear(); for(Class logicClass : GreenhouseManager.greenhouseLogics){ - try{ - logics.add(createLogic(logicClass)); - }catch(Exception e){ - Log.error("Fail to create a greenhouse logic with the class: " + logicClass); - e.printStackTrace(); + IGreenhouseLogic logic = createLogic(logicClass); + if(logic != null){ + logics.add(logic); } } } - private IGreenhouseLogic createLogic(Class logicClass) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException{ - return logicClass.getConstructor(IGreenhouseController.class).newInstance(this); + private IGreenhouseLogic createLogic(Class logicClass) { + try { + return logicClass.getConstructor(IGreenhouseController.class).newInstance(this); + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException + | NoSuchMethodException | SecurityException e) { + e.printStackTrace(); + Log.error("Fail to create a greenhouse logic with the class: " + logicClass); + return null; + } } @Override @@ -547,7 +552,6 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im boolean isNextRoof = false; Class myClass = this.getClass(); - List internalBlocks = Lists.newArrayList(); height: for (int y = minimumCoord.getY(); y <= maximumCoord.getY(); y++) { for (int x = minimumCoord.getX(); x <= maximumCoord.getX(); x++) { for (int z = minimumCoord.getZ(); z <= maximumCoord.getZ(); z++) { @@ -624,37 +628,32 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im } } } - if(isNextRoof){ - CreateInternalBlockEvent event = new CreateInternalBlockEvent(createState(), new InternalBlock(worldObj, getMinimumCoord().add(1, 1, 1))); - - MinecraftForge.EVENT_BUS.post(event); - - checkInternalBlock(event.internalBlock, internalBlocks); - }else if(internalBlocks.isEmpty()){ + internalBlocks.clear(); + + if(isNextRoof){ + checkInternalBlock(createInternalBlock(new InternalBlock(worldObj, getMinimumCoord().add(1, 1, 1)))); + } + if(internalBlocks.isEmpty()){ throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.space.closed")); } this.internalBlocks.addAll(internalBlocks); + + int hatches = 0; + for(IMultiblockComponent comp : connectedParts){ + if(comp instanceof IGreenhouseComponent.ButterflyHatch){ + hatches++; + } + } + if(hatches > 1){ + throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.butterflyhatch.tomany")); + } } @Override protected void updateClient(int tickCount) { } - - @Override - protected void isGoodForExteriorLevel(IMultiblockComponent part, int level) throws MultiblockValidationException { - - } - - @Override - protected void isGoodForInterior(IMultiblockComponent part) throws MultiblockValidationException { - - } - @Override - protected void isBlockGoodForInterior(World world, BlockPos pos) throws MultiblockValidationException { - } - - private void checkInternalBlock(IInternalBlock blockToCheck, List internalBlocks) throws MultiblockValidationException{ + private void checkInternalBlock(IInternalBlock blockToCheck) throws MultiblockValidationException{ internalBlocks.add(blockToCheck); BlockPos posRoot = blockToCheck.getPos(); @@ -684,22 +683,28 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im faceToCheck.setTested(true); } }else{ - CreateInternalBlockEvent createEvent = new CreateInternalBlockEvent(createState(), new InternalBlock(worldObj, posFacing, face.getOpposite(), blockToCheck)); - MinecraftForge.EVENT_BUS.post(createEvent); - - IInternalBlock internalBlock = createEvent.internalBlock; + IInternalBlock internalBlock = createInternalBlock(new InternalBlock(worldObj, posFacing, face.getOpposite(), blockToCheck)); // Check is the internal block in the list if(internalBlocks.contains(internalBlock)){ faceToCheck.setTested(true); }else{ - checkInternalBlock(internalBlock, internalBlocks); + checkInternalBlock(internalBlock); } } } } } + private IInternalBlock createInternalBlock(IInternalBlock internalBlock){ + CreateInternalBlockEvent createEvent = new CreateInternalBlockEvent(createState(), internalBlock); + + MinecraftForge.EVENT_BUS.post(createEvent); + + return createEvent.internalBlock; + + } + @Override public List getInternalBlocks() { return internalBlocks; @@ -717,5 +722,19 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im } return null; } + + @Override + protected void isGoodForExteriorLevel(IMultiblockComponent part, int level) throws MultiblockValidationException { + + } + + @Override + protected void isGoodForInterior(IMultiblockComponent part) throws MultiblockValidationException { + + } + + @Override + protected void isBlockGoodForInterior(World world, BlockPos pos) throws MultiblockValidationException { + } } diff --git a/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java b/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java index 58f3628e7..18225b310 100644 --- a/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java +++ b/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java @@ -27,19 +27,34 @@ import forestry.energy.EnergyManager; public interface IGreenhouseControllerInternal extends IGreenhouseController, IMultiblockControllerInternal, IRestrictedAccess, IStreamableGui { + /** + * @return The inventory of the controller. + */ @Nonnull IInventoryAdapter getInternalInventory(); + /** + * @return The tank manager of the controller. + */ @Nonnull ITankManager getTankManager(); + + /** + * @return The energy manager of the controller. + */ @Nullable EnergyManager getEnergyManager(); - @Nullable + + /** + * @return The current state of the greenhouse controller. + */ + @Nonnull IGreenhouseState createState(); - @Nonnull + /** + * @return A list with all internal block's of the greenhouse. + */ List getInternalBlocks(); - }