mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-20 12:09:39 +00:00
Add GreenhouseLogicTerrain and adding multiblock error renderer
This commit is contained in:
1 parent
02f5c7121d
commit
55919a135e
27 files changed
+392
-63
No files matched your search
@@ -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<? extends IGreenhouseLogic> logic);
|
||||
void registerGreenhouseLogic(Class<? extends IGreenhouseLogic> logic);
|
||||
|
||||
List<Class<? extends IGreenhouseLogic>> 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);
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +134,12 @@ public abstract class FakeMultiblockController implements IMultiblockControllerI
|
||||
public String getLastValidationError() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockPos getLastValidationErrorPosition() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public Collection<IMultiblockComponent> getComponents() {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<IMultiblockControllerInternal> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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<EnumHumidity> getToleratedHumidity(EnumHumidity prefered, EnumTolerance tolerance) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<String> 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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<Class<? extends IGreenhouseLogic>> greenhouseLogics = new ArrayList<>();
|
||||
private final List<ITerrainRecipe> terrainRecipes = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
@@ -48,7 +57,7 @@ public class GreenhouseHelper implements IGreenhouseHelper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGreenhouseLogic(Class<? extends IGreenhouseLogic> logic) {
|
||||
public void registerGreenhouseLogic(Class<? extends IGreenhouseLogic> logic) {
|
||||
if (!greenhouseLogics.contains(logic)) {
|
||||
greenhouseLogics.add(logic);
|
||||
}
|
||||
@@ -58,5 +67,35 @@ public class GreenhouseHelper implements IGreenhouseHelper {
|
||||
public List<Class<? extends IGreenhouseLogic>> 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,12 +167,14 @@ public class GuiGreenhouse extends GuiForestryTitled<ContainerGreenhouse> {
|
||||
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"));
|
||||
|
||||
|
||||
@@ -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<BlockPos> 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];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class GreenhouseMultiblockSizeLimits implements IMultiblockSizeLimits {
|
||||
|
||||
@Override
|
||||
public int getMinimumNumberOfBlocksForAssembledMachine() {
|
||||
return (5 * 5 * 5) - (3 * 3 * 3);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user