mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-27 15:22:57 +00:00
Clean Up and improve greenhouse climate system
This commit is contained in:
1 parent
8bf6b19a63
commit
e0bff8ec64
72 files changed
+628
-913
No files matched your search
@@ -34,6 +34,6 @@ public interface IClimateManager {
|
||||
@Nullable
|
||||
IClimateRegion getRegionForPos(World world, BlockPos pos);
|
||||
|
||||
Map<Integer, List<IClimateRegion>> getRegions();
|
||||
Map<World, List<IClimateRegion>> getRegions();
|
||||
|
||||
}
|
||||
@@ -9,6 +9,9 @@ import forestry.api.core.INbtReadable;
|
||||
import forestry.api.core.INbtWritable;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
* A IClimatePosition contains the climate infos (temperature and humidity) of one position.
|
||||
*/
|
||||
public interface IClimatePosition extends INbtReadable, INbtWritable {
|
||||
|
||||
IClimateRegion getClimateRegion();
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
package forestry.api.climate;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.core.INbtReadable;
|
||||
import forestry.api.core.INbtWritable;
|
||||
@@ -17,25 +17,30 @@ public interface IClimateRegion extends INbtReadable, INbtWritable {
|
||||
|
||||
World getWorld();
|
||||
|
||||
int getTicksPerUpdate();
|
||||
|
||||
void setPosition(BlockPos pos, float temperature, float humidity);
|
||||
|
||||
@Nullable
|
||||
IClimatePosition getPosition(BlockPos pos);
|
||||
|
||||
Collection<IClimatePosition> getPositions();
|
||||
|
||||
void addSource(IClimateSource source);
|
||||
|
||||
void removeSource(IClimateSource source);
|
||||
|
||||
Collection<IClimateSource> getSources();
|
||||
|
||||
void calculateAverageClimate();
|
||||
|
||||
float getAverageTemperature();
|
||||
|
||||
float getAverageHumidity();
|
||||
|
||||
/**
|
||||
* Update the climate in a region.
|
||||
*/
|
||||
void updateClimate(int ticks);
|
||||
|
||||
int getTicksPerUpdate();
|
||||
|
||||
Map<BlockPos, IClimatePosition> getPositions();
|
||||
|
||||
void addSource(IClimateSource source);
|
||||
|
||||
void removeSource(IClimateSource source);
|
||||
|
||||
Collection<IClimateSource> getSources();
|
||||
|
||||
Collection<BlockPos> getOtherPositions();
|
||||
|
||||
float getTemperature();
|
||||
|
||||
float getHumidity();
|
||||
|
||||
}
|
||||
@@ -5,9 +5,14 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.climate;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import forestry.api.core.ILocatable;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public interface IClimateSourceProvider extends ILocatable {
|
||||
|
||||
IClimateSource getClimateSource();
|
||||
|
||||
Set<BlockPos> getPositionsInRange();
|
||||
}
|
||||
@@ -9,7 +9,7 @@ public interface IClimatiserDefinition {
|
||||
|
||||
float getChange();
|
||||
|
||||
double getRange();
|
||||
float getRange();
|
||||
|
||||
EnumClimatiserModes getMode();
|
||||
|
||||
|
||||
@@ -7,12 +7,10 @@ package forestry.api.core;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
|
||||
import forestry.api.multiblock.IGreenhouseController;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
public interface IGreenhouseHelper {
|
||||
|
||||
@@ -18,7 +18,7 @@ public interface IGreenhouseHelper {
|
||||
* @return A {@link IGreenhouseController} of a greenhouse, when the pos is a greenhouse
|
||||
*/
|
||||
@Nullable
|
||||
IGreenhouseController getGreenhouseController(World world, BlockPos pos);
|
||||
IGreenhouseController getGreenhouseController(IBlockAccess world, BlockPos pos);
|
||||
|
||||
void addGreenhouseLogic(Class<? extends IGreenhouseLogic> logic);
|
||||
|
||||
|
||||
@@ -5,10 +5,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.multiblock;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
import forestry.api.climate.IClimateControl;
|
||||
import forestry.api.climate.IClimateControlProvider;
|
||||
import forestry.api.climate.IClimateRegion;
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
@@ -28,10 +26,6 @@ public interface IGreenhouseController extends IMultiblockController, IGreenhous
|
||||
*/
|
||||
List<IGreenhouseLogic> getLogics();
|
||||
|
||||
@Nullable
|
||||
IClimateRegion getRegion();
|
||||
|
||||
@Override
|
||||
IClimateControl getClimateControl();
|
||||
|
||||
}
|
||||
@@ -133,7 +133,7 @@ public abstract class EntityMinecartBeeHousingBase extends EntityMinecartContain
|
||||
|
||||
@Override
|
||||
public boolean isRaining() {
|
||||
return world.isRaining();
|
||||
return world.isRainingAt(getPosition().up());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -38,7 +38,7 @@ public class ItemBlockWoodDoor extends ItemBlockWood<BlockArbDoor> {
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (player.canPlayerEdit(pos, facing, itemstack) && this.block.canPlaceBlockAt(worldIn, pos)) {
|
||||
EnumFacing enumfacing = EnumFacing.fromAngle((double) player.rotationYaw);
|
||||
EnumFacing enumfacing = EnumFacing.fromAngle(player.rotationYaw);
|
||||
int i = enumfacing.getFrontOffsetX();
|
||||
int j = enumfacing.getFrontOffsetZ();
|
||||
boolean flag = i < 0 && hitZ < 0.5F || i > 0 && hitZ > 0.5F || j < 0 && hitX > 0.5F || j > 0 && hitX < 0.5F;
|
||||
|
||||
@@ -24,7 +24,6 @@ import forestry.core.blocks.properties.UnlistedBlockPos;
|
||||
import forestry.core.models.ModelBlockCached;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
|
||||
@@ -10,9 +10,21 @@
|
||||
******************************************************************************/
|
||||
package forestry.core;
|
||||
|
||||
import forestry.api.apiculture.BeeManager;
|
||||
import forestry.api.apiculture.EnumBeeType;
|
||||
import forestry.api.arboriculture.EnumGermlingType;
|
||||
import forestry.api.arboriculture.TreeManager;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.Tabs;
|
||||
import forestry.api.lepidopterology.ButterflyManager;
|
||||
import forestry.api.lepidopterology.EnumFlutterType;
|
||||
import forestry.apiculture.genetics.Bee;
|
||||
import forestry.apiculture.genetics.BeeDefinition;
|
||||
import forestry.arboriculture.genetics.Tree;
|
||||
import forestry.arboriculture.genetics.TreeDefinition;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.lepidopterology.genetics.Butterfly;
|
||||
import forestry.lepidopterology.genetics.ButterflyDefinition;
|
||||
import forestry.plugins.ForestryPluginUids;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -57,14 +69,11 @@ public class CreativeTabForestry extends CreativeTabs {
|
||||
iconItem = ForgeRegistries.ITEMS.getValue(new ResourceLocation(Constants.MOD_ID, "ffarm"));
|
||||
break;
|
||||
case 2:
|
||||
iconItem = ForgeRegistries.ITEMS.getValue(new ResourceLocation(Constants.MOD_ID, "beeDroneGE"));
|
||||
break;
|
||||
return BeeManager.beeRoot.getMemberStack(new Bee(BeeDefinition.FOREST.getGenome()), EnumBeeType.DRONE);
|
||||
case 3:
|
||||
iconItem = ForgeRegistries.ITEMS.getValue(new ResourceLocation(Constants.MOD_ID, "sapling"));
|
||||
break;
|
||||
return TreeManager.treeRoot.getMemberStack(new Tree(TreeDefinition.Oak.getGenome()), EnumGermlingType.SAPLING);
|
||||
case 4:
|
||||
iconItem = ForgeRegistries.ITEMS.getValue(new ResourceLocation(Constants.MOD_ID, "butterflyGE"));
|
||||
break;
|
||||
return ButterflyManager.butterflyRoot.getMemberStack(new Butterfly(ButterflyDefinition.Brimstone.getGenome()), EnumFlutterType.BUTTERFLY);
|
||||
default:
|
||||
iconItem = ForgeRegistries.ITEMS.getValue(new ResourceLocation(Constants.MOD_ID, "fertilizerCompound"));
|
||||
break;
|
||||
|
||||
@@ -23,7 +23,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
|
||||
public class ClimateEventHandler {
|
||||
|
||||
private final Map<Integer, Integer> serverTicks;
|
||||
private final Map<World, Integer> serverTicks;
|
||||
|
||||
public ClimateEventHandler() {
|
||||
serverTicks = new HashMap<>();
|
||||
@@ -156,18 +156,17 @@ public class ClimateEventHandler {
|
||||
MinecraftServer server = world.getMinecraftServer();
|
||||
if (server != null) {
|
||||
server.addScheduledTask(() -> {
|
||||
Integer dim = event.world.provider.getDimension();
|
||||
if (!serverTicks.containsKey(dim)) {
|
||||
serverTicks.put(dim, 1);
|
||||
if (!serverTicks.containsKey(world)) {
|
||||
serverTicks.put(world, 1);
|
||||
}
|
||||
int ticks = serverTicks.get(dim);
|
||||
Map<Integer, List<IClimateRegion>> regions = ForestryAPI.climateManager.getRegions();
|
||||
if (regions.containsKey(dim)) {
|
||||
for (IClimateRegion region : regions.get(dim)) {
|
||||
int ticks = serverTicks.get(world);
|
||||
Map<World, List<IClimateRegion>> regions = ForestryAPI.climateManager.getRegions();
|
||||
if (regions.containsKey(world)) {
|
||||
for (IClimateRegion region : regions.get(world)) {
|
||||
region.updateClimate(ticks);
|
||||
}
|
||||
}
|
||||
serverTicks.put(dim, ticks + 1);
|
||||
serverTicks.put(world, ticks + 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import forestry.api.climate.IClimateManager;
|
||||
import forestry.api.climate.IClimatePosition;
|
||||
import forestry.api.climate.IClimateProvider;
|
||||
@@ -27,7 +26,7 @@ import net.minecraft.world.World;
|
||||
|
||||
public class ClimateManager implements IClimateManager {
|
||||
|
||||
protected final Map<Integer, List<IClimateRegion>> regions;
|
||||
protected final Map<World, List<IClimateRegion>> regions;
|
||||
private final Object regionsMutex;
|
||||
|
||||
public ClimateManager() {
|
||||
@@ -38,15 +37,17 @@ public class ClimateManager implements IClimateManager {
|
||||
@Override
|
||||
public void addRegion(IClimateRegion region) {
|
||||
synchronized (regionsMutex) {
|
||||
Integer dimensionID = region.getWorld().provider.getDimension();
|
||||
if (!regions.containsKey(dimensionID)) {
|
||||
this.regions.put(dimensionID, new ArrayList<>());
|
||||
World world = region.getWorld();
|
||||
if (!regions.containsKey(world)) {
|
||||
this.regions.put(world, new ArrayList<>());
|
||||
}
|
||||
List<IClimateRegion> regions = this.regions.get(dimensionID);
|
||||
List<IClimateRegion> regions = this.regions.get(world);
|
||||
if (!regions.contains(region)) {
|
||||
for (BlockPos pos : region.getPositions().keySet()) {
|
||||
if (getRegionForPos(region.getWorld(), pos) != null) {
|
||||
return;
|
||||
if(!regions.isEmpty()){
|
||||
for (IClimatePosition pos : region.getPositions()) {
|
||||
if (getRegionForPos(world, pos.getPos()) != null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
regions.add(region);
|
||||
@@ -57,23 +58,21 @@ public class ClimateManager implements IClimateManager {
|
||||
@Override
|
||||
public void removeRegion(IClimateRegion region) {
|
||||
synchronized (regionsMutex) {
|
||||
Integer dimensionID = region.getWorld().provider.getDimension();
|
||||
if (!regions.containsKey(dimensionID)) {
|
||||
this.regions.put(dimensionID, new ArrayList<>());
|
||||
}
|
||||
List<IClimateRegion> regions = this.regions.get(dimensionID);
|
||||
if (regions.contains(region)) {
|
||||
regions.remove(region);
|
||||
World world = region.getWorld();
|
||||
if (!regions.containsKey(world)) {
|
||||
this.regions.put(world, new ArrayList<>());
|
||||
}
|
||||
List<IClimateRegion> regions = this.regions.get(world);
|
||||
regions.remove(region);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSource(IClimateSourceProvider source) {
|
||||
synchronized (regionsMutex) {
|
||||
Integer dimensionID = source.getWorldObj().provider.getDimension();
|
||||
if (!regions.containsKey(dimensionID)) {
|
||||
regions.put(dimensionID, new ArrayList<>());
|
||||
World world = source.getWorldObj();
|
||||
if (!regions.containsKey(world)) {
|
||||
regions.put(world, new ArrayList<>());
|
||||
}
|
||||
IClimateRegion region = getRegionForPos(source.getWorldObj(), source.getCoordinates());
|
||||
if (region != null) {
|
||||
@@ -87,9 +86,9 @@ public class ClimateManager implements IClimateManager {
|
||||
@Override
|
||||
public void addSource(IClimateSourceProvider source) {
|
||||
synchronized (regionsMutex) {
|
||||
Integer dimensionID = source.getWorldObj().provider.getDimension();
|
||||
if (!regions.containsKey(dimensionID)) {
|
||||
regions.put(dimensionID, new ArrayList<>());
|
||||
World world = source.getWorldObj();
|
||||
if (!regions.containsKey(world)) {
|
||||
regions.put(world, new ArrayList<>());
|
||||
}
|
||||
IClimateRegion region = getRegionForPos(source.getWorldObj(), source.getCoordinates());
|
||||
if (region != null) {
|
||||
@@ -121,20 +120,20 @@ public class ClimateManager implements IClimateManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, List<IClimateRegion>> getRegions() {
|
||||
public Map<World, List<IClimateRegion>> getRegions() {
|
||||
return regions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimatePosition getPosition(World world, BlockPos pos) {
|
||||
Integer dimensionID = world.provider.getDimension();
|
||||
if (!regions.containsKey(dimensionID)) {
|
||||
regions.put(dimensionID, new ArrayList<>());
|
||||
if (!regions.containsKey(world)) {
|
||||
regions.put(world, new ArrayList<>());
|
||||
return null;
|
||||
}
|
||||
for (IClimateRegion region : regions.get(dimensionID)) {
|
||||
if (region.getPositions().keySet().contains(pos)) {
|
||||
return region.getPositions().get(pos);
|
||||
for (IClimateRegion region : regions.get(world)) {
|
||||
IClimatePosition position = region.getPosition(pos);
|
||||
if(position != null){
|
||||
return position;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -142,15 +141,12 @@ public class ClimateManager implements IClimateManager {
|
||||
|
||||
@Override
|
||||
public IClimateRegion getRegionForPos(World world, BlockPos pos) {
|
||||
Integer dimensionID = world.provider.getDimension();
|
||||
if (!regions.containsKey(dimensionID)) {
|
||||
this.regions.put(dimensionID, new ArrayList<>());
|
||||
if (!regions.containsKey(world)) {
|
||||
this.regions.put(world, new ArrayList<>());
|
||||
}
|
||||
List<IClimateRegion> regions = this.regions.get(dimensionID);
|
||||
List<IClimateRegion> regions = this.regions.get(world);
|
||||
for (IClimateRegion region : regions) {
|
||||
if (region.getPositions().keySet().contains(pos)) {
|
||||
return region;
|
||||
} else if (region.getOtherPositions().contains(pos)) {
|
||||
if (region.getPosition(pos) != null) {
|
||||
return region;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,37 +17,36 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
public class ClimatePosition implements IClimatePosition {
|
||||
protected final IClimateRegion climateRegion;
|
||||
protected final IClimateRegion region;
|
||||
|
||||
protected final BlockPos pos;
|
||||
protected float temperature;
|
||||
protected float humidity;
|
||||
|
||||
public ClimatePosition(IClimateRegion climateRegion, BlockPos pos, NBTTagCompound nbtTag) {
|
||||
this.climateRegion = climateRegion;
|
||||
public ClimatePosition(IClimateRegion rRegion, BlockPos pos, NBTTagCompound nbtTag) {
|
||||
this.region = rRegion;
|
||||
this.pos = pos;
|
||||
readFromNBT(nbtTag);
|
||||
}
|
||||
|
||||
public ClimatePosition(IClimateRegion climateRegion, BlockPos pos) {
|
||||
Biome biome = climateRegion.getWorld().getBiome(pos);
|
||||
this.climateRegion = climateRegion;
|
||||
public ClimatePosition(IClimateRegion region, BlockPos pos) {
|
||||
Biome biome = region.getWorld().getBiome(pos);
|
||||
this.region = region;
|
||||
this.pos = pos;
|
||||
this.temperature = biome.getTemperature();
|
||||
this.humidity = biome.getRainfall();
|
||||
}
|
||||
|
||||
public ClimatePosition(IClimateRegion climateRegion, BlockPos pos, float temperature, float humidity) {
|
||||
this.climateRegion = climateRegion;
|
||||
public ClimatePosition(IClimateRegion region, BlockPos pos, float temperature, float humidity) {
|
||||
this.region = region;
|
||||
this.pos = pos;
|
||||
this.temperature = temperature;
|
||||
this.humidity = humidity;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IClimateRegion getClimateRegion() {
|
||||
return climateRegion;
|
||||
return region;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,296 @@
|
||||
/*******************************************************************************
|
||||
* 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.core.climate;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import forestry.api.climate.IClimateControl;
|
||||
import forestry.api.climate.IClimatePosition;
|
||||
import forestry.api.climate.IClimateRegion;
|
||||
import forestry.api.climate.IClimateSource;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ClimateRegion implements IClimateRegion, IStreamable {
|
||||
protected final World world;
|
||||
protected final IGreenhouseControllerInternal controller;
|
||||
protected final Set<IClimatePosition> positions;
|
||||
protected final Set<IClimateSource> sources;
|
||||
protected float temperature;
|
||||
protected float humidity;
|
||||
|
||||
public ClimateRegion(IGreenhouseControllerInternal controller, Set<IClimatePosition> positions) {
|
||||
this.world = controller.getWorldObj();
|
||||
this.controller = controller;
|
||||
this.positions = positions;
|
||||
this.sources = new HashSet<>();
|
||||
calculateAverageClimate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an empty region.
|
||||
*/
|
||||
public ClimateRegion(IGreenhouseControllerInternal controller) {
|
||||
this.world = controller.getWorldObj();
|
||||
this.controller = controller;
|
||||
this.positions = new HashSet<>();
|
||||
this.sources = new HashSet<>();
|
||||
}
|
||||
|
||||
|
||||
public ClimateRegion(IGreenhouseControllerInternal controller, NBTTagCompound nbtTag) {
|
||||
this.world = controller.getWorldObj();
|
||||
this.controller = controller;
|
||||
this.positions = new HashSet<>();
|
||||
this.sources = new HashSet<>();
|
||||
readFromNBT(nbtTag);
|
||||
calculateAverageClimate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculateAverageClimate(){
|
||||
humidity = 0.0F;
|
||||
temperature = 0.0F;
|
||||
if(!positions.isEmpty()){
|
||||
int positions = 0;
|
||||
for (IClimatePosition position : this.positions) {
|
||||
if (position != null) {
|
||||
positions++;
|
||||
humidity += position.getHumidity();
|
||||
temperature += position.getTemperature();
|
||||
}
|
||||
}
|
||||
|
||||
temperature /= positions;
|
||||
humidity /= positions;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateClimate(int ticks) {
|
||||
boolean hasChange = false;
|
||||
for (IClimateSource source : sources) {
|
||||
if (source != null) {
|
||||
if (ticks % source.getTicksForChange(this) == 0) {
|
||||
hasChange |= source.changeClimate(ticks, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ticks % getTicksPerUpdate() == 0) {
|
||||
for (IClimatePosition position : positions) {
|
||||
BlockPos pos = position.getPos();
|
||||
if (world.isBlockLoaded(pos)) {
|
||||
hasChange |= updateSides(position);
|
||||
if (!controller.isAssembled()) {
|
||||
IClimateControl climateControl = getControl(pos);
|
||||
|
||||
if (position.getTemperature() != climateControl.getControlTemperature()) {
|
||||
if (position.getTemperature() > climateControl.getControlTemperature()) {
|
||||
position.addTemperature(-Math.min(0.01F, position.getTemperature() - climateControl.getControlTemperature()));
|
||||
hasChange = true;
|
||||
} else {
|
||||
position.addTemperature(Math.min(0.01F, climateControl.getControlTemperature() - position.getTemperature()));
|
||||
hasChange = true;
|
||||
}
|
||||
}
|
||||
if (position.getHumidity() != climateControl.getControlHumidity()) {
|
||||
if (position.getHumidity() > climateControl.getControlHumidity()) {
|
||||
position.addHumidity(-Math.min(0.01F, position.getHumidity() - climateControl.getControlHumidity()));
|
||||
hasChange = true;
|
||||
} else {
|
||||
position.addHumidity(Math.min(0.01F, climateControl.getControlHumidity() - position.getHumidity()));
|
||||
hasChange = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasChange) {
|
||||
calculateAverageClimate();
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean updateSides(IClimatePosition positon) {
|
||||
BlockPos pos = positon.getPos();
|
||||
IClimateControl climateControl = getControl(pos);
|
||||
boolean hasChange = false;
|
||||
if (climateControl.getControlTemperature() != temperature || climateControl.getControlHumidity() != humidity) {
|
||||
for (EnumFacing facing : EnumFacing.VALUES) {
|
||||
IClimatePosition climatedInfoFace = getPosition(pos.offset(facing));
|
||||
if (climatedInfoFace != null) {
|
||||
if (positon.getTemperature() > climatedInfoFace.getTemperature() + 0.01F) {
|
||||
float change = Math.min(0.01F, positon.getTemperature() - climatedInfoFace.getTemperature());
|
||||
positon.addTemperature(-change);
|
||||
climatedInfoFace.addTemperature(change);
|
||||
hasChange = true;
|
||||
}
|
||||
if (positon.getHumidity() > climatedInfoFace.getHumidity() + 0.01F) {
|
||||
float change = Math.min(0.01F, positon.getHumidity() - climatedInfoFace.getHumidity());
|
||||
positon.addHumidity(-change);
|
||||
climatedInfoFace.addHumidity(change);
|
||||
hasChange = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return hasChange;
|
||||
}
|
||||
|
||||
protected IClimateControl getControl(BlockPos pos) {
|
||||
if (world.isBlockLoaded(pos)) {
|
||||
if (!controller.isAssembled()) {
|
||||
return BiomeClimateControl.getControl(world.getBiome(pos));
|
||||
}
|
||||
}
|
||||
return controller.getClimateControl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IClimatePosition> getPositions() {
|
||||
return positions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimatePosition getPosition(BlockPos pos) {
|
||||
for(IClimatePosition position : positions){
|
||||
if(position.getPos().equals(pos)){
|
||||
return position;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
NBTTagList positionList = new NBTTagList();
|
||||
for (IClimatePosition positon : positions) {
|
||||
BlockPos pos = positon.getPos();
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setInteger("X", pos.getX());
|
||||
tag.setInteger("Y", pos.getY());
|
||||
tag.setInteger("Z", pos.getZ());
|
||||
positionList.appendTag(positon.writeToNBT(tag));
|
||||
}
|
||||
nbt.setTag("Positions", positionList);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
NBTTagList positionList = nbt.getTagList("Positions", 10);
|
||||
for (int i = 0; i < positionList.tagCount(); i++) {
|
||||
NBTTagCompound positionTag = positionList.getCompoundTagAt(i);
|
||||
int xPos = positionTag.getInteger("X");
|
||||
int yPos = positionTag.getInteger("Y");
|
||||
int zPos = positionTag.getInteger("Z");
|
||||
BlockPos pos = new BlockPos(xPos, yPos, zPos);
|
||||
IClimatePosition position = getPosition(pos);
|
||||
if (position != null) {
|
||||
position.readFromNBT(positionTag);
|
||||
} else {
|
||||
positions.add(new ClimatePosition(this, pos, positionTag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTicksPerUpdate() {
|
||||
return 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void setPosition(BlockPos pos, float temperature, float humidity) {
|
||||
IClimatePosition position = getPosition(pos);
|
||||
if (position != null) {
|
||||
position.setHumidity(humidity);
|
||||
position.setTemperature(temperature);
|
||||
} else {
|
||||
positions.add(new ClimatePosition(this, pos, temperature, humidity));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void addSource(IClimateSource source) {
|
||||
if (!sources.contains(source)) {
|
||||
sources.add(source);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void removeSource(IClimateSource source) {
|
||||
if (sources.contains(source)) {
|
||||
sources.remove(source);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IClimateSource> getSources() {
|
||||
return sources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(PacketBufferForestry data) {
|
||||
if (!positions.isEmpty()) {
|
||||
data.writeInt(positions.size());
|
||||
data.writeFloat(temperature);
|
||||
data.writeFloat(humidity);
|
||||
} else {
|
||||
data.writeInt(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(PacketBufferForestry data) throws IOException {
|
||||
int size = data.readInt();
|
||||
if (size != 0) {
|
||||
temperature = data.readFloat();
|
||||
humidity = data.readFloat();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAverageTemperature() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAverageHumidity() {
|
||||
return humidity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof ClimateRegion)){
|
||||
return false;
|
||||
}
|
||||
ClimateRegion region = (ClimateRegion) obj;
|
||||
if(region.controller != controller){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,318 +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.core.climate;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import forestry.api.climate.IClimateControl;
|
||||
import forestry.api.climate.IClimatePosition;
|
||||
import forestry.api.climate.IClimateRegion;
|
||||
import forestry.api.climate.IClimateSource;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.utils.ClimateUtil;
|
||||
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ClimateRoom implements IClimateRegion, IStreamable {
|
||||
|
||||
protected final World world;
|
||||
protected final IGreenhouseControllerInternal controller;
|
||||
protected final Map<BlockPos, IClimatePosition> positions;
|
||||
protected final List<BlockPos> wallPositions;
|
||||
protected final List<IClimateSource> sources;
|
||||
protected float temperature;
|
||||
protected float humidity;
|
||||
|
||||
public ClimateRoom(ClimateRoom oldRoom, Map<BlockPos, IClimatePosition> newPositions, List<BlockPos> newWallPositions) {
|
||||
this.world = oldRoom.getWorld();
|
||||
this.controller = oldRoom.controller;
|
||||
this.positions = new HashMap<>();
|
||||
this.wallPositions = newWallPositions;
|
||||
this.sources = new ArrayList<>();
|
||||
for (Entry<BlockPos, IClimatePosition> positionEntry : newPositions.entrySet()) {
|
||||
BlockPos pos = positionEntry.getKey();
|
||||
IClimatePosition position = positionEntry.getValue();
|
||||
IClimatePosition oldPosition = oldRoom.getPositions().get(pos);
|
||||
float temperature = position.getTemperature();
|
||||
float humidity = position.getHumidity();
|
||||
if (oldPosition != null) {
|
||||
temperature = oldPosition.getTemperature();
|
||||
humidity = oldPosition.getHumidity();
|
||||
}
|
||||
addPosition(pos, temperature, humidity);
|
||||
}
|
||||
this.temperature = getExactTemperature();
|
||||
this.humidity = getExactHumidity();
|
||||
}
|
||||
|
||||
public ClimateRoom(IGreenhouseControllerInternal controller, Map<BlockPos, IClimatePosition> innerPositions, List<BlockPos> wallPositions) {
|
||||
this.world = controller.getWorldObj();
|
||||
this.controller = controller;
|
||||
this.positions = innerPositions;
|
||||
this.wallPositions = wallPositions;
|
||||
this.sources = new ArrayList<>();
|
||||
this.temperature = getExactTemperature();
|
||||
this.humidity = getExactHumidity();
|
||||
}
|
||||
|
||||
public ClimateRoom(IGreenhouseControllerInternal controller, List<BlockPos> wallPositions, NBTTagCompound nbtTag) {
|
||||
this.world = controller.getWorldObj();
|
||||
this.controller = controller;
|
||||
this.positions = new HashMap<>();
|
||||
this.wallPositions = new ArrayList<>();
|
||||
this.sources = new ArrayList<>();
|
||||
readFromNBT(nbtTag);
|
||||
this.temperature = getExactTemperature();
|
||||
this.humidity = getExactHumidity();
|
||||
}
|
||||
|
||||
private float getExactTemperature() {
|
||||
float temperature = 0.0F;
|
||||
int positions = 0;
|
||||
|
||||
for (IClimatePosition position : this.positions.values()) {
|
||||
if (position != null) {
|
||||
positions++;
|
||||
temperature += position.getTemperature();
|
||||
}
|
||||
}
|
||||
return temperature / positions;
|
||||
}
|
||||
|
||||
private float getExactHumidity() {
|
||||
float humidity = 0.0F;
|
||||
int positions = 0;
|
||||
|
||||
for (IClimatePosition position : this.positions.values()) {
|
||||
if (position != null) {
|
||||
positions++;
|
||||
humidity += position.getHumidity();
|
||||
}
|
||||
}
|
||||
return humidity / positions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateClimate(int ticks) {
|
||||
boolean hasChange = false;
|
||||
;
|
||||
for (IClimateSource source : sources) {
|
||||
if (source != null) {
|
||||
if (ticks % source.getTicksForChange(this) == 0) {
|
||||
hasChange |= source.changeClimate(ticks, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ticks % getTicksPerUpdate() == 0) {
|
||||
for (Entry<BlockPos, IClimatePosition> position : positions.entrySet()) {
|
||||
BlockPos pos = position.getKey();
|
||||
if (world.isBlockLoaded(pos)) {
|
||||
hasChange |= updateSides(pos);
|
||||
|
||||
if (!controller.isAssembled()) {
|
||||
IClimateControl climateControl = getControl(pos);
|
||||
IClimatePosition climatedInfo = positions.get(pos);
|
||||
|
||||
if (climatedInfo.getTemperature() != climateControl.getControlTemperature()) {
|
||||
if (climatedInfo.getTemperature() > climateControl.getControlTemperature()) {
|
||||
climatedInfo.addTemperature(-Math.min(0.01F, climatedInfo.getTemperature() - climateControl.getControlTemperature()));
|
||||
hasChange = true;
|
||||
} else {
|
||||
climatedInfo.addTemperature(Math.min(0.01F, climateControl.getControlTemperature() - climatedInfo.getTemperature()));
|
||||
hasChange = true;
|
||||
}
|
||||
}
|
||||
if (climatedInfo.getHumidity() != climateControl.getControlHumidity()) {
|
||||
if (climatedInfo.getHumidity() > climateControl.getControlHumidity()) {
|
||||
climatedInfo.addHumidity(-Math.min(0.01F, climatedInfo.getHumidity() - climateControl.getControlHumidity()));
|
||||
hasChange = true;
|
||||
} else {
|
||||
climatedInfo.addHumidity(Math.min(0.01F, climateControl.getControlHumidity() - climatedInfo.getHumidity()));
|
||||
hasChange = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasChange) {
|
||||
temperature = getExactTemperature();
|
||||
humidity = getExactHumidity();
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean updateSides(BlockPos pos) {
|
||||
IClimatePosition climatedInfo = positions.get(pos);
|
||||
IClimateControl climateControl = getControl(pos);
|
||||
boolean hasChange = false;
|
||||
if (climateControl.getControlTemperature() != temperature || climateControl.getControlHumidity() != humidity) {
|
||||
for (EnumFacing facing : EnumFacing.VALUES) {
|
||||
IClimatePosition climatedInfoFace = positions.get(pos.offset(facing));
|
||||
if (climatedInfoFace != null) {
|
||||
if (climatedInfo.getTemperature() > climatedInfoFace.getTemperature() + 0.01F) {
|
||||
float change = Math.min(0.01F, climatedInfo.getTemperature() - climatedInfoFace.getTemperature());
|
||||
climatedInfo.addTemperature(-change);
|
||||
climatedInfoFace.addTemperature(change);
|
||||
hasChange = true;
|
||||
}
|
||||
if (climatedInfo.getHumidity() > climatedInfoFace.getHumidity() + 0.01F) {
|
||||
float change = Math.min(0.01F, climatedInfo.getHumidity() - climatedInfoFace.getHumidity());
|
||||
climatedInfo.addHumidity(-change);
|
||||
climatedInfoFace.addHumidity(change);
|
||||
hasChange = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return hasChange;
|
||||
}
|
||||
|
||||
protected IClimateControl getControl(BlockPos pos) {
|
||||
if (world.isBlockLoaded(pos)) {
|
||||
if (!controller.isAssembled()) {
|
||||
return BiomeClimateControl.getControl(world.getBiome(pos));
|
||||
}
|
||||
}
|
||||
return controller.getClimateControl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
NBTTagList positionList = new NBTTagList();
|
||||
for (Entry<BlockPos, IClimatePosition> entry : positions.entrySet()) {
|
||||
BlockPos pos = entry.getKey();
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setInteger("X", pos.getX());
|
||||
tag.setInteger("Y", pos.getY());
|
||||
tag.setInteger("Z", pos.getZ());
|
||||
positionList.appendTag(entry.getValue().writeToNBT(tag));
|
||||
}
|
||||
nbt.setTag("Positions", positionList);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
NBTTagList positionList = nbt.getTagList("Positions", 10);
|
||||
for (int i = 0; i < positionList.tagCount(); i++) {
|
||||
NBTTagCompound positionTag = positionList.getCompoundTagAt(i);
|
||||
int xPos = positionTag.getInteger("X");
|
||||
int yPos = positionTag.getInteger("Y");
|
||||
int zPos = positionTag.getInteger("Z");
|
||||
BlockPos pos = new BlockPos(xPos, yPos, zPos);
|
||||
IClimatePosition position = positions.get(pos);
|
||||
if (position != null) {
|
||||
position.readFromNBT(positionTag);
|
||||
} else {
|
||||
positions.put(pos, new ClimatePosition(this, pos, positionTag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTicksPerUpdate() {
|
||||
return 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<BlockPos, IClimatePosition> getPositions() {
|
||||
return positions;
|
||||
}
|
||||
|
||||
public synchronized void addPosition(BlockPos pos, float temperature, float humidity) {
|
||||
IClimatePosition otherPosition = positions.get(pos);
|
||||
if (otherPosition != null) {
|
||||
otherPosition.setHumidity(humidity);
|
||||
otherPosition.setTemperature(temperature);
|
||||
} else {
|
||||
positions.put(pos, new ClimatePosition(this, pos, temperature, humidity));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void addSource(IClimateSource source) {
|
||||
if (!sources.contains(source)) {
|
||||
sources.add(source);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void removeSource(IClimateSource source) {
|
||||
if (sources.contains(source)) {
|
||||
sources.remove(source);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IClimateSource> getSources() {
|
||||
return sources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockPos> getOtherPositions() {
|
||||
return wallPositions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(PacketBufferForestry data) {
|
||||
if (!positions.isEmpty()) {
|
||||
data.writeInt(positions.size());
|
||||
for (IClimatePosition pos : positions.values()) {
|
||||
ClimateUtil.writeRoomPositionData(pos, data);
|
||||
}
|
||||
data.writeFloat(temperature);
|
||||
data.writeFloat(humidity);
|
||||
} else {
|
||||
data.writeInt(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(PacketBufferForestry data) throws IOException {
|
||||
int size = data.readInt();
|
||||
if (size != 0) {
|
||||
positions.clear();
|
||||
;
|
||||
for (int index = 0; index < size; index++) {
|
||||
ClimateUtil.readRoomPositionData(this, data);
|
||||
}
|
||||
temperature = data.readFloat();
|
||||
humidity = data.readFloat();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTemperature() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHumidity() {
|
||||
return humidity;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,10 +18,10 @@ public class ClimatiserDefinition implements IClimatiserDefinition {
|
||||
|
||||
protected final float change;
|
||||
protected final EnumClimatiserModes mode;
|
||||
protected final double range;
|
||||
protected final float range;
|
||||
protected final EnumClimatiserTypes type;
|
||||
|
||||
public ClimatiserDefinition(float change, EnumClimatiserModes mode, double range, EnumClimatiserTypes type) {
|
||||
public ClimatiserDefinition(float change, EnumClimatiserModes mode, float range, EnumClimatiserTypes type) {
|
||||
this.change = change;
|
||||
this.mode = mode;
|
||||
this.range = range;
|
||||
@@ -34,7 +34,7 @@ public class ClimatiserDefinition implements IClimatiserDefinition {
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getRange() {
|
||||
public float getRange() {
|
||||
return range;
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,8 @@ public abstract class GuiForestry<C extends Container, I extends IInventory> ext
|
||||
int maxLedgerWidth = (this.width - this.xSize) / 2;
|
||||
|
||||
this.ledgerManager.setMaxWidth(maxLedgerWidth);
|
||||
|
||||
this.ledgerManager.clear();
|
||||
|
||||
addLedgers();
|
||||
}
|
||||
|
||||
@@ -247,10 +248,12 @@ public abstract class GuiForestry<C extends Container, I extends IInventory> ext
|
||||
return ySize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGuiLeft() {
|
||||
return guiLeft;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGuiTop() {
|
||||
return guiTop;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,10 @@ public class LedgerManager {
|
||||
errorLedgers.add(new ErrorLedger(this));
|
||||
}
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
this.ledgers.clear();
|
||||
}
|
||||
|
||||
public void add(Ledger ledger) {
|
||||
this.ledgers.add(ledger);
|
||||
|
||||
@@ -12,7 +12,6 @@ package forestry.core.items;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.plugins.PluginManager;
|
||||
|
||||
@@ -32,7 +32,6 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -14,7 +14,6 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.lwjgl.util.vector.Vector3f;
|
||||
|
||||
/**
|
||||
* A face of a {@link ModelBakerModel }
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.Set;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.core.utils.Log;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
@@ -116,7 +117,7 @@ public class MultiblockRegistry {
|
||||
* @param world The world whose controllers you wish to retrieve.
|
||||
* @return An unmodifiable set of controllers active in the given world.
|
||||
*/
|
||||
public static Set<IMultiblockControllerInternal> getControllersFromWorld(World world) {
|
||||
public static Set<IMultiblockControllerInternal> getControllersFromWorld(IBlockAccess world) {
|
||||
if (registries.containsKey(world)) {
|
||||
return registries.get(world).getControllers();
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ package forestry.core.network;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.Log;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -51,7 +50,10 @@ public class PacketHandler {
|
||||
public void onPacket(ClientCustomPacketEvent event) {
|
||||
PacketBufferForestry data = new PacketBufferForestry(event.getPacket().payload());
|
||||
EntityPlayer player = Proxies.common.getPlayer();
|
||||
|
||||
if(player == null){
|
||||
return;
|
||||
}
|
||||
|
||||
byte packetIdOrdinal = data.readByte();
|
||||
PacketIdClient packetId = PacketIdClient.VALUES[packetIdOrdinal];
|
||||
IForestryPacketHandlerClient packetHandler = packetId.getPacketHandler();
|
||||
|
||||
@@ -12,6 +12,8 @@ package forestry.core.proxy;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.core.TickHandlerCoreServer;
|
||||
import forestry.core.multiblock.MultiblockServerTickHandler;
|
||||
import forestry.core.worldgen.WorldGenerator;
|
||||
@@ -77,6 +79,7 @@ public class ProxyCommon {
|
||||
return FMLClientHandler.instance().getClient();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public EntityPlayer getPlayer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.genetics.EnumTolerance;
|
||||
import forestry.api.genetics.IClimateHelper;
|
||||
import forestry.core.climate.ClimateRoom;
|
||||
import forestry.core.climate.ClimateRegion;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
|
||||
public class ClimateUtil implements IClimateHelper {
|
||||
@@ -214,8 +214,8 @@ public class ClimateUtil implements IClimateHelper {
|
||||
data.writeFloat(position.getHumidity());
|
||||
}
|
||||
|
||||
public static void readRoomPositionData(ClimateRoom room, PacketBufferForestry data) {
|
||||
room.addPosition(data.readBlockPos(), data.readFloat(), data.readFloat());
|
||||
public static void readRoomPositionData(ClimateRegion room, PacketBufferForestry data) {
|
||||
room.setPosition(data.readBlockPos(), data.readFloat(), data.readFloat());
|
||||
}
|
||||
|
||||
public static void readPositionData(IClimatePosition position, PacketBufferForestry data) {
|
||||
|
||||
@@ -88,6 +88,9 @@ public class EnergyHelper {
|
||||
}
|
||||
|
||||
public static boolean isEnergyReceiverOrEngine(EnumFacing side, TileEntity tile) {
|
||||
if(tile == null){
|
||||
return false;
|
||||
}
|
||||
if (tile instanceof TileEngine) { // engine chaining
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import forestry.core.tiles.TileUtil;
|
||||
import forestry.farming.blocks.BlockFarm;
|
||||
import forestry.farming.blocks.EnumFarmBlockType;
|
||||
import forestry.farming.tiles.TileFarm;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@@ -25,6 +25,9 @@ import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class GreenhouseClimateSource<P extends TileGreenhouseClimatiser> extends ClimateSource<P> {
|
||||
|
||||
private static final int COOLDOWN = 10;
|
||||
private int currentCooldown;
|
||||
|
||||
public GreenhouseClimateSource(int ticksForChange) {
|
||||
super(ticksForChange);
|
||||
}
|
||||
@@ -34,6 +37,10 @@ public class GreenhouseClimateSource<P extends TileGreenhouseClimatiser> extends
|
||||
if (provider == null) {
|
||||
return false;
|
||||
}
|
||||
if(currentCooldown > 0){
|
||||
currentCooldown--;
|
||||
return false;
|
||||
}
|
||||
IClimatiserDefinition definition = provider.getDefinition();
|
||||
IMultiblockLogic logic = provider.getMultiblockLogic();
|
||||
IMultiblockController controller = logic.getController();
|
||||
@@ -52,22 +59,22 @@ public class GreenhouseClimateSource<P extends TileGreenhouseClimatiser> extends
|
||||
float maxChange = definition.getChange();
|
||||
if (isActive) {
|
||||
if (canChange(type, EnumClimatiserTypes.TEMPERATURE)) {
|
||||
if (region.getTemperature() < controlTemp) {
|
||||
if (region.getAverageTemperature() < controlTemp) {
|
||||
if (!canChange(mode, EnumClimatiserModes.POSITIVE)) {
|
||||
isActive = false;
|
||||
}
|
||||
} else if (region.getTemperature() > controlTemp) {
|
||||
} else if (region.getAverageTemperature() > controlTemp) {
|
||||
if (!canChange(mode, EnumClimatiserModes.NEGATIVE)) {
|
||||
isActive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (canChange(type, EnumClimatiserTypes.HUMIDITY)) {
|
||||
if (region.getTemperature() < controlHum) {
|
||||
if (region.getAverageTemperature() < controlHum) {
|
||||
if (!canChange(mode, EnumClimatiserModes.POSITIVE)) {
|
||||
isActive = false;
|
||||
}
|
||||
} else if (region.getTemperature() > controlHum) {
|
||||
} else if (region.getAverageTemperature() > controlHum) {
|
||||
if (!canChange(mode, EnumClimatiserModes.NEGATIVE)) {
|
||||
isActive = false;
|
||||
}
|
||||
@@ -77,39 +84,37 @@ public class GreenhouseClimateSource<P extends TileGreenhouseClimatiser> extends
|
||||
|
||||
if (isActive) {
|
||||
for (BlockPos pos : positionsInRange) {
|
||||
IClimatePosition position = region.getPositions().get(pos);
|
||||
IClimatePosition position = region.getPosition(pos);
|
||||
if (position != null) {
|
||||
double distance = pos.distanceSq(provider.getCoordinates());
|
||||
double range = definition.getRange();
|
||||
if (distance <= range) {
|
||||
float change = maxChange;
|
||||
if (distance > 0) {
|
||||
change = (float) (maxChange / distance);
|
||||
}
|
||||
if (canChange(type, EnumClimatiserTypes.TEMPERATURE)) {
|
||||
if (position.getTemperature() < controlTemp) {
|
||||
if (canChange(mode, EnumClimatiserModes.POSITIVE)) {
|
||||
position.addTemperature(Math.min(change, controlTemp - position.getTemperature()));
|
||||
hasChange = true;
|
||||
}
|
||||
} else if (position.getTemperature() > controlTemp) {
|
||||
if (canChange(mode, EnumClimatiserModes.NEGATIVE)) {
|
||||
position.addTemperature(-Math.min(position.getTemperature() - controlTemp, change));
|
||||
hasChange = true;
|
||||
}
|
||||
float change = maxChange;
|
||||
if (distance > 0) {
|
||||
change = (float) (maxChange / distance);
|
||||
}
|
||||
if (canChange(type, EnumClimatiserTypes.TEMPERATURE)) {
|
||||
if (position.getTemperature() < controlTemp) {
|
||||
if (canChange(mode, EnumClimatiserModes.POSITIVE)) {
|
||||
position.addTemperature(Math.min(change, controlTemp - position.getTemperature()));
|
||||
hasChange = true;
|
||||
}
|
||||
} else if (position.getTemperature() > controlTemp) {
|
||||
if (canChange(mode, EnumClimatiserModes.NEGATIVE)) {
|
||||
position.addTemperature(-Math.min(position.getTemperature() - controlTemp, change));
|
||||
hasChange = true;
|
||||
}
|
||||
}
|
||||
if (canChange(type, EnumClimatiserTypes.HUMIDITY)) {
|
||||
if (position.getHumidity() < controlHum) {
|
||||
if (canChange(mode, EnumClimatiserModes.POSITIVE)) {
|
||||
position.addHumidity(Math.min(change, controlHum - position.getHumidity()));
|
||||
hasChange = true;
|
||||
}
|
||||
} else if (position.getHumidity() > controlHum) {
|
||||
if (canChange(mode, EnumClimatiserModes.NEGATIVE)) {
|
||||
position.addHumidity(-Math.min(position.getHumidity() - controlHum, change));
|
||||
hasChange = true;
|
||||
}
|
||||
}
|
||||
if (canChange(type, EnumClimatiserTypes.HUMIDITY)) {
|
||||
if (position.getHumidity() < controlHum) {
|
||||
if (canChange(mode, EnumClimatiserModes.POSITIVE)) {
|
||||
position.addHumidity(Math.min(change, controlHum - position.getHumidity()));
|
||||
hasChange = true;
|
||||
}
|
||||
} else if (position.getHumidity() > controlHum) {
|
||||
if (canChange(mode, EnumClimatiserModes.NEGATIVE)) {
|
||||
position.addHumidity(-Math.min(position.getHumidity() - controlHum, change));
|
||||
hasChange = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -117,6 +122,12 @@ public class GreenhouseClimateSource<P extends TileGreenhouseClimatiser> extends
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!hasChange){
|
||||
currentCooldown = COOLDOWN;
|
||||
if(isActive){
|
||||
isActive = false;
|
||||
}
|
||||
}
|
||||
if (provider.isActive() != isActive) {
|
||||
provider.setActive(isActive);
|
||||
}
|
||||
|
||||
@@ -59,39 +59,36 @@ public class GreenhouseClimateWindow extends GreenhouseClimateSource<TileGreenho
|
||||
float maxChange = definition.getChange();
|
||||
|
||||
for (BlockPos pos : positionsInRange) {
|
||||
IClimatePosition position = region.getPositions().get(pos);
|
||||
IClimatePosition position = region.getPosition(pos);
|
||||
if (position != null) {
|
||||
double distance = pos.distanceSq(provider.getCoordinates());
|
||||
double range = definition.getRange();
|
||||
if (distance <= range) {
|
||||
float change = maxChange;
|
||||
if (distance > 0) {
|
||||
change = (float) (maxChange / distance);
|
||||
}
|
||||
if (canChange(type, EnumClimatiserTypes.TEMPERATURE)) {
|
||||
if (position.getTemperature() < controlTemp) {
|
||||
if (canChange(mode, EnumClimatiserModes.POSITIVE)) {
|
||||
position.addTemperature(Math.min(change, controlTemp - position.getTemperature()));
|
||||
hasChange = true;
|
||||
}
|
||||
} else if (position.getTemperature() > controlTemp) {
|
||||
if (canChange(mode, EnumClimatiserModes.NEGATIVE)) {
|
||||
position.addTemperature(-Math.min(position.getTemperature() - controlTemp, change));
|
||||
hasChange = true;
|
||||
}
|
||||
float change = maxChange;
|
||||
if (distance > 0) {
|
||||
change = (float) (maxChange / distance);
|
||||
}
|
||||
if (canChange(type, EnumClimatiserTypes.TEMPERATURE)) {
|
||||
if (position.getTemperature() < controlTemp) {
|
||||
if (canChange(mode, EnumClimatiserModes.POSITIVE)) {
|
||||
position.addTemperature(Math.min(change, controlTemp - position.getTemperature()));
|
||||
hasChange = true;
|
||||
}
|
||||
} else if (position.getTemperature() > controlTemp) {
|
||||
if (canChange(mode, EnumClimatiserModes.NEGATIVE)) {
|
||||
position.addTemperature(-Math.min(position.getTemperature() - controlTemp, change));
|
||||
hasChange = true;
|
||||
}
|
||||
}
|
||||
if (canChange(type, EnumClimatiserTypes.HUMIDITY)) {
|
||||
if (position.getHumidity() < controlHum) {
|
||||
if (canChange(mode, EnumClimatiserModes.POSITIVE)) {
|
||||
position.addHumidity(Math.min(change, controlHum - position.getHumidity()));
|
||||
hasChange = true;
|
||||
}
|
||||
} else if (position.getHumidity() > controlHum) {
|
||||
if (canChange(mode, EnumClimatiserModes.NEGATIVE)) {
|
||||
position.addHumidity(-Math.min(position.getHumidity() - controlHum, change));
|
||||
hasChange = true;
|
||||
}
|
||||
}
|
||||
if (canChange(type, EnumClimatiserTypes.HUMIDITY)) {
|
||||
if (position.getHumidity() < controlHum) {
|
||||
if (canChange(mode, EnumClimatiserModes.POSITIVE)) {
|
||||
position.addHumidity(Math.min(change, controlHum - position.getHumidity()));
|
||||
hasChange = true;
|
||||
}
|
||||
} else if (position.getHumidity() > controlHum) {
|
||||
if (canChange(mode, EnumClimatiserModes.NEGATIVE)) {
|
||||
position.addHumidity(-Math.min(position.getHumidity() - controlHum, change));
|
||||
hasChange = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import forestry.core.multiblock.MultiblockRegistry;
|
||||
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
|
||||
import forestry.greenhouse.multiblock.InternalBlockCheck;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
public class GreenhouseHelper implements IGreenhouseHelper {
|
||||
|
||||
@@ -31,7 +31,7 @@ public class GreenhouseHelper implements IGreenhouseHelper {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public IGreenhouseController getGreenhouseController(World world, BlockPos pos) {
|
||||
public IGreenhouseController getGreenhouseController(IBlockAccess world, BlockPos pos) {
|
||||
for (IMultiblockControllerInternal controllerInternal : MultiblockRegistry.getControllersFromWorld(world)) {
|
||||
if (controllerInternal instanceof IGreenhouseControllerInternal &&
|
||||
controllerInternal.isAssembled() &&
|
||||
|
||||
@@ -36,7 +36,7 @@ import forestry.greenhouse.tiles.TileGreenhouseGearbox;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseHatch;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseHeater;
|
||||
import forestry.greenhouse.tiles.TileGreenhousePlain;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseSprinkler;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseHumidifier;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseValve;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseWindow;
|
||||
import forestry.plugins.BlankForestryPlugin;
|
||||
@@ -149,7 +149,7 @@ public class PluginGreenhouse extends BlankForestryPlugin {
|
||||
'#', OreDictUtil.INGOT_IRON,
|
||||
'T', coreItems.tubes.get(EnumElectronTube.TIN, 1));
|
||||
|
||||
Block greenhouseDryerBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.DRYER);
|
||||
Block greenhouseDryerBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.DEHUMIDIFIER);
|
||||
RecipeUtil.addRecipe(greenhouseDryerBlock,
|
||||
"T#T",
|
||||
"#X#",
|
||||
@@ -158,7 +158,7 @@ public class PluginGreenhouse extends BlankForestryPlugin {
|
||||
'#', OreDictUtil.INGOT_TIN,
|
||||
'T', coreItems.tubes.get(EnumElectronTube.BLAZE, 1));
|
||||
|
||||
Block greenhouseSprinklerBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.HUMUDIFIER);
|
||||
Block greenhouseSprinklerBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.HUMIDIFIER);
|
||||
RecipeUtil.addRecipe(greenhouseSprinklerBlock,
|
||||
"TXT",
|
||||
"GIG",
|
||||
@@ -229,7 +229,7 @@ public class PluginGreenhouse extends BlankForestryPlugin {
|
||||
GameRegistry.registerTileEntity(TileGreenhouseFan.class, "forestry.GreenhouseFan");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseHeater.class, "forestry.GreenhouseHeater");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseDryer.class, "forestry.GreenhouseDryer");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseSprinkler.class, "forestry.GreenhouseSprinkler");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseHumidifier.class, "forestry.GreenhouseSprinkler");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseValve.class, "forestry.GreenhouseValve");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseGearbox.class, "forestry.GreenhouseGearbox");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseControl.class, "forestry.GreenhouseController");
|
||||
|
||||
@@ -21,7 +21,6 @@ import forestry.api.core.IModelManager;
|
||||
import forestry.api.core.ISpriteRegister;
|
||||
import forestry.api.core.ITextureManager;
|
||||
import forestry.api.core.Tabs;
|
||||
import forestry.api.multiblock.IGreenhouseComponent;
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.core.CreativeTabForestry;
|
||||
import forestry.core.blocks.BlockStructure;
|
||||
@@ -44,7 +43,7 @@ import forestry.greenhouse.tiles.TileGreenhouseGearbox;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseHatch;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseHeater;
|
||||
import forestry.greenhouse.tiles.TileGreenhousePlain;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseSprinkler;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseHumidifier;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseValve;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseWindow;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseWindow.WindowMode;
|
||||
@@ -81,7 +80,6 @@ import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.common.property.ExtendedBlockState;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import net.minecraftforge.common.property.IUnlistedProperty;
|
||||
import net.minecraftforge.common.property.Properties;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -302,8 +300,10 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
switch (type) {
|
||||
case GEARBOX:
|
||||
return new TileGreenhouseGearbox();
|
||||
case DRYER:
|
||||
case DEHUMIDIFIER:
|
||||
return new TileGreenhouseDryer();
|
||||
case HUMIDIFIER:
|
||||
return new TileGreenhouseHumidifier();
|
||||
case VALVE:
|
||||
return new TileGreenhouseValve();
|
||||
case FAN:
|
||||
|
||||
@@ -8,8 +8,6 @@ import forestry.core.config.Constants;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouse.State;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseHatch;
|
||||
import net.minecraft.block.BlockFurnace;
|
||||
import net.minecraft.block.BlockStone;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -26,19 +24,24 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
public enum BlockGreenhouseType {
|
||||
PLAIN,
|
||||
GLASS(Material.GLASS),
|
||||
//item, energy / fluid
|
||||
HATCH_INPUT(true),
|
||||
HATCH_OUTPUT(true),
|
||||
//energy
|
||||
GEARBOX(true),
|
||||
//water
|
||||
VALVE(true),
|
||||
FAN(true, true),
|
||||
HEATER(true, true),
|
||||
DRYER(true, true),
|
||||
//temperature
|
||||
HEATER(true, true), FAN(true, true),
|
||||
//humidity
|
||||
HUMIDIFIER(true, true), DEHUMIDIFIER(true, true),
|
||||
//temperature and humidity
|
||||
WINDOW(Material.GLASS, false, true),
|
||||
//temperature and humidity
|
||||
WINDOW_UP(Material.GLASS, false, true),
|
||||
CONTROL(true),
|
||||
HUMUDIFIER(true, true), //humidifier
|
||||
DOOR,
|
||||
CLIMATE_CONTROL(true),
|
||||
WINDOW(Material.GLASS, false, true),
|
||||
WINDOW_UP(Material.GLASS, false, true),
|
||||
BUTTERFLY_HATCH(true);
|
||||
|
||||
public static final BlockGreenhouseType[] VALUES = values();
|
||||
@@ -79,11 +82,11 @@ public enum BlockGreenhouseType {
|
||||
private enum BlockGreenhouseSprites {
|
||||
GEARS("gears"),
|
||||
VALVE("valve"),
|
||||
FAN_OFF("fan.off"), FAN_ON("fan.on"),
|
||||
HEATER_OFF("heater.off"), HEATER_ON("heater.on"),
|
||||
DRYER("dryer"),
|
||||
FAN_OFF("fan.off"), FAN_ON("fan.on"),
|
||||
HUMIDIFIER_OFF("humidifier.off"), HUMIDIFIER_ON("humidifier.on"),
|
||||
DEHUMIDIFIER_OFF("dehumidifier.off"), DEHUMIDIFIER_ON("dehumidifier.on"),
|
||||
CONTROL("control"),
|
||||
HUMUDIFIER_OFF("humidifier.on"), HUMUDIFIER_ON("humidifier.on"),
|
||||
HATCH_DEFAULT("hatch"), HATCH_INPUT("hatch_input"), HATCH_OUTPUT("hatch_output"),
|
||||
CLIMATE_CONTROL("climate_control"),
|
||||
BUTTERFLY_HATCH("butterfly_hatch");
|
||||
@@ -128,20 +131,30 @@ public enum BlockGreenhouseType {
|
||||
return sprites.get(BlockGreenhouseSprites.GEARS);
|
||||
case VALVE:
|
||||
return sprites.get(BlockGreenhouseSprites.VALVE);
|
||||
case FAN:
|
||||
if (state == null || state.getValue(BlockGreenhouse.STATE) == State.OFF) {
|
||||
return sprites.get(BlockGreenhouseSprites.FAN_OFF);
|
||||
} else {
|
||||
return sprites.get(BlockGreenhouseSprites.FAN_ON);
|
||||
}
|
||||
case HEATER:
|
||||
if (state == null || state.getValue(BlockGreenhouse.STATE) == State.OFF) {
|
||||
return sprites.get(BlockGreenhouseSprites.HEATER_OFF);
|
||||
} else {
|
||||
return sprites.get(BlockGreenhouseSprites.HEATER_ON);
|
||||
}
|
||||
case DRYER:
|
||||
return sprites.get(BlockGreenhouseSprites.DRYER);
|
||||
case FAN:
|
||||
if (state == null || state.getValue(BlockGreenhouse.STATE) == State.OFF) {
|
||||
return sprites.get(BlockGreenhouseSprites.FAN_OFF);
|
||||
} else {
|
||||
return sprites.get(BlockGreenhouseSprites.FAN_ON);
|
||||
}
|
||||
case HUMIDIFIER:
|
||||
if (state == null || state.getValue(BlockGreenhouse.STATE) == State.OFF) {
|
||||
return sprites.get(BlockGreenhouseSprites.HUMIDIFIER_OFF);
|
||||
} else {
|
||||
return sprites.get(BlockGreenhouseSprites.HUMIDIFIER_ON);
|
||||
}
|
||||
case DEHUMIDIFIER:
|
||||
if (state == null || state.getValue(BlockGreenhouse.STATE) == State.OFF) {
|
||||
return sprites.get(BlockGreenhouseSprites.DEHUMIDIFIER_OFF);
|
||||
} else {
|
||||
return sprites.get(BlockGreenhouseSprites.DEHUMIDIFIER_ON);
|
||||
}
|
||||
case CONTROL:
|
||||
return sprites.get(BlockGreenhouseSprites.CONTROL);
|
||||
case HATCH_OUTPUT:
|
||||
|
||||
@@ -49,7 +49,7 @@ public class ItemBlockGreenhouseDoor extends ItemBlockForestry<BlockGreenhouseDo
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
|
||||
if (player.canPlayerEdit(pos, facing, itemstack) && this.block.canPlaceBlockAt(worldIn, pos)) {
|
||||
EnumFacing enumfacing = EnumFacing.fromAngle((double) player.rotationYaw);
|
||||
EnumFacing enumfacing = EnumFacing.fromAngle(player.rotationYaw);
|
||||
int i = enumfacing.getFrontOffsetX();
|
||||
int j = enumfacing.getFrontOffsetZ();
|
||||
boolean flag = i < 0 && hitZ < 0.5F || i > 0 && hitZ > 0.5F || j < 0 && hitX > 0.5F || j > 0 && hitX < 0.5F;
|
||||
|
||||
@@ -23,7 +23,6 @@ import forestry.core.models.ModelBlockDefault;
|
||||
import forestry.core.utils.CamouflageUtil;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouse;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouseType;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
|
||||
@@ -101,10 +101,6 @@ public class FakeGreenhouseController extends FakeMultiblockController implement
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearRegion() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Listener> getListenerComponents() {
|
||||
return Collections.emptySet();
|
||||
|
||||
@@ -14,10 +14,9 @@ import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
@@ -45,7 +44,7 @@ import forestry.api.multiblock.IGreenhouseComponent.Climatiser;
|
||||
import forestry.api.multiblock.IGreenhouseController;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.core.climate.ClimatePosition;
|
||||
import forestry.core.climate.ClimateRoom;
|
||||
import forestry.core.climate.ClimateRegion;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.fluids.FilteredTank;
|
||||
import forestry.core.fluids.StandardTank;
|
||||
@@ -65,10 +64,8 @@ import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.core.utils.Translator;
|
||||
import forestry.energy.EnergyManager;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouse;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouseType;
|
||||
import forestry.greenhouse.inventory.InventoryGreenhouse;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseSprinkler;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseHumidifier;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -101,8 +98,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
private ItemStack camouflagePlainBlock;
|
||||
private ItemStack camouflageGlassBlock;
|
||||
private ItemStack camouflageDoorBlock;
|
||||
@Nullable
|
||||
private ClimateRoom region;
|
||||
private ClimateRegion region;
|
||||
|
||||
public GreenhouseController(World world) {
|
||||
super(world, GreenhouseMultiblockSizeLimits.instance);
|
||||
@@ -115,6 +111,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
camouflagePlainBlock = getDefaultCamouflageBlock(CamouflageManager.DEFAULT);
|
||||
camouflageGlassBlock = getDefaultCamouflageBlock(CamouflageManager.GLASS);
|
||||
camouflageDoorBlock = getDefaultCamouflageBlock(CamouflageManager.DOOR);
|
||||
this.region = new ClimateRegion(this);
|
||||
}
|
||||
|
||||
/* CLIMATE */
|
||||
@@ -130,18 +127,12 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
|
||||
@Override
|
||||
public float getExactTemperature() {
|
||||
if (region == null) {
|
||||
return 0;
|
||||
}
|
||||
return region.getTemperature();
|
||||
return region.getAverageTemperature();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getExactHumidity() {
|
||||
if (region == null) {
|
||||
return 0;
|
||||
}
|
||||
return region.getHumidity();
|
||||
return region.getAverageHumidity();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -173,9 +164,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
data.setTag("logic" + logic.getName(), nbtTag);
|
||||
}
|
||||
|
||||
if (region != null) {
|
||||
data.setTag("Region", region.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
data.setTag("Region", region.writeToNBT(new NBTTagCompound()));
|
||||
|
||||
return data;
|
||||
}
|
||||
@@ -204,8 +193,6 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
NBTTagCompound nbtTag = data.getCompoundTag("Region");
|
||||
if (region != null) {
|
||||
region.readFromNBT(nbtTag);
|
||||
} else {
|
||||
region = new ClimateRoom(this, getWallPositions(), nbtTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -234,12 +221,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
CamouflageUtil.writeCamouflageBlockToData(data, this, CamouflageManager.DEFAULT);
|
||||
CamouflageUtil.writeCamouflageBlockToData(data, this, CamouflageManager.GLASS);
|
||||
CamouflageUtil.writeCamouflageBlockToData(data, this, CamouflageManager.DOOR);
|
||||
if (region != null) {
|
||||
data.writeBoolean(true);
|
||||
region.writeData(data);
|
||||
} else {
|
||||
data.writeBoolean(false);
|
||||
}
|
||||
region.writeData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -250,9 +232,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
CamouflageUtil.readCamouflageBlockFromData(data, this);
|
||||
CamouflageUtil.readCamouflageBlockFromData(data, this);
|
||||
CamouflageUtil.readCamouflageBlockFromData(data, this);
|
||||
if (data.readBoolean()) {
|
||||
region.readData(data);
|
||||
}
|
||||
region.readData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -384,6 +364,21 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
return FakeInventoryAdapter.instance();
|
||||
}
|
||||
}
|
||||
|
||||
private void addNewPositions(Collection<IClimatePosition> newPositions){
|
||||
for (IClimatePosition position : newPositions) {
|
||||
BlockPos pos = position.getPos();
|
||||
IClimatePosition oldPosition = region.getPosition(pos);
|
||||
float temperature = position.getTemperature();
|
||||
float humidity = position.getHumidity();
|
||||
if (oldPosition != null) {
|
||||
temperature = oldPosition.getTemperature();
|
||||
humidity = oldPosition.getHumidity();
|
||||
}
|
||||
region.setPosition(pos, temperature, humidity);
|
||||
}
|
||||
region.calculateAverageClimate();
|
||||
}
|
||||
|
||||
/* CONTROLLER */
|
||||
@Override
|
||||
@@ -391,29 +386,17 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
super.onMachineAssembled();
|
||||
|
||||
createLogics();
|
||||
if (region != null) {
|
||||
Map<BlockPos, IClimatePosition> internalPositions = new HashMap<>();
|
||||
for (IInternalBlock block : internalBlocks) {
|
||||
if (block != null) {
|
||||
internalPositions.put(block.getPos(), new ClimatePosition(region, block.getPos()));
|
||||
}
|
||||
Set<IClimatePosition> internalPositions = new HashSet<>();
|
||||
for (IInternalBlock block : internalBlocks) {
|
||||
if (block != null) {
|
||||
internalPositions.add(new ClimatePosition(region, block.getPos()));
|
||||
}
|
||||
ForestryAPI.climateManager.removeRegion(region);
|
||||
region = new ClimateRoom(region, internalPositions, getWallPositions());
|
||||
ForestryAPI.climateManager.addRegion(region);
|
||||
} else {
|
||||
Map<BlockPos, IClimatePosition> internalPositions = new HashMap<>();
|
||||
region = new ClimateRoom(this, internalPositions, getWallPositions());
|
||||
for (IInternalBlock block : internalBlocks) {
|
||||
if (block != null) {
|
||||
internalPositions.put(block.getPos(), new ClimatePosition(region, block.getPos()));
|
||||
}
|
||||
}
|
||||
ForestryAPI.climateManager.addRegion(region);
|
||||
}
|
||||
addNewPositions(internalPositions);
|
||||
ForestryAPI.climateManager.addRegion(region);
|
||||
|
||||
for (IClimateSourceProvider source : climatiserComponents) {
|
||||
ForestryAPI.climateManager.addSource(source);
|
||||
region.addSource(source.getClimateSource());
|
||||
}
|
||||
|
||||
for (IMultiblockComponent comp : connectedParts) {
|
||||
@@ -429,9 +412,11 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
|
||||
internalBlocks.clear();
|
||||
logics.clear();
|
||||
|
||||
ForestryAPI.climateManager.removeRegion(region);
|
||||
|
||||
for (IClimateSourceProvider source : climatiserComponents) {
|
||||
ForestryAPI.climateManager.removeSource(source);
|
||||
region.removeSource(source.getClimateSource());
|
||||
}
|
||||
|
||||
for (IMultiblockComponent comp : connectedParts) {
|
||||
@@ -467,18 +452,12 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
@Override
|
||||
protected void onAssimilate(IMultiblockControllerInternal assimilated) {
|
||||
IGreenhouseControllerInternal internal = (IGreenhouseControllerInternal) assimilated;
|
||||
if (internal.getRegion() != null) {
|
||||
if (region != null) {
|
||||
ForestryAPI.climateManager.removeRegion(region);
|
||||
region = new ClimateRoom(region, internal.getRegion().getPositions(), getWallPositions());
|
||||
ForestryAPI.climateManager.addRegion(region);
|
||||
}
|
||||
}
|
||||
addNewPositions(internal.getRegion().getPositions());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAssimilated(IMultiblockControllerInternal assimilator) {
|
||||
if (region != null) {
|
||||
if(isAssembled()){
|
||||
ForestryAPI.climateManager.removeRegion(region);
|
||||
}
|
||||
}
|
||||
@@ -705,7 +684,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
if (tileFace instanceof IGreenhouseComponent) {
|
||||
if (((IGreenhouseComponent) tileFace).getMultiblockLogic().getController() != this) {
|
||||
throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.error.not.connected.part"));
|
||||
} else if (!(tileFace instanceof TileGreenhouseSprinkler)) {
|
||||
} else if (!(tileFace instanceof TileGreenhouseHumidifier)) {
|
||||
faceToCheck.setTested(true);
|
||||
}
|
||||
} else {
|
||||
@@ -770,11 +749,6 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
return region;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearRegion() {
|
||||
region = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<IGreenhouseComponent.Listener> getListenerComponents() {
|
||||
return listenerComponents;
|
||||
@@ -789,14 +763,4 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
return canWork;
|
||||
}
|
||||
|
||||
protected List<BlockPos> getWallPositions() {
|
||||
List<BlockPos> wallPositions = new ArrayList<>();
|
||||
for (IMultiblockComponent comp : connectedParts) {
|
||||
if (comp != null) {
|
||||
wallPositions.add(comp.getCoordinates());
|
||||
}
|
||||
}
|
||||
return wallPositions;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,7 +35,6 @@ public interface IGreenhouseControllerInternal extends IGreenhouseController, IM
|
||||
*/
|
||||
ITankManager getTankManager();
|
||||
|
||||
|
||||
/**
|
||||
* @return The energy manager of the controller.
|
||||
*/
|
||||
@@ -47,14 +46,18 @@ public interface IGreenhouseControllerInternal extends IGreenhouseController, IM
|
||||
Set<IInternalBlock> getInternalBlocks();
|
||||
|
||||
/**
|
||||
* Set the region to null.
|
||||
* @return True if the greenhouse can work.
|
||||
*/
|
||||
void clearRegion();
|
||||
|
||||
boolean canWork();
|
||||
|
||||
/**
|
||||
* @return A Set with listener componets.
|
||||
*/
|
||||
Set<IGreenhouseComponent.Listener> getListenerComponents();
|
||||
|
||||
/**
|
||||
* @return A butterfly hatch, if one exists.
|
||||
*/
|
||||
@Nullable
|
||||
IGreenhouseComponent.ButterflyHatch getButterflyHatch();
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class InternalBlock implements IInternalBlock {
|
||||
return false;
|
||||
}
|
||||
IInternalBlock internalBlock = (IInternalBlock) obj;
|
||||
return internalBlock.getPos().equals(getPos());
|
||||
return getPos().equals(internalBlock.getPos());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,12 +18,9 @@ import forestry.greenhouse.PluginGreenhouse;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouseType;
|
||||
import forestry.greenhouse.blocks.BlockRegistryGreenhouse;
|
||||
import forestry.greenhouse.models.ModelGreenhouse;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseSprinkler;
|
||||
import forestry.plugins.ForestryPluginUids;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraftforge.client.model.animation.AnimationTESR;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
|
||||
public class ProxyGreenhouseClient extends ProxyGreenhouse {
|
||||
|
||||
|
||||
@@ -10,8 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse.tiles;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import forestry.api.climate.IClimateSource;
|
||||
import forestry.api.climate.IClimatiserDefinition;
|
||||
@@ -26,7 +27,6 @@ import forestry.energy.EnergyManager;
|
||||
import forestry.greenhouse.GreenhouseClimateSource;
|
||||
import forestry.greenhouse.multiblock.MultiblockLogicGreenhouse;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class TileGreenhouseClimatiser extends TileGreenhouse implements IActivatable, IGreenhouseComponent.Climatiser {
|
||||
@@ -37,14 +37,7 @@ public class TileGreenhouseClimatiser extends TileGreenhouse implements IActivat
|
||||
private final IClimatiserDefinition definition;
|
||||
private final ClimateSource source;
|
||||
|
||||
@Nullable
|
||||
protected EnumFacing inwards;
|
||||
@Nullable
|
||||
protected EnumFacing leftwards;
|
||||
@Nullable
|
||||
protected BlockPos maxPos;
|
||||
@Nullable
|
||||
protected BlockPos minPos;
|
||||
protected final Set<BlockPos> positionsInRange;
|
||||
|
||||
private boolean active;
|
||||
|
||||
@@ -56,6 +49,7 @@ public class TileGreenhouseClimatiser extends TileGreenhouse implements IActivat
|
||||
this.definition = definition;
|
||||
this.source = source;
|
||||
this.source.setProvider(this);
|
||||
this.positionsInRange = new HashSet();
|
||||
}
|
||||
|
||||
protected TileGreenhouseClimatiser(IClimatiserDefinition definition) {
|
||||
@@ -64,26 +58,19 @@ public class TileGreenhouseClimatiser extends TileGreenhouse implements IActivat
|
||||
|
||||
@Override
|
||||
public void onMachineBroken() {
|
||||
inwards = null;
|
||||
leftwards = null;
|
||||
|
||||
minPos = null;
|
||||
maxPos = null;
|
||||
positionsInRange.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMachineAssembled(IMultiblockController multiblockController, BlockPos minCoord, BlockPos maxCoord) {
|
||||
recalculateDirections(minCoord, maxCoord);
|
||||
int range = Math.round((float) definition.getRange() / 2);
|
||||
positionsInRange.clear();
|
||||
float range = definition.getRange();
|
||||
|
||||
if (inwards != null) {
|
||||
if (leftwards != null) {
|
||||
maxPos = getCoordinates().offset(inwards, range).offset(leftwards, range).offset(EnumFacing.UP, range);
|
||||
minPos = getCoordinates().offset(inwards).offset(leftwards.getOpposite(), range).offset(EnumFacing.DOWN, range);
|
||||
|
||||
} else {
|
||||
maxPos = getCoordinates().offset(inwards, range).offset(EnumFacing.EAST, range).offset(EnumFacing.NORTH, range);
|
||||
minPos = getCoordinates().offset(inwards).offset(EnumFacing.WEST, range).offset(EnumFacing.SOUTH, range);
|
||||
Iterator<BlockPos> positions = BlockPos.getAllInBox(pos.add(-range, -range, -range), pos.add(range, range, range)).iterator();
|
||||
while(positions.hasNext()){
|
||||
BlockPos pos = positions.next();
|
||||
if(pos.distanceSq(this.pos) <= range){
|
||||
positionsInRange.add(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,43 +94,6 @@ public class TileGreenhouseClimatiser extends TileGreenhouse implements IActivat
|
||||
return active;
|
||||
}
|
||||
|
||||
public void recalculateDirections(BlockPos minCoord, BlockPos maxCoord) {
|
||||
inwards = null;
|
||||
leftwards = null;
|
||||
|
||||
int facesMatching = 0;
|
||||
if (maxCoord.getX() == getCoordinates().getX() || minCoord.getX() == getCoordinates().getX()) {
|
||||
facesMatching++;
|
||||
}
|
||||
if (maxCoord.getY() == getCoordinates().getY() || minCoord.getY() == getCoordinates().getY()) {
|
||||
facesMatching++;
|
||||
}
|
||||
if (maxCoord.getZ() == getCoordinates().getZ() || minCoord.getZ() == getCoordinates().getZ()) {
|
||||
facesMatching++;
|
||||
}
|
||||
if (facesMatching == 1) {
|
||||
if (maxCoord.getX() == getCoordinates().getX()) {
|
||||
inwards = EnumFacing.WEST;
|
||||
leftwards = EnumFacing.SOUTH;
|
||||
} else if (minCoord.getX() == getCoordinates().getX()) {
|
||||
inwards = EnumFacing.EAST;
|
||||
leftwards = EnumFacing.NORTH;
|
||||
} else if (maxCoord.getZ() == getCoordinates().getZ()) {
|
||||
inwards = EnumFacing.NORTH;
|
||||
leftwards = EnumFacing.WEST;
|
||||
} else if (minCoord.getZ() == getCoordinates().getZ()) {
|
||||
inwards = EnumFacing.SOUTH;
|
||||
leftwards = EnumFacing.EAST;
|
||||
} else if (maxCoord.getY() == getCoordinates().getY()) {
|
||||
inwards = EnumFacing.DOWN;
|
||||
} else {
|
||||
inwards = EnumFacing.UP;
|
||||
}
|
||||
} else {
|
||||
inwards = EnumFacing.DOWN;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimatiserDefinition getDefinition() {
|
||||
return definition;
|
||||
@@ -165,11 +115,9 @@ public class TileGreenhouseClimatiser extends TileGreenhouse implements IActivat
|
||||
return EnergyHelper.consumeEnergyToDoWork(energyManager, WORK_CYCLES, ENERGY_PER_OPERATION);
|
||||
}
|
||||
|
||||
public Iterable<BlockPos> getPositionsInRange() {
|
||||
if (maxPos == null || minPos == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return BlockPos.getAllInBox(maxPos, minPos);
|
||||
@Override
|
||||
public Set<BlockPos> getPositionsInRange() {
|
||||
return positionsInRange;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,7 +17,7 @@ import forestry.core.climate.ClimatiserDefinition;
|
||||
|
||||
public class TileGreenhouseDryer extends TileGreenhouseClimatiser {
|
||||
|
||||
private static final IClimatiserDefinition DEFINITION = new ClimatiserDefinition(0.015F, EnumClimatiserModes.NEGATIVE, 5D, EnumClimatiserTypes.HUMIDITY);
|
||||
private static final IClimatiserDefinition DEFINITION = new ClimatiserDefinition(0.015F, EnumClimatiserModes.NEGATIVE, 5F, EnumClimatiserTypes.HUMIDITY);
|
||||
|
||||
public TileGreenhouseDryer() {
|
||||
super(DEFINITION);
|
||||
|
||||
@@ -17,7 +17,7 @@ import forestry.core.climate.ClimatiserDefinition;
|
||||
|
||||
public class TileGreenhouseFan extends TileGreenhouseClimatiser {
|
||||
|
||||
private static final IClimatiserDefinition DEFINITION = new ClimatiserDefinition(0.015F, EnumClimatiserModes.NEGATIVE, 5D, EnumClimatiserTypes.TEMPERATURE);
|
||||
private static final IClimatiserDefinition DEFINITION = new ClimatiserDefinition(0.015F, EnumClimatiserModes.NEGATIVE, 5F, EnumClimatiserTypes.TEMPERATURE);
|
||||
|
||||
public TileGreenhouseFan() {
|
||||
super(DEFINITION);
|
||||
|
||||
@@ -17,7 +17,7 @@ import forestry.core.climate.ClimatiserDefinition;
|
||||
|
||||
public class TileGreenhouseHeater extends TileGreenhouseClimatiser {
|
||||
|
||||
private static final IClimatiserDefinition DEFINITION = new ClimatiserDefinition(0.015F, EnumClimatiserModes.POSITIVE, 5D, EnumClimatiserTypes.TEMPERATURE);
|
||||
private static final IClimatiserDefinition DEFINITION = new ClimatiserDefinition(0.015F, EnumClimatiserModes.POSITIVE, 5F, EnumClimatiserTypes.TEMPERATURE);
|
||||
|
||||
public TileGreenhouseHeater() {
|
||||
super(DEFINITION);
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*******************************************************************************
|
||||
* 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.tiles;
|
||||
|
||||
import forestry.api.climate.EnumClimatiserModes;
|
||||
import forestry.api.climate.EnumClimatiserTypes;
|
||||
import forestry.api.climate.IClimatiserDefinition;
|
||||
import forestry.core.climate.ClimatiserDefinition;
|
||||
|
||||
public class TileGreenhouseHumidifier extends TileGreenhouseClimatiser {
|
||||
|
||||
private static final IClimatiserDefinition DEFINITION = new ClimatiserDefinition(0.015F, EnumClimatiserModes.POSITIVE, 5F, EnumClimatiserTypes.HUMIDITY);
|
||||
|
||||
public TileGreenhouseHumidifier() {
|
||||
super(DEFINITION);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,105 +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.tiles;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import forestry.api.climate.EnumClimatiserModes;
|
||||
import forestry.api.climate.EnumClimatiserTypes;
|
||||
import forestry.api.climate.IClimatiserDefinition;
|
||||
import forestry.api.multiblock.IMultiblockLogic;
|
||||
import forestry.core.climate.ClimatiserDefinition;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.animation.Animation;
|
||||
import net.minecraftforge.common.animation.TimeValues;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.model.animation.CapabilityAnimation;
|
||||
import net.minecraftforge.common.model.animation.IAnimationStateMachine;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidTank;
|
||||
|
||||
public class TileGreenhouseSprinkler extends TileGreenhouseClimatiser {
|
||||
|
||||
private final IAnimationStateMachine asm;
|
||||
private final TimeValues.VariableValue clickTime = new TimeValues.VariableValue(Float.NEGATIVE_INFINITY);
|
||||
|
||||
protected static final int WATER_PER_OPERATION = 25;
|
||||
private static final IClimatiserDefinition DEFINITION = new ClimatiserDefinition(0.005F, EnumClimatiserModes.POSITIVE, 9, EnumClimatiserTypes.HUMIDITY);
|
||||
|
||||
public TileGreenhouseSprinkler() {
|
||||
super(DEFINITION, 20 + WATER_PER_OPERATION / 10);
|
||||
asm = Proxies.render.loadAnimationState(new ResourceLocation(Constants.MOD_ID, "asms/block/sprinkler.json"), ImmutableMap.of(
|
||||
"cycle_length", new TimeValues.VariableValue(20),
|
||||
"click_time", clickTime
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFastRenderer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWork() {
|
||||
IMultiblockLogic logic = getMultiblockLogic();
|
||||
if (!logic.isConnected()) {
|
||||
return false;
|
||||
}
|
||||
return consumeWaterToDoWork(WORK_CYCLES, WATER_PER_OPERATION, getMultiblockLogic().getController().getTankManager().getTank(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActive(boolean active) {
|
||||
super.setActive(active);
|
||||
if (world != null && world.isRemote) {
|
||||
if (asm.currentState().equals("moving") && !isActive()) {
|
||||
clickTime.setValue(Animation.getWorldTime(getWorld(), Animation.getPartialTickTime()));
|
||||
asm.transition("stopping");
|
||||
} else if (asm.currentState().equals("default") && isActive()) {
|
||||
float time = Animation.getWorldTime(getWorld(), Animation.getPartialTickTime());
|
||||
clickTime.setValue(time);
|
||||
asm.transition("starting");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean consumeWaterToDoWork(int ticksPerWorkCycle, int fluidPerWorkCycle, IFluidTank tank) {
|
||||
int fluidPerCycle = (int) Math.ceil(fluidPerWorkCycle / (float) ticksPerWorkCycle);
|
||||
if (tank.getFluid() == null || tank.getFluid().amount < fluidPerCycle) {
|
||||
return false;
|
||||
}
|
||||
FluidStack drained = tank.drain(fluidPerCycle, true);
|
||||
|
||||
return drained != null && drained.amount > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing side) {
|
||||
if (capability == CapabilityAnimation.ANIMATION_CAPABILITY) {
|
||||
return true;
|
||||
}
|
||||
return super.hasCapability(capability, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing side) {
|
||||
if (capability == CapabilityAnimation.ANIMATION_CAPABILITY) {
|
||||
return CapabilityAnimation.ANIMATION_CAPABILITY.cast(asm);
|
||||
}
|
||||
return super.getCapability(capability, side);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.climate.EnumClimatiserModes;
|
||||
import forestry.api.climate.EnumClimatiserTypes;
|
||||
import forestry.api.climate.IClimatiserDefinition;
|
||||
import forestry.core.climate.ClimatiserDefinition;
|
||||
import forestry.greenhouse.GreenhouseClimateWindow;
|
||||
import forestry.greenhouse.PluginGreenhouse;
|
||||
@@ -27,9 +28,10 @@ import net.minecraft.util.math.BlockPos;
|
||||
public class TileGreenhouseWindow extends TileGreenhouseClimatiser {
|
||||
@Nullable
|
||||
private WindowMode mode;
|
||||
private static final IClimatiserDefinition DEFINITION = new ClimatiserDefinition(0.001F, EnumClimatiserModes.NONE, 5F, EnumClimatiserTypes.NONE);
|
||||
|
||||
public TileGreenhouseWindow() {
|
||||
super(new ClimatiserDefinition(0.001F, EnumClimatiserModes.NONE, 5D, EnumClimatiserTypes.NONE), new GreenhouseClimateWindow(20));
|
||||
super(DEFINITION, new GreenhouseClimateWindow(20));
|
||||
}
|
||||
|
||||
public void onNeighborBlockChange() {
|
||||
|
||||
@@ -13,8 +13,6 @@ package forestry.lepidopterology.genetics;
|
||||
import java.awt.Color;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.genetics.IAllele;
|
||||
|
||||
@@ -13,8 +13,6 @@ package forestry.lepidopterology.genetics;
|
||||
import java.awt.Color;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IClassification;
|
||||
import forestry.api.lepidopterology.ButterflyManager;
|
||||
|
||||
Reference in new issue
Block a user