mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 20:42:35 +00:00
Add Greenhous Helper and State
This commit is contained in:
1 parent
eebd9c6ecf
commit
a0fb568144
9 files changed
+146
-4
No files matched your search
@@ -27,7 +27,7 @@ public class DefaultGreenhouseLogic implements IGreenhouseLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWork() {
|
||||
public void work() {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.greenhouse;
|
||||
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IGreenhouseHelper {
|
||||
|
||||
IGreenhouseState getGreenhouseState(World world, BlockPos pos);
|
||||
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import forestry.api.multiblock.IGreenhouseController;
|
||||
|
||||
public interface IGreenhouseLogic extends INbtWritable, INbtReadable {
|
||||
|
||||
void onWork();
|
||||
void work();
|
||||
|
||||
void onChange(EnumGreenhouseChangeType type, Object event);
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.greenhouse;
|
||||
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IGreenhouseState {
|
||||
|
||||
EnumTemperature getTemperature();
|
||||
|
||||
EnumHumidity getHumidity();
|
||||
|
||||
float getExactTemperature();
|
||||
|
||||
float getExactHumidity();
|
||||
|
||||
World getWorld();
|
||||
|
||||
}
|
||||
@@ -144,7 +144,7 @@ public class BlockSoil extends Block implements IItemTyped, IItemModelRegister {
|
||||
for (int j = -1; j < 2; j++) {
|
||||
IBlockState state = world.getBlockState(new BlockPos(pos.getX() + i, pos.getY() + 1, pos.getZ() + j));
|
||||
Block block = state.getBlock();
|
||||
if (block == Blocks.log || block == Blocks.sapling || block instanceof IGrowable) {
|
||||
if (block == Blocks.log || block == Blocks.log2 || block == Blocks.sapling || block instanceof IGrowable) {
|
||||
// We are not returning true if we are the base of a sapling.
|
||||
return !(i == 0 && j == 0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse;
|
||||
|
||||
import forestry.api.greenhouse.IGreenhouseHelper;
|
||||
import forestry.api.greenhouse.IGreenhouseState;
|
||||
import forestry.core.multiblock.IMultiblockControllerInternal;
|
||||
import forestry.core.multiblock.MultiblockRegistry;
|
||||
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class GreenhouseHelper implements IGreenhouseHelper {
|
||||
|
||||
@Override
|
||||
public IGreenhouseState getGreenhouseState(World world, BlockPos pos) {
|
||||
for(IMultiblockControllerInternal controllerInternal : MultiblockRegistry.getControllersFromWorld(world)){
|
||||
if(controllerInternal instanceof IGreenhouseControllerInternal){
|
||||
if(controllerInternal.isAssembled()){
|
||||
if(((IGreenhouseControllerInternal) controllerInternal).isInGreenhouse(pos)){
|
||||
return ((IGreenhouseControllerInternal) controllerInternal).createState();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*******************************************************************************
|
||||
* 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.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.greenhouse.IGreenhouseState;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class GreenhouseState implements IGreenhouseState {
|
||||
|
||||
private final float humidity;
|
||||
private final float temperature;
|
||||
private final World world;
|
||||
|
||||
public GreenhouseState(World world, float humidity, float temperature) {
|
||||
this.world = world;
|
||||
this.humidity = humidity;
|
||||
this.temperature = temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumTemperature getTemperature() {
|
||||
return EnumTemperature.getFromValue(temperature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumHumidity getHumidity() {
|
||||
return EnumHumidity.getFromValue(humidity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getExactTemperature() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getExactHumidity() {
|
||||
return humidity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -34,7 +34,7 @@ public class GreenhouseEffect extends DefaultGreenhouseLogic implements IGreenho
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWork() {
|
||||
public void work() {
|
||||
if(controller == null || !controller.isAssembled()){
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import forestry.api.core.CamouflageEvents.CamouflageChangeEvent;
|
||||
import forestry.api.greenhouse.EnumGreenhouseChangeType;
|
||||
import forestry.api.greenhouse.GreenhouseManager;
|
||||
import forestry.api.greenhouse.IGreenhouseLogic;
|
||||
import forestry.api.greenhouse.IGreenhouseState;
|
||||
import forestry.api.core.EnumCamouflageType;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
@@ -50,6 +51,7 @@ import forestry.core.tiles.ILiquidTankTile;
|
||||
import forestry.core.utils.CamouflageUtil;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.energy.EnergyManager;
|
||||
import forestry.greenhouse.GreenhouseState;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouse;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouseType;
|
||||
import forestry.greenhouse.network.packets.PacketCamouflageUpdate;
|
||||
@@ -435,6 +437,10 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
inventory.drainCan(tankManager);
|
||||
}
|
||||
|
||||
for(IGreenhouseLogic logic : logics){
|
||||
logic.work();
|
||||
}
|
||||
|
||||
for (IGreenhouseComponent.Active activeComponent : activeComponents) {
|
||||
activeComponent.updateServer(tickCount);
|
||||
}
|
||||
@@ -695,5 +701,10 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
public List<IGreenhouseLogic> getLogics() {
|
||||
return logics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGreenhouseState createState() {
|
||||
return new GreenhouseState(worldObj, getBiome().rainfall + humidChange, getBiome().temperature + tempChange);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user