diff --git a/src/main/java/forestry/api/greenhouse/IGreenhouseHousing.java b/src/main/java/forestry/api/greenhouse/IGreenhouseHousing.java index 39828fb10..ab6eee873 100644 --- a/src/main/java/forestry/api/greenhouse/IGreenhouseHousing.java +++ b/src/main/java/forestry/api/greenhouse/IGreenhouseHousing.java @@ -8,14 +8,14 @@ package forestry.api.greenhouse; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; import forestry.api.core.IErrorLogicSource; +import forestry.core.tiles.IClimatised; +import net.minecraft.util.BlockPos; import net.minecraft.world.World; -public interface IGreenhouseHousing extends IErrorLogicSource { - - EnumTemperature getTemperature(); - - EnumHumidity getHumidity(); +public interface IGreenhouseHousing extends IErrorLogicSource, IClimatised { World getWorld(); + boolean isInGreenhouse(BlockPos pos); + } diff --git a/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java b/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java index 88dc232f2..49f7b1f54 100644 --- a/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java +++ b/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java @@ -537,24 +537,6 @@ public abstract class MultiblockControllerBase implements IMultiblockControllerI } } - protected BlockPos getMaxXYCoord() { - BlockPos maximumCoord = new BlockPos(0, 0, 0); - - for (IMultiblockComponent part : connectedParts) { - BlockPos partCoords = part.getCoordinates(); - int maxX = maximumCoord.getX(); - int maxZ = maximumCoord.getZ(); - if (partCoords.getX() > maximumCoord.getX()) { - maxX = partCoords.getX(); - } - if (partCoords.getZ() > maximumCoord.getZ()) { - maxZ = partCoords.getZ(); - } - maximumCoord = new BlockPos(maxX, 0, maxZ); - } - return maximumCoord; - } - /** * @return The minimum bounding-box coordinate containing this machine's blocks. */ diff --git a/src/main/java/forestry/greenhouse/PluginGreenhouse.java b/src/main/java/forestry/greenhouse/PluginGreenhouse.java index a6b14c5b0..a508f987d 100644 --- a/src/main/java/forestry/greenhouse/PluginGreenhouse.java +++ b/src/main/java/forestry/greenhouse/PluginGreenhouse.java @@ -6,21 +6,27 @@ 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.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; 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.common.registry.GameRegistry; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -38,6 +44,20 @@ public class PluginGreenhouse extends BlankForestryPlugin { blocks = new BlockRegistryGreenhouse(); } + @Override + public void doInit() { + super.doInit(); + + GameRegistry.registerTileEntity(TileGreenhouseFan.class, "forestry.greenhouse.fan"); + GameRegistry.registerTileEntity(TileGreenhouseHeater.class, "forestry.greenhouse.heater"); + GameRegistry.registerTileEntity(TileGreenhouseDryer.class, "forestry.greenhouse.dryer"); + GameRegistry.registerTileEntity(TileGreenhouseSprinkler.class, "forestry.greenhouse.sprinkler"); + GameRegistry.registerTileEntity(TileGreenhouseValve.class, "forestry.greenhouse.valve"); + GameRegistry.registerTileEntity(TileGreenhouseGearbox.class, "forestry.greenhouse.gearbox"); + GameRegistry.registerTileEntity(TileGreenhouseControl.class, "forestry.greenhouse.controller"); + GameRegistry.registerTileEntity(TileGreenhousePlain.class, "forestry.greenhouse.plain"); + } + @Override public void preInit(){ MinecraftForge.EVENT_BUS.register(this); diff --git a/src/main/java/forestry/greenhouse/blocks/BlockGreenhouse.java b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouse.java index 29915a1a9..221969638 100644 --- a/src/main/java/forestry/greenhouse/blocks/BlockGreenhouse.java +++ b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouse.java @@ -16,6 +16,7 @@ import java.util.Map; import javax.annotation.Nonnull; +import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; @@ -23,6 +24,7 @@ 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.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; @@ -121,11 +123,6 @@ public abstract class BlockGreenhouse extends BlockStructure { public void getSubBlocks(Item item, CreativeTabs tab, List list) { list.add(new ItemStack(item)); } - - @Override - public int damageDropped(IBlockState state) { - return getMetaFromState(state); - } @Override public TileEntity createTileEntity(World world, IBlockState state) { @@ -159,18 +156,44 @@ public abstract class BlockGreenhouse extends BlockStructure { @Override @SideOnly(Side.CLIENT) public EnumWorldBlockLayer getBlockLayer() { + if(getGreenhouseType() == BlockGreenhouseType.GLASS){ + return EnumWorldBlockLayer.TRANSLUCENT; + } 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); + public boolean isFullCube() { + return getGreenhouseType() != BlockGreenhouseType.GLASS && getGreenhouseType() == BlockGreenhouseType.SPRINKLER; } + @Override + public boolean isOpaqueCube() { + return getGreenhouseType() != BlockGreenhouseType.GLASS; + } + + @SideOnly(Side.CLIENT) + public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side) + { + IBlockState iblockstate = worldIn.getBlockState(pos); + Block block = iblockstate.getBlock(); + + if (getGreenhouseType() == BlockGreenhouseType.GLASS) + { + if (worldIn.getBlockState(pos.offset(side.getOpposite())) != iblockstate) + { + return true; + } + + if (block == this) + { + return false; + } + } + + return block == this ? false : super.shouldSideBeRendered(worldIn, pos, side); + } + @SideOnly(Side.CLIENT) @Override public void registerModel(Item item, IModelManager manager) { diff --git a/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseType.java b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseType.java index 829f8275a..bcbd0df75 100644 --- a/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseType.java +++ b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseType.java @@ -72,7 +72,6 @@ public enum BlockGreenhouseType { 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") ); diff --git a/src/main/java/forestry/greenhouse/models/ModelGreenhouse.java b/src/main/java/forestry/greenhouse/models/ModelGreenhouse.java index c28e0d51f..9fbf39f48 100644 --- a/src/main/java/forestry/greenhouse/models/ModelGreenhouse.java +++ b/src/main/java/forestry/greenhouse/models/ModelGreenhouse.java @@ -5,6 +5,7 @@ import forestry.greenhouse.blocks.BlockGreenhouseType; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BlockModelShapes; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; @@ -45,11 +46,24 @@ public class ModelGreenhouse extends ModelBlockOverlay { BlockModelShapes modelShapes = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes(); baker.addBakedModel(modelShapes.getModelForState(Block.getBlockFromItem(camouflageBlockStack.getItem()).getStateFromMeta(camouflageBlockStack.getItemDamage()))); } + else if(block.getGreenhouseType() == BlockGreenhouseType.GLASS){ + TextureAtlasSprite glassSprite = BlockGreenhouseType.getSprite(BlockGreenhouseType.GLASS, null); + baker.addBlockModel(block, pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.GLASS, null), 100); + baker.setParticleSprite(glassSprite); + }else{ + TextureAtlasSprite plainSprite = BlockGreenhouseType.getSprite(BlockGreenhouseType.PLAIN, null); + baker.addBlockModel(block, pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.PLAIN, null), 100); + baker.setParticleSprite(plainSprite); + } }else{ if(block.getGreenhouseType() == BlockGreenhouseType.GLASS){ + TextureAtlasSprite glassSprite = BlockGreenhouseType.getSprite(BlockGreenhouseType.GLASS, null); baker.addBlockModel(block, pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.GLASS, null), 100); + baker.setParticleSprite(glassSprite); }else{ + TextureAtlasSprite plainSprite = BlockGreenhouseType.getSprite(BlockGreenhouseType.PLAIN, null); baker.addBlockModel(block, pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.PLAIN, null), 100); + baker.setParticleSprite(plainSprite); } } if(block.getGreenhouseType() != BlockGreenhouseType.PLAIN && block.getGreenhouseType() != BlockGreenhouseType.GLASS){ diff --git a/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java b/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java index 50f6f15c5..84550357c 100644 --- a/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java +++ b/src/main/java/forestry/greenhouse/multiblock/FakeGreenhouseController.java @@ -14,6 +14,7 @@ import forestry.core.fluids.FakeTankManager; import forestry.core.fluids.ITankManager; import forestry.core.multiblock.FakeMultiblockController; import forestry.energy.EnergyManager; +import net.minecraft.util.BlockPos; public class FakeGreenhouseController extends FakeMultiblockController implements IGreenhouseControllerInternal { public static final FakeGreenhouseController instance = new FakeGreenhouseController(); @@ -31,5 +32,10 @@ public class FakeGreenhouseController extends FakeMultiblockController implement public EnergyManager getEnergyManager() { return null; } + + @Override + public boolean isInGreenhouse(BlockPos pos) { + return false; + } } diff --git a/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java b/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java index 6fb2ce268..87cc6e99d 100644 --- a/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java +++ b/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java @@ -42,6 +42,7 @@ import forestry.core.tiles.ILiquidTankTile; import forestry.energy.EnergyManager; import forestry.greenhouse.blocks.BlockGreenhouse; import forestry.greenhouse.network.packets.PacketCamouflageUpdate; +import forestry.greenhouse.tiles.TileGreenhouseSprinkler; import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -341,6 +342,20 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im } + @Override + protected void isBlockGoodForInterior(World world, BlockPos pos) throws MultiblockValidationException { + } + + @Override + public boolean isInGreenhouse(BlockPos pos) { + for(InternalBlock inerBlock : internalBlocks){ + if(inerBlock.pos.equals(pos)){ + return true; + } + } + return false; + } + @Override protected void isMachineWhole() throws MultiblockValidationException { int minX = getSizeLimits().getMinimumXSize(); @@ -442,7 +457,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im } } else { if (part != null) { - if (!myClass.equals(part.getMultiblockLogic().getController().getClass())) { + if (myClass.equals(part.getMultiblockLogic().getController().getClass())) { throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.invalid.part", x, y, z, myClass.getSimpleName())); } isGoodForInterior(part); @@ -453,31 +468,49 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im } } if(isNextRoof){ - addInternalBlock(new InternalBlock(getMinimumCoord().add(1, 1, 1)), internalBlocks); - }else{ - throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.space.closed")); + InternalBlock iB = new InternalBlock(getMinimumCoord().add(1, 1, 1)); + internalBlocks.add(iB); + addInternalBlock(iB, internalBlocks); + break; } } + if(internalBlocks.isEmpty()){ + throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.space.closed")); + } this.internalBlocks.addAll(internalBlocks); } - private InternalBlock addInternalBlock(InternalBlock internalBlock, List internalBlocks) throws MultiblockValidationException{ + private void addInternalBlock(InternalBlock internalBlock, List internalBlocks) throws MultiblockValidationException{ isBlockGoodForInterior(worldObj, internalBlock.pos); for(Map.Entry entry : internalBlock.testetFaces.entrySet()){ if(!entry.getValue()){ BlockPos posFacing = new BlockPos(internalBlock.pos.getX() + entry.getKey().getFrontOffsetX(), internalBlock.pos.getY() + entry.getKey().getFrontOffsetY(), internalBlock.pos.getZ() + entry.getKey().getFrontOffsetZ()); BlockPos minPos = getMinimumCoord(); - BlockPos maxPos = getMaxXYCoord(); + BlockPos maxPos = getMaximumCoord(); 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); + + TileEntity tile = worldObj.getTileEntity(posFacing); + + if(tile instanceof IGreenhouseComponent){ + if(((IGreenhouseComponent) tile).getMultiblockLogic().getController() != this){ + throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.not.connected.part", posFacing.getX(), posFacing.getY(), posFacing.getZ())); + } + else if(!(tile instanceof TileGreenhouseSprinkler)){ + entry.setValue(true); + } + }else{ + InternalBlock iB = new InternalBlock(posFacing, entry.getKey().getOpposite(), internalBlock); + if(!internalBlocks.contains(iB)){ + internalBlocks.add(iB); + addInternalBlock(iB, internalBlocks); + }else{ + entry.setValue(true); + } } - internalBlocks.add(addInternalBlock(new InternalBlock(posFacing, entry.getKey(), internalBlock), internalBlocks)); } } - return internalBlock; } @Override @@ -485,25 +518,34 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im return CamouflageType.DEFAULT; } - private class InternalBlock{ + private static class InternalBlock{ public BlockPos pos; public EnumMap testetFaces = Maps.newEnumMap(EnumFacing.class); public InternalBlock root; - public InternalBlock(BlockPos pos) { + private InternalBlock(BlockPos pos) { this.pos = pos; for(EnumFacing facing : EnumFacing.VALUES){ testetFaces.put(facing, false); } } - public InternalBlock(BlockPos pos, EnumFacing facing, InternalBlock root) { + private InternalBlock(BlockPos pos, EnumFacing facing, InternalBlock root) { this.pos = pos; for(EnumFacing f : EnumFacing.VALUES){ - testetFaces.put(facing, f == facing); + testetFaces.put(f, f == facing); } this.root = root; } + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof InternalBlock)){ + return false; + } + InternalBlock ib = (InternalBlock) obj; + return ib.pos.equals(pos); + } } } diff --git a/src/main/java/forestry/greenhouse/multiblock/GreenhouseMultiblockSizeLimits.java b/src/main/java/forestry/greenhouse/multiblock/GreenhouseMultiblockSizeLimits.java index 55e7bf91e..22629a967 100644 --- a/src/main/java/forestry/greenhouse/multiblock/GreenhouseMultiblockSizeLimits.java +++ b/src/main/java/forestry/greenhouse/multiblock/GreenhouseMultiblockSizeLimits.java @@ -21,7 +21,7 @@ class GreenhouseMultiblockSizeLimits implements IMultiblockSizeLimits { @Override public int getMinimumNumberOfBlocksForAssembledMachine() { - return 5 * 5 * 6; + return 5 * 5 * 5 - 36; } @Override @@ -51,6 +51,6 @@ class GreenhouseMultiblockSizeLimits implements IMultiblockSizeLimits { @Override public int getMinimumYSize() { - return 6; + return 5; } } diff --git a/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java b/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java index b2896f9ee..fda716c0e 100644 --- a/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java +++ b/src/main/java/forestry/greenhouse/multiblock/IGreenhouseControllerInternal.java @@ -20,7 +20,7 @@ import forestry.core.network.IStreamableGui; import forestry.core.tiles.IClimatised; import forestry.energy.EnergyManager; -public interface IGreenhouseControllerInternal extends IGreenhouseController, IMultiblockControllerInternal, IClimatised, IRestrictedAccess, IStreamableGui { +public interface IGreenhouseControllerInternal extends IGreenhouseController, IMultiblockControllerInternal, IRestrictedAccess, IStreamableGui { ITankManager getTankManager(); diff --git a/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouseClient.java b/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouseClient.java index 6edafb10e..0b0188d07 100644 --- a/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouseClient.java +++ b/src/main/java/forestry/greenhouse/proxy/ProxyGreenhouseClient.java @@ -12,11 +12,8 @@ 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; diff --git a/src/main/resources/assets/forestry/textures/blocks/greenhouse/control.png b/src/main/resources/assets/forestry/textures/blocks/greenhouse/control.png new file mode 100644 index 000000000..37df85dbf Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/greenhouse/control.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/greenhouse/fan.off.png b/src/main/resources/assets/forestry/textures/blocks/greenhouse/fan.off.png new file mode 100644 index 000000000..92e13e9f3 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/greenhouse/fan.off.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/greenhouse/fan.on.png b/src/main/resources/assets/forestry/textures/blocks/greenhouse/fan.on.png new file mode 100644 index 000000000..f41110ebb Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/greenhouse/fan.on.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/greenhouse/gears.png b/src/main/resources/assets/forestry/textures/blocks/greenhouse/gears.png new file mode 100644 index 000000000..59bf36b01 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/greenhouse/gears.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/greenhouse/heater.off.png b/src/main/resources/assets/forestry/textures/blocks/greenhouse/heater.off.png new file mode 100644 index 000000000..ef81898b3 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/greenhouse/heater.off.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/greenhouse/heater.on.png b/src/main/resources/assets/forestry/textures/blocks/greenhouse/heater.on.png new file mode 100644 index 000000000..fc8f2eb7b Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/greenhouse/heater.on.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/greenhouse/valve.png b/src/main/resources/assets/forestry/textures/blocks/greenhouse/valve.png new file mode 100644 index 000000000..39d88861b Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/greenhouse/valve.png differ