diff --git a/src/main/java/forestry/api/core/IModelBaker.java b/src/main/java/forestry/api/core/IModelBaker.java index 9ec693c72..86aaffe80 100644 --- a/src/main/java/forestry/api/core/IModelBaker.java +++ b/src/main/java/forestry/api/core/IModelBaker.java @@ -5,10 +5,13 @@ ******************************************************************************/ package forestry.api.core; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.model.IBakedModel; import net.minecraft.util.BlockPos; - import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -18,29 +21,31 @@ import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public interface IModelBaker { - void setRenderBoundsFromBlock(Block block); + void setRenderBoundsFromBlock(@Nonnull Block block); void setRenderBounds(double d, double e, double f, double g, double h, double i ); void setColorIndex(int color); - void addBlockModel(Block block, BlockPos pos, TextureAtlasSprite[] sprites, int colorIndex); + void addBlockModel(@Nonnull Block block, @Nullable BlockPos pos, @Nonnull TextureAtlasSprite[] sprites, int colorIndex); - void addBlockModel(Block block, BlockPos pos, TextureAtlasSprite sprites, int colorIndex); + void addBlockModel(@Nonnull Block block, @Nullable BlockPos pos, @Nonnull TextureAtlasSprite sprites, int colorIndex); - void addFaceXNeg(TextureAtlasSprite sprite); + void addBakedModel(@Nonnull IBakedModel model); - void addFaceYNeg(TextureAtlasSprite sprite); - - void addFaceZNeg(TextureAtlasSprite sprite); - - void addFaceYPos(TextureAtlasSprite sprite); - - void addFaceZPos(TextureAtlasSprite sprite); - - void addFaceXPos(TextureAtlasSprite sprite); + void addFaceXNeg(@Nonnull TextureAtlasSprite sprite); - void setParticleSprite(TextureAtlasSprite particleSprite); + void addFaceYNeg(@Nonnull TextureAtlasSprite sprite); + + void addFaceZNeg(@Nonnull TextureAtlasSprite sprite); + + void addFaceYPos(@Nonnull TextureAtlasSprite sprite); + + void addFaceZPos(@Nonnull TextureAtlasSprite sprite); + + void addFaceXPos(@Nonnull TextureAtlasSprite sprite); + + void setParticleSprite(@Nullable TextureAtlasSprite particleSprite); IModelBakerModel bakeModel(boolean flip); diff --git a/src/main/java/forestry/api/greenhouse/DefaultGreenhouseListener.java b/src/main/java/forestry/api/greenhouse/DefaultGreenhouseListener.java new file mode 100644 index 000000000..db33ce3ac --- /dev/null +++ b/src/main/java/forestry/api/greenhouse/DefaultGreenhouseListener.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.greenhouse; + +import forestry.api.multiblock.IGreenhouseController; + +public class DefaultGreenhouseListener implements IGreenhouseListener { + + @Override + public boolean canWork(G greenhouse) { + return true; + } + +} diff --git a/src/main/java/forestry/api/greenhouse/IGreenhouseHousing.java b/src/main/java/forestry/api/greenhouse/IGreenhouseHousing.java new file mode 100644 index 000000000..39828fb10 --- /dev/null +++ b/src/main/java/forestry/api/greenhouse/IGreenhouseHousing.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.greenhouse; + +import forestry.api.core.EnumHumidity; +import forestry.api.core.EnumTemperature; +import forestry.api.core.IErrorLogicSource; +import net.minecraft.world.World; + +public interface IGreenhouseHousing extends IErrorLogicSource { + + EnumTemperature getTemperature(); + + EnumHumidity getHumidity(); + + World getWorld(); + +} diff --git a/src/main/java/forestry/api/greenhouse/IGreenhouseListener.java b/src/main/java/forestry/api/greenhouse/IGreenhouseListener.java new file mode 100644 index 000000000..7a094e966 --- /dev/null +++ b/src/main/java/forestry/api/greenhouse/IGreenhouseListener.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.greenhouse; + +import forestry.api.multiblock.IGreenhouseController; + +public interface IGreenhouseListener { + + /** + * Called before the greenhouse work + * + * @param greenhouse The greenhouse multiblock + * @return Can the greenhouse work + */ + boolean canWork(G greenhouse); + +} diff --git a/src/main/java/forestry/api/multiblock/IGreenhouseComponent.java b/src/main/java/forestry/api/multiblock/IGreenhouseComponent.java new file mode 100644 index 000000000..9d7d6a7aa --- /dev/null +++ b/src/main/java/forestry/api/multiblock/IGreenhouseComponent.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.multiblock; + +import forestry.api.core.IClimateControlled; +import forestry.api.greenhouse.IGreenhouseHousing; +import forestry.api.greenhouse.IGreenhouseListener; + +public interface IGreenhouseComponent extends IMultiblockComponent { + @Override + T getMultiblockLogic(); + + interface Listener extends IGreenhouseComponent { + IGreenhouseListener getGreenhouseListener(); + } + + interface Climatiser extends IGreenhouseComponent { + void changeClimate(int tickCount, G greenhouse); + } + + interface Active extends IGreenhouseComponent { + void updateServer(int tickCount); + + void updateClient(int tickCount); + } + +} diff --git a/src/main/java/forestry/api/multiblock/IGreenhouseController.java b/src/main/java/forestry/api/multiblock/IGreenhouseController.java new file mode 100644 index 000000000..c5952aba9 --- /dev/null +++ b/src/main/java/forestry/api/multiblock/IGreenhouseController.java @@ -0,0 +1,12 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.multiblock; + +import forestry.api.greenhouse.IGreenhouseHousing; + +public interface IGreenhouseController extends IMultiblockController, IGreenhouseHousing { + +} diff --git a/src/main/java/forestry/api/multiblock/IMultiblockLogicGreenhouse.java b/src/main/java/forestry/api/multiblock/IMultiblockLogicGreenhouse.java new file mode 100644 index 000000000..518aab47e --- /dev/null +++ b/src/main/java/forestry/api/multiblock/IMultiblockLogicGreenhouse.java @@ -0,0 +1,14 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.multiblock; + +public interface IMultiblockLogicGreenhouse extends IMultiblockLogic { + /** + * @return the multiblock controller for this logic + */ + @Override + IGreenhouseController getController(); +} diff --git a/src/main/java/forestry/apiculture/multiblock/TileAlvearyPlain.java b/src/main/java/forestry/apiculture/multiblock/TileAlvearyPlain.java index 9c353bc40..5d014e930 100644 --- a/src/main/java/forestry/apiculture/multiblock/TileAlvearyPlain.java +++ b/src/main/java/forestry/apiculture/multiblock/TileAlvearyPlain.java @@ -14,13 +14,10 @@ import java.util.ArrayList; import java.util.Collection; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraftforge.fml.common.Optional; -import forestry.api.multiblock.IMultiblockController; -import forestry.apiculture.blocks.BlockAlveary; import forestry.apiculture.trigger.ApicultureTriggers; import buildcraft.api.statements.IStatementContainer; diff --git a/src/main/java/forestry/arboriculture/PluginArboriculture.java b/src/main/java/forestry/arboriculture/PluginArboriculture.java index a8ca5e21d..fbce52a24 100644 --- a/src/main/java/forestry/arboriculture/PluginArboriculture.java +++ b/src/main/java/forestry/arboriculture/PluginArboriculture.java @@ -57,9 +57,9 @@ import forestry.arboriculture.genetics.alleles.AlleleFruit; import forestry.arboriculture.genetics.alleles.AlleleGrowth; import forestry.arboriculture.genetics.alleles.AlleleLeafEffect; import forestry.arboriculture.items.ItemRegistryArboriculture; +import forestry.arboriculture.models.TextureLeaves; import forestry.arboriculture.network.PacketRegistryArboriculture; import forestry.arboriculture.proxy.ProxyArboriculture; -import forestry.arboriculture.render.TextureLeaves; import forestry.arboriculture.tiles.TileFruitPod; import forestry.arboriculture.tiles.TileLeaves; import forestry.arboriculture.tiles.TileSapling; diff --git a/src/main/java/forestry/arboriculture/blocks/BlockFruitPod.java b/src/main/java/forestry/arboriculture/blocks/BlockFruitPod.java index e84c0da34..fc264fdf6 100644 --- a/src/main/java/forestry/arboriculture/blocks/BlockFruitPod.java +++ b/src/main/java/forestry/arboriculture/blocks/BlockFruitPod.java @@ -34,7 +34,7 @@ import net.minecraftforge.fml.relauncher.SideOnly; import forestry.api.arboriculture.IAlleleFruit; import forestry.api.core.IStateMapperRegister; import forestry.arboriculture.genetics.alleles.AlleleFruit; -import forestry.arboriculture.render.FruitPodStateMapper; +import forestry.arboriculture.models.FruitPodStateMapper; import forestry.arboriculture.tiles.TileFruitPod; import forestry.core.proxy.Proxies; import forestry.core.tiles.TileUtil; diff --git a/src/main/java/forestry/arboriculture/blocks/BlockSapling.java b/src/main/java/forestry/arboriculture/blocks/BlockSapling.java index 53a25ca44..6da644611 100644 --- a/src/main/java/forestry/arboriculture/blocks/BlockSapling.java +++ b/src/main/java/forestry/arboriculture/blocks/BlockSapling.java @@ -39,7 +39,7 @@ import forestry.api.core.IItemModelRegister; import forestry.api.core.IModelManager; import forestry.api.core.IStateMapperRegister; import forestry.arboriculture.blocks.property.PropertyTree; -import forestry.arboriculture.render.SaplingStateMapper; +import forestry.arboriculture.models.SaplingStateMapper; import forestry.arboriculture.tiles.TileSapling; import forestry.core.proxy.Proxies; import forestry.core.tiles.TileUtil; diff --git a/src/main/java/forestry/arboriculture/genetics/TreeDefinition.java b/src/main/java/forestry/arboriculture/genetics/TreeDefinition.java index 62f0d5101..4d7dea66f 100644 --- a/src/main/java/forestry/arboriculture/genetics/TreeDefinition.java +++ b/src/main/java/forestry/arboriculture/genetics/TreeDefinition.java @@ -45,8 +45,8 @@ import forestry.api.world.ITreeGenData; import forestry.arboriculture.PluginArboriculture; import forestry.arboriculture.genetics.alleles.AlleleFruit; import forestry.arboriculture.genetics.alleles.AlleleGrowth; -import forestry.arboriculture.render.ModelProviderGermling; -import forestry.arboriculture.render.ModelProviderGermlingVanilla; +import forestry.arboriculture.models.ModelProviderGermling; +import forestry.arboriculture.models.ModelProviderGermlingVanilla; import forestry.arboriculture.tiles.TileLeaves; import forestry.arboriculture.worldgen.BlockTypeLog; import forestry.arboriculture.worldgen.WorldGenAcacia; diff --git a/src/main/java/forestry/arboriculture/genetics/TreeFactory.java b/src/main/java/forestry/arboriculture/genetics/TreeFactory.java index eb440b46e..aec48738b 100644 --- a/src/main/java/forestry/arboriculture/genetics/TreeFactory.java +++ b/src/main/java/forestry/arboriculture/genetics/TreeFactory.java @@ -20,7 +20,7 @@ import forestry.api.arboriculture.ITreeFactory; import forestry.api.arboriculture.ITreeGenerator; import forestry.api.genetics.IClassification; import forestry.arboriculture.genetics.alleles.AlleleTreeSpecies; -import forestry.arboriculture.render.SpriteProviderLeaves; +import forestry.arboriculture.models.SpriteProviderLeaves; public class TreeFactory implements ITreeFactory { @Override diff --git a/src/main/java/forestry/arboriculture/render/FruitPodStateMapper.java b/src/main/java/forestry/arboriculture/models/FruitPodStateMapper.java similarity index 97% rename from src/main/java/forestry/arboriculture/render/FruitPodStateMapper.java rename to src/main/java/forestry/arboriculture/models/FruitPodStateMapper.java index 928fa07fc..ffb5a4967 100644 --- a/src/main/java/forestry/arboriculture/render/FruitPodStateMapper.java +++ b/src/main/java/forestry/arboriculture/models/FruitPodStateMapper.java @@ -1,4 +1,4 @@ -package forestry.arboriculture.render; +package forestry.arboriculture.models; import java.util.Map; diff --git a/src/main/java/forestry/arboriculture/render/ModelDecorativeLeaves.java b/src/main/java/forestry/arboriculture/models/ModelDecorativeLeaves.java similarity index 90% rename from src/main/java/forestry/arboriculture/render/ModelDecorativeLeaves.java rename to src/main/java/forestry/arboriculture/models/ModelDecorativeLeaves.java index 40b880787..1caa47dd4 100644 --- a/src/main/java/forestry/arboriculture/render/ModelDecorativeLeaves.java +++ b/src/main/java/forestry/arboriculture/models/ModelDecorativeLeaves.java @@ -8,7 +8,7 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.arboriculture.render; +package forestry.arboriculture.models; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; @@ -17,7 +17,7 @@ import net.minecraft.client.resources.model.IBakedModel; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockPos; import net.minecraft.world.IBlockAccess; - +import net.minecraftforge.common.property.IExtendedBlockState; import forestry.api.arboriculture.IAlleleTreeSpecies; import forestry.api.arboriculture.ILeafSpriteProvider; import forestry.api.arboriculture.ITreeGenome; @@ -75,13 +75,12 @@ public class ModelDecorativeLeaves extends ModelBlockOverlay { } @Override - public boolean bakeWorldBlock(BlockForestryLeaves block, IBlockAccess world, BlockPos pos, IModelBaker baker) { + public void bakeWorldBlock(BlockForestryLeaves block, IBlockAccess world, BlockPos pos, IExtendedBlockState stateExtended, IModelBaker baker) { TileLeaves tile = TileUtil.getTile(world, pos, TileLeaves.class); if (tile == null) { - return false; + return; } TextureAtlasSprite leaveSprite = tile.getLeaveSprite(Proxies.render.fancyGraphicsEnabled()); @@ -83,7 +83,5 @@ public class ModelLeaves extends ModelBlockOverlay { // Set the particle sprite baker.setParticleSprite(leaveSprite); - - return true; } } diff --git a/src/main/java/forestry/arboriculture/render/ModelProviderGermling.java b/src/main/java/forestry/arboriculture/models/ModelProviderGermling.java similarity index 97% rename from src/main/java/forestry/arboriculture/render/ModelProviderGermling.java rename to src/main/java/forestry/arboriculture/models/ModelProviderGermling.java index 4340aec3e..678173fbd 100644 --- a/src/main/java/forestry/arboriculture/render/ModelProviderGermling.java +++ b/src/main/java/forestry/arboriculture/models/ModelProviderGermling.java @@ -8,7 +8,7 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.arboriculture.render; +package forestry.arboriculture.models; import javax.annotation.Nonnull; diff --git a/src/main/java/forestry/arboriculture/render/ModelProviderGermlingVanilla.java b/src/main/java/forestry/arboriculture/models/ModelProviderGermlingVanilla.java similarity index 98% rename from src/main/java/forestry/arboriculture/render/ModelProviderGermlingVanilla.java rename to src/main/java/forestry/arboriculture/models/ModelProviderGermlingVanilla.java index 869617a42..e19828f27 100644 --- a/src/main/java/forestry/arboriculture/render/ModelProviderGermlingVanilla.java +++ b/src/main/java/forestry/arboriculture/models/ModelProviderGermlingVanilla.java @@ -8,7 +8,7 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.arboriculture.render; +package forestry.arboriculture.models; import javax.annotation.Nonnull; diff --git a/src/main/java/forestry/arboriculture/render/SaplingStateMapper.java b/src/main/java/forestry/arboriculture/models/SaplingStateMapper.java similarity index 97% rename from src/main/java/forestry/arboriculture/render/SaplingStateMapper.java rename to src/main/java/forestry/arboriculture/models/SaplingStateMapper.java index e3c2c7df3..3e8d06fca 100644 --- a/src/main/java/forestry/arboriculture/render/SaplingStateMapper.java +++ b/src/main/java/forestry/arboriculture/models/SaplingStateMapper.java @@ -1,4 +1,4 @@ -package forestry.arboriculture.render; +package forestry.arboriculture.models; import com.google.common.collect.Maps; diff --git a/src/main/java/forestry/arboriculture/render/SpriteProviderLeaves.java b/src/main/java/forestry/arboriculture/models/SpriteProviderLeaves.java similarity index 97% rename from src/main/java/forestry/arboriculture/render/SpriteProviderLeaves.java rename to src/main/java/forestry/arboriculture/models/SpriteProviderLeaves.java index f5b1858b0..5579baeaf 100644 --- a/src/main/java/forestry/arboriculture/render/SpriteProviderLeaves.java +++ b/src/main/java/forestry/arboriculture/models/SpriteProviderLeaves.java @@ -8,7 +8,7 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.arboriculture.render; +package forestry.arboriculture.models; import java.awt.Color; diff --git a/src/main/java/forestry/arboriculture/render/TextureLeaves.java b/src/main/java/forestry/arboriculture/models/TextureLeaves.java similarity index 95% rename from src/main/java/forestry/arboriculture/render/TextureLeaves.java rename to src/main/java/forestry/arboriculture/models/TextureLeaves.java index 504b7ad92..e8ce7caef 100644 --- a/src/main/java/forestry/arboriculture/render/TextureLeaves.java +++ b/src/main/java/forestry/arboriculture/models/TextureLeaves.java @@ -1,70 +1,70 @@ -/******************************************************************************* - * 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.arboriculture.render; - -import java.util.EnumMap; -import java.util.Locale; -import java.util.Map; - -import net.minecraft.client.renderer.texture.TextureAtlasSprite; - -import forestry.api.arboriculture.EnumLeafType; -import forestry.core.render.TextureManager; - -public class TextureLeaves { - private static final Map leafTextures = new EnumMap<>(EnumLeafType.class); - - static { - for (EnumLeafType leafType : EnumLeafType.values()) { - leafTextures.put(leafType, new TextureLeaves(leafType)); - } - } - - public static TextureLeaves get(EnumLeafType leafType) { - return leafTextures.get(leafType); - } - - public static void registerAllSprites() { - for (TextureLeaves leafTexture : leafTextures.values()) { - leafTexture.registerSprites(); - } - } - - private final EnumLeafType leafType; - - private TextureAtlasSprite plain; - private TextureAtlasSprite pollinated; - private TextureAtlasSprite fancy; - - private TextureLeaves(EnumLeafType enumLeafType) { - this.leafType = enumLeafType; - } - - private void registerSprites() { - String ident = leafType.toString().toLowerCase(Locale.ENGLISH); - - plain = TextureManager.registerSprite("blocks/leaves/" + ident + ".plain"); - pollinated = TextureManager.registerSprite("blocks/leaves/" + ident + ".changed"); - fancy = TextureManager.registerSprite("blocks/leaves/" + ident + ".fancy"); - } - - public TextureAtlasSprite getPlain() { - return plain; - } - - public TextureAtlasSprite getPollinated() { - return pollinated; - } - - public TextureAtlasSprite getFancy() { - return fancy; - } +/******************************************************************************* + * 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.arboriculture.models; + +import java.util.EnumMap; +import java.util.Locale; +import java.util.Map; + +import net.minecraft.client.renderer.texture.TextureAtlasSprite; + +import forestry.api.arboriculture.EnumLeafType; +import forestry.core.render.TextureManager; + +public class TextureLeaves { + private static final Map leafTextures = new EnumMap<>(EnumLeafType.class); + + static { + for (EnumLeafType leafType : EnumLeafType.values()) { + leafTextures.put(leafType, new TextureLeaves(leafType)); + } + } + + public static TextureLeaves get(EnumLeafType leafType) { + return leafTextures.get(leafType); + } + + public static void registerAllSprites() { + for (TextureLeaves leafTexture : leafTextures.values()) { + leafTexture.registerSprites(); + } + } + + private final EnumLeafType leafType; + + private TextureAtlasSprite plain; + private TextureAtlasSprite pollinated; + private TextureAtlasSprite fancy; + + private TextureLeaves(EnumLeafType enumLeafType) { + this.leafType = enumLeafType; + } + + private void registerSprites() { + String ident = leafType.toString().toLowerCase(Locale.ENGLISH); + + plain = TextureManager.registerSprite("blocks/leaves/" + ident + ".plain"); + pollinated = TextureManager.registerSprite("blocks/leaves/" + ident + ".changed"); + fancy = TextureManager.registerSprite("blocks/leaves/" + ident + ".fancy"); + } + + public TextureAtlasSprite getPlain() { + return plain; + } + + public TextureAtlasSprite getPollinated() { + return pollinated; + } + + public TextureAtlasSprite getFancy() { + return fancy; + } } \ No newline at end of file diff --git a/src/main/java/forestry/arboriculture/proxy/ProxyArboricultureClient.java b/src/main/java/forestry/arboriculture/proxy/ProxyArboricultureClient.java index ee3005672..bc5244a4f 100644 --- a/src/main/java/forestry/arboriculture/proxy/ProxyArboricultureClient.java +++ b/src/main/java/forestry/arboriculture/proxy/ProxyArboricultureClient.java @@ -15,8 +15,8 @@ import net.minecraft.world.ColorizerFoliage; import forestry.arboriculture.PluginArboriculture; import forestry.arboriculture.blocks.BlockDecorativeLeaves; -import forestry.arboriculture.render.ModelDecorativeLeaves; -import forestry.arboriculture.render.ModelLeaves; +import forestry.arboriculture.models.ModelDecorativeLeaves; +import forestry.arboriculture.models.ModelLeaves; import forestry.core.models.BlockModelIndex; import forestry.core.proxy.Proxies; diff --git a/src/main/java/forestry/core/gui/widgets/TankWidget.java b/src/main/java/forestry/core/gui/widgets/TankWidget.java index 2bfe96672..840889bc0 100755 --- a/src/main/java/forestry/core/gui/widgets/TankWidget.java +++ b/src/main/java/forestry/core/gui/widgets/TankWidget.java @@ -26,11 +26,6 @@ import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidTank; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import org.lwjgl.opengl.GL11; - import forestry.api.core.IToolPipette; import forestry.core.fluids.tanks.StandardTank; import forestry.core.gui.IContainerLiquidTanks; @@ -160,10 +155,10 @@ public class TankWidget extends Widget { private static void drawFluidTexture(double xCoord, double yCoord, TextureAtlasSprite textureSprite, int maskTop, int maskRight, double zLevel) { - double uMin = (double) textureSprite.getMinU(); - double uMax = (double) textureSprite.getMaxU(); - double vMin = (double) textureSprite.getMinV(); - double vMax = (double) textureSprite.getMaxV(); + double uMin = textureSprite.getMinU(); + double uMax = textureSprite.getMaxU(); + double vMin = textureSprite.getMinV(); + double vMax = textureSprite.getMaxV(); uMax = uMax - (maskRight / 16.0 * (uMax - uMin)); vMax = vMax - (maskTop / 16.0 * (vMax - vMin)); diff --git a/src/main/java/forestry/core/inventory/ItemInventory.java b/src/main/java/forestry/core/inventory/ItemInventory.java index ad3b3c967..bd6261bec 100755 --- a/src/main/java/forestry/core/inventory/ItemInventory.java +++ b/src/main/java/forestry/core/inventory/ItemInventory.java @@ -18,7 +18,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ChatComponentText; import net.minecraft.util.IChatComponent; - import forestry.core.tiles.IFilterSlotDelegate; public abstract class ItemInventory implements IInventory, IFilterSlotDelegate { diff --git a/src/main/java/forestry/core/models/ModelBlockOverlay.java b/src/main/java/forestry/core/models/ModelBlockOverlay.java index e195ecaff..c9e33b000 100644 --- a/src/main/java/forestry/core/models/ModelBlockOverlay.java +++ b/src/main/java/forestry/core/models/ModelBlockOverlay.java @@ -115,7 +115,7 @@ public abstract class ModelBlockOverlay implements IFlexibleBak B bBlock = blockClass.cast(block); baker.setRenderBoundsFromBlock(block); - bakeWorldBlock(bBlock, world, pos, baker); + bakeWorldBlock(bBlock, world, pos, stateExtended, baker); return latestBlockModel = baker.bakeModel(false); } @@ -136,8 +136,8 @@ public abstract class ModelBlockOverlay implements IFlexibleBak return latestItemModel = baker.bakeModel(true); } - protected abstract void bakeInventoryBlock(B block, ItemStack item, IModelBaker baker); + protected abstract void bakeInventoryBlock(@Nonnull B block, @Nonnull ItemStack item, @Nonnull IModelBaker baker); - protected abstract boolean bakeWorldBlock(B block, IBlockAccess world, BlockPos pos, IModelBaker baker); + protected abstract void bakeWorldBlock(@Nonnull B block, @Nonnull IBlockAccess world, @Nonnull BlockPos pos, @Nonnull IExtendedBlockState stateExtended, @Nonnull IModelBaker baker); } diff --git a/src/main/java/forestry/core/models/baker/ModelBaker.java b/src/main/java/forestry/core/models/baker/ModelBaker.java index c6a52b678..dfdc125ac 100644 --- a/src/main/java/forestry/core/models/baker/ModelBaker.java +++ b/src/main/java/forestry/core/models/baker/ModelBaker.java @@ -11,6 +11,8 @@ package forestry.core.models.baker; import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import java.util.ArrayList; import java.util.List; @@ -20,6 +22,7 @@ import net.minecraft.client.renderer.block.model.BlockFaceUV; import net.minecraft.client.renderer.block.model.BlockPartFace; import net.minecraft.client.renderer.block.model.FaceBakery; import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.model.IBakedModel; import net.minecraft.client.resources.model.ModelRotation; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; @@ -43,6 +46,7 @@ public class ModelBaker implements IModelBaker { private static final float quadsUV[] = new float[]{0, 0, 1, 1, 0, 0, 1, 1}; private final List faces = new ArrayList<>(); + private final List bakedModels = new ArrayList<>(); protected double renderMinX; protected double renderMaxX; @@ -60,7 +64,7 @@ public class ModelBaker implements IModelBaker { protected final float[] defUVs = new float[] { 0, 0, 1, 1 }; @Override - public void setRenderBoundsFromBlock(Block block) { + public void setRenderBoundsFromBlock(@Nonnull Block block) { if (block == null) return; @@ -90,7 +94,7 @@ public class ModelBaker implements IModelBaker { } @Override - public void addBlockModel(Block block, BlockPos pos, TextureAtlasSprite[] textures, int colorIndex) { + public void addBlockModel(@Nonnull Block block, @Nullable BlockPos pos, @Nonnull TextureAtlasSprite[] textures, int colorIndex) { setRenderBoundsFromBlock(block); setColorIndex(colorIndex); @@ -138,9 +142,14 @@ public class ModelBaker implements IModelBaker { } @Override - public void addBlockModel(Block block, BlockPos pos, TextureAtlasSprite texture, int colorIndex) { + public void addBlockModel(@Nonnull Block block, @Nullable BlockPos pos, @Nonnull TextureAtlasSprite texture, int colorIndex) { addBlockModel(block, pos, new TextureAtlasSprite[]{ texture , texture, texture, texture, texture, texture }, colorIndex); } + + @Override + public void addBakedModel(@Nonnull IBakedModel model) { + this.bakedModels.add(model); + } protected float[] getFaceUvs(final EnumFacing face, final Vector3f to_16, final Vector3f from_16) { float from_a = 0; @@ -209,7 +218,7 @@ public class ModelBaker implements IModelBaker { } @Override - public void addFaceXNeg(TextureAtlasSprite sprite) { + public void addFaceXNeg(@Nonnull TextureAtlasSprite sprite) { boolean isEdge = renderMinX < 0.0001; Vector3f to = new Vector3f((float) renderMinX * 16.0f, (float) renderMinY * 16.0f, (float) renderMinZ * 16.0f); Vector3f from = new Vector3f((float) renderMinX * 16.0f, (float) renderMaxY * 16.0f, (float) renderMaxZ * 16.0f); @@ -218,7 +227,7 @@ public class ModelBaker implements IModelBaker { } @Override - public void addFaceYNeg(TextureAtlasSprite sprite) { + public void addFaceYNeg(@Nonnull TextureAtlasSprite sprite) { boolean isEdge = renderMinY < 0.0001; Vector3f to = new Vector3f((float) renderMinX * 16.0f, (float) renderMinY * 16.0f, (float) renderMinZ * 16.0f); Vector3f from = new Vector3f((float) renderMaxX * 16.0f, (float) renderMinY * 16.0f, (float) renderMaxZ * 16.0f); @@ -227,7 +236,7 @@ public class ModelBaker implements IModelBaker { } @Override - public void addFaceZNeg(TextureAtlasSprite sprite) { + public void addFaceZNeg(@Nonnull TextureAtlasSprite sprite) { boolean isEdge = renderMinZ < 0.0001; Vector3f to = new Vector3f((float) renderMinX * 16.0f, (float) renderMinY * 16.0f, (float) renderMinZ * 16.0f); Vector3f from = new Vector3f((float) renderMaxX * 16.0f, (float) renderMaxY * 16.0f, (float) renderMinZ * 16.0f); @@ -236,7 +245,7 @@ public class ModelBaker implements IModelBaker { } @Override - public void addFaceYPos(TextureAtlasSprite sprite) { + public void addFaceYPos(@Nonnull TextureAtlasSprite sprite) { boolean isEdge = renderMaxY > 0.9999; Vector3f to = new Vector3f((float) renderMinX * 16.0f, (float) renderMaxY * 16.0f, (float) renderMinZ * 16.0f); Vector3f from = new Vector3f((float) renderMaxX * 16.0f, (float) renderMaxY * 16.0f, (float) renderMaxZ * 16.0f); @@ -245,7 +254,7 @@ public class ModelBaker implements IModelBaker { } @Override - public void addFaceZPos(TextureAtlasSprite sprite) { + public void addFaceZPos(@Nonnull TextureAtlasSprite sprite) { boolean isEdge = renderMaxZ > 0.9999; Vector3f to = new Vector3f((float) renderMinX * 16.0f, (float) renderMinY * 16.0f, (float) renderMaxZ * 16.0f); Vector3f from = new Vector3f((float) renderMaxX * 16.0f, (float) renderMaxY * 16.0f, (float) renderMaxZ * 16.0f); @@ -254,7 +263,7 @@ public class ModelBaker implements IModelBaker { } @Override - public void addFaceXPos(TextureAtlasSprite sprite) { + public void addFaceXPos(@Nonnull TextureAtlasSprite sprite) { boolean isEdge = renderMaxX > 0.9999; Vector3f to = new Vector3f((float) renderMaxX * 16.0f, (float) renderMinY * 16.0f, (float) renderMinZ * 16.0f); @@ -289,6 +298,15 @@ public class ModelBaker implements IModelBaker { else this.currentModel.getGeneralQuads().add(bf); } + + //Add baked models to the current model. + for(IBakedModel bakedModel : bakedModels){ + for(EnumFacing gce : EnumFacing.VALUES){ + this.currentModel.getFaceQuads(gce).addAll(bakedModel.getFaceQuads(gce)); + } + this.currentModel.getGeneralQuads().addAll(bakedModel.getGeneralQuads()); + } + return currentModel; } diff --git a/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java b/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java index 49f7b1f54..88dc232f2 100644 --- a/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java +++ b/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java @@ -537,6 +537,24 @@ public abstract class MultiblockControllerBase implements IMultiblockControllerI } } + protected BlockPos getMaxXYCoord() { + BlockPos maximumCoord = new BlockPos(0, 0, 0); + + for (IMultiblockComponent part : connectedParts) { + BlockPos partCoords = part.getCoordinates(); + int maxX = maximumCoord.getX(); + int maxZ = maximumCoord.getZ(); + if (partCoords.getX() > maximumCoord.getX()) { + maxX = partCoords.getX(); + } + if (partCoords.getZ() > maximumCoord.getZ()) { + maxZ = partCoords.getZ(); + } + maximumCoord = new BlockPos(maxX, 0, maxZ); + } + return maximumCoord; + } + /** * @return The minimum bounding-box coordinate containing this machine's blocks. */ diff --git a/src/main/java/forestry/core/multiblock/RectangularMultiblockControllerBase.java b/src/main/java/forestry/core/multiblock/RectangularMultiblockControllerBase.java index dcd3f4ceb..7da1f98ca 100644 --- a/src/main/java/forestry/core/multiblock/RectangularMultiblockControllerBase.java +++ b/src/main/java/forestry/core/multiblock/RectangularMultiblockControllerBase.java @@ -123,6 +123,10 @@ public abstract class RectangularMultiblockControllerBase extends MultiblockCont } } } + + protected IMultiblockSizeLimits getSizeLimits() { + return sizeLimits; + } protected abstract void isGoodForExteriorLevel(IMultiblockComponent part, int level) throws MultiblockValidationException; diff --git a/src/main/java/forestry/core/network/PacketIdServer.java b/src/main/java/forestry/core/network/PacketIdServer.java index b970106ae..839836736 100644 --- a/src/main/java/forestry/core/network/PacketIdServer.java +++ b/src/main/java/forestry/core/network/PacketIdServer.java @@ -30,6 +30,9 @@ public enum PacketIdServer implements IPacketId { // Factory WORKTABLE_NEI_SELECT, + + //Greenhouse + TILE_FORESTRY_CAMOUFLAGE, // Mail LETTER_INFO_REQUEST, diff --git a/src/main/java/forestry/core/render/TextureManager.java b/src/main/java/forestry/core/render/TextureManager.java index ac6434d25..f10d03e32 100755 --- a/src/main/java/forestry/core/render/TextureManager.java +++ b/src/main/java/forestry/core/render/TextureManager.java @@ -69,7 +69,7 @@ public class TextureManager implements ITextureManager { return map.registerSprite(new ResourceLocation("forestry:" + identifier)); } - public TextureAtlasSprite getSprite(String modID, String identifier) { + public static TextureAtlasSprite getSprite(String modID, String identifier) { TextureMap map = Proxies.common.getClientInstance().getTextureMapBlocks(); if (map.getAtlasSprite(new ResourceLocation(modID + ":" + identifier).toString()) == map.getMissingSprite()) { return map.registerSprite(new ResourceLocation(modID + ":" + identifier)); @@ -77,7 +77,7 @@ public class TextureManager implements ITextureManager { return map.getAtlasSprite(new ResourceLocation(modID + ":" + identifier).toString()); } - public TextureAtlasSprite getSprite(String modID, String modifier, String identifier) { + public static TextureAtlasSprite getSprite(String modID, String modifier, String identifier) { TextureMap map = Proxies.common.getClientInstance().getTextureMapBlocks(); if (map.getAtlasSprite(new ResourceLocation(modID + ":" + modifier + "/" + identifier).toString()) == map.getMissingSprite()) { return map.registerSprite(new ResourceLocation(modID + ":" + modifier + "/" + identifier)); diff --git a/src/main/java/forestry/core/tiles/ICamouflagedBlock.java b/src/main/java/forestry/core/tiles/ICamouflagedBlock.java new file mode 100644 index 000000000..848c18b8c --- /dev/null +++ b/src/main/java/forestry/core/tiles/ICamouflagedBlock.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * 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.core.tiles; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockPos; + +public interface ICamouflagedBlock { + + ItemStack getCamouflageBlock(); + + boolean setCamouflageBlock(ItemStack camouflageBlock); + + BlockPos getCoordinates(); + + CamouflageType getType(); + + public enum CamouflageType{ + DEFAULT, GLASS + } + +} diff --git a/src/main/java/forestry/core/utils/BlockUtil.java b/src/main/java/forestry/core/utils/BlockUtil.java index eb6d509e4..6dccdb418 100644 --- a/src/main/java/forestry/core/utils/BlockUtil.java +++ b/src/main/java/forestry/core/utils/BlockUtil.java @@ -15,7 +15,7 @@ import javax.annotation.Nullable; import java.util.List; import net.minecraft.block.Block; -import net.minecraft.block.BlockCocoa; +import net.minecraft.block.BlockDirectional; import net.minecraft.block.BlockPlanks; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; @@ -86,7 +86,7 @@ public abstract class BlockUtil { return false; } - IBlockState state = Blocks.cocoa.getDefaultState().withProperty(BlockCocoa.FACING, facing); + IBlockState state = Blocks.cocoa.getDefaultState().withProperty(BlockDirectional.FACING, facing); world.setBlockState(pos, state); return true; } diff --git a/src/main/java/forestry/farming/models/EnumFarmBlockTexture.java b/src/main/java/forestry/farming/models/EnumFarmBlockTexture.java index aa68233e3..c9bdf4ed4 100644 --- a/src/main/java/forestry/farming/models/EnumFarmBlockTexture.java +++ b/src/main/java/forestry/farming/models/EnumFarmBlockTexture.java @@ -44,51 +44,50 @@ public enum EnumFarmBlockTexture { */ @SideOnly(Side.CLIENT) public static TextureAtlasSprite getSprite(EnumFarmBlockTexture texture, int side) { - TextureManager manager = TextureManager.getInstance(); switch (texture) { case BRICK: - return manager.getSprite("minecraft", "blocks/brick"); + return TextureManager.getSprite("minecraft", "blocks/brick"); case BRICK_STONE: - return manager.getSprite("minecraft", "blocks/stonebrick"); + return TextureManager.getSprite("minecraft", "blocks/stonebrick"); case BRICK_CHISELED: - return manager.getSprite("minecraft", "blocks/stonebrick_carved"); + return TextureManager.getSprite("minecraft", "blocks/stonebrick_carved"); case BRICK_CRACKED: - return manager.getSprite("minecraft", "blocks/stonebrick_cracked"); + return TextureManager.getSprite("minecraft", "blocks/stonebrick_cracked"); case BRICK_MOSSY: - return manager.getSprite("minecraft", "blocks/stonebrick_mossy"); + return TextureManager.getSprite("minecraft", "blocks/stonebrick_mossy"); case BRICK_NETHER: - return manager.getSprite("minecraft", "blocks/nether_brick"); + return TextureManager.getSprite("minecraft", "blocks/nether_brick"); case SANDSTONE_CHISELED: if (side == 0) { - return manager.getSprite("minecraft", "blocks/sandstone_bottom"); + return TextureManager.getSprite("minecraft", "blocks/sandstone_bottom"); } else if (side == 1) { - return manager.getSprite("minecraft", "blocks/sandstone_top"); + return TextureManager.getSprite("minecraft", "blocks/sandstone_top"); } - return manager.getSprite("minecraft", "blocks/sandstone_carved"); + return TextureManager.getSprite("minecraft", "blocks/sandstone_carved"); case SANDSTONE_SMOOTH: if (side == 0) { - return manager.getSprite("minecraft", "blocks/sandstone_bottom"); + return TextureManager.getSprite("minecraft", "blocks/sandstone_bottom"); } else if (side == 1) { - return manager.getSprite("minecraft", "blocks/sandstone_top"); + return TextureManager.getSprite("minecraft", "blocks/sandstone_top"); } - return manager.getSprite("minecraft", "blocks/sandstone_smooth"); + return TextureManager.getSprite("minecraft", "blocks/sandstone_smooth"); case QUARTZ: if (side == 0) { - return manager.getSprite("minecraft", "blocks/quartz_block_bottom"); + return TextureManager.getSprite("minecraft", "blocks/quartz_block_bottom"); } else if (side == 1) { - return manager.getSprite("minecraft", "blocks/quartz_block_top"); + return TextureManager.getSprite("minecraft", "blocks/quartz_block_top"); } - return manager.getSprite("minecraft", "blocks/quartz_block_side"); + return TextureManager.getSprite("minecraft", "blocks/quartz_block_side"); case QUARTZ_CHISELED: if (side == 0 || side == 1) { - return manager.getSprite("minecraft", "blocks/quartz_block_chiseled_top"); + return TextureManager.getSprite("minecraft", "blocks/quartz_block_chiseled_top"); } - return manager.getSprite("minecraft", "blocks/quartz_block_chiseled"); + return TextureManager.getSprite("minecraft", "blocks/quartz_block_chiseled"); case QUARTZ_LINES: if (side == 0 || side == 1) { - return manager.getSprite("minecraft", "blocks/quartz_block_lines_top"); + return TextureManager.getSprite("minecraft", "blocks/quartz_block_lines_top"); } - return manager.getSprite("minecraft", "blocks/quartz_block_lines"); + return TextureManager.getSprite("minecraft", "blocks/quartz_block_lines"); default: return null; } diff --git a/src/main/java/forestry/farming/models/ModelFarmBlock.java b/src/main/java/forestry/farming/models/ModelFarmBlock.java index 244a1a801..81eb5c5b3 100644 --- a/src/main/java/forestry/farming/models/ModelFarmBlock.java +++ b/src/main/java/forestry/farming/models/ModelFarmBlock.java @@ -4,7 +4,7 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockPos; import net.minecraft.world.IBlockAccess; - +import net.minecraftforge.common.property.IExtendedBlockState; import forestry.api.core.IModelBaker; import forestry.core.models.ModelBlockOverlay; import forestry.farming.blocks.BlockFarm; @@ -32,7 +32,7 @@ public class ModelFarmBlock extends ModelBlockOverlay { } @Override - public boolean bakeWorldBlock(BlockFarm blockFarm, IBlockAccess world, BlockPos pos, IModelBaker baker) { + public void bakeWorldBlock(BlockFarm blockFarm, IBlockAccess world, BlockPos pos, IExtendedBlockState stateExtended, IModelBaker baker) { TileFarm farm = (TileFarm) world.getTileEntity(pos); @@ -45,8 +45,6 @@ public class ModelFarmBlock extends ModelBlockOverlay { // Set the particle sprite baker.setParticleSprite(textures[0]); - - return true; } private static TextureAtlasSprite[] getSprites(EnumFarmBlockTexture texture) { diff --git a/src/main/java/forestry/greenhouse/PluginGreenhouse.java b/src/main/java/forestry/greenhouse/PluginGreenhouse.java new file mode 100644 index 000000000..a6b14c5b0 --- /dev/null +++ b/src/main/java/forestry/greenhouse/PluginGreenhouse.java @@ -0,0 +1,90 @@ +package forestry.greenhouse; + +import java.util.List; +import javax.annotation.Nonnull; + +import com.google.common.collect.Lists; + +import forestry.core.config.Constants; +import forestry.farming.blocks.EnumFarmBlockType; +import forestry.farming.proxy.ProxyFarming; +import forestry.greenhouse.blocks.BlockGreenhouseType; +import forestry.greenhouse.blocks.BlockRegistryGreenhouse; +import forestry.greenhouse.proxy.ProxyGreenhouse; +import forestry.plugins.BlankForestryPlugin; +import forestry.plugins.ForestryPlugin; +import forestry.plugins.ForestryPluginUids; +import net.minecraft.client.Minecraft; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraftforge.client.event.TextureStitchEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.common.SidedProxy; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@ForestryPlugin(pluginID = ForestryPluginUids.GREENHOUSE, name = "Greenhouse", author = "Nedelosk", url = Constants.URL, unlocalizedDescription = "for.plugin.greenhouse.description") +public class PluginGreenhouse extends BlankForestryPlugin { + + @SidedProxy(clientSide = "forestry.greenhouse.proxy.ProxyGreenhouseClient", serverSide = "forestry.greenhouse.proxy.ProxyGreenhouse") + public static ProxyGreenhouse proxy; + + public static BlockRegistryGreenhouse blocks; + private static final List greenhouseGlass = Lists.newArrayList(); + + @Override + public void registerItemsAndBlocks() { + blocks = new BlockRegistryGreenhouse(); + } + + @Override + public void preInit(){ + MinecraftForge.EVENT_BUS.register(this); + + addGreenhouseGlass(new ItemStack(Blocks.glass, 1, 0)); + addGreenhouseGlass(new ItemStack(Blocks.stained_glass, 1, 0)); + addGreenhouseGlass(new ItemStack(Blocks.stained_glass, 1, 1)); + addGreenhouseGlass(new ItemStack(Blocks.stained_glass, 1, 2)); + addGreenhouseGlass(new ItemStack(Blocks.stained_glass, 1, 3)); + addGreenhouseGlass(new ItemStack(Blocks.stained_glass, 1, 4)); + addGreenhouseGlass(new ItemStack(Blocks.stained_glass, 1, 5)); + addGreenhouseGlass(new ItemStack(Blocks.stained_glass, 1, 6)); + addGreenhouseGlass(new ItemStack(Blocks.stained_glass, 1, 7)); + addGreenhouseGlass(new ItemStack(Blocks.stained_glass, 1, 8)); + addGreenhouseGlass(new ItemStack(Blocks.stained_glass, 1, 9)); + addGreenhouseGlass(new ItemStack(Blocks.stained_glass, 1, 10)); + addGreenhouseGlass(new ItemStack(Blocks.stained_glass, 1, 11)); + addGreenhouseGlass(new ItemStack(Blocks.stained_glass, 1, 12)); + addGreenhouseGlass(new ItemStack(Blocks.stained_glass, 1, 13)); + addGreenhouseGlass(new ItemStack(Blocks.stained_glass, 1, 14)); + addGreenhouseGlass(new ItemStack(Blocks.stained_glass, 1, 15)); + + proxy.initializeModels(); + } + + public static void addGreenhouseGlass(@Nonnull ItemStack stack){ + for(ItemStack glass : greenhouseGlass){ + if(ItemStack.areItemStackTagsEqual(stack, glass)){ + return; + } + } + greenhouseGlass.add(stack); + } + + public static boolean isGreenhouseGlass(@Nonnull ItemStack stack){ + for(ItemStack glass : greenhouseGlass){ + if(ItemStack.areItemStackTagsEqual(stack, glass)){ + return true; + } + } + return false; + } + + @SubscribeEvent + @SideOnly(Side.CLIENT) + public void handleTextureRemap(TextureStitchEvent.Pre event) { + BlockGreenhouseType.registerSprites(); + } + +} diff --git a/src/main/java/forestry/greenhouse/blocks/BlockGreenhouse.java b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouse.java new file mode 100644 index 000000000..29915a1a9 --- /dev/null +++ b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouse.java @@ -0,0 +1,187 @@ +/******************************************************************************* + * 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.blocks; + +import java.util.EnumMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.Nonnull; + +import net.minecraft.block.material.Material; +import net.minecraft.block.properties.IProperty; +import net.minecraft.block.properties.PropertyEnum; +import net.minecraft.block.state.BlockState; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.resources.model.ModelResourceLocation; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumWorldBlockLayer; +import net.minecraft.util.IStringSerializable; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +import net.minecraftforge.client.model.ModelLoader; +import net.minecraftforge.common.property.ExtendedBlockState; +import net.minecraftforge.common.property.IExtendedBlockState; +import net.minecraftforge.common.property.IUnlistedProperty; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.core.IModelManager; +import forestry.core.CreativeTabForestry; +import forestry.core.blocks.BlockStructure; +import forestry.core.blocks.propertys.UnlistedBlockAccess; +import forestry.core.blocks.propertys.UnlistedBlockPos; +import forestry.greenhouse.tiles.TileGreenhouseControl; +import forestry.greenhouse.tiles.TileGreenhouseDryer; +import forestry.greenhouse.tiles.TileGreenhouseFan; +import forestry.greenhouse.tiles.TileGreenhouseGearbox; +import forestry.greenhouse.tiles.TileGreenhouseHeater; +import forestry.greenhouse.tiles.TileGreenhousePlain; +import forestry.greenhouse.tiles.TileGreenhouseSprinkler; +import forestry.greenhouse.tiles.TileGreenhouseValve; + +public abstract class BlockGreenhouse extends BlockStructure { + + public static final PropertyEnum STATE = PropertyEnum.create("state", State.class); + + public static enum State implements IStringSerializable { + ON, OFF; + + @Override + public String getName() { + return name().toLowerCase(); + } + } + + public static Map create() { + Map blockMap = new EnumMap<>(BlockGreenhouseType.class); + for (final BlockGreenhouseType type : BlockGreenhouseType.VALUES) { + BlockGreenhouse block = new BlockGreenhouse() { + @Nonnull + @Override + public BlockGreenhouseType getGreenhouseType() { + return type; + } + }; + blockMap.put(type, block); + } + return blockMap; + } + + public BlockGreenhouse() { + super(Material.rock); + BlockGreenhouseType greenhouseType = getGreenhouseType(); + IBlockState defaultState = this.blockState.getBaseState(); + if(greenhouseType.activatable){ + defaultState = defaultState.withProperty(STATE, State.OFF); + } + setDefaultState(defaultState); + + setHardness(1.0f); + setHarvestLevel("pickaxe", 0); + setCreativeTab(CreativeTabForestry.tabForestry); + } + + @Override + public int getMetaFromState(IBlockState state) { + return 0; + } + + @Override + public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) { + return ((IExtendedBlockState) super.getExtendedState(state, world, pos)).withProperty(UnlistedBlockPos.POS, pos) + .withProperty(UnlistedBlockAccess.BLOCKACCESS, world); + } + + @Override + protected BlockState createBlockState() { + if(getGreenhouseType().activatable){ + return new ExtendedBlockState(this, new IProperty[]{STATE}, new IUnlistedProperty[]{UnlistedBlockPos.POS, UnlistedBlockAccess.BLOCKACCESS}); + }else{ + return new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[]{UnlistedBlockPos.POS, UnlistedBlockAccess.BLOCKACCESS}); + } + } + + @Override + @SideOnly(Side.CLIENT) + public void getSubBlocks(Item item, CreativeTabs tab, List list) { + list.add(new ItemStack(item)); + } + + @Override + public int damageDropped(IBlockState state) { + return getMetaFromState(state); + } + + @Override + public TileEntity createTileEntity(World world, IBlockState state) { + BlockGreenhouseType type = getGreenhouseType(); + switch (type) { + case GEARBOX: + return new TileGreenhouseGearbox(); + case SPRINKLER: + return new TileGreenhouseSprinkler(); + case DRYER: + return new TileGreenhouseDryer(); + case VALVE: + return new TileGreenhouseValve(); + case FAN: + return new TileGreenhouseFan(); + case HEATER: + return new TileGreenhouseHeater(); + case CONTROL: + return new TileGreenhouseControl(); + default: + return new TileGreenhousePlain(); + } + } + + @Override + public TileEntity createNewTileEntity(World world, int meta) { + return createTileEntity(world, getStateFromMeta(meta)); + } + + /* MODELS */ + @Override + @SideOnly(Side.CLIENT) + public EnumWorldBlockLayer getBlockLayer() { + return EnumWorldBlockLayer.CUTOUT; + } + + @Override + public boolean isNormalCube(IBlockAccess world, BlockPos pos) { + IBlockState state = world.getBlockState(pos); + if(getGreenhouseType() == BlockGreenhouseType.SPRINKLER){ + return false; + } + return super.isNormalCube(world, pos); + } + + @SideOnly(Side.CLIENT) + @Override + public void registerModel(Item item, IModelManager manager) { + ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation("forestry:greenhouse", "inventory")); + } + + @Override + public boolean canConnectRedstone(IBlockAccess world, BlockPos pos, EnumFacing side) { + return getGreenhouseType() == BlockGreenhouseType.CONTROL; + } + + @Nonnull + public abstract BlockGreenhouseType getGreenhouseType(); +} diff --git a/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseType.java b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseType.java new file mode 100644 index 000000000..829f8275a --- /dev/null +++ b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseType.java @@ -0,0 +1,119 @@ +package forestry.greenhouse.blocks; + +import java.util.Arrays; +import java.util.List; +import java.util.Locale; + +import javax.annotation.Nullable; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.core.render.TextureManager; +import forestry.greenhouse.blocks.BlockGreenhouse.State; + +public enum BlockGreenhouseType { + PLAIN(true), + GLASS(true), + GEARBOX(true), + VALVE(true), + FAN(true, true), + HEATER(true, true), + DRYER(true, true), + CONTROL(true), + SPRINKLER(false, true); + + public static final BlockGreenhouseType[] VALUES = values(); + + /* TEXTURE IDS*/ + private static final int TYPE_PLAIN = 0; + private static final int TYPE_GLASS = 1; + private static final int TYPE_GEARS = 2; + private static final int TYPE_VALVE = 3; + private static final int TYPE_FAN_OFF = 4; + private static final int TYPE_FAN_ON = 5; + private static final int TYPE_HEATER_OFF = 6; + private static final int TYPE_HEATER_ON = 7; + private static final int TYPE_DRYER = 8; + private static final int TYPE_CONTROL = 9; + + public final boolean canCamouflage; + public final boolean activatable; + + BlockGreenhouseType(boolean canCamouflage, boolean activatable) { + this.canCamouflage = canCamouflage; + this.activatable = activatable; + } + + BlockGreenhouseType(boolean canCamouflage) { + this.canCamouflage = canCamouflage; + this.activatable = false; + } + + BlockGreenhouseType() { + this.canCamouflage = false; + this.activatable = false; + } + + @SideOnly(Side.CLIENT) + private static List sprites; + + @SideOnly(Side.CLIENT) + public static void registerSprites() { + sprites = Arrays.asList( + TextureManager.getSprite("minecraft", "blocks/brick"), + TextureManager.getSprite("minecraft", "blocks/glass_green"), + TextureManager.registerSprite("blocks/greenhouse/gears"), + TextureManager.registerSprite("blocks/greenhouse/valve"), + TextureManager.registerSprite("blocks/greenhouse/fan.off"), + TextureManager.registerSprite("blocks/greenhouse/fan.on"), + TextureManager.registerSprite("blocks/greenhouse/heater.off"), + TextureManager.registerSprite("blocks/greenhouse/heater.off"), + TextureManager.registerSprite("blocks/greenhouse/heater"), + TextureManager.registerSprite("blocks/greenhouse/dryer"), + TextureManager.registerSprite("blocks/greenhouse/control") + ); + } + + /** + * @return The texture sprite from the type and the {@link IBlockState} of the greenhouse block + */ + @SideOnly(Side.CLIENT) + public static TextureAtlasSprite getSprite(BlockGreenhouseType type, @Nullable IBlockState state) { + switch (type) { + case PLAIN: + return sprites.get(TYPE_PLAIN); + case GLASS: + return sprites.get(TYPE_GLASS); + case GEARBOX: + return sprites.get(TYPE_GEARS); + case VALVE: + return sprites.get(TYPE_VALVE); + case FAN: + if(state == null || state.getValue(BlockGreenhouse.STATE) == State.OFF) + return sprites.get(TYPE_FAN_OFF); + else + return sprites.get(TYPE_FAN_ON); + case HEATER: + if(state == null || state.getValue(BlockGreenhouse.STATE) == State.OFF) + return sprites.get(TYPE_HEATER_OFF); + else + return sprites.get(TYPE_HEATER_ON); + case DRYER: + return sprites.get(TYPE_DRYER); + case CONTROL: + return sprites.get(TYPE_CONTROL); + default: + return Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite(); + } + } + + @Override + public String toString() { + return name().toLowerCase(Locale.ENGLISH); + } + +} diff --git a/src/main/java/forestry/greenhouse/blocks/BlockRegistryGreenhouse.java b/src/main/java/forestry/greenhouse/blocks/BlockRegistryGreenhouse.java new file mode 100644 index 000000000..b5ef2329d --- /dev/null +++ b/src/main/java/forestry/greenhouse/blocks/BlockRegistryGreenhouse.java @@ -0,0 +1,25 @@ +package forestry.greenhouse.blocks; + +import java.util.Map; + +import forestry.core.blocks.BlockRegistry; +import forestry.core.items.ItemBlockForestry; +import net.minecraft.item.ItemStack; + +public class BlockRegistryGreenhouse extends BlockRegistry{ + + private final Map greenhouseBlockMap; + + public BlockRegistryGreenhouse() { + greenhouseBlockMap = BlockGreenhouse.create(); + for (BlockGreenhouse block : greenhouseBlockMap.values()) { + registerBlock(block, new ItemBlockForestry(block), "greenhouse." + block.getGreenhouseType()); + } + } + + public ItemStack getGreenhouseBlock(BlockGreenhouseType type) { + BlockGreenhouse greenhouseBlock = greenhouseBlockMap.get(type); + return new ItemStack(greenhouseBlock); + } + +} diff --git a/src/main/java/forestry/greenhouse/gui/ContainerGreenhouse.java b/src/main/java/forestry/greenhouse/gui/ContainerGreenhouse.java new file mode 100644 index 000000000..f48b1775d --- /dev/null +++ b/src/main/java/forestry/greenhouse/gui/ContainerGreenhouse.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * 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.gui; + +import net.minecraft.entity.player.InventoryPlayer; + +import forestry.core.gui.ContainerTile; +import forestry.core.network.packets.PacketGuiUpdate; +import forestry.greenhouse.tiles.TileGreenhouse; + +public class ContainerGreenhouse extends ContainerTile { + + public ContainerGreenhouse(InventoryPlayer playerInventory, TileGreenhouse tile) { + super(tile, playerInventory, 8, 84); + } + + @Override + public void detectAndSendChanges() { + super.detectAndSendChanges(); + PacketGuiUpdate packet = new PacketGuiUpdate(tile); + sendPacketToCrafters(packet); + } + +} diff --git a/src/main/java/forestry/greenhouse/gui/GuiGreenhouse.java b/src/main/java/forestry/greenhouse/gui/GuiGreenhouse.java new file mode 100644 index 000000000..c35545f75 --- /dev/null +++ b/src/main/java/forestry/greenhouse/gui/GuiGreenhouse.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * 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.gui; + +import net.minecraft.entity.player.EntityPlayer; + +import forestry.core.config.Constants; +import forestry.core.gui.GuiForestryTitled; +import forestry.core.gui.ledgers.ClimateLedger; +import forestry.core.gui.widgets.TankWidget; +import forestry.greenhouse.multiblock.IGreenhouseControllerInternal; +import forestry.greenhouse.tiles.TileGreenhouse; + +public class GuiGreenhouse extends GuiForestryTitled { + + public GuiGreenhouse(EntityPlayer player, TileGreenhouse tile) { + super(Constants.TEXTURE_PATH_GUI + "/greenhouse.png", new ContainerGreenhouse(player.inventory, tile), tile); + + widgetManager.add(new TankWidget(widgetManager, 80, 14, 0).setOverlayOrigin(176, 0)); + } + + @Override + protected void addLedgers() { + IGreenhouseControllerInternal greenhouseController = inventory.getMultiblockLogic().getController(); + ledgerManager.add(new ClimateLedger(ledgerManager, greenhouseController)); + super.addLedgers(); + } +} diff --git a/src/main/java/forestry/greenhouse/gui/widgets/WidgetCamouflageSlot.java b/src/main/java/forestry/greenhouse/gui/widgets/WidgetCamouflageSlot.java new file mode 100644 index 000000000..b0e8ad6b1 --- /dev/null +++ b/src/main/java/forestry/greenhouse/gui/widgets/WidgetCamouflageSlot.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * 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.gui.widgets; + +import forestry.core.gui.tooltips.ToolTip; +import forestry.core.gui.widgets.Widget; +import forestry.core.gui.widgets.WidgetManager; +import forestry.core.proxy.Proxies; +import forestry.core.tiles.ICamouflagedBlock; +import forestry.core.tiles.ICamouflagedBlock.CamouflageType; +import forestry.greenhouse.PluginGreenhouse; +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +public class WidgetCamouflageSlot extends Widget { + + private ICamouflagedBlock camouflagedBlock; + + public WidgetCamouflageSlot(WidgetManager manager, int xPos, int yPos, ICamouflagedBlock camouflagedBlock) { + super(manager, xPos, yPos); + + this.camouflagedBlock = camouflagedBlock; + } + + @Override + public void draw(int startX, int startY) { + if (camouflagedBlock == null || camouflagedBlock.getCamouflageBlock() != null) { + Proxies.render.bindTexture(TextureMap.locationBlocksTexture); + RenderItem renderItem = Proxies.common.getClientInstance().getRenderItem(); + renderItem.renderItemIntoGUI(camouflagedBlock.getCamouflageBlock(), startX + xPos, startY + yPos); + } + } + + @Override + public void handleMouseClick(int mouseX, int mouseY, int mouseButton) { + super.handleMouseClick(mouseX, mouseY, mouseButton); + if(GuiScreen.isShiftKeyDown()){ + camouflagedBlock.setCamouflageBlock(null); + }else{ + EntityPlayer player = Minecraft.getMinecraft().thePlayer; + ItemStack heldStack = player.getHeldItem(); + if(heldStack != null && Block.getBlockFromItem(heldStack.getItem()) != null){ + Block block = Block.getBlockFromItem(heldStack.getItem()); + if(camouflagedBlock.getType() == CamouflageType.DEFAULT && !block.isOpaqueCube() && block.isNormalCube(player.worldObj, camouflagedBlock.getCoordinates()) || camouflagedBlock.getType() == CamouflageType.GLASS && block.isOpaqueCube() && PluginGreenhouse.isGreenhouseGlass(heldStack)){ + camouflagedBlock.setCamouflageBlock(heldStack); + } + } + } + } + + @Override + public ToolTip getToolTip(int mouseX, int mouseY) { + if (isMouseOver(mouseX, mouseY)) { + return toolTip; + } else { + return null; + } + } + + protected final ToolTip toolTip = new ToolTip(250) { + @Override + public void refresh() { + toolTip.clear(); + if (camouflagedBlock == null || camouflagedBlock.getCamouflageBlock() == null) { + return; + } + toolTip.add(camouflagedBlock.getCamouflageBlock().getTooltip(Proxies.common.getClientInstance().thePlayer, false)); + } + }; + +} diff --git a/src/main/java/forestry/greenhouse/models/ModelGreenhouse.java b/src/main/java/forestry/greenhouse/models/ModelGreenhouse.java new file mode 100644 index 000000000..c28e0d51f --- /dev/null +++ b/src/main/java/forestry/greenhouse/models/ModelGreenhouse.java @@ -0,0 +1,60 @@ +package forestry.greenhouse.models; + +import forestry.greenhouse.blocks.BlockGreenhouse; +import forestry.greenhouse.blocks.BlockGreenhouseType; +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.BlockModelShapes; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.BlockPos; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.property.IExtendedBlockState; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import forestry.api.core.IModelBaker; +import forestry.core.models.ModelBlockOverlay; +import forestry.core.tiles.ICamouflagedBlock; + +public class ModelGreenhouse extends ModelBlockOverlay { + + public ModelGreenhouse() { + super(BlockGreenhouse.class); + } + + @Override + protected void bakeInventoryBlock(BlockGreenhouse block, ItemStack item, IModelBaker baker) { + bakeBlockModel(block, null, null, baker, null); + } + + @Override + protected void bakeWorldBlock(BlockGreenhouse block, IBlockAccess world, BlockPos pos, IExtendedBlockState stateExtended, IModelBaker baker) { + TileEntity tile = world.getTileEntity(pos); + if(!(tile instanceof ICamouflagedBlock)){ + return; + } + bakeBlockModel(block, pos, stateExtended, baker, (ICamouflagedBlock) tile); + } + + private void bakeBlockModel(@Nonnull BlockGreenhouse block, @Nullable BlockPos pos, @Nullable IExtendedBlockState stateExtended, @Nonnull IModelBaker baker, @Nullable ICamouflagedBlock camouflageBlock){ + if(camouflageBlock != null){ + ItemStack camouflageBlockStack = camouflageBlock.getCamouflageBlock(); + if(camouflageBlockStack != null){ + BlockModelShapes modelShapes = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes(); + baker.addBakedModel(modelShapes.getModelForState(Block.getBlockFromItem(camouflageBlockStack.getItem()).getStateFromMeta(camouflageBlockStack.getItemDamage()))); + } + }else{ + if(block.getGreenhouseType() == BlockGreenhouseType.GLASS){ + baker.addBlockModel(block, pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.GLASS, null), 100); + }else{ + baker.addBlockModel(block, pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.PLAIN, null), 100); + } + } + if(block.getGreenhouseType() != BlockGreenhouseType.PLAIN && block.getGreenhouseType() != BlockGreenhouseType.GLASS){ + baker.addBlockModel(block, pos, BlockGreenhouseType.getSprite(block.getGreenhouseType(), stateExtended), 101); + } + } + +} diff --git a/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java b/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java new file mode 100644 index 000000000..50f6f15c5 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * 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.multiblock; + +import forestry.core.fluids.FakeTankManager; +import forestry.core.fluids.ITankManager; +import forestry.core.multiblock.FakeMultiblockController; +import forestry.energy.EnergyManager; + +public class FakeGreenhouseController extends FakeMultiblockController implements IGreenhouseControllerInternal { + public static final FakeGreenhouseController instance = new FakeGreenhouseController(); + + private FakeGreenhouseController() { + + } + + @Override + public ITankManager getTankManager() { + return FakeTankManager.instance; + } + + @Override + public EnergyManager getEnergyManager() { + return null; + } + +} diff --git a/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java b/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java new file mode 100644 index 000000000..6fb2ce268 --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java @@ -0,0 +1,509 @@ +/******************************************************************************* + * 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.multiblock; + +import java.io.IOException; +import java.util.EnumMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; + +import forestry.api.core.EnumHumidity; +import forestry.api.core.EnumTemperature; +import forestry.api.core.IClimateControlled; +import forestry.api.multiblock.IGreenhouseComponent; +import forestry.api.multiblock.IMultiblockComponent; +import forestry.core.access.EnumAccess; +import forestry.core.config.Constants; +import forestry.core.fluids.ITankManager; +import forestry.core.fluids.TankManager; +import forestry.core.fluids.tanks.FilteredTank; +import forestry.core.fluids.tanks.StandardTank; +import forestry.core.multiblock.IMultiblockControllerInternal; +import forestry.core.multiblock.MultiblockValidationException; +import forestry.core.multiblock.RectangularMultiblockControllerBase; +import forestry.core.network.DataInputStreamForestry; +import forestry.core.network.DataOutputStreamForestry; +import forestry.core.proxy.Proxies; +import forestry.core.tiles.ICamouflagedBlock; +import forestry.core.tiles.ILiquidTankTile; +import forestry.energy.EnergyManager; +import forestry.greenhouse.blocks.BlockGreenhouse; +import forestry.greenhouse.network.packets.PacketCamouflageUpdate; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraftforge.fluids.FluidRegistry; + +public class GreenhouseController extends RectangularMultiblockControllerBase implements IGreenhouseControllerInternal, IClimateControlled, ILiquidTankTile, ICamouflagedBlock { + + private final List internalBlocks = Lists.newArrayList(); + private final Set listenerComponents = new HashSet<>(); + private final Set climatiserComponents = new HashSet<>(); + private final Set activeComponents = new HashSet<>(); + + private float tempChange; + private float humidChange; + private BiomeGenBase cachedBiome; + private final TankManager tankManager; + private final StandardTank resourceTank; + private final EnergyManager energyManager; + private ItemStack camouflageBlock; + + public GreenhouseController(World world) { + super(world, GreenhouseMultiblockSizeLimits.instance); + tempChange = 0; + humidChange = 0; + + this.resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, FluidRegistry.WATER); + this.tankManager = new TankManager(this, resourceTank); + this.energyManager = new EnergyManager(2000, 100000); + } + + @Override + public EnumTemperature getTemperature() { + BlockPos coords = getReferenceCoord(); + return EnumTemperature.getFromValue(getExactTemperature()); + } + + private BiomeGenBase getBiome() { + if (cachedBiome == null) { + BlockPos coords = getReferenceCoord(); + cachedBiome = worldObj.getBiomeGenForCoords(coords); + } + return cachedBiome; + } + + @Override + public EnumHumidity getHumidity() { + return EnumHumidity.getFromValue(getExactHumidity()); + } + + @Override + public float getExactTemperature() { + BlockPos coords = getReferenceCoord(); + return getBiome().getFloatTemperature(coords) + tempChange; + } + + @Override + public float getExactHumidity() { + return getBiome().rainfall + tempChange; + } + + @Override + public void addTemperatureChange(float change, float boundaryDown, float boundaryUp) { + BlockPos coordinates = getCoordinates(); + + float temperature = getBiome().getFloatTemperature(coordinates); + + tempChange += change; + tempChange = Math.max(boundaryDown - temperature, tempChange); + tempChange = Math.min(boundaryUp - temperature, tempChange); + } + + @Override + public void addHumidityChange(float change, float boundaryDown, float boundaryUp) { + float humidity = getBiome().rainfall; + + humidChange += change; + humidChange = Math.max(boundaryDown - humidity, humidChange); + humidChange = Math.min(boundaryUp - humidity, humidChange); + } + + private static float equalizeChange(float change) { + if (change == 0) { + return 0; + } + + change *= 0.95f; + if (change <= 0.001f && change >= -0.001f) { + change = 0; + } + return change; + } + + @Override + public World getWorld() { + return worldObj; + } + + @Override + public void formatDescriptionPacket(NBTTagCompound data) { + writeToNBT(data); + } + + @Override + public void decodeDescriptionPacket(NBTTagCompound data) { + readFromNBT(data); + } + + @Override + public void writeToNBT(NBTTagCompound data) { + super.writeToNBT(data); + + data.setFloat("Temperature", tempChange); + data.setFloat("Humidity", humidChange); + tankManager.writeToNBT(data); + energyManager.writeToNBT(data); + + if(camouflageBlock != null){ + NBTTagCompound nbtTag = new NBTTagCompound(); + camouflageBlock.writeToNBT(nbtTag); + data.setTag("CamouflageBlock", nbtTag); + } + } + + @Override + public void readFromNBT(NBTTagCompound data) { + super.readFromNBT(data); + + tempChange = data.getFloat("Temperature"); + humidChange = data.getFloat("Humidity"); + tankManager.readFromNBT(data); + energyManager.readFromNBT(data); + + if(data.hasKey("CamouflageBlock")){ + setCamouflageBlock(ItemStack.loadItemStackFromNBT(data.getCompoundTag("CamouflageBlock"))); + } + } + + @Override + public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) { + if (oldAccess == EnumAccess.SHARED || newAccess == EnumAccess.SHARED) { + // pipes connected to this need to update + for (IMultiblockComponent part : connectedParts) { + if (part instanceof TileEntity) { + TileEntity tile = (TileEntity) part; + worldObj.notifyBlockOfStateChange(tile.getPos(), tile.getBlockType()); + } + } + markDirty(); + } + } + + @Override + public void writeGuiData(DataOutputStreamForestry data) throws IOException { + data.writeVarInt(Math.round(tempChange * 100)); + data.writeVarInt(Math.round(humidChange * 100)); + tankManager.writeData(data); + energyManager.writeData(data); + ItemStack camouflageBlock = getCamouflageBlock(); + if(camouflageBlock != null){ + data.writeShort(1); + data.writeItemStack(camouflageBlock); + }else{ + data.writeShort(0); + } + } + + @Override + public void readGuiData(DataInputStreamForestry data) throws IOException { + tempChange = data.readVarInt() / 100.0F; + humidChange = data.readVarInt() / 100.0F; + tankManager.readData(data); + energyManager.readData(data); + if(data.readShort() == 1){ + setCamouflageBlock(data.readItemStack()); + } + } + + @Override + public boolean setCamouflageBlock(ItemStack camouflageBlock) { + this.camouflageBlock = camouflageBlock; + + if (worldObj != null && worldObj.isRemote) { + for(IMultiblockComponent comp : connectedParts){ + ICamouflagedBlock camBlock = (ICamouflagedBlock) comp; + worldObj.markBlockForUpdate(camBlock.getCoordinates()); + Proxies.net.sendToServer(new PacketCamouflageUpdate(this, true)); + } + } + return true; + } + + @Override + public ItemStack getCamouflageBlock() { + return camouflageBlock; + } + + @Override + public BlockPos getCoordinates() { + BlockPos coord = getReferenceCoord(); + return new BlockPos(coord); + } + + @Override + public ITankManager getTankManager() { + return tankManager; + } + + @Override + public EnergyManager getEnergyManager() { + return energyManager; + } + + @Override + protected void onAttachedPartWithMultiblockData(IMultiblockComponent part, NBTTagCompound data) { + readFromNBT(data); + } + + @Override + protected void onMachineDisassembled() { + super.onMachineDisassembled(); + + internalBlocks.clear(); + } + + @Override + protected void onBlockAdded(IMultiblockComponent newPart) { + if(newPart instanceof IGreenhouseComponent.Listener){ + listenerComponents.add((IGreenhouseComponent.Listener) newPart); + }else if(newPart instanceof IGreenhouseComponent.Climatiser){ + climatiserComponents.add((IGreenhouseComponent.Climatiser) newPart); + }else if(newPart instanceof IGreenhouseComponent.Active){ + activeComponents.add((IGreenhouseComponent.Active) newPart); + } + } + + @Override + protected void onBlockRemoved(IMultiblockComponent oldPart) { + if(oldPart instanceof IGreenhouseComponent.Listener){ + listenerComponents.remove(oldPart); + }else if(oldPart instanceof IGreenhouseComponent.Climatiser){ + climatiserComponents.remove(oldPart); + }else if(oldPart instanceof IGreenhouseComponent.Active){ + activeComponents.remove(oldPart); + } + } + + @Override + protected void onAssimilate(IMultiblockControllerInternal assimilated) { + } + + @Override + public void onAssimilated(IMultiblockControllerInternal assimilator) { + } + + @Override + protected boolean updateServer(int tickCount) { + for (IGreenhouseComponent.Active activeComponent : activeComponents) { + activeComponent.updateServer(tickCount); + } + + boolean canWork = true; + + for (IGreenhouseComponent.Listener listenerComponent : listenerComponents) { + canWork = listenerComponent.getGreenhouseListener().canWork(this); + } + + if(canWork){ + + for (IGreenhouseComponent.Climatiser climatiser : climatiserComponents) { + climatiser.changeClimate(tickCount, this); + } + + tempChange = equalizeChange(tempChange); + humidChange = equalizeChange(humidChange); + } + + return canWork; + } + + @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 isMachineWhole() throws MultiblockValidationException { + int minX = getSizeLimits().getMinimumXSize(); + int minY = getSizeLimits().getMinimumYSize(); + int minZ = getSizeLimits().getMinimumZSize(); + + if (connectedParts.size() < getSizeLimits().getMinimumNumberOfBlocksForAssembledMachine()) { + throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.small", minX, minY, minZ)); + } + + BlockPos maximumCoord = getMaximumCoord(); + BlockPos minimumCoord = getMinimumCoord(); + + // Quickly check for exceeded dimensions + int deltaX = maximumCoord.getX() - minimumCoord.getX() + 1; + int deltaY = maximumCoord.getY() - minimumCoord.getY() + 1; + int deltaZ = maximumCoord.getZ() - minimumCoord.getZ() + 1; + + int maxX = getSizeLimits().getMaximumXSize(); + int maxY = getSizeLimits().getMaximumYSize(); + int maxZ = getSizeLimits().getMaximumZSize(); + + if (maxX > 0 && deltaX > maxX) { + throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.large.x", maxX)); + } + if (maxY > 0 && deltaY > maxY) { + throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.large.y", maxY)); + } + if (maxZ > 0 && deltaZ > maxZ) { + throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.large.z", maxZ)); + } + if (deltaX < minX) { + throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.small.x", minX)); + } + if (deltaY < minY) { + throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.small.y", minY)); + } + if (deltaZ < minZ) { + throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.small.z", minZ)); + } + + // Now we run a simple check on each block within that volume. + // Any block deviating = NO DEAL SIR + TileEntity te; + IMultiblockComponent part; + boolean isNextRoof = false; + Class myClass = this.getClass(); + + List internalBlocks = Lists.newArrayList(); + 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++) { + // Okay, figure out what sort of block this should be. + BlockPos pos = new BlockPos(x, y, z); + te = this.worldObj.getTileEntity(pos); + if (te instanceof IMultiblockComponent) { + part = (IMultiblockComponent) te; + } else { + // This is permitted so that we can incorporate certain non-multiblock parts inside interiors + part = null; + } + + // Validate block type against both part-level and material-level validators. + int extremes = 0; + + if (x == minimumCoord.getX()) { + extremes++; + } + if (z == minimumCoord.getZ()) { + extremes++; + } + + if (x == maximumCoord.getX()) { + extremes++; + } + if (z == maximumCoord.getZ()) { + extremes++; + } + + + if (extremes >= 1) { + // Side + BlockPos posUp = pos.add(0, 1, 0); + IBlockState state = worldObj.getBlockState(posUp); + if(!(state.getBlock() instanceof BlockGreenhouse)){ + isNextRoof = true; + break; + } + + int exteriorLevel = y - minimumCoord.getY(); + if (part != null) { + // Ensure this part should actually be allowed within a cube of this controller's type + if (!myClass.equals(part.getMultiblockLogic().getController().getClass())) { + throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.invalid.part", x, y, z, myClass.getSimpleName())); + } + isGoodForExteriorLevel(part, exteriorLevel); + } else { + isBlockGoodForExteriorLevel(exteriorLevel, this.worldObj, pos); + } + } else { + if (part != null) { + if (!myClass.equals(part.getMultiblockLogic().getController().getClass())) { + throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.invalid.part", x, y, z, myClass.getSimpleName())); + } + isGoodForInterior(part); + } else { + isBlockGoodForInterior(this.worldObj, pos); + } + } + } + } + if(isNextRoof){ + addInternalBlock(new InternalBlock(getMinimumCoord().add(1, 1, 1)), internalBlocks); + }else{ + throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.space.closed")); + } + } + this.internalBlocks.addAll(internalBlocks); + } + + private InternalBlock addInternalBlock(InternalBlock internalBlock, List internalBlocks) throws MultiblockValidationException{ + isBlockGoodForInterior(worldObj, internalBlock.pos); + for(Map.Entry entry : internalBlock.testetFaces.entrySet()){ + if(!entry.getValue()){ + BlockPos posFacing = new BlockPos(internalBlock.pos.getX() + entry.getKey().getFrontOffsetX(), internalBlock.pos.getY() + entry.getKey().getFrontOffsetY(), internalBlock.pos.getZ() + entry.getKey().getFrontOffsetZ()); + BlockPos minPos = getMinimumCoord(); + BlockPos maxPos = getMaxXYCoord(); + if(minPos.getX() > posFacing.getX() || minPos.getZ() > posFacing.getZ() || maxPos.getX() < posFacing.getX() || maxPos.getZ() < posFacing.getZ()){ + throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.space.closed")); + } + if(worldObj.getTileEntity(posFacing) instanceof IGreenhouseComponent && worldObj.getBlockState(posFacing).getBlock().isSideSolid(worldObj, posFacing, entry.getKey())){ + entry.setValue(true); + } + internalBlocks.add(addInternalBlock(new InternalBlock(posFacing, entry.getKey(), internalBlock), internalBlocks)); + } + } + return internalBlock; + } + + @Override + public CamouflageType getType() { + return CamouflageType.DEFAULT; + } + + private class InternalBlock{ + public BlockPos pos; + public EnumMap testetFaces = Maps.newEnumMap(EnumFacing.class); + public InternalBlock root; + + public InternalBlock(BlockPos pos) { + this.pos = pos; + for(EnumFacing facing : EnumFacing.VALUES){ + testetFaces.put(facing, false); + } + } + + public InternalBlock(BlockPos pos, EnumFacing facing, InternalBlock root) { + this.pos = pos; + for(EnumFacing f : EnumFacing.VALUES){ + testetFaces.put(facing, f == facing); + } + this.root = root; + } + } + +} diff --git a/src/main/java/forestry/greenhouse/multiblock/GreenhouseMultiblockSizeLimits.java b/src/main/java/forestry/greenhouse/multiblock/GreenhouseMultiblockSizeLimits.java new file mode 100644 index 000000000..55e7bf91e --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/GreenhouseMultiblockSizeLimits.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * 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.multiblock; + +import forestry.core.multiblock.IMultiblockSizeLimits; + +class GreenhouseMultiblockSizeLimits implements IMultiblockSizeLimits { + public static final GreenhouseMultiblockSizeLimits instance = new GreenhouseMultiblockSizeLimits(); + + private GreenhouseMultiblockSizeLimits() { + + } + + @Override + public int getMinimumNumberOfBlocksForAssembledMachine() { + return 5 * 5 * 6; + } + + @Override + public int getMaximumXSize() { + return 64; + } + + @Override + public int getMaximumZSize() { + return 64; + } + + @Override + public int getMaximumYSize() { + return 150; + } + + @Override + public int getMinimumXSize() { + return 5; + } + + @Override + public int getMinimumZSize() { + return 5; + } + + @Override + public int getMinimumYSize() { + return 6; + } +} diff --git a/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java b/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java new file mode 100644 index 000000000..b2896f9ee --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * 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.multiblock; + +import javax.annotation.Nullable; + +import forestry.api.multiblock.IGreenhouseController; +import forestry.core.access.IRestrictedAccess; +import forestry.core.fluids.ITankManager; +import forestry.core.multiblock.IMultiblockControllerInternal; +import forestry.core.network.IStreamableGui; +import forestry.core.tiles.IClimatised; +import forestry.energy.EnergyManager; + +public interface IGreenhouseControllerInternal extends IGreenhouseController, IMultiblockControllerInternal, IClimatised, IRestrictedAccess, IStreamableGui { + + ITankManager getTankManager(); + + @Nullable + EnergyManager getEnergyManager(); + +} diff --git a/src/main/java/forestry/greenhouse/multiblock/MultiblockLogicGreenhouse.java b/src/main/java/forestry/greenhouse/multiblock/MultiblockLogicGreenhouse.java new file mode 100644 index 000000000..7a990dd3c --- /dev/null +++ b/src/main/java/forestry/greenhouse/multiblock/MultiblockLogicGreenhouse.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * 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.multiblock; + +import forestry.api.multiblock.IMultiblockLogicGreenhouse; +import forestry.core.multiblock.MultiblockLogic; +import net.minecraft.world.World; + +public class MultiblockLogicGreenhouse extends MultiblockLogic implements IMultiblockLogicGreenhouse { + + public MultiblockLogicGreenhouse() { + super(IGreenhouseControllerInternal.class); + } + + @Override + public IGreenhouseControllerInternal getController() { + if (super.isConnected()) { + return controller; + } else { + return FakeGreenhouseController.instance; + } + } + + @Override + public IGreenhouseControllerInternal createNewController(World world) { + return new GreenhouseController(world); + } + +} diff --git a/src/main/java/forestry/greenhouse/network/PacketRegistryGreenhouse.java b/src/main/java/forestry/greenhouse/network/PacketRegistryGreenhouse.java new file mode 100644 index 000000000..facddea69 --- /dev/null +++ b/src/main/java/forestry/greenhouse/network/PacketRegistryGreenhouse.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * 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.network; + +import forestry.core.network.PacketRegistry; +import forestry.greenhouse.network.packets.PacketCamouflageUpdate; + +public class PacketRegistryGreenhouse extends PacketRegistry { + @Override + public void registerPackets() { + registerServerPacket(new PacketCamouflageUpdate()); + } +} diff --git a/src/main/java/forestry/greenhouse/network/packets/PacketCamouflageUpdate.java b/src/main/java/forestry/greenhouse/network/packets/PacketCamouflageUpdate.java new file mode 100644 index 000000000..ff88aada7 --- /dev/null +++ b/src/main/java/forestry/greenhouse/network/packets/PacketCamouflageUpdate.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * 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.network.packets; + +import java.io.IOException; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import forestry.api.multiblock.IMultiblockComponent; +import forestry.api.multiblock.IMultiblockController; +import forestry.core.network.DataInputStreamForestry; +import forestry.core.network.DataOutputStreamForestry; +import forestry.core.network.IForestryPacketServer; +import forestry.core.network.PacketIdServer; +import forestry.core.network.packets.PacketCoordinates; +import forestry.core.tiles.ICamouflagedBlock; + +public class PacketCamouflageUpdate extends PacketCoordinates implements IForestryPacketServer { + + private ItemStack camouflageBlock; + private boolean isMultiblock; + + public PacketCamouflageUpdate() { + } + + public PacketCamouflageUpdate(ICamouflagedBlock tile, boolean isMultiblock) { + super(tile.getCoordinates()); + this.camouflageBlock = tile.getCamouflageBlock(); + this.isMultiblock = isMultiblock; + } + + public PacketCamouflageUpdate(ICamouflagedBlock tile) { + super(tile.getCoordinates()); + this.camouflageBlock = tile.getCamouflageBlock(); + this.isMultiblock = false; + } + + @Override + public PacketIdServer getPacketId() { + return PacketIdServer.TILE_FORESTRY_CAMOUFLAGE; + } + + @Override + protected void writeData(DataOutputStreamForestry data) throws IOException { + super.writeData(data); + data.writeBoolean(isMultiblock); + data.writeItemStack(camouflageBlock); + } + + @Override + public void readData(DataInputStreamForestry data) throws IOException { + super.readData(data); + isMultiblock = data.readBoolean(); + camouflageBlock = data.readItemStack(); + } + + @Override + public void onPacketData(DataInputStreamForestry data, EntityPlayerMP player) { + TileEntity tile = getTarget(player.worldObj); + if (tile instanceof ICamouflagedBlock) { + if(isMultiblock){ + if(tile instanceof IMultiblockComponent){ + IMultiblockController controller = ((IMultiblockComponent) tile).getMultiblockLogic().getController(); + if(controller instanceof ICamouflagedBlock){ + ((ICamouflagedBlock) controller).setCamouflageBlock(camouflageBlock); + } + } + }else{ + ((ICamouflagedBlock) tile).setCamouflageBlock(camouflageBlock); + } + } + } +} diff --git a/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouse.java b/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouse.java new file mode 100644 index 000000000..877c17fa2 --- /dev/null +++ b/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouse.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * 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.proxy; + +public class ProxyGreenhouse { + + public void initializeModels() { + } +} diff --git a/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouseClient.java b/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouseClient.java new file mode 100644 index 000000000..6edafb10e --- /dev/null +++ b/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouseClient.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * 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.proxy; + +import net.minecraft.block.Block; +import net.minecraft.client.resources.model.ModelResourceLocation; +import net.minecraft.item.ItemStack; +import forestry.core.models.BlockModelIndex; +import forestry.core.proxy.Proxies; +import forestry.farming.PluginFarming; +import forestry.farming.models.ModelFarmBlock; +import forestry.greenhouse.PluginGreenhouse; +import forestry.greenhouse.blocks.BlockGreenhouseType; +import forestry.greenhouse.models.ModelGreenhouse; + +public class ProxyGreenhouseClient extends ProxyGreenhouse { + + @Override + public void initializeModels() { + for(BlockGreenhouseType greenhouseType : BlockGreenhouseType.VALUES){ + Proxies.render.registerBlockModel(new BlockModelIndex(new ModelResourceLocation("forestry:greenhouse." + greenhouseType), + new ModelResourceLocation("forestry:greenhouse", "inventory"), new ModelGreenhouse(), + Block.getBlockFromItem(PluginGreenhouse.blocks.getGreenhouseBlock(greenhouseType).getItem()))); + } + } +} diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouse.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouse.java new file mode 100644 index 000000000..743332850 --- /dev/null +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhouse.java @@ -0,0 +1,202 @@ +/******************************************************************************* + * 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.tiles; + +import java.io.IOException; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.BlockPos; + +import forestry.api.core.IErrorLogic; +import forestry.api.core.IErrorLogicSource; +import forestry.api.multiblock.IGreenhouseComponent; +import forestry.api.multiblock.IMultiblockController; +import forestry.core.access.EnumAccess; +import forestry.core.access.IAccessHandler; +import forestry.core.access.IRestrictedAccess; +import forestry.core.config.Config; +import forestry.core.gui.IHintSource; +import forestry.core.multiblock.MultiblockTileEntityForestry; +import forestry.core.network.DataInputStreamForestry; +import forestry.core.network.DataOutputStreamForestry; +import forestry.core.network.IStreamableGui; +import forestry.core.proxy.Proxies; +import forestry.core.tiles.ICamouflagedBlock; +import forestry.core.tiles.ITitled; +import forestry.greenhouse.blocks.BlockGreenhouseType; +import forestry.greenhouse.gui.ContainerGreenhouse; +import forestry.greenhouse.gui.GuiGreenhouse; +import forestry.greenhouse.multiblock.MultiblockLogicGreenhouse; +import forestry.greenhouse.network.packets.PacketCamouflageUpdate; + +public abstract class TileGreenhouse extends MultiblockTileEntityForestry implements IGreenhouseComponent, IHintSource, IStreamableGui, IErrorLogicSource, IRestrictedAccess, ITitled, ICamouflagedBlock { + + private ItemStack camouflageBlock; + + protected TileGreenhouse() { + super(new MultiblockLogicGreenhouse()); + camouflageBlock = null; + } + + @Override + public void onMachineAssembled(IMultiblockController multiblockController, BlockPos minCoord, BlockPos maxCoord) { + worldObj.notifyBlockOfStateChange(getPos(), worldObj.getBlockState(pos).getBlock()); + markDirty(); + } + + @Override + public void onMachineBroken() { + worldObj.notifyBlockOfStateChange(getPos(), worldObj.getBlockState(pos).getBlock()); + markDirty(); + } + + @Override + public boolean allowsAutomation() { + return false; + } + + /* SAVING & LOADING */ + @Override + public void readFromNBT(NBTTagCompound nbttagcompound) { + super.readFromNBT(nbttagcompound); + + if(nbttagcompound.hasKey("CamouflageBlock")){ + camouflageBlock = ItemStack.loadItemStackFromNBT(nbttagcompound.getCompoundTag("CamouflageBlock")); + } + } + + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) { + super.writeToNBT(nbttagcompound); + + + if(camouflageBlock != null){ + NBTTagCompound nbtTag = new NBTTagCompound(); + camouflageBlock.writeToNBT(nbtTag); + nbttagcompound.setTag("CamouflageBlock", nbtTag); + } + } + + /* CONSTRUCTION MATERIAL */ + @Override + public boolean setCamouflageBlock(ItemStack camouflageBlock) { + this.camouflageBlock = camouflageBlock; + + if (worldObj != null) { + if (worldObj.isRemote) { + worldObj.markBlockRangeForRenderUpdate(getPos(), getPos()); + } else { + Proxies.net.sendToServer(new PacketCamouflageUpdate(this)); + } + } + return true; + } + + @Override + public ItemStack getCamouflageBlock() { + return camouflageBlock; + } + + public BlockGreenhouseType getGreenhouseBlockType() { + return BlockGreenhouseType.VALUES[getBlockMetadata()]; + } + + /* TILEFORESTRY */ + + @Override + protected void encodeDescriptionPacket(NBTTagCompound packetData) { + super.encodeDescriptionPacket(packetData); + if(camouflageBlock != null){ + NBTTagCompound nbtTag = new NBTTagCompound(); + camouflageBlock.writeToNBT(nbtTag); + packetData.setTag("CamouflageBlock", nbtTag); + } + } + + @Override + protected void decodeDescriptionPacket(NBTTagCompound packetData) { + super.decodeDescriptionPacket(packetData); + if(packetData.hasKey("CamouflageBlock")){ + setCamouflageBlock(ItemStack.loadItemStackFromNBT(packetData.getCompoundTag("CamouflageBlock"))); + } + } + + /* IHintSource */ + @Override + public List getHints() { + return Config.hints.get("greenhouse"); + } + + /* IStreamableGui */ + @Override + public void writeGuiData(DataOutputStreamForestry data) throws IOException { + getMultiblockLogic().getController().writeGuiData(data); + ItemStack camouflageBlock = getCamouflageBlock(); + if(camouflageBlock != null){ + data.writeShort(1); + data.writeItemStack(camouflageBlock); + }else{ + data.writeShort(0); + } + } + + @Override + public void readGuiData(DataInputStreamForestry data) throws IOException { + getMultiblockLogic().getController().readGuiData(data); + if(data.readShort() == 1){ + setCamouflageBlock(data.readItemStack()); + } + + } + + /* IErrorLogicSource */ + @Override + public IErrorLogic getErrorLogic() { + return getMultiblockLogic().getController().getErrorLogic(); + } + + @Override + public IAccessHandler getAccessHandler() { + return getMultiblockLogic().getController().getAccessHandler(); + } + + @Override + public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) { + getMultiblockLogic().getController().onSwitchAccess(oldAccess, newAccess); + } + + /* ITitled */ + @Override + public String getUnlocalizedTitle() { + return "for.gui.greenhouse.title"; + } + + @Override + public Object getGui(EntityPlayer player, int data) { + return new GuiGreenhouse(player, this); + } + + @Override + public Object getContainer(EntityPlayer player, int data) { + return new ContainerGreenhouse(player.inventory, this); + } + + @Override + public CamouflageType getType() { + if(BlockGreenhouseType.VALUES[getBlockMetadata()] == BlockGreenhouseType.GLASS){ + return CamouflageType.GLASS; + } + return CamouflageType.DEFAULT; + } +} diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseClimatiser.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseClimatiser.java new file mode 100644 index 000000000..bb2324734 --- /dev/null +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseClimatiser.java @@ -0,0 +1,116 @@ +package forestry.greenhouse.tiles; + +import forestry.api.core.IClimateControlled; +import forestry.api.greenhouse.IGreenhouseHousing; +import forestry.api.multiblock.IGreenhouseComponent; +import forestry.api.multiblock.IGreenhouseController; +import forestry.apiculture.network.packets.PacketActiveUpdate; +import forestry.core.proxy.Proxies; +import forestry.core.tiles.IActivatable; +import forestry.greenhouse.multiblock.IGreenhouseControllerInternal; +import net.minecraft.nbt.NBTTagCompound; + +public class TileGreenhouseClimatiser extends TileGreenhouse implements IActivatable, IGreenhouseComponent.Climatiser { + + protected static final int WORK_CYCLES = 1; + protected static final int ENERGY_PER_OPERATION = 50; + + protected enum ClimitiserType{ + TEMPERATURE, HUMIDITY + } + + protected interface IClimitiserDefinition { + float getChangePerTransfer(); + + float getBoundaryUp(); + + float getBoundaryDown(); + + ClimitiserType getType(); + } + + private final IClimitiserDefinition definition; + + protected int workingTime = 0; + + private boolean active; + + protected TileGreenhouseClimatiser(IClimitiserDefinition definition) { + this.definition = definition; + } + + @Override + public void changeClimate(int tick, G greenhouse) { + IGreenhouseControllerInternal greenhouseInternal = (IGreenhouseControllerInternal) greenhouse; + if (workingTime < 20 && greenhouseInternal.getEnergyManager().consumeEnergyToDoWork(WORK_CYCLES, ENERGY_PER_OPERATION)) { + // one tick of work for every 10 RF + workingTime += ENERGY_PER_OPERATION / 10; + } + + if (workingTime > 0) { + workingTime--; + if(definition.getType() == ClimitiserType.TEMPERATURE){ + greenhouse.addTemperatureChange(definition.getChangePerTransfer(), definition.getBoundaryDown(), definition.getBoundaryUp()); + }else if(definition.getType() == ClimitiserType.HUMIDITY){ + greenhouse.addHumidityChange(definition.getChangePerTransfer(), definition.getBoundaryDown(), definition.getBoundaryUp()); + } + } + + setActive(workingTime > 0); + } + + /* LOADING & SAVING */ + @Override + public void readFromNBT(NBTTagCompound nbttagcompound) { + super.readFromNBT(nbttagcompound); + workingTime = nbttagcompound.getInteger("Heating"); + setActive(workingTime > 0); + } + + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) { + super.writeToNBT(nbttagcompound); + nbttagcompound.setInteger("Heating", workingTime); + } + + /* Network */ + @Override + protected void encodeDescriptionPacket(NBTTagCompound packetData) { + super.encodeDescriptionPacket(packetData); + packetData.setBoolean("Active", active); + } + + @Override + protected void decodeDescriptionPacket(NBTTagCompound packetData) { + super.decodeDescriptionPacket(packetData); + setActive(packetData.getBoolean("Active")); + } + + /* IActivatable */ + @Override + public boolean isActive() { + return active; + } + + public IClimitiserDefinition getDefinition() { + return definition; + } + + @Override + public void setActive(boolean active) { + if (this.active == active) { + return; + } + + this.active = active; + + if (worldObj != null) { + if (worldObj.isRemote) { + worldObj.markBlockRangeForRenderUpdate(getPos(), getPos()); + } else { + Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this), worldObj); + } + } + } + +} diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseControl.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseControl.java new file mode 100644 index 000000000..15c603f62 --- /dev/null +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseControl.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * 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.tiles; + +import net.minecraft.util.EnumFacing; +import net.minecraft.world.World; + +import forestry.api.greenhouse.DefaultGreenhouseListener; +import forestry.api.greenhouse.IGreenhouseHousing; +import forestry.api.greenhouse.IGreenhouseListener; +import forestry.api.multiblock.IGreenhouseComponent; +import forestry.api.multiblock.IGreenhouseController; +import forestry.core.utils.vect.Vect; + +public class TileGreenhouseControl extends TileGreenhouse implements IGreenhouseComponent.Listener { + + private final IGreenhouseListener greenhouseListener; + + public TileGreenhouseControl() { + this.greenhouseListener = new ControlGreenhouseListener(this); + } + + @Override + public IGreenhouseListener getGreenhouseListener() { + return greenhouseListener; + } + + private static class ControlGreenhouseListener extends DefaultGreenhouseListener { + private final TileGreenhouseControl tile; + + public ControlGreenhouseListener(TileGreenhouseControl tile) { + this.tile = tile; + } + + @Override + public boolean canWork(G greenhouse) { + return hasRedstoneSignal(); + } + + private boolean hasRedstoneSignal() { + for(EnumFacing direction : EnumFacing.VALUES){ + Vect side = new Vect(tile).add(direction); + EnumFacing dir = direction.getOpposite(); + World world = tile.getWorld(); + if(world.getRedstonePower(side, dir) > 0 || world.getStrongPower(side, dir) > 0){ + return true; + } + } + return false; + } + } + +} diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseDryer.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseDryer.java new file mode 100644 index 000000000..b4daebcc3 --- /dev/null +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseDryer.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * 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.tiles; + +public class TileGreenhouseDryer extends TileGreenhouseClimatiser { + + private static final DryerDefinition definition = new DryerDefinition(); + + public TileGreenhouseDryer() { + super(definition); + } + + private static class DryerDefinition implements IClimitiserDefinition { + + @Override + public float getChangePerTransfer() { + return -0.01f; + } + + @Override + public float getBoundaryUp() { + return 2.5f; + } + + @Override + public float getBoundaryDown() { + return 0.05f; + } + + @Override + public ClimitiserType getType() { + return ClimitiserType.HUMIDITY; + } + } + +} diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseFan.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseFan.java new file mode 100644 index 000000000..9a4e3d7f1 --- /dev/null +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseFan.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * 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.tiles; + + +public class TileGreenhouseFan extends TileGreenhouseClimatiser { + + private static final FanDefinition definition = new FanDefinition(); + + public TileGreenhouseFan() { + super(definition); + } + + private static class FanDefinition implements IClimitiserDefinition { + + @Override + public float getChangePerTransfer() { + return -0.01f; + } + + @Override + public float getBoundaryUp() { + return 2.5f; + } + + @Override + public float getBoundaryDown() { + return 0.05f; + } + + @Override + public ClimitiserType getType() { + return ClimitiserType.TEMPERATURE; + } + } + +} diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseGearbox.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseGearbox.java new file mode 100644 index 000000000..9ddc32453 --- /dev/null +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseGearbox.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * 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.tiles; + +import net.minecraft.util.EnumFacing; + +import forestry.energy.EnergyManager; + +import cofh.api.energy.IEnergyHandler; +import cofh.api.energy.IEnergyReceiver; + +public class TileGreenhouseGearbox extends TileGreenhouse implements IEnergyReceiver, IEnergyHandler { + + public TileGreenhouseGearbox() { + } + + /* IEnergyReceiver */ + @Override + public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) { + if(getEnergyManager() == null) + return 0; + return getEnergyManager().receiveEnergy(from, maxReceive, simulate); + } + + @Override + public int getEnergyStored(EnumFacing from) { + if(getEnergyManager() == null) + return 0; + return getEnergyManager().getEnergyStored(from); + } + + @Override + public int getMaxEnergyStored(EnumFacing from) { + if(getEnergyManager() == null) + return 0; + return getEnergyManager().getMaxEnergyStored(from); + } + + @Override + public boolean canConnectEnergy(EnumFacing from) { + return getEnergyManager() != null && getEnergyManager().canConnectEnergy(from); + } + + private EnergyManager getEnergyManager() { + if(!getMultiblockLogic().isConnected()) + return null; + return getMultiblockLogic().getController().getEnergyManager(); + } + +} diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseHeater.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseHeater.java new file mode 100644 index 000000000..1fd93df19 --- /dev/null +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseHeater.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * 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.tiles; + +public class TileGreenhouseHeater extends TileGreenhouseClimatiser{ + + private static final HeaterDefinition definition = new HeaterDefinition(); + + public TileGreenhouseHeater() { + super(definition); + } + + private static class HeaterDefinition implements IClimitiserDefinition { + + @Override + public float getChangePerTransfer() { + return 0.01f; + } + + @Override + public float getBoundaryUp() { + return 2.5f; + } + + @Override + public float getBoundaryDown() { + return 0.0f; + } + + @Override + public ClimitiserType getType() { + return ClimitiserType.TEMPERATURE; + } + } + +} diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhousePlain.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhousePlain.java new file mode 100644 index 000000000..9ac011d68 --- /dev/null +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhousePlain.java @@ -0,0 +1,15 @@ +/******************************************************************************* + * 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.tiles; + +public class TileGreenhousePlain extends TileGreenhouse { + +} diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseSprinkler.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseSprinkler.java new file mode 100644 index 000000000..d8725aa8a --- /dev/null +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseSprinkler.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * 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.tiles; + +import forestry.api.core.IClimateControlled; +import forestry.api.greenhouse.IGreenhouseHousing; +import forestry.api.multiblock.IGreenhouseController; +import forestry.core.fluids.tanks.StandardTank; +import forestry.greenhouse.multiblock.IGreenhouseControllerInternal; + +public class TileGreenhouseSprinkler extends TileGreenhouseClimatiser { + + protected static final int WATER_PER_OPERATION = 75; + private static final SprinklerDefinition definition = new SprinklerDefinition(); + + public TileGreenhouseSprinkler() { + super(definition); + } + + @Override + public void changeClimate(int tick, G greenhouse) { + IGreenhouseControllerInternal greenhouseInternal = (IGreenhouseControllerInternal) greenhouse; + if (workingTime < 20 && consumeWaterToDoWork(WORK_CYCLES, WATER_PER_OPERATION, (StandardTank) greenhouseInternal.getTankManager().getTank(0))) { + // one tick of work for every 10 RF + workingTime += ENERGY_PER_OPERATION / 10; + } + + if (workingTime > 0) { + workingTime--; + greenhouse.addHumidityChange(definition.getChangePerTransfer(), definition.getBoundaryDown(), definition.getBoundaryUp()); + } + + setActive(workingTime > 0); + } + + public boolean consumeWaterToDoWork(int ticksPerWorkCycle, int fluidPerWorkCycle, StandardTank tank) { + int fluidPerCycle = (int) Math.ceil(fluidPerWorkCycle / (float) ticksPerWorkCycle); + if (tank.getFluid().amount < fluidPerCycle) { + return false; + } + + modifyWaterStored(-fluidPerCycle, tank); + return true; + } + + public void modifyWaterStored(int fluid, StandardTank tank) { + + tank.getFluid().amount += fluid; + + if (tank.getFluid().amount > tank.getCapacity()) { + tank.getFluid().amount = tank.getCapacity(); + } else if (tank.getFluid().amount < 0) { + tank.getFluid().amount = 0; + } + } + + private static class SprinklerDefinition implements IClimitiserDefinition { + + @Override + public float getChangePerTransfer() { + return 0.02f; + } + + @Override + public float getBoundaryUp() { + return 2.5f; + } + + @Override + public float getBoundaryDown() { + return 0.05f; + } + + @Override + public ClimitiserType getType() { + return ClimitiserType.HUMIDITY; + } + } + +} diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseValve.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseValve.java new file mode 100644 index 000000000..3d8a1f7d5 --- /dev/null +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseValve.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * 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.tiles; + +import net.minecraft.util.EnumFacing; + +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidHandler; + +import forestry.core.fluids.ITankManager; +import forestry.core.tiles.ILiquidTankTile; + +public class TileGreenhouseValve extends TileGreenhouse implements ILiquidTankTile, IFluidHandler { + + /* ILIQUIDTANKCONTAINER */ + @Override + public int fill(EnumFacing from, FluidStack resource, boolean doFill) { + return getTankManager().fill(from, resource, doFill); + } + + @Override + public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain) { + return getTankManager().drain(from, resource, doDrain); + } + + @Override + public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain) { + return getTankManager().drain(from, maxDrain, doDrain); + } + + @Override + public boolean canFill(EnumFacing from, Fluid fluid) { + return getTankManager().canFill(from, fluid); + } + + @Override + public boolean canDrain(EnumFacing from, Fluid fluid) { + return getTankManager().canDrain(from, fluid); + } + + @Override + public FluidTankInfo[] getTankInfo(EnumFacing from) { + return getTankManager().getTankInfo(from); + } + + @Override + public ITankManager getTankManager() { + return getMultiblockLogic().getController().getTankManager(); + } +} diff --git a/src/main/java/forestry/plugins/ForestryPluginUids.java b/src/main/java/forestry/plugins/ForestryPluginUids.java index f3625d4e7..a1734534a 100644 --- a/src/main/java/forestry/plugins/ForestryPluginUids.java +++ b/src/main/java/forestry/plugins/ForestryPluginUids.java @@ -7,6 +7,7 @@ public class ForestryPluginUids { public static final String ENERGY = "forestry.energy"; public static final String FACTORY = "forestry.factory"; public static final String FARMING = "forestry.farming"; + public static final String GREENHOUSE = "forestry.greenhouse"; public static final String FLUIDS = "forestry.fluids"; public static final String FOOD = "forestry.food"; public static final String LEPIDOPTEROLOGY = "forestry.lepidopterology"; diff --git a/src/main/resources/assets/forestry/textures/gui/greenhouse.png b/src/main/resources/assets/forestry/textures/gui/greenhouse.png new file mode 100644 index 000000000..8f95f13b7 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/gui/greenhouse.png differ