mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-18 19:29:17 +00:00
Rework sytem
This commit is contained in:
1 parent
725d85181d
commit
2cd76bdad7
20 files changed
+353
-604
No files matched your search
@@ -1,12 +1,7 @@
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.core.climate;
|
||||
|
||||
|
||||
@@ -5,8 +5,12 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.core.climate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -16,8 +20,14 @@ public interface IClimateManager {
|
||||
|
||||
float getHumidity(World world, BlockPos pos);
|
||||
|
||||
void registerWorld(IClimateWorld climateWorld);
|
||||
void addRegion(IClimateRegion region);
|
||||
|
||||
Map<Integer, IClimateWorld> getClimateWorlds();
|
||||
void removeRegion(IClimateRegion region);
|
||||
|
||||
@Nullable
|
||||
IClimateRegion getRegionForPos(World world, BlockPos pos);
|
||||
|
||||
@Nonnull
|
||||
Map<Integer, List<IClimateRegion>> getRegions();
|
||||
|
||||
}
|
||||
+6
-13
@@ -5,37 +5,30 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.core.climate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import forestry.api.core.INbtReadable;
|
||||
import forestry.api.core.INbtWritable;
|
||||
import forestry.core.climate.IClimateHandler;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public interface IClimatedPosition extends INbtReadable, INbtWritable {
|
||||
public interface IClimatePosition extends INbtReadable, INbtWritable {
|
||||
|
||||
@Nonnull
|
||||
IClimateWorld getClimateWorld();
|
||||
IClimateRegion getClimateRegion();
|
||||
|
||||
@Nonnull
|
||||
BlockPos getPos();
|
||||
|
||||
void addHandler(IClimateHandler climateHandler);
|
||||
|
||||
void removeHandler(IClimateHandler climateHandler);
|
||||
|
||||
void setTemperature(float temperature);
|
||||
|
||||
void addTemperature(float temperature);
|
||||
|
||||
float getTemperature();
|
||||
|
||||
void setHumidity(float humidity);
|
||||
|
||||
void addHumidity(float humidity);
|
||||
|
||||
float getHumidity();
|
||||
|
||||
List<IClimateHandler> getHandlers();
|
||||
|
||||
void updateClimate();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.core.climate;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import forestry.api.core.INbtReadable;
|
||||
import forestry.api.core.INbtWritable;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IClimateRegion extends INbtReadable, INbtWritable {
|
||||
|
||||
@Nonnull
|
||||
World getWorld();
|
||||
|
||||
void updateClimate();
|
||||
|
||||
@Nonnull
|
||||
Map<BlockPos, IClimatePosition> getPositions();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.core.climate;
|
||||
|
||||
public interface IClimateSource {
|
||||
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
package forestry.api.core.climate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IClimateWorld {
|
||||
|
||||
@Nonnull
|
||||
World getWorld();
|
||||
|
||||
int getDimensionID();
|
||||
|
||||
void updateClimate();
|
||||
|
||||
void addPositions(BlockPos minPos, BlockPos maxPos);
|
||||
|
||||
void addPosition(BlockPos pos);
|
||||
|
||||
void addPosition(IClimatedPosition position);
|
||||
|
||||
void addPositions(List<IClimatedPosition> positions);
|
||||
|
||||
IClimatedPosition getPosition(BlockPos pos);
|
||||
|
||||
IClimatedPosition createPosition(BlockPos pos);
|
||||
|
||||
void addChunk(ClimateChunk climateChunk);
|
||||
|
||||
void removeChunk(ChunkPos pos);
|
||||
|
||||
@Nonnull
|
||||
Map<ChunkPos, ClimateChunk> getClimateChunks();
|
||||
|
||||
@Nonnull
|
||||
List<ClimateChunk> getDirtyClimateChunks();
|
||||
|
||||
void addDirtyClimateChunk(ClimateChunk chunk);
|
||||
|
||||
public static class ClimateChunk{
|
||||
|
||||
@Nonnull
|
||||
protected final Map<BlockPos, IClimatedPosition> climates;
|
||||
@Nonnull
|
||||
protected final IClimateWorld world;
|
||||
@Nonnull
|
||||
protected final ChunkPos chunkPos;
|
||||
|
||||
public ClimateChunk(@Nonnull IClimateWorld world, @Nonnull ChunkPos chunkPos) {
|
||||
this.world = world;
|
||||
this.chunkPos = chunkPos;
|
||||
climates = new HashMap<>();
|
||||
for(int x = chunkPos.getXStart();x < chunkPos.getXEnd();x++){
|
||||
for(int y = 0;y < world.getWorld().getActualHeight();y++){
|
||||
for(int z = chunkPos.getZStart();z < chunkPos.getZEnd();z++){
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
climates.put(pos, world.createPosition(pos));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addPosition(IClimatedPosition position){
|
||||
world.addDirtyClimateChunk(this);
|
||||
climates.put(position.getPos(), position);
|
||||
}
|
||||
|
||||
public Map<BlockPos, IClimatedPosition> getClimates() {
|
||||
return climates;
|
||||
}
|
||||
|
||||
public IClimateWorld getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public ChunkPos getChunkPos() {
|
||||
return chunkPos;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,13 +7,15 @@ package forestry.api.multiblock;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.core.climate.IClimateRegion;
|
||||
import forestry.api.greenhouse.EnumGreenhouseEventType;
|
||||
import forestry.api.greenhouse.IGreenhouseHousing;
|
||||
import forestry.api.greenhouse.IGreenhouseLogic;
|
||||
import forestry.core.climate.IClimateHandler;
|
||||
|
||||
public interface IGreenhouseController extends IMultiblockController, IGreenhouseHousing, ICamouflageHandler, IClimateHandler {
|
||||
public interface IGreenhouseController extends IMultiblockController, IGreenhouseHousing, ICamouflageHandler {
|
||||
|
||||
/**
|
||||
* Handle change events.
|
||||
@@ -24,5 +26,8 @@ public interface IGreenhouseController extends IMultiblockController, IGreenhous
|
||||
* @return The logics of the greenhouse.
|
||||
*/
|
||||
List<IGreenhouseLogic> getLogics();
|
||||
|
||||
@Nullable
|
||||
IClimateRegion getRegion();
|
||||
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
package forestry.core.climate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import forestry.api.core.climate.IClimateWorld;
|
||||
import forestry.api.core.climate.IClimateWorld.ClimateChunk;
|
||||
import forestry.api.core.climate.IClimatedPosition;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraftforge.event.world.ChunkDataEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class ClimateEventHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public void chunkSave(ChunkDataEvent.Save event){
|
||||
int dimensionID = event.getWorld().provider.getDimension();
|
||||
World world = event.getWorld();
|
||||
Chunk chunk = event.getChunk();
|
||||
ChunkPos chunkPos = new ChunkPos(event.getChunk().xPosition, event.getChunk().zPosition);
|
||||
IClimateWorld climateWorld = ClimateManager.getOrCreateWorld(world);
|
||||
|
||||
if(climateWorld != null){
|
||||
ClimateChunk climateChunk = climateWorld.getClimateChunks().get(chunkPos);
|
||||
if(climateChunk != null){
|
||||
NBTTagCompound forestryTag = new NBTTagCompound();
|
||||
event.getData().setTag("Forestry", forestryTag);
|
||||
|
||||
NBTTagList posList = new NBTTagList();
|
||||
for(IClimatedPosition position : climateChunk.getClimates().values()) {
|
||||
if(position != null){
|
||||
NBTTagCompound positionTag = position.writeToNBT(new NBTTagCompound());
|
||||
BlockPos pos = position.getPos();
|
||||
|
||||
positionTag.setInteger("PosX", pos.getX());
|
||||
positionTag.setInteger("PosY", pos.getY());
|
||||
positionTag.setInteger("PosZ", pos.getZ());
|
||||
|
||||
posList.appendTag(positionTag);
|
||||
}
|
||||
}
|
||||
|
||||
forestryTag.setTag("Positions", forestryTag);
|
||||
if(!chunk.isLoaded()){
|
||||
climateWorld.removeChunk(chunkPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void chunkLoad(ChunkDataEvent.Load event){
|
||||
int dimensionID = event.getWorld().provider.getDimension();
|
||||
World world = event.getWorld();
|
||||
Chunk chunk = event.getChunk();
|
||||
|
||||
IClimateWorld climateWorld = ClimateManager.getOrCreateWorld(world);
|
||||
|
||||
ChunkPos chunkPos = new ChunkPos(event.getChunk().xPosition, event.getChunk().zPosition);
|
||||
NBTTagCompound chunkTag = event.getData();
|
||||
|
||||
if(chunkTag.hasKey("Forestry")){
|
||||
NBTTagCompound forestryTag = chunkTag.getCompoundTag("Forestry");
|
||||
|
||||
Map<BlockPos, IClimatedPosition> positions = new HashMap();
|
||||
NBTTagList posList = forestryTag.getTagList("Positions", 10);
|
||||
for(int i = 0;i < posList.tagCount();i++){
|
||||
NBTTagCompound positionTag = posList.getCompoundTagAt(i);
|
||||
|
||||
int posX = positionTag.getInteger("PosX");
|
||||
int posY = positionTag.getInteger("PosY");
|
||||
int posZ = positionTag.getInteger("PosZ");
|
||||
|
||||
BlockPos pos = new BlockPos(posX, posY, posZ);
|
||||
IClimatedPosition position = new ClimatedPosition(climateWorld, pos);
|
||||
position.readFromNBT(positionTag);
|
||||
positions.put(pos, position);
|
||||
}
|
||||
|
||||
ClimateChunk climateChunk = climateWorld.getClimateChunks().get(chunkPos);
|
||||
if(climateChunk == null){
|
||||
climateChunk = new ClimateChunk(climateWorld, chunkPos);
|
||||
}else{
|
||||
for(Entry<BlockPos, IClimatedPosition> entry : positions.entrySet()){
|
||||
climateChunk.getClimates().replace(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
climateWorld.addChunk(climateChunk);
|
||||
}else{
|
||||
climateWorld.addChunk(new ClimateChunk(climateWorld, chunkPos));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,69 +14,102 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.climate.IClimateManager;
|
||||
import forestry.api.core.climate.IClimateWorld;
|
||||
import forestry.api.core.climate.IClimatePosition;
|
||||
import forestry.api.core.climate.IClimateRegion;
|
||||
|
||||
public class ClimateManager implements IClimateManager{
|
||||
|
||||
public Map<Integer, IClimateWorld> climateWorlds;
|
||||
protected Map<Integer, List<IClimateRegion>> regions;
|
||||
|
||||
public ClimateManager() {
|
||||
climateWorlds = new ConcurrentHashMap<>();
|
||||
regions = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRegion(IClimateRegion region) {
|
||||
if(region == null){
|
||||
return;
|
||||
}
|
||||
List<IClimateRegion> regions = getOrCreateRegions(region.getWorld());
|
||||
List<BlockPos> positions = (List<BlockPos>) region.getPositions().keySet();
|
||||
for(IClimateRegion otherRegion : regions){
|
||||
for(BlockPos pos : otherRegion.getPositions().keySet()){
|
||||
if(positions.contains(pos)){
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!regions.contains(region)){
|
||||
regions.add(region);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRegion(IClimateRegion region) {
|
||||
if(region == null){
|
||||
return;
|
||||
}
|
||||
List<IClimateRegion> regions = getOrCreateRegions(region.getWorld());
|
||||
if(regions.contains(region)){
|
||||
regions.remove(region);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTemperature(World world, BlockPos pos) {
|
||||
IClimateWorld climateWorld = getOrCreateWorld(world);
|
||||
Biome biome = world.getBiome(pos);
|
||||
|
||||
if(climateWorld.getPosition(pos) != null){
|
||||
return climateWorld.getPosition(pos).getTemperature();
|
||||
IClimateRegion region = getRegionForPos(world, pos);
|
||||
if(region!= null){
|
||||
IClimatePosition position = region.getPositions().get(pos);
|
||||
|
||||
if(position != null){
|
||||
return position.getTemperature();
|
||||
}
|
||||
}
|
||||
|
||||
return biome.getTemperature();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHumidity(World world, BlockPos pos) {
|
||||
IClimateWorld climateWorld = getOrCreateWorld(world);
|
||||
Biome biome = world.getBiome(pos);
|
||||
|
||||
if(climateWorld.getPosition(pos) != null){
|
||||
return climateWorld.getPosition(pos).getHumidity();
|
||||
IClimateRegion region = getRegionForPos(world, pos);
|
||||
if(region!= null){
|
||||
IClimatePosition position = region.getPositions().get(pos);
|
||||
|
||||
if(position != null){
|
||||
return position.getHumidity();
|
||||
}
|
||||
}
|
||||
|
||||
return biome.getRainfall();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerWorld(IClimateWorld climateWorld) {
|
||||
if(!climateWorlds.containsKey(Integer.valueOf(climateWorld.getDimensionID()))){
|
||||
climateWorlds.put(climateWorld.getDimensionID(), climateWorld);
|
||||
}
|
||||
public Map<Integer, List<IClimateRegion>> getRegions() {
|
||||
return regions;
|
||||
}
|
||||
|
||||
public static IClimateWorld getOrCreateWorld(World world){
|
||||
if(world == null){
|
||||
return null;
|
||||
}
|
||||
IClimateWorld climateWorld = ForestryAPI.climateManager.getClimateWorlds().get(Integer.valueOf(world.provider.getDimension()));
|
||||
|
||||
if(climateWorld == null){
|
||||
climateWorld = new ClimateWorld();
|
||||
ForestryAPI.climateManager.registerWorld(climateWorld);
|
||||
}
|
||||
return climateWorld;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<Integer, IClimateWorld> getClimateWorlds() {
|
||||
return climateWorlds;
|
||||
public IClimateRegion getRegionForPos(World world, BlockPos pos){
|
||||
for(IClimateRegion region : getOrCreateRegions(world)){
|
||||
if(region.getPositions().keySet().contains(pos)){
|
||||
return region;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<IClimateRegion> getOrCreateRegions(World world){
|
||||
List<IClimateRegion> regions = this.regions.get(Integer.valueOf(world.provider.getDimension()));
|
||||
if(regions == null){
|
||||
regions = new ArrayList<>();
|
||||
this.regions.put(Integer.valueOf(world.provider.getDimension()), regions);
|
||||
}
|
||||
return regions;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package forestry.core.climate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import forestry.api.core.climate.IClimatePosition;
|
||||
import forestry.api.core.climate.IClimateRegion;
|
||||
import forestry.api.multiblock.IGreenhouseController;
|
||||
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;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
public class ClimateRoom implements IClimateRegion {
|
||||
|
||||
protected World world;
|
||||
protected IGreenhouseController controller;
|
||||
protected Map<BlockPos, IClimatePosition> positions;
|
||||
|
||||
public ClimateRoom(ClimateRoom room, Map<BlockPos, IClimatePosition> innerPositions) {
|
||||
this.world = room.getWorld();
|
||||
this.controller = room.controller;
|
||||
Map<BlockPos, IClimatePosition> newPositions = new HashMap<>();
|
||||
for(Entry<BlockPos, IClimatePosition> positionEntry : innerPositions.entrySet()){
|
||||
IClimatePosition position = this.positions.get(positionEntry.getKey());
|
||||
if(position == null){
|
||||
newPositions.put(positionEntry.getKey(), positionEntry.getValue());
|
||||
}else{
|
||||
newPositions.put(positionEntry.getKey(), position);
|
||||
}
|
||||
}
|
||||
this.positions = newPositions;
|
||||
}
|
||||
|
||||
public ClimateRoom(IGreenhouseController controller, Map<BlockPos, IClimatePosition> innerPositions) {
|
||||
this.world = controller.getWorldObj();
|
||||
this.controller = controller;
|
||||
this.positions = innerPositions;
|
||||
}
|
||||
|
||||
public ClimateRoom(IGreenhouseController controller, NBTTagCompound nbtTag) {
|
||||
this.world = controller.getWorldObj();
|
||||
this.controller = controller;
|
||||
this.positions = new HashMap<>();
|
||||
readFromNBT(nbtTag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateClimate() {
|
||||
for(Entry<BlockPos, IClimatePosition> position : positions.entrySet()){
|
||||
BlockPos pos = position.getKey();
|
||||
if(world.isBlockLoaded(pos)){
|
||||
updateSides(pos);
|
||||
if(!controller.isAssembled()){
|
||||
Biome biome = world.getBiome(pos);
|
||||
|
||||
float biomeTemperature = biome.getTemperature();
|
||||
float biomeHumidity = biome.getRainfall();
|
||||
IClimatePosition climatedInfo = positions.get(pos);
|
||||
|
||||
if(climatedInfo.getTemperature() != biomeTemperature){
|
||||
if(climatedInfo.getTemperature() > biomeTemperature){
|
||||
climatedInfo.addTemperature(-0.01F);
|
||||
}else{
|
||||
climatedInfo.addTemperature(0.01F);
|
||||
}
|
||||
}
|
||||
|
||||
if(climatedInfo.getHumidity() != biomeHumidity){
|
||||
if(climatedInfo.getHumidity() > biomeHumidity){
|
||||
climatedInfo.addHumidity(-0.01F);
|
||||
}else{
|
||||
climatedInfo.addHumidity(0.01F);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSides(BlockPos pos){
|
||||
IClimatePosition climatedInfo = positions.get(pos);
|
||||
for(EnumFacing facing : EnumFacing.VALUES){
|
||||
BlockPos facePos = pos.offset(facing);
|
||||
IClimatePosition climatedInfoFace = positions.get(facePos);
|
||||
if(climatedInfoFace != null){
|
||||
if(climatedInfo.getTemperature() > climatedInfoFace.getTemperature() + 0.01F){
|
||||
climatedInfo.addTemperature(-0.01F);
|
||||
climatedInfoFace.addTemperature(0.01F);
|
||||
}
|
||||
if(climatedInfo.getHumidity() > climatedInfoFace.getHumidity() + 0.01F){
|
||||
climatedInfo.addHumidity(-0.01F);
|
||||
climatedInfoFace.addHumidity(0.01F);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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("XPos", pos.getX());
|
||||
tag.setInteger("YPos", pos.getY());
|
||||
tag.setInteger("ZPos", 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("XPos");
|
||||
int yPos = positionTag.getInteger("YPos");
|
||||
int zPos = positionTag.getInteger("ZPos");
|
||||
BlockPos pos = new BlockPos(xPos, yPos, zPos);
|
||||
ClimatedPosition position = new ClimatedPosition(this, pos);
|
||||
position.readFromNBT(positionTag);
|
||||
positions.put(pos, position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<BlockPos, IClimatePosition> getPositions() {
|
||||
return positions;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
package forestry.core.climate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import forestry.api.core.climate.IClimateWorld;
|
||||
import forestry.api.core.climate.IClimatedPosition;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
public class ClimateWorld implements IClimateWorld{
|
||||
|
||||
protected int dimensionID;
|
||||
protected World world;
|
||||
protected Map<ChunkPos, ClimateChunk> climateChunks = new ConcurrentHashMap();
|
||||
protected List<ClimateChunk> dirtyClimateChunks = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void addPosition(BlockPos pos){
|
||||
addPosition(createPosition(pos));
|
||||
}
|
||||
|
||||
protected ClimateChunk getOrCreateChunk(ChunkPos chunkPos){
|
||||
ClimateChunk chunk = climateChunks.get(chunkPos);
|
||||
if(chunk == null){
|
||||
chunk = new ClimateChunk(this, chunkPos);
|
||||
climateChunks.put(chunkPos, chunk);
|
||||
}
|
||||
return chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimatedPosition createPosition(BlockPos pos) {
|
||||
Biome biome = world.getBiome(pos);
|
||||
return new ClimatedPosition(this, pos, biome.getTemperature(), biome.getRainfall());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPositions(BlockPos minPos, BlockPos maxPos) {
|
||||
for(BlockPos pos : BlockPos.getAllInBox(minPos, maxPos)){
|
||||
addPosition(pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPosition(IClimatedPosition position) {
|
||||
ChunkPos chunkPos = new ChunkPos(position.getPos());
|
||||
getOrCreateChunk(chunkPos).addPosition(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPositions(List<IClimatedPosition> positions) {
|
||||
for(IClimatedPosition position : positions){
|
||||
addPosition(position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimatedPosition getPosition(BlockPos pos) {
|
||||
ClimateChunk climateChunk = climateChunks.get(new ChunkPos(pos));
|
||||
if(climateChunk != null){
|
||||
return climateChunk.getClimates().get(pos);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateClimate() {
|
||||
for(ClimateChunk climateChunk : climateChunks.values()){
|
||||
for(IClimatedPosition position : climateChunk.getClimates().values()){
|
||||
position.updateClimate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChunk(ClimateChunk climateChunk) {
|
||||
if(climateChunk == null){
|
||||
return;
|
||||
}
|
||||
climateChunks.put(climateChunk.getChunkPos(), climateChunk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeChunk(ChunkPos chunkPos) {
|
||||
if(chunkPos == null){
|
||||
return;
|
||||
}
|
||||
climateChunks.remove(chunkPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<ChunkPos, ClimateChunk> getClimateChunks() {
|
||||
return climateChunks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDimensionID() {
|
||||
return dimensionID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDirtyClimateChunk(ClimateChunk chunk) {
|
||||
this.dirtyClimateChunks.add(chunk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ClimateChunk> getDirtyClimateChunks() {
|
||||
return dirtyClimateChunks;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,52 +10,40 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.climate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import forestry.api.core.climate.IClimateWorld;
|
||||
import forestry.api.core.climate.IClimatedPosition;
|
||||
import forestry.api.greenhouse.GreenhouseManager;
|
||||
import forestry.api.multiblock.IGreenhouseController;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.api.multiblock.IMultiblockLogic;
|
||||
import forestry.api.core.climate.IClimateRegion;
|
||||
import forestry.api.core.climate.IClimatePosition;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
public class ClimatedPosition implements IClimatedPosition {
|
||||
public class ClimatedPosition implements IClimatePosition {
|
||||
|
||||
@Nonnull
|
||||
protected final IClimateWorld climateWorld;
|
||||
protected final IClimateRegion climateRegion;
|
||||
@Nonnull
|
||||
protected final BlockPos pos;
|
||||
protected float temperature;
|
||||
protected float humidity;
|
||||
protected List<IClimateHandler> handlers;
|
||||
|
||||
public ClimatedPosition(IClimateWorld climateWorld, BlockPos pos) {
|
||||
this.climateWorld = climateWorld;
|
||||
public ClimatedPosition(IClimateRegion climateRegion, BlockPos pos) {
|
||||
this.climateRegion = climateRegion;
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
public ClimatedPosition(@Nonnull IClimateWorld climateWorld, @Nonnull BlockPos pos, float temperature, float humidity) {
|
||||
this.climateWorld = climateWorld;
|
||||
public ClimatedPosition(@Nonnull IClimateRegion climateRegion, @Nonnull BlockPos pos, float temperature, float humidity) {
|
||||
this.climateRegion = climateRegion;
|
||||
this.pos = pos;
|
||||
this.temperature = temperature;
|
||||
this.humidity = humidity;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Nonnull
|
||||
@Override
|
||||
public IClimateWorld getClimateWorld() {
|
||||
return climateWorld;
|
||||
public IClimateRegion getClimateRegion() {
|
||||
return climateRegion;
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public BlockPos getPos() {
|
||||
@@ -72,6 +60,16 @@ public class ClimatedPosition implements IClimatedPosition {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTemperature(float temperature) {
|
||||
setTemperature(getTemperature() + temperature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addHumidity(float humidity) {
|
||||
setHumidity(getHumidity() + humidity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHumidity(float humidity) {
|
||||
this.humidity = humidity;
|
||||
@@ -86,11 +84,6 @@ public class ClimatedPosition implements IClimatedPosition {
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
temperature = nbt.getFloat("Temperature");
|
||||
humidity = nbt.getFloat("Humidity");
|
||||
NBTTagList handlersNBT = nbt.getTagList("Handlers", 10);
|
||||
for(int i = 0;i < handlersNBT.tagCount();i++){
|
||||
NBTTagCompound handlerNBT = handlersNBT.getCompoundTagAt(i);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,94 +92,5 @@ public class ClimatedPosition implements IClimatedPosition {
|
||||
nbt.setFloat("Humidity", humidity);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addHandler(IClimateHandler climateHandler) {
|
||||
if(climateHandler == null){
|
||||
return;
|
||||
}
|
||||
handlers.add(climateHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHandler(IClimateHandler climateHandler) {
|
||||
if(climateHandler == null){
|
||||
return;
|
||||
}
|
||||
handlers.remove(climateHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateClimate() {
|
||||
boolean canHold = false;
|
||||
for(IClimateHandler handler : getHandlers()){
|
||||
if(handler != null){
|
||||
if(handler.canHoldClimate(this)){
|
||||
canHold = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!canHold){
|
||||
Biome biome = climateWorld.getWorld().getBiome(pos);
|
||||
float biomeTemperature = biome.getTemperature();
|
||||
float biomeHumidity = biome.getRainfall();
|
||||
|
||||
if(temperature != biomeTemperature){
|
||||
if(temperature > biomeTemperature){
|
||||
temperature-=0.01F;
|
||||
}else{
|
||||
temperature+=0.01F;
|
||||
}
|
||||
}
|
||||
|
||||
if(humidity != biomeHumidity){
|
||||
if(humidity > biomeHumidity){
|
||||
humidity-=0.01F;
|
||||
}else{
|
||||
humidity+=0.01F;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(IClimateHandler handler : getHandlers()){
|
||||
if(handler != null){
|
||||
if(handler.canHandle(this)){
|
||||
handler.updateClimate(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IClimateHandler> getHandlers() {
|
||||
List<IClimateHandler> handlers = new ArrayList<>();
|
||||
TileEntity tile = climateWorld.getWorld().getTileEntity(pos);
|
||||
if(tile != null){
|
||||
if(tile instanceof IClimateHandler){
|
||||
handlers.add((IClimateHandler) tile);
|
||||
}
|
||||
if(tile instanceof IMultiblockComponent){
|
||||
IMultiblockComponent component = (IMultiblockComponent) tile;
|
||||
IMultiblockLogic logic = component.getMultiblockLogic();
|
||||
if(logic.getController() instanceof IClimateHandler){
|
||||
handlers.add((IClimateHandler) logic.getController());
|
||||
}
|
||||
}
|
||||
IGreenhouseController greenhouse = GreenhouseManager.greenhouseHelper.getGreenhouseController(climateWorld.getWorld(), pos);
|
||||
|
||||
if(greenhouse != null){
|
||||
handlers.add(greenhouse);
|
||||
}
|
||||
}
|
||||
handlers.addAll(this.handlers);
|
||||
Iterator<IClimateHandler> iHandlers = handlers.iterator();
|
||||
while(iHandlers.hasNext()){
|
||||
IClimateHandler handler = iHandlers.next();
|
||||
if(!handler.canHandle(this)){
|
||||
iHandlers.remove();
|
||||
}
|
||||
}
|
||||
return handlers;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package forestry.core.climate;
|
||||
|
||||
import forestry.api.core.climate.IClimateWorld;
|
||||
import forestry.api.core.climate.IClimatedPosition;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public interface IClimateHandler {
|
||||
|
||||
BlockPos getPos();
|
||||
|
||||
IClimateWorld getWorld();
|
||||
|
||||
boolean canHandle(IClimatedPosition position);
|
||||
|
||||
void updateClimate(IClimatedPosition position);
|
||||
|
||||
boolean canHoldClimate(IClimatedPosition position);
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import java.util.Random;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.IChunkGenerator;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
@@ -23,10 +24,10 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.terraingen.PopulateChunkEvent;
|
||||
import net.minecraftforge.fml.common.IWorldGenerator;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
import forestry.core.PluginCore;
|
||||
import forestry.core.blocks.BlockResourceOre;
|
||||
import forestry.core.blocks.EnumResourceType;
|
||||
import forestry.core.climate.ClimateManager;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.plugins.PluginManager;
|
||||
|
||||
|
||||
@@ -10,15 +10,11 @@
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse.logics;
|
||||
|
||||
import net.minecraft.block.BlockDoor;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import forestry.api.greenhouse.DefaultGreenhouseLogic;
|
||||
import forestry.api.greenhouse.IGreenhouseClimaLogic;
|
||||
import forestry.api.multiblock.IGreenhouseController;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseDoor;
|
||||
|
||||
public class GreenhouseLogicGreenhouseDoor extends DefaultGreenhouseLogic implements IGreenhouseClimaLogic {
|
||||
|
||||
@@ -30,7 +26,7 @@ public class GreenhouseLogicGreenhouseDoor extends DefaultGreenhouseLogic implem
|
||||
|
||||
@Override
|
||||
public void work() {
|
||||
if (controller == null || !controller.isAssembled()) {
|
||||
/*if (controller == null || !controller.isAssembled()) {
|
||||
return;
|
||||
}
|
||||
if (workTimer++ > 20) {
|
||||
@@ -46,7 +42,7 @@ public class GreenhouseLogicGreenhouseDoor extends DefaultGreenhouseLogic implem
|
||||
controller.addTemperatureChange(-0.0001F * openDoors, 0.05F, 2.5F);
|
||||
controller.addHumidityChange(-0.0001F * openDoors, 0.05F, 2.5F);
|
||||
workTimer = 0;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,7 +36,7 @@ public class GreenhouseLogicGreenhouseEffect extends DefaultGreenhouseLogic impl
|
||||
|
||||
@Override
|
||||
public void work() {
|
||||
if (controller == null || !controller.isAssembled()) {
|
||||
/*if (controller == null || !controller.isAssembled()) {
|
||||
return;
|
||||
}
|
||||
if (controller.getWorldObj().isDaytime()) {
|
||||
@@ -44,7 +44,7 @@ public class GreenhouseLogicGreenhouseEffect extends DefaultGreenhouseLogic impl
|
||||
controller.addTemperatureChange(lightTransmittance / 100, 0F, 2.5F);
|
||||
workTimer = 0;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,8 +19,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import forestry.api.core.EnumCamouflageType;
|
||||
import forestry.api.core.climate.IClimateWorld;
|
||||
import forestry.api.core.climate.IClimatedPosition;
|
||||
import forestry.api.core.climate.IClimateRegion;
|
||||
import forestry.api.greenhouse.EnumGreenhouseEventType;
|
||||
import forestry.api.greenhouse.IGreenhouseLogic;
|
||||
import forestry.api.greenhouse.IInternalBlock;
|
||||
@@ -92,29 +91,9 @@ public class FakeGreenhouseController extends FakeMultiblockController implement
|
||||
public String getUnlocalizedType() {
|
||||
return "for.multiblock.greenhouse.type";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockPos getPos() {
|
||||
public IClimateRegion getRegion() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateWorld getWorld() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHoldClimate(IClimatedPosition position) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHandle(IClimatedPosition position) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateClimate(IClimatedPosition position) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -14,11 +14,12 @@ import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -33,9 +34,10 @@ import net.minecraftforge.fluids.FluidRegistry;
|
||||
import forestry.api.core.EnumCamouflageType;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.ICamouflagedTile;
|
||||
import forestry.api.core.climate.IClimateWorld;
|
||||
import forestry.api.core.climate.IClimatedPosition;
|
||||
import forestry.api.core.climate.IClimatePosition;
|
||||
import forestry.api.core.climate.IClimateRegion;
|
||||
import forestry.api.greenhouse.EnumGreenhouseEventType;
|
||||
import forestry.api.greenhouse.GreenhouseEvents.CamouflageChangeEvent;
|
||||
import forestry.api.greenhouse.GreenhouseEvents.CheckInternalBlockFaceEvent;
|
||||
@@ -49,7 +51,8 @@ import forestry.api.multiblock.IGreenhouseComponent.ButterflyHatch;
|
||||
import forestry.api.multiblock.IGreenhouseController;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.core.access.EnumAccess;
|
||||
import forestry.core.climate.ClimateManager;
|
||||
import forestry.core.climate.ClimateRoom;
|
||||
import forestry.core.climate.ClimatedPosition;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
@@ -91,6 +94,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
private ItemStack camouflagePlainBlock;
|
||||
private ItemStack camouflageGlassBlock;
|
||||
private ItemStack camouflageDoorBlock;
|
||||
private ClimateRoom region;
|
||||
|
||||
public GreenhouseController(World world) {
|
||||
super(world, GreenhouseMultiblockSizeLimits.instance);
|
||||
@@ -120,12 +124,11 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
@Override
|
||||
public float getExactTemperature() {
|
||||
int dimensionID = worldObj.provider.getDimension();
|
||||
IClimateWorld climateWorld = ClimateManager.getOrCreateWorld(worldObj);
|
||||
|
||||
float temperature = 0.0F;
|
||||
|
||||
for(IInternalBlock internalBlock : internalBlocks){
|
||||
IClimatedPosition position = climateWorld.getPosition(internalBlock.getPos());
|
||||
IClimatePosition position = region.getPositions().get(internalBlock.getPos());
|
||||
if(position != null){
|
||||
temperature+=position.getTemperature();
|
||||
}
|
||||
@@ -136,12 +139,10 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
@Override
|
||||
public float getExactHumidity() {
|
||||
int dimensionID = worldObj.provider.getDimension();
|
||||
IClimateWorld climateWorld = ClimateManager.getOrCreateWorld(worldObj);
|
||||
|
||||
float humidity = 0.0F;
|
||||
|
||||
for(IInternalBlock internalBlock : internalBlocks){
|
||||
IClimatedPosition position = climateWorld.getPosition(internalBlock.getPos());
|
||||
IClimatePosition position = region.getPositions().get(internalBlock.getPos());
|
||||
if(position != null){
|
||||
humidity+=position.getHumidity();
|
||||
}
|
||||
@@ -178,6 +179,10 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
logic.writeToNBT(nbtTag);
|
||||
data.setTag("logic" + logic.getName(), nbtTag);
|
||||
}
|
||||
|
||||
if(region != null){
|
||||
data.setTag("Region", region.writeToNBT(data));
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
@@ -201,6 +206,11 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
for (IGreenhouseLogic logic : getLogics()) {
|
||||
logic.readFromNBT(data.getCompoundTag("logic" + logic.getName()));
|
||||
}
|
||||
|
||||
if(data.hasKey("Region")){
|
||||
NBTTagCompound nbtTag = data.getCompoundTag("Region");
|
||||
region = new ClimateRoom(this, nbtTag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -394,6 +404,24 @@ 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 ClimatedPosition(region, block.getPos()));
|
||||
}
|
||||
}
|
||||
region = new ClimateRoom(region, internalPositions);
|
||||
}else{
|
||||
Map<BlockPos, IClimatePosition> internalPositions = new HashMap<>();
|
||||
for(IInternalBlock block : internalBlocks){
|
||||
if(block != null){
|
||||
internalPositions.put(block.getPos(), new ClimatedPosition(region, block.getPos()));
|
||||
}
|
||||
}
|
||||
region = new ClimateRoom(this, internalPositions);
|
||||
ForestryAPI.climateManager.addRegion(region);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -711,52 +739,8 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getPos() {
|
||||
return getReferenceCoord();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateWorld getWorld() {
|
||||
return ClimateManager.getOrCreateWorld(worldObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHandle(IClimatedPosition position) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateClimate(IClimatedPosition position) {
|
||||
for(EnumFacing facing : EnumFacing.VALUES){
|
||||
BlockPos facePos = position.getPos().offset(facing);
|
||||
if(isInternalBlock(facePos)){
|
||||
IClimatedPosition climatedPosition = position.getClimateWorld().getPosition(facePos);
|
||||
if(climatedPosition != null){
|
||||
if(position.getTemperature() > climatedPosition.getTemperature() + 0.01F){
|
||||
position.setTemperature(position.getTemperature() - 0.01F);
|
||||
climatedPosition.setTemperature(climatedPosition.getTemperature() + 0.01F);
|
||||
}
|
||||
if(position.getHumidity() > climatedPosition.getHumidity() + 0.01F){
|
||||
position.setHumidity(position.getHumidity()-0.01F);
|
||||
climatedPosition.setHumidity(climatedPosition.getHumidity() + 0.01F);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInternalBlock(BlockPos pos){
|
||||
for(IInternalBlock internalBlock : internalBlocks){
|
||||
if(internalBlock != null && internalBlock.getPos().equals(pos)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHoldClimate(IClimatedPosition position) {
|
||||
return isInternalBlock(position.getPos());
|
||||
public IClimateRegion getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,13 +15,12 @@ import javax.annotation.Nonnull;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import forestry.api.core.climate.IClimateWorld;
|
||||
import forestry.api.core.climate.IClimatedPosition;
|
||||
import forestry.api.core.climate.IClimatePosition;
|
||||
import forestry.api.core.climate.IClimateRegion;
|
||||
import forestry.api.multiblock.IGreenhouseComponent;
|
||||
import forestry.api.multiblock.IGreenhouseController;
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.apiculture.network.packets.PacketActiveUpdate;
|
||||
import forestry.core.climate.ClimateManager;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.tiles.IActivatable;
|
||||
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
|
||||
@@ -87,10 +86,10 @@ public class TileGreenhouseClimatiser extends TileGreenhouse implements IActivat
|
||||
IGreenhouseControllerInternal greenhouseInternal = (IGreenhouseControllerInternal) greenhouse;
|
||||
if (workingTime == 0 && greenhouseInternal.getEnergyManager().consumeEnergyToDoWork(WORK_CYCLES, ENERGY_PER_OPERATION)) {
|
||||
int dimensionID = worldObj.provider.getDimension();
|
||||
IClimateWorld climateWorld = ClimateManager.getOrCreateWorld(worldObj);
|
||||
IClimateRegion region = greenhouse.getRegion();
|
||||
|
||||
for(BlockPos pos : BlockPos.getAllInBox(maxPos, minPos)){
|
||||
IClimatedPosition position = climateWorld.getPosition(pos);
|
||||
IClimatePosition position = region.getPositions().get(pos);
|
||||
if(position != null){
|
||||
if (definition.getType() == ClimitiserType.TEMPERATURE) {
|
||||
if(position.getTemperature() >= 2.0F){
|
||||
|
||||
@@ -20,10 +20,9 @@ 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 forestry.api.core.climate.IClimateWorld;
|
||||
import forestry.api.core.climate.IClimatedPosition;
|
||||
import forestry.api.core.climate.IClimatePosition;
|
||||
import forestry.api.core.climate.IClimateRegion;
|
||||
import forestry.api.multiblock.IGreenhouseController;
|
||||
import forestry.core.climate.ClimateManager;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.proxy.Proxies;
|
||||
@@ -57,10 +56,10 @@ public class TileGreenhouseSprinkler extends TileGreenhouseClimatiser {
|
||||
IGreenhouseControllerInternal greenhouseInternal = (IGreenhouseControllerInternal) greenhouse;
|
||||
if (workingTime == 0 && consumeWaterToDoWork(WORK_CYCLES, WATER_PER_OPERATION, (StandardTank) greenhouseInternal.getTankManager().getTank(0))) {
|
||||
int dimensionID = worldObj.provider.getDimension();
|
||||
IClimateWorld climateWorld = ClimateManager.getOrCreateWorld(worldObj);
|
||||
IClimateRegion region = greenhouse.getRegion();
|
||||
|
||||
for(BlockPos pos : BlockPos.getAllInBox(maxPos, minPos)){
|
||||
IClimatedPosition position = climateWorld.getPosition(pos);
|
||||
IClimatePosition position = region.getPositions().get(pos);
|
||||
if(position != null){
|
||||
if(position.getHumidity() >= 2.0F){
|
||||
if(position.getHumidity() > 2.0F){
|
||||
|
||||
Reference in new issue
Block a user