Add Basic Greenhouse

This commit is contained in:
Nedelosk committed 2016-03-12 21:43:13 +01:00
1 parent c28c1c4298
commit 9a0e5dc3e3
63 files changed
+2527 -164

No files matched your search

@@ -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);
@@ -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 <G extends IGreenhouseController & IGreenhouseHousing> boolean canWork(G greenhouse) {
return true;
}
}
@@ -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();
}
@@ -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
*/
<G extends IGreenhouseController & IGreenhouseHousing> boolean canWork(G greenhouse);
}
@@ -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<T extends IMultiblockLogicGreenhouse> extends IMultiblockComponent {
@Override
T getMultiblockLogic();
interface Listener extends IGreenhouseComponent {
IGreenhouseListener getGreenhouseListener();
}
interface Climatiser extends IGreenhouseComponent {
<G extends IGreenhouseController & IGreenhouseHousing & IClimateControlled> void changeClimate(int tickCount, G greenhouse);
}
interface Active extends IGreenhouseComponent {
void updateServer(int tickCount);
void updateClient(int tickCount);
}
}
@@ -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 {
}
@@ -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();
}
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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
@@ -1,4 +1,4 @@
package forestry.arboriculture.render;
package forestry.arboriculture.models;
import java.util.Map;
@@ -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<BlockDecorativeLeav
}
@Override
protected boolean bakeWorldBlock(BlockDecorativeLeaves block, IBlockAccess world, BlockPos pos, IModelBaker baker) {
return false;
protected void bakeWorldBlock(BlockDecorativeLeaves block, IBlockAccess world, BlockPos pos, IExtendedBlockState stateExtended, IModelBaker baker) {
}
public static boolean bakeBlock(BlockDecorativeLeaves block, TreeDefinition treeDefinition, IModelBaker baker) {
public static void bakeBlock(BlockDecorativeLeaves block, TreeDefinition treeDefinition, IModelBaker baker) {
if (treeDefinition == null) {
return false;
return;
}
ITreeGenome genome = treeDefinition.getGenome();
@@ -101,7 +100,5 @@ public class ModelDecorativeLeaves extends ModelBlockOverlay<BlockDecorativeLeav
// Set the particle sprite
baker.setParticleSprite(leaveSprite);
return true;
}
}
@@ -8,13 +8,13 @@
* 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.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.arboriculture.blocks.BlockForestryLeaves;
import forestry.arboriculture.genetics.TreeRoot;
@@ -63,10 +63,10 @@ public class ModelLeaves extends ModelBlockOverlay<BlockForestryLeaves> {
}
@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<BlockForestryLeaves> {
// Set the particle sprite
baker.setParticleSprite(leaveSprite);
return true;
}
}
@@ -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;
@@ -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;
@@ -1,4 +1,4 @@
package forestry.arboriculture.render;
package forestry.arboriculture.models;
import com.google.common.collect.Maps;
@@ -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;
@@ -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<EnumLeafType, TextureLeaves> 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<EnumLeafType, TextureLeaves> 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;
}
}
@@ -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;
@@ -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));
@@ -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 {
@@ -115,7 +115,7 @@ public abstract class ModelBlockOverlay<B extends Block> 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<B extends Block> 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);
}
@@ -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<ModelBakerFace> faces = new ArrayList<>();
private final List<IBakedModel> 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;
}
@@ -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.
*/
@@ -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;
@@ -30,6 +30,9 @@ public enum PacketIdServer implements IPacketId {
// Factory
WORKTABLE_NEI_SELECT,
//Greenhouse
TILE_FORESTRY_CAMOUFLAGE,
// Mail
LETTER_INFO_REQUEST,
@@ -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));
@@ -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
}
}
@@ -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;
}
@@ -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;
}
@@ -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<BlockFarm> {
}
@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<BlockFarm> {
// Set the particle sprite
baker.setParticleSprite(textures[0]);
return true;
}
private static TextureAtlasSprite[] getSprites(EnumFarmBlockTexture texture) {
@@ -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<ItemStack> 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();
}
}
@@ -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<BlockGreenhouseType, BlockGreenhouse> create() {
Map<BlockGreenhouseType, BlockGreenhouse> 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<ItemStack> 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();
}
@@ -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<TextureAtlasSprite> 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);
}
}
@@ -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<BlockGreenhouseType, BlockGreenhouse> 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);
}
}
@@ -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<TileGreenhouse> {
public ContainerGreenhouse(InventoryPlayer playerInventory, TileGreenhouse tile) {
super(tile, playerInventory, 8, 84);
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
PacketGuiUpdate packet = new PacketGuiUpdate(tile);
sendPacketToCrafters(packet);
}
}
@@ -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<ContainerGreenhouse, TileGreenhouse> {
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();
}
}
@@ -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));
}
};
}
@@ -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<BlockGreenhouse> {
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);
}
}
}
@@ -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;
}
}
@@ -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<InternalBlock> internalBlocks = Lists.newArrayList();
private final Set<IGreenhouseComponent.Listener> listenerComponents = new HashSet<>();
private final Set<IGreenhouseComponent.Climatiser> climatiserComponents = new HashSet<>();
private final Set<IGreenhouseComponent.Active> 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<? extends RectangularMultiblockControllerBase> myClass = this.getClass();
List<InternalBlock> 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<InternalBlock> internalBlocks) throws MultiblockValidationException{
isBlockGoodForInterior(worldObj, internalBlock.pos);
for(Map.Entry<EnumFacing, Boolean> 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<EnumFacing, Boolean> 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;
}
}
}
@@ -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;
}
}
@@ -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();
}
@@ -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<IGreenhouseControllerInternal> 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);
}
}
@@ -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());
}
}
@@ -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);
}
}
}
}
@@ -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() {
}
}
@@ -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())));
}
}
}
@@ -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<MultiblockLogicGreenhouse> 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<String> 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;
}
}
@@ -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 <G extends IGreenhouseController & IGreenhouseHousing & IClimateControlled> 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);
}
}
}
}
@@ -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 <G extends IGreenhouseController & IGreenhouseHousing> 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;
}
}
}
@@ -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;
}
}
}
@@ -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;
}
}
}
@@ -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();
}
}
@@ -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;
}
}
}
@@ -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 {
}
@@ -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 <G extends IGreenhouseController & IGreenhouseHousing & IClimateControlled> 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;
}
}
}
@@ -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();
}
}
@@ -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";