diff --git a/src/main/java/forestry/api/greenhouse/IGreenhouseHelper.java b/src/main/java/forestry/api/greenhouse/IGreenhouseHelper.java index b80623e9e..b6bf7e255 100644 --- a/src/main/java/forestry/api/greenhouse/IGreenhouseHelper.java +++ b/src/main/java/forestry/api/greenhouse/IGreenhouseHelper.java @@ -8,7 +8,10 @@ package forestry.api.greenhouse; import javax.annotation.Nullable; import java.util.List; +import forestry.api.climate.IClimateInfo; import forestry.api.multiblock.IGreenhouseController; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -20,8 +23,14 @@ public interface IGreenhouseHelper { @Nullable IGreenhouseController getGreenhouseController(World world, BlockPos pos); - void addGreenhouseLogic(Class logic); + void registerGreenhouseLogic(Class logic); List> getGreenhouseLogics(); + + void registerTerrainRecipe(Block inputBlock, IBlockState outputState, IClimateInfo minClimate, IClimateInfo maxClimate, float chance); + + void registerTerrainRecipe(IBlockState inputState, IBlockState outputState, IClimateInfo minClimate, IClimateInfo maxClimate, float chance); + + ITerrainRecipe getValidTerrainRecipe(IBlockState blockState, IClimateInfo climateInfo); } diff --git a/src/main/java/forestry/api/greenhouse/IOvergrowth.java b/src/main/java/forestry/api/greenhouse/IOvergrowth.java new file mode 100644 index 000000000..6d53f23d8 --- /dev/null +++ b/src/main/java/forestry/api/greenhouse/IOvergrowth.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * 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.climate.IClimateInfo; + +public interface IOvergrowth { + + IClimateInfo getMinClimate(); + + IClimateInfo getMaxClimate(); + + float getChance(); + +} diff --git a/src/main/java/forestry/api/greenhouse/ITerrainRecipe.java b/src/main/java/forestry/api/greenhouse/ITerrainRecipe.java index 4f7a06389..c6f5bc4c5 100644 --- a/src/main/java/forestry/api/greenhouse/ITerrainRecipe.java +++ b/src/main/java/forestry/api/greenhouse/ITerrainRecipe.java @@ -1,3 +1,8 @@ +/******************************************************************************* + * 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.climate.IClimateInfo; @@ -5,12 +10,14 @@ import net.minecraft.block.state.IBlockState; public interface ITerrainRecipe { - IBlockState getInput(); + boolean matches(IBlockState blockState); IBlockState getResult(); IClimateInfo getMinClimate(); IClimateInfo getMaxClimate(); + + float getChance(); } diff --git a/src/main/java/forestry/api/multiblock/IMultiblockController.java b/src/main/java/forestry/api/multiblock/IMultiblockController.java index 0b1d08a69..41e4c37a0 100644 --- a/src/main/java/forestry/api/multiblock/IMultiblockController.java +++ b/src/main/java/forestry/api/multiblock/IMultiblockController.java @@ -6,6 +6,9 @@ package forestry.api.multiblock; import javax.annotation.Nullable; + +import net.minecraft.util.math.BlockPos; + import java.util.Collection; /** @@ -33,6 +36,9 @@ public interface IMultiblockController { */ @Nullable String getLastValidationError(); + + @Nullable + BlockPos getLastValidationErrorPosition(); /** * @return all the multiblock components attached to this controller diff --git a/src/main/java/forestry/core/config/Config.java b/src/main/java/forestry/core/config/Config.java index 728359e6c..4a943014d 100755 --- a/src/main/java/forestry/core/config/Config.java +++ b/src/main/java/forestry/core/config/Config.java @@ -75,6 +75,8 @@ public class Config { // Performance public static boolean enableBackpackResupply = true; + public static int planterThrottle = 10; + public static int harvesterThrottle = 200; // Customization private static boolean craftingBronzeEnabled = true; @@ -211,6 +213,12 @@ public class Config { enableBackpackResupply = configCommon.getBooleanLocalized("performance", "backpacks.resupply", enableBackpackResupply); + planterThrottle = configCommon.getIntLocalized("performance", "performance.planter", planterThrottle, 1, 2000); + //propThrottle.Comment = "higher numbers increase working speeds of planters but also increase cpu load."; + + harvesterThrottle = configCommon.getIntLocalized("performance", "performance.harvester", harvesterThrottle, 1, 2000); + //propThrottle.Comment = "higher numbers increase working speeds of harvesters but also increase cpu load."; + mailAlertEnabled = configCommon.getBooleanLocalized("tweaks.gui.mail.alert", "enabled", mailAlertEnabled); mailAlertXPosition = configCommon.getEnumLocalized("tweaks.gui.mail.alert", "xPosition", mailAlertXPosition, GuiMailboxInfo.XPosition.values()); mailAlertYPosition = configCommon.getEnumLocalized("tweaks.gui.mail.alert", "yPosition", mailAlertYPosition, GuiMailboxInfo.YPosition.values()); diff --git a/src/main/java/forestry/core/fluids/FilteredTank.java b/src/main/java/forestry/core/fluids/FilteredTank.java index 3a072a052..160c33742 100644 --- a/src/main/java/forestry/core/fluids/FilteredTank.java +++ b/src/main/java/forestry/core/fluids/FilteredTank.java @@ -61,7 +61,7 @@ public class FilteredTank extends StandardTank { } private boolean fluidMatchesFilter(FluidStack resource) { - return resource.getFluid() != null && + return resource != null && resource.getFluid() != null && filters.contains(resource.getFluid().getName()); } diff --git a/src/main/java/forestry/core/multiblock/FakeMultiblockController.java b/src/main/java/forestry/core/multiblock/FakeMultiblockController.java index 8a79ba3c4..e7faea857 100644 --- a/src/main/java/forestry/core/multiblock/FakeMultiblockController.java +++ b/src/main/java/forestry/core/multiblock/FakeMultiblockController.java @@ -134,7 +134,12 @@ public abstract class FakeMultiblockController implements IMultiblockControllerI public String getLastValidationError() { return null; } - + + @Override + public BlockPos getLastValidationErrorPosition() { + return null; + } + @Override public Collection getComponents() { diff --git a/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java b/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java index 7c2dd3fba..210aef68d 100644 --- a/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java +++ b/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java @@ -274,6 +274,14 @@ public abstract class MultiblockControllerBase implements IMultiblockControllerI } return lastValidationException.getMessage(); } + + @Override + public BlockPos getLastValidationErrorPosition() { + if (lastValidationException == null) { + return null; + } + return lastValidationException.getPosition(); + } @Override public void reassemble() { @@ -484,7 +492,7 @@ public abstract class MultiblockControllerBase implements IMultiblockControllerI */ protected void isBlockGoodForExteriorLevel(int level, World world, BlockPos pos) throws MultiblockValidationException { Block block = world.getBlockState(pos).getBlock(); - throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.error.invalid.interior", block.getLocalizedName())); + throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.error.invalid.interior", block.getLocalizedName()), pos); } /** @@ -496,7 +504,7 @@ public abstract class MultiblockControllerBase implements IMultiblockControllerI */ protected void isBlockGoodForInterior(World world, BlockPos pos) throws MultiblockValidationException { Block block = world.getBlockState(pos).getBlock(); - throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.error.invalid.interior", block.getLocalizedName())); + throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.error.invalid.interior", block.getLocalizedName()), pos); } @Override diff --git a/src/main/java/forestry/core/multiblock/MultiblockEventHandler.java b/src/main/java/forestry/core/multiblock/MultiblockEventHandler.java index 8da7b96f9..bd00c3a68 100644 --- a/src/main/java/forestry/core/multiblock/MultiblockEventHandler.java +++ b/src/main/java/forestry/core/multiblock/MultiblockEventHandler.java @@ -1,7 +1,19 @@ package forestry.core.multiblock; +import java.util.Set; + +import forestry.api.multiblock.IMultiblockController; +import forestry.core.utils.Log; +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.RenderGlobal; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; +import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.event.world.ChunkEvent; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; @@ -26,4 +38,45 @@ public class MultiblockEventHandler { public void onWorldUnload(WorldEvent.Unload unloadWorldEvent) { MultiblockRegistry.onWorldUnloaded(unloadWorldEvent.getWorld()); } + + @SubscribeEvent + public void onWorldRenderLast(RenderWorldLastEvent event){ + try{ + World world = Minecraft.getMinecraft().world; + Set controllers = MultiblockRegistry.getControllersFromWorld(world); + if(!controllers.isEmpty()){ + float partialTicks = event.getPartialTicks(); + EntityPlayer player = Minecraft.getMinecraft().player; + double playerX = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks; + double playerY = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks; + double playerZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks; + + GlStateManager.pushMatrix(); + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); + GlStateManager.disableTexture2D(); + GlStateManager.glLineWidth(2.0F); + GlStateManager.depthMask(false); + for(IMultiblockController controller : controllers){ + if(controller != null){ + BlockPos lastErrorPosition = controller.getLastValidationErrorPosition(); + if(lastErrorPosition != null){ + if(world.isBlockLoaded(lastErrorPosition) && player.getDistanceSq(lastErrorPosition) < 64F){ + AxisAlignedBB box = Block.FULL_BLOCK_AABB.offset(lastErrorPosition.getX() - playerX, lastErrorPosition.getY() - playerY, lastErrorPosition.getZ() - playerZ); + RenderGlobal.drawSelectionBoundingBox(box, 1.0F, 0.0F, 0.0F, 0.25F); + RenderGlobal.renderFilledBox(box, 1.0F, 0.0F, 0.0F, 0.125F); + } + } + } + } + + GlStateManager.depthMask(true); + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + GlStateManager.popMatrix(); + } + }catch(Exception e){ + Log.error("Failed to render the position of a multiblock exeption.", e); + } + } } diff --git a/src/main/java/forestry/core/multiblock/MultiblockValidationException.java b/src/main/java/forestry/core/multiblock/MultiblockValidationException.java index 0ba1260cd..3cd7f5e6b 100644 --- a/src/main/java/forestry/core/multiblock/MultiblockValidationException.java +++ b/src/main/java/forestry/core/multiblock/MultiblockValidationException.java @@ -1,5 +1,9 @@ package forestry.core.multiblock; +import javax.annotation.Nullable; + +import net.minecraft.util.math.BlockPos; + /** * An exception thrown when trying to validate a multiblock. Requires a string describing why the multiblock * could not assemble. @@ -8,7 +12,19 @@ package forestry.core.multiblock; */ public class MultiblockValidationException extends Exception { + @Nullable + private BlockPos position; + public MultiblockValidationException(String reason) { super(reason); } + + public MultiblockValidationException(String reason, BlockPos position) { + super(reason); + this.position = position; + } + + public BlockPos getPosition() { + return position; + } } diff --git a/src/main/java/forestry/core/recipes/RecipeUtil.java b/src/main/java/forestry/core/recipes/RecipeUtil.java index aaa5d99ca..62f84eb27 100644 --- a/src/main/java/forestry/core/recipes/RecipeUtil.java +++ b/src/main/java/forestry/core/recipes/RecipeUtil.java @@ -11,8 +11,6 @@ package forestry.core.recipes; import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; import forestry.api.recipes.IDescriptiveRecipe; diff --git a/src/main/java/forestry/core/utils/ClimateUtil.java b/src/main/java/forestry/core/utils/ClimateUtil.java index 9e25ba8a0..58df0e8a9 100644 --- a/src/main/java/forestry/core/utils/ClimateUtil.java +++ b/src/main/java/forestry/core/utils/ClimateUtil.java @@ -13,6 +13,7 @@ package forestry.core.utils; import java.util.ArrayList; import java.util.Locale; +import forestry.api.climate.IClimateInfo; import forestry.api.climate.IClimatePosition; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; @@ -43,6 +44,22 @@ public class ClimateUtil implements IClimateHelper { public boolean isWithinLimits(EnumHumidity humidity, EnumHumidity baseHumid, EnumTolerance tolHumid) { return getToleratedHumidity(baseHumid, tolHumid).contains(humidity); } + + public static boolean isWithinLimits(IClimateInfo minInfo, IClimateInfo maxInfo, IClimateInfo info){ + if(0.0F != minInfo.getTemperature() && info.getTemperature() < minInfo.getTemperature()){ + return false; + } + if(0.0F != minInfo.getHumidity() && info.getHumidity() < minInfo.getHumidity()){ + return false; + } + if(0.0F != maxInfo.getTemperature() && info.getTemperature() > maxInfo.getTemperature()){ + return false; + } + if(0.0F != maxInfo.getHumidity() & info.getHumidity() > maxInfo.getHumidity()){ + return false; + } + return true; + } @Override public ArrayList getToleratedHumidity(EnumHumidity prefered, EnumTolerance tolerance) { diff --git a/src/main/java/forestry/factory/recipes/jei/WorktableRecipeTransferHandler.java b/src/main/java/forestry/factory/recipes/jei/WorktableRecipeTransferHandler.java index 2dbf10afc..910179afb 100644 --- a/src/main/java/forestry/factory/recipes/jei/WorktableRecipeTransferHandler.java +++ b/src/main/java/forestry/factory/recipes/jei/WorktableRecipeTransferHandler.java @@ -1,7 +1,6 @@ package forestry.factory.recipes.jei; import javax.annotation.Nullable; -import java.util.Collections; import java.util.List; import java.util.Map; diff --git a/src/main/java/forestry/farming/items/ItemBlockFarm.java b/src/main/java/forestry/farming/items/ItemBlockFarm.java index 1272909f8..2fe5dc0b0 100644 --- a/src/main/java/forestry/farming/items/ItemBlockFarm.java +++ b/src/main/java/forestry/farming/items/ItemBlockFarm.java @@ -12,11 +12,13 @@ package forestry.farming.items; import java.util.List; +import forestry.core.utils.Translator; import forestry.farming.models.EnumFarmBlockTexture; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; +import net.minecraft.util.text.TextFormatting; public class ItemBlockFarm extends ItemBlock { @@ -32,11 +34,12 @@ public class ItemBlockFarm extends ItemBlock { @Override public void addInformation(ItemStack itemstack, EntityPlayer player, List info, boolean par4) { + info.add(Translator.translateToLocal("tile.for.ffarm.tooltip")); if (itemstack.getTagCompound() == null) { return; } - info.add(EnumFarmBlockTexture.getFromCompound(itemstack.getTagCompound()).getName()); + info.add(TextFormatting.ITALIC + EnumFarmBlockTexture.getFromCompound(itemstack.getTagCompound()).getName()); } @Override diff --git a/src/main/java/forestry/greenhouse/GreenhouseClimateWindow.java b/src/main/java/forestry/greenhouse/GreenhouseClimateWindow.java index dcb2117c5..02d2ca841 100644 --- a/src/main/java/forestry/greenhouse/GreenhouseClimateWindow.java +++ b/src/main/java/forestry/greenhouse/GreenhouseClimateWindow.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ package forestry.greenhouse; import javax.annotation.Nullable; diff --git a/src/main/java/forestry/greenhouse/GreenhouseHelper.java b/src/main/java/forestry/greenhouse/GreenhouseHelper.java index 056d6efd6..e502787c6 100644 --- a/src/main/java/forestry/greenhouse/GreenhouseHelper.java +++ b/src/main/java/forestry/greenhouse/GreenhouseHelper.java @@ -11,23 +11,32 @@ package forestry.greenhouse; import javax.annotation.Nullable; + +import com.google.common.base.Preconditions; + import java.util.ArrayList; import java.util.List; +import forestry.api.climate.IClimateInfo; import forestry.api.greenhouse.IGreenhouseHelper; import forestry.api.greenhouse.IGreenhouseLogic; import forestry.api.greenhouse.IInternalBlock; +import forestry.api.greenhouse.ITerrainRecipe; import forestry.api.multiblock.IGreenhouseController; import forestry.core.multiblock.IMultiblockControllerInternal; import forestry.core.multiblock.MultiblockRegistry; +import forestry.core.utils.ClimateUtil; import forestry.greenhouse.multiblock.IGreenhouseControllerInternal; import forestry.greenhouse.multiblock.InternalBlockCheck; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class GreenhouseHelper implements IGreenhouseHelper { private final List> greenhouseLogics = new ArrayList<>(); + private final List terrainRecipes = new ArrayList<>(); @Override @Nullable @@ -48,7 +57,7 @@ public class GreenhouseHelper implements IGreenhouseHelper { } @Override - public void addGreenhouseLogic(Class logic) { + public void registerGreenhouseLogic(Class logic) { if (!greenhouseLogics.contains(logic)) { greenhouseLogics.add(logic); } @@ -58,5 +67,35 @@ public class GreenhouseHelper implements IGreenhouseHelper { public List> getGreenhouseLogics() { return greenhouseLogics; } + + @Override + public void registerTerrainRecipe(IBlockState inputState, IBlockState outputState, IClimateInfo minClimate, IClimateInfo maxClimate, float chance) { + Preconditions.checkNotNull(inputState); + Preconditions.checkNotNull(outputState); + Preconditions.checkNotNull(minClimate); + Preconditions.checkNotNull(maxClimate); + terrainRecipes.add(new TerrainRecipeState(inputState, outputState, minClimate, maxClimate, chance)); + } + + @Override + public void registerTerrainRecipe(Block inputBlock, IBlockState outputState, IClimateInfo minClimate, IClimateInfo maxClimate, float chance) { + Preconditions.checkNotNull(inputBlock); + Preconditions.checkNotNull(outputState); + Preconditions.checkNotNull(minClimate); + Preconditions.checkNotNull(maxClimate); + terrainRecipes.add(new TerrainRecipeBlock(inputBlock, outputState, minClimate, maxClimate, chance)); + } + + @Override + public ITerrainRecipe getValidTerrainRecipe(IBlockState blockState, IClimateInfo climateInfo) { + for(ITerrainRecipe recipe : terrainRecipes){ + if(recipe.matches(blockState)){ + if(ClimateUtil.isWithinLimits(recipe.getMinClimate(), recipe.getMaxClimate(), climateInfo)){ + return recipe; + } + } + } + return null; + } } diff --git a/src/main/java/forestry/greenhouse/PluginGreenhouse.java b/src/main/java/forestry/greenhouse/PluginGreenhouse.java index 307cdc021..50c27a766 100644 --- a/src/main/java/forestry/greenhouse/PluginGreenhouse.java +++ b/src/main/java/forestry/greenhouse/PluginGreenhouse.java @@ -16,6 +16,7 @@ import com.google.common.base.Preconditions; import forestry.api.core.ForestryAPI; import forestry.api.greenhouse.GreenhouseManager; import forestry.core.PluginCore; +import forestry.core.climate.ClimateInfo; import forestry.core.config.Constants; import forestry.core.items.EnumElectronTube; import forestry.core.items.ItemRegistryCore; @@ -24,6 +25,7 @@ import forestry.core.utils.OreDictUtil; import forestry.greenhouse.blocks.BlockGreenhouseType; import forestry.greenhouse.blocks.BlockRegistryGreenhouse; import forestry.greenhouse.logics.GreenhouseLogicGreenhouseEffect; +import forestry.greenhouse.logics.GreenhouseLogicTerrain; import forestry.greenhouse.proxy.ProxyGreenhouse; import forestry.greenhouse.tiles.TileGreenhouseButterflyHatch; import forestry.greenhouse.tiles.TileGreenhouseClimateControl; @@ -67,12 +69,47 @@ public class PluginGreenhouse extends BlankForestryPlugin { public void setupAPI() { GreenhouseManager.greenhouseHelper = new GreenhouseHelper(); } - + @Override public void registerItemsAndBlocks() { blocks = new BlockRegistryGreenhouse(); } + @Override + public void preInit() { + MinecraftForge.EVENT_BUS.register(new EventHandlerGreenhouse()); + + proxy.initializeModels(); + + GreenhouseManager.greenhouseHelper.registerGreenhouseLogic(GreenhouseLogicGreenhouseEffect.class); + GreenhouseManager.greenhouseHelper.registerGreenhouseLogic(GreenhouseLogicTerrain.class); + + GreenhouseManager.greenhouseHelper.registerTerrainRecipe(Blocks.DIRT, Blocks.SAND.getDefaultState(), new ClimateInfo(1.2F, -1.0F), new ClimateInfo(-1.0F, -1.0F), 0.5F); + GreenhouseManager.greenhouseHelper.registerTerrainRecipe(Blocks.GRASS, Blocks.SAND.getDefaultState(), new ClimateInfo(1.2F, -1.0F), new ClimateInfo(-1.0F, -1.0F), 0.5F); + GreenhouseManager.greenhouseHelper.registerTerrainRecipe(Blocks.FARMLAND, Blocks.SAND.getDefaultState(), new ClimateInfo(1.2F, -1.0F), new ClimateInfo(-1.0F, -1.0F), 0.5F); + } + + @Override + public void doInit() { + super.doInit(); + + GameRegistry.registerTileEntity(TileGreenhouseFan.class, "forestry.GreenhouseFan"); + GameRegistry.registerTileEntity(TileGreenhouseHeater.class, "forestry.GreenhouseHeater"); + GameRegistry.registerTileEntity(TileGreenhouseDryer.class, "forestry.GreenhouseDryer"); + GameRegistry.registerTileEntity(TileGreenhouseHumidifier.class, "forestry.GreenhouseSprinkler"); + GameRegistry.registerTileEntity(TileGreenhouseValve.class, "forestry.GreenhouseValve"); + GameRegistry.registerTileEntity(TileGreenhouseGearbox.class, "forestry.GreenhouseGearbox"); + GameRegistry.registerTileEntity(TileGreenhouseControl.class, "forestry.GreenhouseController"); + GameRegistry.registerTileEntity(TileGreenhousePlain.class, "forestry.GreenhousePlain"); + GameRegistry.registerTileEntity(TileGreenhouseDoor.class, "forestry.GreenhouseDoor"); + GameRegistry.registerTileEntity(TileGreenhouseHatch.class, "forestry.GreenhouseHatch"); + GameRegistry.registerTileEntity(TileGreenhouseClimateControl.class, "forestry.GreenhouseClimateControl"); + GameRegistry.registerTileEntity(TileGreenhouseWindow.class, "forestry.GreenhouseWindow"); + if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.LEPIDOPTEROLOGY)) { + GameRegistry.registerTileEntity(TileGreenhouseButterflyHatch.class, "forestry.GreenhouseButterflyHatch"); + } + } + @Override public void registerRecipes() { ItemRegistryCore coreItems = PluginCore.getItems(); @@ -225,34 +262,4 @@ public class PluginGreenhouse extends BlankForestryPlugin { } } - @Override - public void doInit() { - super.doInit(); - - GameRegistry.registerTileEntity(TileGreenhouseFan.class, "forestry.GreenhouseFan"); - GameRegistry.registerTileEntity(TileGreenhouseHeater.class, "forestry.GreenhouseHeater"); - GameRegistry.registerTileEntity(TileGreenhouseDryer.class, "forestry.GreenhouseDryer"); - GameRegistry.registerTileEntity(TileGreenhouseHumidifier.class, "forestry.GreenhouseSprinkler"); - GameRegistry.registerTileEntity(TileGreenhouseValve.class, "forestry.GreenhouseValve"); - GameRegistry.registerTileEntity(TileGreenhouseGearbox.class, "forestry.GreenhouseGearbox"); - GameRegistry.registerTileEntity(TileGreenhouseControl.class, "forestry.GreenhouseController"); - GameRegistry.registerTileEntity(TileGreenhousePlain.class, "forestry.GreenhousePlain"); - GameRegistry.registerTileEntity(TileGreenhouseDoor.class, "forestry.GreenhouseDoor"); - GameRegistry.registerTileEntity(TileGreenhouseHatch.class, "forestry.GreenhouseHatch"); - GameRegistry.registerTileEntity(TileGreenhouseClimateControl.class, "forestry.GreenhouseClimateControl"); - GameRegistry.registerTileEntity(TileGreenhouseWindow.class, "forestry.GreenhouseWindow"); - if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.LEPIDOPTEROLOGY)) { - GameRegistry.registerTileEntity(TileGreenhouseButterflyHatch.class, "forestry.GreenhouseButterflyHatch"); - } - } - - @Override - public void preInit() { - MinecraftForge.EVENT_BUS.register(new EventHandlerGreenhouse()); - - proxy.initializeModels(); - - GreenhouseManager.greenhouseHelper.addGreenhouseLogic(GreenhouseLogicGreenhouseEffect.class); - } - } diff --git a/src/main/java/forestry/greenhouse/TerrainRecipe.java b/src/main/java/forestry/greenhouse/TerrainRecipe.java new file mode 100644 index 000000000..69947dbf8 --- /dev/null +++ b/src/main/java/forestry/greenhouse/TerrainRecipe.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.greenhouse; + +import forestry.api.climate.IClimateInfo; +import forestry.api.greenhouse.ITerrainRecipe; +import net.minecraft.block.state.IBlockState; + +public abstract class TerrainRecipe implements ITerrainRecipe { + + public IBlockState result; + public IClimateInfo minClimate, maxClimate; + public float chance; + + public TerrainRecipe(IBlockState result, IClimateInfo minClimate, IClimateInfo maxClimate, float chance) { + this.result = result; + this.minClimate = minClimate; + this.maxClimate = maxClimate; + this.chance = chance; + } + + @Override + public IBlockState getResult() { + return result; + } + + @Override + public IClimateInfo getMinClimate() { + return minClimate; + } + + @Override + public IClimateInfo getMaxClimate() { + return maxClimate; + } + + @Override + public float getChance() { + return chance; + } + +} diff --git a/src/main/java/forestry/greenhouse/TerrainRecipeBlock.java b/src/main/java/forestry/greenhouse/TerrainRecipeBlock.java new file mode 100644 index 000000000..24a8a1c43 --- /dev/null +++ b/src/main/java/forestry/greenhouse/TerrainRecipeBlock.java @@ -0,0 +1,21 @@ +package forestry.greenhouse; + +import forestry.api.climate.IClimateInfo; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; + +public class TerrainRecipeBlock extends TerrainRecipe { + + private Block input; + + public TerrainRecipeBlock(Block input, IBlockState result, IClimateInfo minClimate, IClimateInfo maxClimate, float chance) { + super(result, minClimate, maxClimate, chance); + this.input = input; + } + + @Override + public boolean matches(IBlockState blockState) { + return blockState.getBlock() == input; + } + +} diff --git a/src/main/java/forestry/greenhouse/TerrainRecipeState.java b/src/main/java/forestry/greenhouse/TerrainRecipeState.java new file mode 100644 index 000000000..88acf2d7d --- /dev/null +++ b/src/main/java/forestry/greenhouse/TerrainRecipeState.java @@ -0,0 +1,20 @@ +package forestry.greenhouse; + +import forestry.api.climate.IClimateInfo; +import net.minecraft.block.state.IBlockState; + +public class TerrainRecipeState extends TerrainRecipe { + + private IBlockState input; + + public TerrainRecipeState(IBlockState input, IBlockState result, IClimateInfo minClimate, IClimateInfo maxClimate, float chance) { + super(result, minClimate, maxClimate, chance); + this.input = input; + } + + @Override + public boolean matches(IBlockState blockState) { + return blockState == input; + } + +} diff --git a/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseDoor.java b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseDoor.java index b2a3cca7c..fd66b58d4 100644 --- a/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseDoor.java +++ b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouseDoor.java @@ -182,7 +182,7 @@ public class BlockGreenhouseDoor extends BlockGreenhouse implements IStateMapper if (flag != state.getValue(OPEN)) { worldIn.setBlockState(pos, state.withProperty(OPEN, flag), 2); worldIn.markBlockRangeForRenderUpdate(pos, pos); - worldIn.playEvent(null, flag ? 1003 : 1006, pos, 0); + worldIn.playEvent(null, flag ? 1006 : 1012, pos, 0); } } } diff --git a/src/main/java/forestry/greenhouse/gui/GuiGreenhouse.java b/src/main/java/forestry/greenhouse/gui/GuiGreenhouse.java index 26f6be26f..d5c8dd9de 100644 --- a/src/main/java/forestry/greenhouse/gui/GuiGreenhouse.java +++ b/src/main/java/forestry/greenhouse/gui/GuiGreenhouse.java @@ -167,12 +167,14 @@ public class GuiGreenhouse extends GuiForestryTitled { protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(f, mouseX, mouseY); - if (temperatureField.getVisible()) { + + if (fieldsEnabeled) { + drawTexturedModalRect(guiLeft + 62, guiTop + 29, 204, 115, 52, 12); + drawTexturedModalRect(guiLeft + 62, guiTop + 59, 204, 127, 52, 12); + textLayout.line = 20; textLayout.drawCenteredLine(Translator.translateToLocal("for.gui.temperature"), 0, ColourProperties.INSTANCE.get("gui.greenhouse.temperature.text")); temperatureField.drawTextBox(); - } - if (humidityField.getVisible()) { textLayout.line = 50; textLayout.drawCenteredLine(Translator.translateToLocal("for.gui.humidity"), 0, ColourProperties.INSTANCE.get("gui.greenhouse.humidity.text")); diff --git a/src/main/java/forestry/greenhouse/logics/GreenhouseLogicTerrain.java b/src/main/java/forestry/greenhouse/logics/GreenhouseLogicTerrain.java index 69f5bfbdf..666286b86 100644 --- a/src/main/java/forestry/greenhouse/logics/GreenhouseLogicTerrain.java +++ b/src/main/java/forestry/greenhouse/logics/GreenhouseLogicTerrain.java @@ -1,42 +1,77 @@ package forestry.greenhouse.logics; -import java.util.HashSet; -import java.util.Set; - import forestry.api.greenhouse.DefaultGreenhouseLogic; +import forestry.api.greenhouse.GreenhouseManager; import forestry.api.greenhouse.IInternalBlock; +import forestry.api.greenhouse.ITerrainRecipe; import forestry.api.multiblock.IGreenhouseController; +import net.minecraft.block.state.IBlockState; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class GreenhouseLogicTerrain extends DefaultGreenhouseLogic { + private static final int TIME = 160; + + private IInternalBlock[] internalBlocks; private World world; - private Set terrain; + private int timeUntilNextTerrain; public GreenhouseLogicTerrain(IGreenhouseController controller) { super(controller, "Terrain"); - this.terrain = new HashSet<>(); + this.internalBlocks = new IInternalBlock[0]; this.world = controller.getWorldObj(); + this.timeUntilNextTerrain = TIME; } @Override public void work() { - if (controller == null || !controller.isAssembled()) { + if(this.world.isRemote || controller == null || !controller.isAssembled() || internalBlocks.length == 0){ return; } + if(this.timeUntilNextTerrain > 0){ + this.timeUntilNextTerrain--; + if(this.timeUntilNextTerrain <= 0){ + IInternalBlock internalBlock = internalBlocks[world.rand.nextInt(internalBlocks.length)]; + BlockPos blockPos = internalBlock.getPos(); + if(world.isBlockLoaded(blockPos) && !world.isAirBlock(blockPos)){ + IBlockState blockState = world.getBlockState(blockPos); + ITerrainRecipe recipe = GreenhouseManager.greenhouseHelper.getValidTerrainRecipe(blockState, controller.getRegion().getPosition(blockPos).getInfo()); + if(recipe != null){ + if(recipe.getChance() > world.rand.nextFloat()){ + world.setBlockState(blockPos, recipe.getResult()); + } + } + } + timeUntilNextTerrain = TIME; + } + } + } + + @Override + public NBTTagCompound writeToNBT(NBTTagCompound nbt) { + nbt.setInteger("Time", timeUntilNextTerrain); + return super.writeToNBT(nbt); + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + timeUntilNextTerrain = nbt.getInteger("Time"); + if(timeUntilNextTerrain <= 0){ + timeUntilNextTerrain = TIME; + } } @Override public void onMachineAssembled() { - for(IInternalBlock internalBlock : controller.getInternalBlocks()){ - BlockPos pos = internalBlock.getPos(); - } + this.internalBlocks = controller.getInternalBlocks().toArray(new IInternalBlock[0]); } @Override public void onMachineDisassembled() { - terrain.clear(); + this.internalBlocks = new IInternalBlock[0]; } } diff --git a/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java b/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java index 0e253dc7f..b5774ef52 100644 --- a/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java +++ b/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java @@ -423,7 +423,6 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im super.onMachineDisassembled(); internalBlocks.clear(); - logics.clear(); ForestryAPI.climateManager.removeRegion(region); @@ -588,7 +587,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im 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(Translator.translateToLocalFormatted("for.multiblock.error.invalid.part", Translator.translateToLocal(getUnlocalizedType()))); + throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.error.invalid.part", Translator.translateToLocal(getUnlocalizedType())), part.getCoordinates()); } isGoodForExteriorLevel(part, exteriorLevel); } else { @@ -600,7 +599,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im if (!myClass.equals(part.getMultiblockLogic().getController().getClass())) { isGoodForInterior(part); } else { - throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.error.invalid.part", Translator.translateToLocal(getUnlocalizedType()))); + throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.error.invalid.part", Translator.translateToLocal(getUnlocalizedType())), part.getCoordinates()); } } else { isBlockGoodForInterior(this.world, pos); @@ -691,14 +690,14 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im BlockPos maxPos = getMaximumCoord(); if (minPos.getX() > posFacing.getX() || minPos.getY() > posFacing.getY() || minPos.getZ() > posFacing.getZ() || maxPos.getX() < posFacing.getX() || maxPos.getY() < posFacing.getY() || maxPos.getZ() < posFacing.getZ()) { - throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.greenhouse.error.space.closed")); + throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.greenhouse.error.space.closed"), posRoot); } TileEntity tileFace = world.getTileEntity(posFacing); if (tileFace instanceof IGreenhouseComponent) { if (((IGreenhouseComponent) tileFace).getMultiblockLogic().getController() != this) { - throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.error.not.connected.part")); + throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.error.not.connected.part"), posRoot); } else if (!(tileFace instanceof TileGreenhouseHumidifier)) { faceToCheck.setTested(true); } diff --git a/src/main/java/forestry/greenhouse/multiblock/GreenhouseMultiblockSizeLimits.java b/src/main/java/forestry/greenhouse/multiblock/GreenhouseMultiblockSizeLimits.java index dca4f9194..74f1242e7 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 * 5) - (3 * 3 * 3); + return 0; } @Override diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseClimatiser.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseClimatiser.java index 011db2236..9aef9eeeb 100644 --- a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseClimatiser.java +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseClimatiser.java @@ -11,7 +11,6 @@ package forestry.greenhouse.tiles; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; import forestry.api.climate.IClimateSource; diff --git a/src/main/resources/assets/forestry/textures/gui/greenhouse.png b/src/main/resources/assets/forestry/textures/gui/greenhouse.png index 348e3f00b..961ccd671 100644 Binary files a/src/main/resources/assets/forestry/textures/gui/greenhouse.png and b/src/main/resources/assets/forestry/textures/gui/greenhouse.png differ