Clean Up greenhouse

This commit is contained in:
Nedelosk committed 2017-01-01 03:06:36 +01:00
1 parent 9d8c616b67
commit 7ff4944281
24 files changed
+7 -680

No files matched your search

@@ -8,7 +8,6 @@ package forestry.api.arboriculture;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IFruitFamily;
import forestry.core.utils.Translator;
import net.minecraft.util.text.translation.I18n;
public enum EnumFruitFamily implements IFruitFamily {
PRUNES("prunes", "Prunus domestica"),
@@ -1,56 +0,0 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.greenhouse;
import forestry.api.multiblock.IGreenhouseController;
import net.minecraft.nbt.NBTTagCompound;
public class DefaultGreenhouseLogic implements IGreenhouseLogic {
public final IGreenhouseController controller;
private final String name;
public DefaultGreenhouseLogic(IGreenhouseController controller, String name) {
this.controller = controller;
this.name = name;
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
return nbt;
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
}
@Override
public void work() {
}
@Override
public void onEvent(EnumGreenhouseEventType type, Object event) {
}
@Override
public IGreenhouseController getController() {
return controller;
}
@Override
public String getName() {
return name;
}
@Override
public void onMachineAssembled() {
}
@Override
public void onMachineDisassembled() {
}
}
@@ -1,12 +0,0 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.greenhouse;
public enum EnumGreenhouseEventType {
CAMOUFLAGE
}
@@ -5,10 +5,6 @@
******************************************************************************/
package forestry.api.greenhouse;
import javax.annotation.Nullable;
import forestry.api.core.ICamouflageHandler;
import forestry.api.core.ICamouflagedTile;
import forestry.api.multiblock.IGreenhouseController;
import net.minecraftforge.fml.common.eventhandler.Event;
@@ -20,24 +16,6 @@ public class GreenhouseEvents extends Event {
this.controller = state;
}
public static class CamouflageChangeEvent extends GreenhouseEvents {
@Nullable
public final ICamouflagedTile camouflagedBlock;
public final ICamouflageHandler camouflageHandler;
public final String camouflageType;
public CamouflageChangeEvent(IGreenhouseController controller, @Nullable ICamouflagedTile camouflagedBlock, ICamouflageHandler camouflageHandler, String camouflageType) {
super(controller);
this.camouflagedBlock = camouflagedBlock;
this.camouflageHandler = camouflageHandler;
this.camouflageType = camouflageType;
}
}
public static class InternalBlockEvent extends GreenhouseEvents {
public final IInternalBlock internalBlock;
@@ -1,11 +0,0 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.greenhouse;
public interface IGreenhouseClimaLogic extends IGreenhouseLogic {
}
@@ -6,12 +6,7 @@
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;
@@ -23,14 +18,4 @@ public interface IGreenhouseHelper {
@Nullable
IGreenhouseController getGreenhouseController(World world, BlockPos pos);
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);
}
@@ -1,31 +0,0 @@
/*******************************************************************************
* 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.api.greenhouse;
import forestry.api.core.INbtReadable;
import forestry.api.core.INbtWritable;
import forestry.api.multiblock.IGreenhouseController;
public interface IGreenhouseLogic extends INbtWritable, INbtReadable {
void work();
void onEvent(EnumGreenhouseEventType type, Object event);
void onMachineAssembled();
void onMachineDisassembled();
IGreenhouseController getController();
String getName();
}
@@ -1,18 +0,0 @@
/*******************************************************************************
* 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,23 +0,0 @@
/*******************************************************************************
* 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;
import net.minecraft.block.state.IBlockState;
public interface ITerrainRecipe {
boolean matches(IBlockState blockState);
IBlockState getResult();
IClimateInfo getMinClimate();
IClimateInfo getMaxClimate();
float getChance();
}
@@ -5,28 +5,15 @@
******************************************************************************/
package forestry.api.multiblock;
import java.util.List;
import java.util.Set;
import forestry.api.climate.IClimateControlProvider;
import forestry.api.climate.IClimateRegion;
import forestry.api.core.ICamouflageHandler;
import forestry.api.greenhouse.EnumGreenhouseEventType;
import forestry.api.greenhouse.IGreenhouseHousing;
import forestry.api.greenhouse.IGreenhouseLogic;
import forestry.api.greenhouse.IInternalBlock;
public interface IGreenhouseController extends IMultiblockController, IGreenhouseHousing, ICamouflageHandler, IClimateControlProvider {
/**
* Handle change events.
*/
void onChange(EnumGreenhouseEventType type, Object event);
/**
* @return The logics of the greenhouse.
*/
List<IGreenhouseLogic> getLogics();
/**
* @return All internal blocks of the greenhouse.
@@ -75,8 +75,8 @@ public class Config {
// Performance
public static boolean enableBackpackResupply = true;
public static int planterThrottle = 10;
public static int harvesterThrottle = 200;
//public static int planterThrottle = 10;
//public static int harvesterThrottle = 200;
// Customization
private static boolean craftingBronzeEnabled = true;
@@ -213,10 +213,10 @@ public class Config {
enableBackpackResupply = configCommon.getBooleanLocalized("performance", "backpacks.resupply", enableBackpackResupply);
planterThrottle = configCommon.getIntLocalized("performance", "performance.planter", planterThrottle, 1, 2000);
//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);
//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);
@@ -1,41 +0,0 @@
/*******************************************************************************
* 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.core.ICamouflageHandler;
import forestry.api.greenhouse.EnumGreenhouseEventType;
import forestry.api.greenhouse.GreenhouseEvents.CamouflageChangeEvent;
import forestry.api.multiblock.IGreenhouseComponent;
import forestry.api.multiblock.IGreenhouseController;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class EventHandlerGreenhouse {
@SubscribeEvent
public void onCamouflageChance(CamouflageChangeEvent event) {
ICamouflageHandler handler = event.camouflageHandler;
IGreenhouseController controller = null;
if (handler instanceof IGreenhouseController) {
controller = (IGreenhouseController) handler;
}
if (handler instanceof IGreenhouseComponent) {
IGreenhouseComponent component = (IGreenhouseComponent) handler;
controller = component.getMultiblockLogic().getController();
}
if (controller != null) {
controller.onChange(EnumGreenhouseEventType.CAMOUFLAGE, event);
}
}
}
@@ -12,32 +12,18 @@ 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
public IGreenhouseController getGreenhouseController(World world, BlockPos pos) {
@@ -56,46 +42,4 @@ public class GreenhouseHelper implements IGreenhouseHelper {
return controller.getInternalBlocks().contains(checkBlock);
}
@Override
public void registerGreenhouseLogic(Class<? extends IGreenhouseLogic> logic) {
if (!greenhouseLogics.contains(logic)) {
greenhouseLogics.add(logic);
}
}
@Override
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,7 +16,6 @@ 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,8 +23,6 @@ import forestry.core.recipes.RecipeUtil;
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;
@@ -46,7 +43,6 @@ import forestry.plugins.ForestryPluginUids;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.registry.GameRegistry;
@@ -77,16 +73,7 @@ public class PluginGreenhouse extends BlankForestryPlugin {
@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
@@ -1,50 +0,0 @@
/*******************************************************************************
* 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;
}
}
@@ -1,21 +0,0 @@
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;
}
}
@@ -1,20 +0,0 @@
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;
}
}
@@ -1,96 +0,0 @@
/*******************************************************************************
* 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.logics;
import forestry.api.core.CamouflageManager;
import forestry.api.core.ICamouflageItemHandler;
import forestry.api.core.ICamouflagedTile;
import forestry.api.greenhouse.DefaultGreenhouseLogic;
import forestry.api.greenhouse.EnumGreenhouseEventType;
import forestry.api.greenhouse.IGreenhouseClimaLogic;
import forestry.api.multiblock.IGreenhouseController;
import forestry.api.multiblock.IMultiblockComponent;
import forestry.core.utils.CamouflageUtil;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
public class GreenhouseLogicGreenhouseEffect extends DefaultGreenhouseLogic implements IGreenhouseClimaLogic {
private float lightTransmittance;
private int workTimer;
public GreenhouseLogicGreenhouseEffect(IGreenhouseController controller) {
super(controller, "GreenhouseEffect");
}
@Override
public void work() {
/*if (controller == null || !controller.isAssembled()) {
return;
}
if (controller.getWorldObj().isDaytime()) {
if (workTimer++ > 20) {
controller.addTemperatureChange(lightTransmittance / 100, 0F, 2.5F);
workTimer = 0;
}
}*/
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
nbt.setInteger("workTimer", workTimer);
nbt.setFloat("lightTransmittance", lightTransmittance);
return nbt;
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
workTimer = nbt.getInteger("workTimer");
lightTransmittance = nbt.getFloat("lightTransmittance");
}
@Override
public void onEvent(EnumGreenhouseEventType type, Object event) {
if (type == EnumGreenhouseEventType.CAMOUFLAGE) {
if (!controller.isAssembled()) {
return;
}
float lightTransmittance = 0F;
int i = 0;
World world = controller.getWorldObj();
for (IMultiblockComponent component : controller.getComponents()) {
if (component instanceof ICamouflagedTile) {
ICamouflagedTile block = (ICamouflagedTile) component;
if (block.getCamouflageType().equals(CamouflageManager.GLASS)) {
if (world.canBlockSeeSky(component.getCoordinates())) {
ItemStack camouflageStack = CamouflageUtil.getCamouflageBlock(world, component.getCoordinates());
ICamouflageItemHandler handler = CamouflageManager.camouflageAccess.getHandlerFromItem(camouflageStack);
if (handler != null) {
float camouflageLightTransmittance = handler.getLightTransmittance(camouflageStack, controller);
if (camouflageLightTransmittance < 1 && camouflageLightTransmittance > 0) {
lightTransmittance = lightTransmittance + camouflageLightTransmittance;
i++;
}
}
}
}
}
}
if (i != 0) {
this.lightTransmittance = lightTransmittance / i;
}
}
}
}
@@ -1,77 +0,0 @@
package forestry.greenhouse.logics;
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 int timeUntilNextTerrain;
public GreenhouseLogicTerrain(IGreenhouseController controller) {
super(controller, "Terrain");
this.internalBlocks = new IInternalBlock[0];
this.world = controller.getWorldObj();
this.timeUntilNextTerrain = TIME;
}
@Override
public void work() {
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() {
this.internalBlocks = controller.getInternalBlocks().toArray(new IInternalBlock[0]);
}
@Override
public void onMachineDisassembled() {
this.internalBlocks = new IInternalBlock[0];
}
}
@@ -1,9 +0,0 @@
@ParametersAreNonnullByDefault
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
package forestry.greenhouse.logics;
import javax.annotation.ParametersAreNonnullByDefault;
import forestry.core.utils.FieldsAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;
@@ -12,13 +12,10 @@ package forestry.greenhouse.multiblock;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import forestry.api.climate.IClimateInfo;
import forestry.api.climate.IClimateRegion;
import forestry.api.greenhouse.EnumGreenhouseEventType;
import forestry.api.greenhouse.IGreenhouseLogic;
import forestry.api.greenhouse.IInternalBlock;
import forestry.api.multiblock.IGreenhouseComponent.ButterflyHatch;
import forestry.api.multiblock.IGreenhouseComponent.Listener;
@@ -78,15 +75,6 @@ public class FakeGreenhouseController extends FakeMultiblockController implement
return BlockPos.ORIGIN;
}
@Override
public List<IGreenhouseLogic> getLogics() {
return Collections.emptyList();
}
@Override
public void onChange(EnumGreenhouseEventType type, Object event) {
}
@Override
public Set<IInternalBlock> getInternalBlocks() {
return Collections.emptySet();
@@ -12,7 +12,6 @@ package forestry.greenhouse.multiblock;
import javax.annotation.Nullable;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@@ -29,19 +28,14 @@ import forestry.api.core.EnumHumidity;
import forestry.api.core.EnumTemperature;
import forestry.api.core.ForestryAPI;
import forestry.api.core.ICamouflagedTile;
import forestry.api.greenhouse.EnumGreenhouseEventType;
import forestry.api.greenhouse.GreenhouseEvents.CamouflageChangeEvent;
import forestry.api.greenhouse.GreenhouseEvents.CheckInternalBlockFaceEvent;
import forestry.api.greenhouse.GreenhouseEvents.CreateInternalBlockEvent;
import forestry.api.greenhouse.GreenhouseManager;
import forestry.api.greenhouse.IGreenhouseLogic;
import forestry.api.greenhouse.IInternalBlock;
import forestry.api.greenhouse.IInternalBlockFace;
import forestry.api.multiblock.IGreenhouseComponent;
import forestry.api.multiblock.IGreenhouseComponent.ButterflyHatch;
import forestry.api.multiblock.IGreenhouseComponent.ClimateControl;
import forestry.api.multiblock.IGreenhouseComponent.Climatiser;
import forestry.api.multiblock.IGreenhouseController;
import forestry.api.multiblock.IMultiblockComponent;
import forestry.core.climate.ClimateInfo;
import forestry.core.climate.ClimatePosition;
@@ -62,7 +56,6 @@ import forestry.core.proxy.Proxies;
import forestry.core.tiles.ILiquidTankTile;
import forestry.core.utils.CamouflageUtil;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.Log;
import forestry.core.utils.Translator;
import forestry.energy.EnergyManager;
import forestry.greenhouse.inventory.InventoryGreenhouse;
@@ -84,7 +77,6 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
private final Set<IGreenhouseComponent.Listener> listenerComponents = new HashSet<>();
private final Set<IGreenhouseComponent.Active> activeComponents = new HashSet<>();
private final Set<IGreenhouseComponent.Climatiser> climatiserComponents = new HashSet<>();
private final List<IGreenhouseLogic> logics = new ArrayList<>();
@Nullable
protected ClimateControl climateControl;
@Nullable
@@ -109,11 +101,10 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
this.energyManager = new EnergyManager(200, 100000);
this.inventory = new InventoryGreenhouse(this);
camouflagePlainBlock = getDefaultCamouflageBlock(CamouflageManager.BLOCK);
camouflageGlassBlock = getDefaultCamouflageBlock(CamouflageManager.GLASS);
camouflageDoorBlock = getDefaultCamouflageBlock(CamouflageManager.DOOR);
this.camouflagePlainBlock = getDefaultCamouflageBlock(CamouflageManager.BLOCK);
this.camouflageGlassBlock = getDefaultCamouflageBlock(CamouflageManager.GLASS);
this.camouflageDoorBlock = getDefaultCamouflageBlock(CamouflageManager.DOOR);
this.region = new ClimateRegion(this);
createLogics();
}
/* CLIMATE */
@@ -160,12 +151,6 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
CamouflageUtil.writeCamouflageBlockToNBT(data, this, CamouflageManager.GLASS);
CamouflageUtil.writeCamouflageBlockToNBT(data, this, CamouflageManager.DOOR);
for (IGreenhouseLogic logic : getLogics()) {
NBTTagCompound nbtTag = new NBTTagCompound();
logic.writeToNBT(nbtTag);
data.setTag("logic" + logic.getName(), nbtTag);
}
data.setTag("Region", region.writeToNBT(new NBTTagCompound()));
return data;
@@ -183,14 +168,6 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
CamouflageUtil.readCamouflageBlockFromNBT(data, this, CamouflageManager.GLASS);
CamouflageUtil.readCamouflageBlockFromNBT(data, this, CamouflageManager.DOOR);
if (logics.isEmpty()) {
createLogics();
}
for (IGreenhouseLogic logic : getLogics()) {
logic.readFromNBT(data.getCompoundTag("logic" + logic.getName()));
}
if (data.hasKey("Region")) {
NBTTagCompound nbtTag = data.getCompoundTag("Region");
if (region != null) {
@@ -285,7 +262,6 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
}
Proxies.net.sendToServer(new PacketCamouflageSelectServer(this, type, CamouflageSelectionType.MULTIBLOCK));
}
MinecraftForge.EVENT_BUS.post(new CamouflageChangeEvent(this, null, this, type));
return true;
}
return false;
@@ -319,43 +295,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
}
}
/* GREENHOUSE */
@Override
public void onChange(EnumGreenhouseEventType type, Object event) {
for (IGreenhouseLogic logic : logics) {
logic.onEvent(type, event);
}
}
/* GREENHOUSE LOGICS */
private void createLogics() {
logics.clear();
for (Class<? extends IGreenhouseLogic> logicClass : GreenhouseManager.greenhouseHelper.getGreenhouseLogics()) {
IGreenhouseLogic logic = createLogic(logicClass);
if (logic != null) {
logics.add(logic);
}
}
}
@Nullable
private IGreenhouseLogic createLogic(Class<? extends IGreenhouseLogic> logicClass) {
try {
return logicClass.getConstructor(IGreenhouseController.class).newInstance(this);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e) {
Log.error("Fail to create a greenhouse logic with the class: {}", logicClass, e);
return null;
}
}
@Override
public List<IGreenhouseLogic> getLogics() {
return logics;
}
/* MANAGERS */
@Override
public TankManager getTankManager() {
return tankManager;
@@ -413,9 +353,6 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
world.markBlockRangeForRenderUpdate(comp.getCoordinates(), comp.getCoordinates());
}
}
for(IGreenhouseLogic logic : logics){
logic.onMachineAssembled();
}
}
@Override
@@ -435,9 +372,6 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
world.markBlockRangeForRenderUpdate(comp.getCoordinates(), comp.getCoordinates());
}
}
for(IGreenhouseLogic logic : logics){
logic.onMachineDisassembled();
}
}
@Override
@@ -482,10 +416,6 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
inventory.drainCan(tankManager);
}
for (IGreenhouseLogic logic : logics) {
logic.work();
}
for (IGreenhouseComponent.Active activeComponent : activeComponents) {
activeComponent.updateServer(tickCount);
}
@@ -17,7 +17,6 @@ import forestry.api.core.ICamouflageHandler;
import forestry.api.core.ICamouflagedTile;
import forestry.api.core.IErrorLogic;
import forestry.api.core.IErrorLogicSource;
import forestry.api.greenhouse.GreenhouseEvents.CamouflageChangeEvent;
import forestry.api.multiblock.IGreenhouseComponent;
import forestry.api.multiblock.IMultiblockController;
import forestry.core.inventory.IInventoryAdapter;
@@ -43,7 +42,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
public abstract class TileGreenhouse extends MultiblockTileEntityForestry<MultiblockLogicGreenhouse> implements IGreenhouseComponent, IStreamableGui, IErrorLogicSource, IOwnedTile, ITitled, ICamouflageHandler, ICamouflagedTile {
protected ItemStack camouflageBlock;
@@ -103,7 +101,6 @@ public abstract class TileGreenhouse extends MultiblockTileEntityForestry<Multib
Proxies.net.sendToServer(new PacketCamouflageSelectServer(this, type, CamouflageSelectionType.TILE));
world.markBlockRangeForRenderUpdate(pos, pos);
}
MinecraftForge.EVENT_BUS.post(new CamouflageChangeEvent(getMultiblockLogic().getController(), this, this, type));
return true;
}
return false;
@@ -19,7 +19,6 @@ import forestry.api.core.ICamouflageHandler;
import forestry.api.core.ICamouflagedTile;
import forestry.api.core.IErrorLogic;
import forestry.api.core.IErrorLogicSource;
import forestry.api.greenhouse.GreenhouseEvents.CamouflageChangeEvent;
import forestry.api.multiblock.IGreenhouseComponent;
import forestry.api.multiblock.IMultiblockController;
import forestry.api.multiblock.MultiblockTileEntityBase;
@@ -41,7 +40,6 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.items.CapabilityItemHandler;
@@ -135,7 +133,6 @@ public class TileGreenhouseHatch extends MultiblockTileEntityBase<MultiblockLogi
if (sendClientUpdate && world != null && world.isRemote) {
Proxies.net.sendToServer(new PacketCamouflageSelectServer(this, type, CamouflageSelectionType.TILE));
}
MinecraftForge.EVENT_BUS.post(new CamouflageChangeEvent(getMultiblockLogic().getController(), this, this, type));
return true;
}
return false;