mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-28 07:35:47 +00:00
Improve Climate Sources
This commit is contained in:
1 parent
ab4489c5aa
commit
1180c16f45
29 files changed
+461
-477
No files matched your search
@@ -5,21 +5,20 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.climate;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
public enum ClimateStateType {
|
||||
IMMUTABLE(0.0F, 2.0F),
|
||||
MUTABLE(0.0F, 2.0F),
|
||||
CHANGE(-3.0F, 3.0F);
|
||||
DEFAULT(0.0F, 2.0F),
|
||||
EXTENDED(-3.0F, 3.0F);
|
||||
|
||||
public final Function<Float, Float> bounds;
|
||||
public final Float boundDown, boundUp;
|
||||
public final float boundDown, boundUp;
|
||||
|
||||
ClimateStateType(Float boundDown, Float boundUp) {
|
||||
this.bounds = v -> MathHelper.clamp(v, boundDown, boundUp);
|
||||
this.boundDown = boundDown;
|
||||
this.boundUp = boundUp;
|
||||
}
|
||||
|
||||
public float clamp(float value) {
|
||||
return MathHelper.clamp(value, boundDown, boundUp);
|
||||
}
|
||||
}
|
||||
@@ -7,21 +7,9 @@ package forestry.api.climate;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
|
||||
public enum ClimateType {
|
||||
TEMPERATURE, HUMIDITY;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public TextureAtlasSprite getSprite() {
|
||||
return ForestryAPI.textureManager.getDefault("misc/" + getName());
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return name().toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ import forestry.api.core.INbtWritable;
|
||||
|
||||
/**
|
||||
* A {@link IClimateState} is used to store and handle temperature and humidity.
|
||||
*
|
||||
* The range of the value of this two goes from 0.0F to 2.0F. And is oriented on the values of {@link Biome#getTemperature()} and {@link Biome#getRainfall()}.
|
||||
*
|
||||
* The values are oriented on the values of {@link Biome#getTemperature()} and {@link Biome#getRainfall()}.
|
||||
*/
|
||||
public interface IClimateState extends INbtWritable {
|
||||
|
||||
@@ -25,18 +25,18 @@ public interface IClimateState extends INbtWritable {
|
||||
IClimateState addHumidity(float humidity);
|
||||
|
||||
IClimateState add(IClimateState state);
|
||||
|
||||
|
||||
IClimateState scale(double factor);
|
||||
|
||||
IClimateState remove(IClimateState state);
|
||||
|
||||
default float get(ClimateType type){
|
||||
return type == ClimateType.HUMIDITY ? getHumidity() : getTemperature();
|
||||
}
|
||||
|
||||
IClimateState toState(ClimateStateType type);
|
||||
IClimateState copy(ClimateStateType type);
|
||||
|
||||
IClimateState setTemperature(float temperature);
|
||||
|
||||
IClimateState setHumidity(float humidity);
|
||||
IClimateState copy();
|
||||
|
||||
boolean isPresent();
|
||||
|
||||
|
||||
@@ -15,16 +15,8 @@ public interface IClimateStates {
|
||||
|
||||
IClimateState create(float temperature, float humidity, ClimateStateType type);
|
||||
|
||||
default IClimateState create(float temperature, float humidity){
|
||||
return create(temperature, humidity, ClimateStateType.MUTABLE);
|
||||
}
|
||||
|
||||
IClimateState create(IClimateState climateState, ClimateStateType type);
|
||||
|
||||
default IClimateState create(IClimateState climateState){
|
||||
return create(climateState, ClimateStateType.MUTABLE);
|
||||
}
|
||||
|
||||
IClimateState absent();
|
||||
|
||||
IClimateState min();
|
||||
|
||||
@@ -31,17 +31,12 @@ public final class AbsentClimateState implements IClimateState {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState toState(ClimateStateType type) {
|
||||
public IClimateState copy(ClimateStateType type) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState setHumidity(float humidity) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState setTemperature(float temperature) {
|
||||
public IClimateState copy() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -60,6 +55,11 @@ public final class AbsentClimateState implements IClimateState {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState scale(double factor) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState remove(IClimateState state){
|
||||
return this;
|
||||
@@ -72,7 +72,7 @@ public final class AbsentClimateState implements IClimateState {
|
||||
|
||||
@Override
|
||||
public ClimateStateType getType() {
|
||||
return ClimateStateType.IMMUTABLE;
|
||||
return ClimateStateType.DEFAULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,7 +91,7 @@ public final class AbsentClimateState implements IClimateState {
|
||||
return false;
|
||||
}
|
||||
IClimateState otherState = (IClimateState) obj;
|
||||
return otherState.getTemperature() == Float.NaN && otherState.getHumidity() == Float.NaN;
|
||||
return Float.isNaN(otherState.getTemperature()) && Float.isNaN(otherState.getHumidity());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,13 +20,13 @@ public class ClimateInfo implements IClimateInfo {
|
||||
private final float humidity;
|
||||
|
||||
public ClimateInfo(float temperature, float humidity) {
|
||||
this.temperature = ClimateStateType.IMMUTABLE.bounds.apply(temperature);
|
||||
this.humidity = ClimateStateType.IMMUTABLE.bounds.apply(humidity);
|
||||
this.temperature = ClimateStateType.DEFAULT.clamp(temperature);
|
||||
this.humidity = ClimateStateType.DEFAULT.clamp(humidity);
|
||||
}
|
||||
|
||||
public ClimateInfo(IClimateState climateState) {
|
||||
this.temperature = climateState.toState(ClimateStateType.IMMUTABLE).getTemperature();
|
||||
this.humidity = climateState.toState(ClimateStateType.IMMUTABLE).getHumidity();
|
||||
this.temperature = climateState.copy(ClimateStateType.DEFAULT).getTemperature();
|
||||
this.humidity = climateState.copy(ClimateStateType.DEFAULT).getHumidity();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -58,7 +58,7 @@ public class ClimateManager implements IClimateManager {
|
||||
|
||||
private IClimateState getBiomeState(Biome biome) {
|
||||
if (!BIOME_STATES.containsKey(biome)) {
|
||||
BIOME_STATES.put(biome, ClimateStates.immutableOf(biome.getTemperature(), biome.getRainfall()));
|
||||
BIOME_STATES.put(biome, ClimateStates.of(biome.getTemperature(), biome.getRainfall()));
|
||||
}
|
||||
return BIOME_STATES.get(biome);
|
||||
}
|
||||
|
||||
@@ -1,206 +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 javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.climate.ClimateType;
|
||||
import forestry.api.climate.IClimateState;
|
||||
import forestry.greenhouse.api.climate.IClimateContainer;
|
||||
import forestry.greenhouse.api.climate.IClimateSource;
|
||||
import forestry.greenhouse.api.climate.IClimateSourceOwner;
|
||||
import forestry.greenhouse.api.greenhouse.GreenhouseManager;
|
||||
|
||||
public abstract class ClimateSource<O extends IClimateSourceOwner> implements IClimateSource {
|
||||
|
||||
protected O owner;
|
||||
protected float change;
|
||||
protected final float range;
|
||||
protected final ClimateSourceType sourceType;
|
||||
protected ClimateSourceMode temperatureMode;
|
||||
protected ClimateSourceMode humidityMode;
|
||||
protected IClimateContainer container;
|
||||
protected boolean addedToManager;
|
||||
protected boolean isActive;
|
||||
|
||||
public ClimateSource(float change, float range, ClimateSourceType sourceType) {
|
||||
this.change = change;
|
||||
this.range = range;
|
||||
this.sourceType = sourceType;
|
||||
this.temperatureMode = ClimateSourceMode.NONE;
|
||||
this.humidityMode = ClimateSourceMode.NONE;
|
||||
}
|
||||
|
||||
public void setHumidityMode(ClimateSourceMode humidityMode) {
|
||||
this.humidityMode = humidityMode;
|
||||
}
|
||||
|
||||
public void setTemperatureMode(ClimateSourceMode temperatureMode) {
|
||||
this.temperatureMode = temperatureMode;
|
||||
}
|
||||
|
||||
public void setOwner(O owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getBoundaryModifier(ClimateType type, boolean boundaryUp) {
|
||||
if(type == ClimateType.HUMIDITY){
|
||||
if(humidityMode == ClimateSourceMode.POSITIVE && boundaryUp){
|
||||
return getRange(ClimateType.HUMIDITY);
|
||||
}else if(humidityMode == ClimateSourceMode.NEGATIVE && !boundaryUp){
|
||||
return getRange(ClimateType.HUMIDITY);
|
||||
}
|
||||
}else {
|
||||
if(temperatureMode == ClimateSourceMode.POSITIVE && boundaryUp){
|
||||
return getRange(ClimateType.TEMPERATURE);
|
||||
}else if(temperatureMode == ClimateSourceMode.NEGATIVE && !boundaryUp){
|
||||
return getRange(ClimateType.TEMPERATURE);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected float getRange(ClimateType type){
|
||||
return range;
|
||||
}
|
||||
|
||||
protected float getChange(ClimateType type) {
|
||||
return change;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return isActive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean affectClimateType(ClimateType type) {
|
||||
return sourceType.affectClimateType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateSourceOwner getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdded(IClimateContainer container) {
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemoved(IClimateContainer container) {
|
||||
this.container = null;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if(!addedToManager){
|
||||
onLoad();
|
||||
}
|
||||
}
|
||||
|
||||
public void onLoad() {
|
||||
World world = owner.getWorldObj();
|
||||
if(!addedToManager && !world.isRemote) {
|
||||
GreenhouseManager.climateManager.addSource(owner);
|
||||
addedToManager = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void invalidate() {
|
||||
this.onChunkUnload();
|
||||
}
|
||||
|
||||
public void onChunkUnload() {
|
||||
World world = owner.getWorldObj();
|
||||
if(addedToManager &&!world.isRemote) {
|
||||
GreenhouseManager.climateManager.removeSource(owner);
|
||||
addedToManager = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState work(IClimateState state, IClimateState target) {
|
||||
beforeWork();
|
||||
ClimateSourceType validType = getValidType(state, target);
|
||||
if(validType == null){
|
||||
isNotValid();
|
||||
isActive = false;
|
||||
return AbsentClimateState.INSTANCE;
|
||||
}
|
||||
if(!canWork(state, target)){
|
||||
isActive = false;
|
||||
return AbsentClimateState.INSTANCE;
|
||||
}
|
||||
removeResources(state, target);
|
||||
isActive = true;
|
||||
return getChange(validType, state, target);
|
||||
}
|
||||
|
||||
protected void isNotValid(){
|
||||
|
||||
}
|
||||
|
||||
protected void beforeWork(){
|
||||
}
|
||||
|
||||
/**
|
||||
* @param state the {@link IClimateState} that the source has to work on.
|
||||
* @param target the by the {@link IClimateContainer} targeted {@link IClimateState}.
|
||||
*
|
||||
* @return true if the source can work, false if it can not.
|
||||
*/
|
||||
protected abstract boolean canWork(IClimateState state, IClimateState target);
|
||||
|
||||
protected abstract void removeResources(IClimateState state, IClimateState target);
|
||||
|
||||
protected abstract IClimateState getChange(ClimateSourceType type, IClimateState state, IClimateState target);
|
||||
|
||||
@Nullable
|
||||
private ClimateSourceType getValidType(IClimateState state, IClimateState target){
|
||||
boolean canChangeHumidity = false;
|
||||
boolean canChangeTemperature = false;
|
||||
if(sourceType.canChangeHumidity()){
|
||||
if(canChange(state.getHumidity(), target.getHumidity(), humidityMode)){
|
||||
canChangeHumidity = true;
|
||||
}
|
||||
}
|
||||
if(sourceType.canChangeTemperature()){
|
||||
if(canChange(state.getTemperature(), target.getTemperature(), temperatureMode)){
|
||||
canChangeTemperature = true;
|
||||
}
|
||||
}
|
||||
if(canChangeHumidity){
|
||||
if(canChangeTemperature){
|
||||
return ClimateSourceType.BOTH;
|
||||
}
|
||||
return ClimateSourceType.HUMIDITY;
|
||||
}else if(canChangeTemperature){
|
||||
return ClimateSourceType.TEMPERATURE;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean canChange(float value, float target, ClimateSourceMode mode){
|
||||
if(mode == ClimateSourceMode.POSITIVE && value < target){
|
||||
return true;
|
||||
}else if(mode == ClimateSourceMode.NEGATIVE && value > target){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,8 +12,6 @@ package forestry.core.climate;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import forestry.api.climate.ClimateStateType;
|
||||
@@ -23,9 +21,9 @@ import forestry.api.climate.IClimateState;
|
||||
class ClimateState implements IClimateState, IClimateInfo {
|
||||
|
||||
// The minimum climate state.
|
||||
public static final ClimateState MIN = new ClimateState(0.0F, 0.0F, ClimateStateType.IMMUTABLE);
|
||||
public static final ClimateState MIN = new ClimateState(0.0F, 0.0F, ClimateStateType.DEFAULT);
|
||||
// The maximum climate state.
|
||||
public static final ClimateState MAX = new ClimateState(2.0F, 2.0F, ClimateStateType.IMMUTABLE);
|
||||
public static final ClimateState MAX = new ClimateState(2.0F, 2.0F, ClimateStateType.DEFAULT);
|
||||
|
||||
public static final String TEMPERATURE_NBT_KEY = "TEMP";
|
||||
public static final String HUMIDITY_NBT_KEY = "HUMID";
|
||||
@@ -33,7 +31,6 @@ class ClimateState implements IClimateState, IClimateInfo {
|
||||
public static final String ABSENT_NBT_KEY = "ABSENT";
|
||||
|
||||
protected final ClimateStateType type;
|
||||
protected final Function<Float, Float> bounds;
|
||||
protected float temperature;
|
||||
protected float humidity;
|
||||
|
||||
@@ -43,20 +40,17 @@ class ClimateState implements IClimateState, IClimateInfo {
|
||||
|
||||
public ClimateState(float temperature, float humidity, ClimateStateType type) {
|
||||
this.type = type;
|
||||
this.bounds = type.bounds;
|
||||
this.temperature = bounds.apply(temperature);
|
||||
this.humidity = bounds.apply(humidity);
|
||||
this.temperature = type.clamp(temperature);
|
||||
this.humidity = type.clamp(humidity);
|
||||
}
|
||||
|
||||
public ClimateState(NBTTagCompound compound, ClimateStateType type) {
|
||||
this.type = type;
|
||||
this.bounds = type.bounds;
|
||||
readFromNBT(compound);
|
||||
}
|
||||
|
||||
public ClimateState(NBTTagCompound compound) {
|
||||
this.type = ClimateStateType.values()[compound.getByte(TYPE_NBT_KEY)];
|
||||
this.bounds = type.bounds;
|
||||
readFromNBT(compound);
|
||||
}
|
||||
|
||||
@@ -70,87 +64,43 @@ class ClimateState implements IClimateState, IClimateInfo {
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
this.temperature = bounds.apply(compound.getFloat(TEMPERATURE_NBT_KEY));
|
||||
this.humidity = bounds.apply(compound.getFloat(HUMIDITY_NBT_KEY));
|
||||
this.temperature = type.clamp(compound.getFloat(TEMPERATURE_NBT_KEY));
|
||||
this.humidity = type.clamp(compound.getFloat(HUMIDITY_NBT_KEY));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState setHumidity(float humidity) {
|
||||
if(type == ClimateStateType.IMMUTABLE){
|
||||
return ClimateStates.immutableOf(getTemperature(), humidity);
|
||||
}
|
||||
this.humidity = bounds.apply(humidity);
|
||||
if(!isPresent()){
|
||||
return AbsentClimateState.INSTANCE;
|
||||
}
|
||||
return this;
|
||||
public IClimateState copy(ClimateStateType type) {
|
||||
return new ClimateState(this, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState setTemperature(float temperature) {
|
||||
if(type == ClimateStateType.IMMUTABLE){
|
||||
return ClimateStates.immutableOf(temperature, getHumidity());
|
||||
}
|
||||
this.temperature = bounds.apply(temperature);
|
||||
if(!isPresent()){
|
||||
return AbsentClimateState.INSTANCE;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState toState(ClimateStateType type) {
|
||||
public IClimateState copy() {
|
||||
return new ClimateState(this, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState addTemperature(float temperature){
|
||||
if (type == ClimateStateType.IMMUTABLE) {
|
||||
return ClimateStates.immutableOf(this.temperature + temperature, humidity);
|
||||
}
|
||||
this.temperature = bounds.apply(this.temperature + temperature);
|
||||
if(!isPresent()){
|
||||
return AbsentClimateState.INSTANCE;
|
||||
}
|
||||
return this;
|
||||
return ClimateStates.of(this.temperature + temperature, humidity, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState addHumidity(float humidity){
|
||||
if (type == ClimateStateType.IMMUTABLE) {
|
||||
return ClimateStates.immutableOf(temperature, this.humidity + humidity);
|
||||
}
|
||||
this.humidity= bounds.apply(this.humidity + humidity);
|
||||
if(!isPresent()){
|
||||
return AbsentClimateState.INSTANCE;
|
||||
}
|
||||
return this;
|
||||
return ClimateStates.of(temperature, this.humidity + humidity, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState add(IClimateState state){
|
||||
if (type == ClimateStateType.IMMUTABLE) {
|
||||
return ClimateStates.immutableOf(this.temperature + state.getTemperature(), this.humidity + state.getHumidity());
|
||||
}
|
||||
addTemperature(state.getTemperature());
|
||||
addHumidity(state.getHumidity());
|
||||
if(!isPresent()){
|
||||
return AbsentClimateState.INSTANCE;
|
||||
}
|
||||
return this;
|
||||
return ClimateStates.of(this.temperature + state.getTemperature(), this.humidity + state.getHumidity(), type);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IClimateState scale(double factor) {
|
||||
return ClimateStates.of((float) (this.temperature * factor), (float) (this.humidity * factor), type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState remove(IClimateState state){
|
||||
if (type == ClimateStateType.IMMUTABLE) {
|
||||
return ClimateStates.immutableOf(this.temperature - state.getTemperature(), this.humidity - state.getHumidity());
|
||||
}
|
||||
addTemperature(-state.getTemperature());
|
||||
addHumidity(-state.getHumidity());
|
||||
if(!isPresent()){
|
||||
return AbsentClimateState.INSTANCE;
|
||||
}
|
||||
return this;
|
||||
return ClimateStates.of(this.temperature - state.getTemperature(), this.humidity - state.getHumidity(), type);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,54 +15,63 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import forestry.api.climate.ClimateStateType;
|
||||
import forestry.api.climate.IClimateState;
|
||||
import forestry.api.climate.IClimateStates;
|
||||
import forestry.greenhouse.climate.modifiers.ClimateSourceModifier;
|
||||
|
||||
public final class ClimateStates implements IClimateStates {
|
||||
|
||||
public static final ClimateStates INSTANCE = new ClimateStates();
|
||||
public static final IClimateState ZERO = of(0.0F, 0.0F);
|
||||
|
||||
private ClimateStates() {
|
||||
}
|
||||
|
||||
public static IClimateState of(float temperature, float humidity, ClimateStateType type) {
|
||||
IClimateState state = INSTANCE.create(temperature, humidity, type);
|
||||
if (!state.isPresent()) {
|
||||
return INSTANCE.absent();
|
||||
}
|
||||
return state;
|
||||
return INSTANCE.create(temperature, humidity, type);
|
||||
}
|
||||
|
||||
public static IClimateState of(float temperature, float humidity) {
|
||||
IClimateState state = INSTANCE.create(temperature, humidity, ClimateStateType.MUTABLE);
|
||||
if (!state.isPresent()) {
|
||||
return INSTANCE.absent();
|
||||
}
|
||||
return state;
|
||||
return INSTANCE.create(temperature, humidity, ClimateStateType.DEFAULT);
|
||||
}
|
||||
|
||||
public static IClimateState immutableOf(float temperature, float humidity) {
|
||||
IClimateState state = INSTANCE.create(temperature, humidity, ClimateStateType.IMMUTABLE);
|
||||
if (!state.isPresent()) {
|
||||
return INSTANCE.absent();
|
||||
}
|
||||
return state;
|
||||
public static IClimateState extendedOf(float temperature, float humidity) {
|
||||
return INSTANCE.create(temperature, humidity, ClimateStateType.EXTENDED);
|
||||
}
|
||||
|
||||
public static IClimateState changeOf(float temperature, float humidity) {
|
||||
IClimateState state = INSTANCE.create(temperature, humidity, ClimateStateType.CHANGE);
|
||||
if (!state.isPresent()) {
|
||||
return INSTANCE.absent();
|
||||
}
|
||||
return state;
|
||||
public static IClimateState extendedZero() {
|
||||
return INSTANCE.create(ZERO, ClimateStateType.EXTENDED);
|
||||
}
|
||||
|
||||
public static boolean isNearTarget(IClimateState state, IClimateState target) {
|
||||
return target.getHumidity() - ClimateSourceModifier.CLIMATE_CHANGE < state.getHumidity()
|
||||
&& target.getHumidity() + ClimateSourceModifier.CLIMATE_CHANGE > state.getHumidity()
|
||||
&& target.getTemperature() - ClimateSourceModifier.CLIMATE_CHANGE < state.getTemperature()
|
||||
&& target.getTemperature() + ClimateSourceModifier.CLIMATE_CHANGE > state.getTemperature();
|
||||
}
|
||||
|
||||
public static boolean isZero(IClimateState state) {
|
||||
return state.getHumidity() == ZERO.getHumidity() && state.getTemperature() == ZERO.getTemperature();
|
||||
}
|
||||
|
||||
public static boolean isNearZero(IClimateState state) {
|
||||
return isNearTarget(state, ZERO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState create(IClimateState climateState, ClimateStateType type) {
|
||||
return new ClimateState(climateState, type);
|
||||
IClimateState state = new ClimateState(climateState, type);
|
||||
if (!state.isPresent()) {
|
||||
return absent();
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState create(float temperature, float humidity, ClimateStateType type) {
|
||||
return new ClimateState(temperature, humidity, type);
|
||||
IClimateState state = new ClimateState(temperature, humidity, type);
|
||||
if (!state.isPresent()) {
|
||||
return absent();
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -65,8 +65,8 @@ public class Config {
|
||||
|
||||
//Greenhouse
|
||||
public static int climateSourceRange = 36;
|
||||
public static float climateSourceEnergyModifier = 1.5F;
|
||||
public static int greenhouseSize = 4;
|
||||
public static boolean showClimateTable = true;
|
||||
|
||||
// Genetics
|
||||
public static boolean pollinateVanillaTrees = true;
|
||||
@@ -258,8 +258,8 @@ public class Config {
|
||||
enableMagicalCropsSupport = configCommon.getBooleanLocalized("tweaks.farms", "magicalcrops", enableMagicalCropsSupport);
|
||||
|
||||
climateSourceRange = configCommon.getIntLocalized("tweaks.greenhouse", "range", climateSourceRange, 9, 270);
|
||||
climateSourceEnergyModifier = configCommon.getFloatLocalized("tweaks.greenhouse", "energy", climateSourceEnergyModifier, 0.0F, 15.0F);
|
||||
greenhouseSize = configCommon.getIntLocalized("tweaks.greenhouse", "size", greenhouseSize, 1, 5);
|
||||
showClimateTable = configCommon.getBooleanLocalized("tweaks.greenhouse", "table", showClimateTable);
|
||||
|
||||
String[] availableStructures = new String[]{"alveary3x3", "farm3x3", "farm3x4", "farm3x5", "farm4x4", "farm5x5"};
|
||||
String[] disabledStructureArray = disabledStructures.toArray(new String[disabledStructures.size()]);
|
||||
|
||||
@@ -9,6 +9,8 @@ import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.climate.ClimateType;
|
||||
import forestry.api.climate.IClimateState;
|
||||
import forestry.api.core.INbtReadable;
|
||||
import forestry.api.core.INbtWritable;
|
||||
|
||||
/**
|
||||
* A climate source is stored in a {@link IClimateSourceOwner}. It is used by the {@link IClimateSourceContainer}s to change the climate of a {@link IClimateContainer}.
|
||||
@@ -16,7 +18,7 @@ import forestry.api.climate.IClimateState;
|
||||
* <p>
|
||||
* In forestry it is used in a part of a {@link IClimateModifier}.
|
||||
*/
|
||||
public interface IClimateSource {
|
||||
public interface IClimateSource extends INbtWritable, INbtReadable {
|
||||
|
||||
/**
|
||||
* The owner of this source.
|
||||
@@ -35,10 +37,10 @@ public interface IClimateSource {
|
||||
boolean affectClimateType(ClimateType type);
|
||||
|
||||
/**
|
||||
* @param state the {@link IClimateState} that the source has to work on.
|
||||
* @param target the by the {@link IClimateContainer} targeted {@link IClimateState}.
|
||||
* @param previousState the {@link IClimateState} that the source has to work on.
|
||||
* @param targetState the by the {@link IClimateSourceContainer} targeted {@link IClimateState}.
|
||||
*/
|
||||
IClimateState work(IClimateState state, IClimateState target);
|
||||
IClimateState work(IClimateState previousState, IClimateState targetState, IClimateState currentState, final double sizeModifier, final boolean canWork);
|
||||
|
||||
/**
|
||||
* @return true if source has changed the climate at the last work cicle.
|
||||
@@ -55,4 +57,9 @@ public interface IClimateSource {
|
||||
*/
|
||||
void onRemoved(IClimateContainer container);
|
||||
|
||||
/**
|
||||
* @return A copy of the current state of this source.
|
||||
*/
|
||||
IClimateState getState();
|
||||
|
||||
}
|
||||
@@ -39,10 +39,12 @@ public interface IClimateSourceContainer {
|
||||
*/
|
||||
IClimateState getBoundaryDown();
|
||||
|
||||
double getSizeModifier();
|
||||
|
||||
/**
|
||||
* Calculates the range of all {@link IClimateSource}s together.
|
||||
* Calculates the up and down boundary and the size modifier.
|
||||
*/
|
||||
void recalculateBoundaries(double sizeModifier);
|
||||
void recalculateBoundaries();
|
||||
|
||||
/**
|
||||
* @return True if the container allows the {@link IClimateSource}s to work.
|
||||
|
||||
@@ -31,6 +31,7 @@ import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.greenhouse.IClimateHousing;
|
||||
import forestry.core.climate.AbsentClimateState;
|
||||
import forestry.core.climate.ClimateStates;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.network.packets.PacketUpdateClimate;
|
||||
@@ -49,6 +50,7 @@ public class ClimateContainer implements IClimateContainer, IStreamable {
|
||||
protected IClimateState targetedState;
|
||||
protected IClimateState boundaryUp;
|
||||
protected IClimateState boundaryDown;
|
||||
protected double sizeModifier;
|
||||
private NBTTagCompound modifierData;
|
||||
|
||||
/**
|
||||
@@ -62,12 +64,13 @@ public class ClimateContainer implements IClimateContainer, IStreamable {
|
||||
this.parent = parent;
|
||||
this.sources = new HashSet<>();
|
||||
this.delay = 20;
|
||||
this.state = parent.getDefaultClimate().toState(ClimateStateType.MUTABLE);
|
||||
this.state = parent.getDefaultClimate().copy();
|
||||
this.modifierData = new NBTTagCompound();
|
||||
this.boundaryUp = ClimateStates.INSTANCE.min();
|
||||
this.boundaryDown = ClimateStates.INSTANCE.min();
|
||||
this.targetedState = AbsentClimateState.INSTANCE;
|
||||
this.canWork = canWork;
|
||||
this.sizeModifier = 1.0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,21 +81,26 @@ public class ClimateContainer implements IClimateContainer, IStreamable {
|
||||
@Override
|
||||
public void updateClimate(int ticks) {
|
||||
if (ticks % getTickDelay() == 0) {
|
||||
IClimateState oldState = state.toState(ClimateStateType.IMMUTABLE);
|
||||
state = parent.getDefaultClimate().toState(ClimateStateType.CHANGE);
|
||||
IClimateState oldState = state.copy(ClimateStateType.DEFAULT);
|
||||
state = parent.getDefaultClimate().copy(ClimateStateType.EXTENDED);
|
||||
for (IClimateModifier modifier : GreenhouseClimateManager.getInstance().getModifiers()) {
|
||||
state = modifier.modifyTarget(this, state, oldState, modifierData).toState(ClimateStateType.CHANGE);
|
||||
state = modifier.modifyTarget(this, state, oldState, modifierData).copy(ClimateStateType.EXTENDED);
|
||||
}
|
||||
state = state.toState(ClimateStateType.MUTABLE);
|
||||
if (!state.equals(oldState)) {
|
||||
BlockPos coordinates = parent.getCoordinates();
|
||||
NetworkUtil.sendNetworkPacket(new PacketUpdateClimate(coordinates, this), coordinates, parent.getWorldObj());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void recalculateBoundaries(double sizeModifier){
|
||||
public double getSizeModifier() {
|
||||
return sizeModifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recalculateBoundaries() {
|
||||
sizeModifier = Math.max(parent.getSize() / Config.climateSourceRange, 1.0D);
|
||||
float temperatureBoundaryUp = 0.0F;
|
||||
float humidityBoundaryUp = 0.0F;
|
||||
float temperatureBoundaryDown = 0.0F;
|
||||
|
||||
@@ -0,0 +1,257 @@
|
||||
/*******************************************************************************
|
||||
* 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.climate;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.climate.ClimateStateType;
|
||||
import forestry.api.climate.ClimateType;
|
||||
import forestry.api.climate.IClimateState;
|
||||
import forestry.core.climate.ClimateStates;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.greenhouse.api.climate.IClimateContainer;
|
||||
import forestry.greenhouse.api.climate.IClimateSource;
|
||||
import forestry.greenhouse.api.climate.IClimateSourceOwner;
|
||||
import forestry.greenhouse.api.greenhouse.GreenhouseManager;
|
||||
|
||||
public abstract class ClimateSource<O extends IClimateSourceOwner> implements IClimateSource {
|
||||
|
||||
protected final float range;
|
||||
protected final ClimateSourceType sourceType;
|
||||
protected O owner;
|
||||
private IClimateState state;
|
||||
protected float change;
|
||||
protected ClimateSourceMode temperatureMode;
|
||||
protected ClimateSourceMode humidityMode;
|
||||
protected IClimateContainer container;
|
||||
protected boolean addedToManager;
|
||||
protected boolean isActive;
|
||||
|
||||
public ClimateSource(float change, float range, ClimateSourceType sourceType) {
|
||||
this.change = change;
|
||||
this.range = range;
|
||||
this.sourceType = sourceType;
|
||||
this.temperatureMode = ClimateSourceMode.NONE;
|
||||
this.humidityMode = ClimateSourceMode.NONE;
|
||||
this.state = ClimateStates.INSTANCE.absent();
|
||||
}
|
||||
|
||||
public void setHumidityMode(ClimateSourceMode humidityMode) {
|
||||
this.humidityMode = humidityMode;
|
||||
}
|
||||
|
||||
public void setTemperatureMode(ClimateSourceMode temperatureMode) {
|
||||
this.temperatureMode = temperatureMode;
|
||||
}
|
||||
|
||||
public void setOwner(O owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getBoundaryModifier(ClimateType type, boolean boundaryUp) {
|
||||
if(type == ClimateType.HUMIDITY){
|
||||
if(humidityMode == ClimateSourceMode.POSITIVE && boundaryUp){
|
||||
return getRange(ClimateType.HUMIDITY);
|
||||
}else if(humidityMode == ClimateSourceMode.NEGATIVE && !boundaryUp){
|
||||
return getRange(ClimateType.HUMIDITY);
|
||||
}
|
||||
}else {
|
||||
if(temperatureMode == ClimateSourceMode.POSITIVE && boundaryUp){
|
||||
return getRange(ClimateType.TEMPERATURE);
|
||||
}else if(temperatureMode == ClimateSourceMode.NEGATIVE && !boundaryUp){
|
||||
return getRange(ClimateType.TEMPERATURE);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected float getRange(ClimateType type){
|
||||
return range;
|
||||
}
|
||||
|
||||
protected float getChange(ClimateType type) {
|
||||
return change;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return isActive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean affectClimateType(ClimateType type) {
|
||||
return sourceType.affectClimateType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateSourceOwner getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdded(IClimateContainer container) {
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemoved(IClimateContainer container) {
|
||||
this.container = null;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if(!addedToManager){
|
||||
onLoad();
|
||||
}
|
||||
}
|
||||
|
||||
public void onLoad() {
|
||||
World world = owner.getWorldObj();
|
||||
if(!addedToManager && !world.isRemote) {
|
||||
GreenhouseManager.climateManager.addSource(owner);
|
||||
addedToManager = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void invalidate() {
|
||||
this.onChunkUnload();
|
||||
}
|
||||
|
||||
public void onChunkUnload() {
|
||||
World world = owner.getWorldObj();
|
||||
if(addedToManager &&!world.isRemote) {
|
||||
GreenhouseManager.climateManager.removeSource(owner);
|
||||
addedToManager = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final IClimateState work(IClimateState previousState, IClimateState targetState, IClimateState currentState, final double sizeModifier, final boolean canWork) {
|
||||
IClimateState state = ClimateStates.INSTANCE.create(getState(), ClimateStateType.EXTENDED);
|
||||
IClimateState change = ClimateStates.extendedZero();
|
||||
IClimateState defaultState = container.getParent().getDefaultClimate();
|
||||
ClimateSourceType validType = getWorkType(currentState, targetState);
|
||||
ClimateSourceType oppositeType = getOppositeWorkType(currentState, defaultState);
|
||||
beforeWork();
|
||||
boolean work = canWork(state, oppositeType);
|
||||
//Test if the source can work and test if the owner has enough resources to work.
|
||||
if (!canWork || !work && oppositeType != null) {
|
||||
isActive = false;
|
||||
isNotValid();
|
||||
if (ClimateStates.isZero(state)) {
|
||||
return change;
|
||||
} else if (ClimateStates.isNearZero(state)) {
|
||||
setState(change);
|
||||
return change;
|
||||
} else if (ClimateStates.isNearTarget(currentState, targetState)) {
|
||||
return change;
|
||||
}
|
||||
//If the state is not already zero, remove one change state from the state.
|
||||
change = getChange(oppositeType, defaultState, currentState);
|
||||
change = ClimateStates.INSTANCE.create(-change.getTemperature(), -change.getHumidity(), ClimateStateType.EXTENDED);
|
||||
} else if (validType == null && oppositeType != null) {
|
||||
//Remove the resources if the owner has enough resources and the state is not the default state.
|
||||
removeResources(state, oppositeType);
|
||||
} else {
|
||||
change = getChange(validType, targetState, previousState);
|
||||
IClimateState changedState = state.add(change.scale(1 / sizeModifier));
|
||||
boolean couldWork = canWork(changedState, oppositeType);
|
||||
//Test if the owner could work with the changed state. If he can remove the resources for the changed state, if not only remove the resources for the old state.
|
||||
removeResources(couldWork ? changedState : state, oppositeType);
|
||||
if (!couldWork) {
|
||||
change = ClimateStates.extendedZero();
|
||||
}
|
||||
}
|
||||
state.add(change.scale(1 / sizeModifier));
|
||||
if (ClimateStates.isZero(state) || ClimateStates.isNearZero(state)) {
|
||||
state = ClimateStates.extendedZero();
|
||||
}
|
||||
if (false) {
|
||||
state = ClimateStates.extendedZero();
|
||||
}
|
||||
if (!state.isPresent()) {
|
||||
state = ClimateStates.extendedZero();
|
||||
Log.error("Failed to update a climate source. Please report this to the authors of the mod. Previous={}, Target={}, Current={}, Size={}", previousState, targetState, currentState, sizeModifier);
|
||||
}
|
||||
setState(state);
|
||||
return change;
|
||||
}
|
||||
|
||||
protected void isNotValid(){
|
||||
|
||||
}
|
||||
|
||||
protected void beforeWork(){
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the source can work, false if it can not.
|
||||
*/
|
||||
protected abstract boolean canWork(IClimateState currentState, ClimateSourceType oppositeType);
|
||||
|
||||
protected abstract void removeResources(IClimateState currentState, ClimateSourceType oppositeType);
|
||||
|
||||
protected abstract IClimateState getChange(@Nullable ClimateSourceType type, IClimateState target, IClimateState currentState);
|
||||
|
||||
@Nullable
|
||||
protected ClimateSourceType getOppositeWorkType(IClimateState state, IClimateState target) {
|
||||
boolean canChangeHumidity = sourceType.canChangeHumidity() && canChange(state.getHumidity(), target.getHumidity(), humidityMode.getOpposite());
|
||||
boolean canChangeTemperature = sourceType.canChangeTemperature() && canChange(state.getTemperature(), target.getTemperature(), temperatureMode.getOpposite());
|
||||
return canChangeHumidity ? canChangeTemperature ? ClimateSourceType.BOTH : ClimateSourceType.HUMIDITY : canChangeTemperature ? ClimateSourceType.TEMPERATURE : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected ClimateSourceType getWorkType(IClimateState state, IClimateState target) {
|
||||
boolean canChangeHumidity = sourceType.canChangeHumidity() && canChange(state.getHumidity(), target.getHumidity(), humidityMode);
|
||||
boolean canChangeTemperature = sourceType.canChangeTemperature() && canChange(state.getTemperature(), target.getTemperature(), temperatureMode);
|
||||
return canChangeHumidity ? canChangeTemperature ? ClimateSourceType.BOTH : ClimateSourceType.HUMIDITY : canChangeTemperature ? ClimateSourceType.TEMPERATURE : null;
|
||||
}
|
||||
|
||||
private boolean canChange(float value, float target, ClimateSourceMode mode){
|
||||
if(mode == ClimateSourceMode.POSITIVE && value < target){
|
||||
return true;
|
||||
}else if(mode == ClimateSourceMode.NEGATIVE && value > target){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClimateState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
protected void setState(IClimateState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
NBTTagCompound sourceData = new NBTTagCompound();
|
||||
state.writeToNBT(sourceData);
|
||||
nbt.setTag("Source", sourceData);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
NBTTagCompound sourceData = nbt.getCompoundTag("Source");
|
||||
if (sourceData.hasNoTags()) {
|
||||
return;
|
||||
}
|
||||
state = ClimateStates.INSTANCE.create(sourceData, ClimateStateType.EXTENDED);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,8 +11,6 @@
|
||||
package forestry.greenhouse.climate;
|
||||
|
||||
import forestry.api.climate.ClimateType;
|
||||
import forestry.core.climate.ClimateSource;
|
||||
import forestry.core.climate.ClimateSourceType;
|
||||
import forestry.greenhouse.api.climate.IClimateSourceCircuitable;
|
||||
import forestry.greenhouse.api.climate.IClimateSourceOwner;
|
||||
|
||||
|
||||
@@ -14,9 +14,8 @@ import forestry.api.climate.ClimateType;
|
||||
import forestry.api.climate.IClimateState;
|
||||
import forestry.api.core.IErrorLogic;
|
||||
import forestry.api.greenhouse.IClimateHousing;
|
||||
import forestry.core.climate.ClimateSourceMode;
|
||||
import forestry.core.climate.ClimateSourceType;
|
||||
import forestry.core.climate.ClimateStates;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.errors.EnumErrorCode;
|
||||
import forestry.energy.EnergyManager;
|
||||
import forestry.greenhouse.api.climate.IClimateContainer;
|
||||
@@ -25,7 +24,7 @@ import forestry.greenhouse.tiles.TileClimatiser;
|
||||
|
||||
public class ClimateSourceClimatiser<O extends TileClimatiser> extends ClimateSourceCircuitable<O> {
|
||||
|
||||
protected static final int ENERGY_PER_OPERATION = 150;
|
||||
protected static final int ENERGY_PER_OPERATION = 75;
|
||||
|
||||
public ClimateSourceClimatiser(ClimateSourceType type, float change, float range) {
|
||||
super(change, range, type);
|
||||
@@ -48,14 +47,14 @@ public class ClimateSourceClimatiser<O extends TileClimatiser> extends ClimateSo
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWork(IClimateState state, IClimateState target) {
|
||||
public boolean canWork(IClimateState currentState, ClimateSourceType oppositeType) {
|
||||
IClimateHousing region = container.getParent();
|
||||
if (region instanceof IGreenhouseControllerInternal) {
|
||||
IGreenhouseControllerInternal controller = (IGreenhouseControllerInternal) region;
|
||||
IErrorLogic errorLogic = owner.getErrorLogic();
|
||||
EnergyManager energyManager = controller.getEnergyManager();
|
||||
|
||||
if (energyManager.extractEnergy(ENERGY_PER_OPERATION, true) > 0) {
|
||||
if (energyManager.extractEnergy((int) (ENERGY_PER_OPERATION * getEnergyModifier(currentState, oppositeType)), true) > 0) {
|
||||
owner.setActive(true);
|
||||
errorLogic.setCondition(false, EnumErrorCode.NO_POWER);
|
||||
return true;
|
||||
@@ -72,19 +71,24 @@ public class ClimateSourceClimatiser<O extends TileClimatiser> extends ClimateSo
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeResources(IClimateState state, IClimateState target) {
|
||||
protected void removeResources(IClimateState currentState, ClimateSourceType oppositeType) {
|
||||
IClimateHousing region = container.getParent();
|
||||
if (region instanceof IGreenhouseControllerInternal) {
|
||||
IGreenhouseControllerInternal controller = (IGreenhouseControllerInternal) region;
|
||||
|
||||
EnergyManager energyManager = controller.getEnergyManager();
|
||||
|
||||
energyManager.extractEnergy(ENERGY_PER_OPERATION, false);
|
||||
energyManager.extractEnergy((int) (ENERGY_PER_OPERATION * getEnergyModifier(currentState, oppositeType)), false);
|
||||
}
|
||||
}
|
||||
|
||||
protected float getEnergyModifier(IClimateState currentState, ClimateSourceType oppositeType) {
|
||||
float change = oppositeType.canChangeTemperature() ? currentState.getTemperature() : oppositeType.canChangeHumidity() ? currentState.getHumidity() : 0.0F;
|
||||
return 1.0F + change * Config.climateSourceEnergyModifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IClimateState getChange(ClimateSourceType type, IClimateState state, IClimateState target) {
|
||||
protected IClimateState getChange(ClimateSourceType type, IClimateState target, IClimateState currentState) {
|
||||
float temperature = 0.0F;
|
||||
float humidity = 0.0F;
|
||||
if (type.canChangeHumidity()) {
|
||||
@@ -93,7 +97,7 @@ public class ClimateSourceClimatiser<O extends TileClimatiser> extends ClimateSo
|
||||
if (type.canChangeTemperature()) {
|
||||
temperature += getChange(ClimateType.TEMPERATURE);
|
||||
}
|
||||
return ClimateStates.changeOf(temperature, humidity);
|
||||
return ClimateStates.extendedOf(temperature, humidity);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,8 +15,6 @@ import net.minecraftforge.fluids.FluidStack;
|
||||
import forestry.api.climate.ClimateType;
|
||||
import forestry.api.climate.IClimateState;
|
||||
import forestry.api.core.IErrorLogic;
|
||||
import forestry.core.climate.ClimateSourceMode;
|
||||
import forestry.core.climate.ClimateSourceType;
|
||||
import forestry.core.climate.ClimateStates;
|
||||
import forestry.core.errors.EnumErrorCode;
|
||||
import forestry.core.fluids.FilteredTank;
|
||||
@@ -59,7 +57,7 @@ public class ClimateSourceHygroregulator extends ClimateSourceCircuitable<TileHy
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWork(IClimateState state, IClimateState target) {
|
||||
public boolean canWork(IClimateState currentState, ClimateSourceType oppositeType) {
|
||||
createRecipe();
|
||||
FilteredTank liquidTank = owner.getLiquidTank();
|
||||
IErrorLogic errorLogic = owner.getErrorLogic();
|
||||
@@ -72,13 +70,13 @@ public class ClimateSourceHygroregulator extends ClimateSourceCircuitable<TileHy
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeResources(IClimateState state, IClimateState target) {
|
||||
protected void removeResources(IClimateState currentState, ClimateSourceType oppositeType) {
|
||||
FilteredTank liquidTank = owner.getLiquidTank();
|
||||
liquidTank.drainInternal(currentRecipe.liquid.amount, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IClimateState getChange(ClimateSourceType type, IClimateState state, IClimateState target) {
|
||||
protected IClimateState getChange(ClimateSourceType type, IClimateState target, IClimateState currentState) {
|
||||
float temperature = 0.0F;
|
||||
float humidity = 0.0F;
|
||||
if (type.canChangeHumidity()) {
|
||||
@@ -87,7 +85,7 @@ public class ClimateSourceHygroregulator extends ClimateSourceCircuitable<TileHy
|
||||
if (type.canChangeTemperature()) {
|
||||
temperature += currentRecipe.tempChange * getChangeMultiplier(ClimateType.TEMPERATURE);
|
||||
}
|
||||
return ClimateStates.changeOf(temperature, humidity);
|
||||
return ClimateStates.extendedOf(temperature, humidity);
|
||||
}
|
||||
|
||||
private void createRecipe() {
|
||||
|
||||
+11
-2
@@ -8,10 +8,19 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.climate;
|
||||
package forestry.greenhouse.climate;
|
||||
|
||||
public enum ClimateSourceMode {
|
||||
POSITIVE(1), NEGATIVE(0), NONE(2);
|
||||
|
||||
POSITIVE, NEGATIVE, NONE
|
||||
private int opposite;
|
||||
|
||||
ClimateSourceMode(int opposite) {
|
||||
this.opposite = opposite;
|
||||
}
|
||||
|
||||
public ClimateSourceMode getOpposite() {
|
||||
return values()[opposite];
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -8,11 +8,11 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.climate;
|
||||
package forestry.greenhouse.climate;
|
||||
|
||||
import forestry.api.climate.ClimateType;
|
||||
import forestry.greenhouse.api.climate.IClimateSource;
|
||||
import forestry.api.climate.IClimateState;
|
||||
import forestry.greenhouse.api.climate.IClimateSource;
|
||||
|
||||
/**
|
||||
* The possible types of the {@link IClimateSource}. Which values the {@link IClimateSource} changes in a {@link IClimateState}.
|
||||
@@ -12,9 +12,6 @@ package forestry.greenhouse.climate;
|
||||
|
||||
import forestry.api.climate.IClimateState;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.core.climate.ClimateSource;
|
||||
import forestry.core.climate.ClimateSourceMode;
|
||||
import forestry.core.climate.ClimateSourceType;
|
||||
import forestry.core.climate.ClimateStates;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseWindow;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseWindow.WindowMode;
|
||||
@@ -46,16 +43,16 @@ public class ClimateSourceWindow extends ClimateSource<TileGreenhouseWindow> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWork(IClimateState state, IClimateState target) {
|
||||
public boolean canWork(IClimateState currentState, ClimateSourceType oppositeType) {
|
||||
return owner.getMode() == WindowMode.OPEN;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removeResources(IClimateState state, IClimateState target) {
|
||||
protected void removeResources(IClimateState currentState, ClimateSourceType oppositeType) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IClimateState getChange(ClimateSourceType type, IClimateState state, IClimateState target) {
|
||||
protected IClimateState getChange(ClimateSourceType type, IClimateState target, IClimateState currentState) {
|
||||
float temperature = 0.0F;
|
||||
float humidity = 0.0F;
|
||||
if (type.canChangeHumidity()) {
|
||||
@@ -72,7 +69,7 @@ public class ClimateSourceWindow extends ClimateSource<TileGreenhouseWindow> {
|
||||
temperature += change;
|
||||
}
|
||||
}
|
||||
return ClimateStates.changeOf(temperature, humidity);
|
||||
return ClimateStates.extendedOf(temperature, humidity);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,9 +22,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import forestry.api.climate.ClimateStateType;
|
||||
import forestry.api.climate.ClimateType;
|
||||
import forestry.api.climate.IClimateState;
|
||||
import forestry.api.greenhouse.IClimateHousing;
|
||||
import forestry.core.climate.ClimateStates;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.utils.StringUtil;
|
||||
import forestry.core.utils.Translator;
|
||||
import forestry.greenhouse.PluginGreenhouse;
|
||||
@@ -36,7 +34,7 @@ public class ClimateSourceModifier implements IClimateModifier {
|
||||
public static final float CLIMATE_CHANGE = 0.01F;
|
||||
|
||||
@Override
|
||||
public IClimateState modifyTarget(IClimateContainer container, IClimateState newState, IClimateState oldState, NBTTagCompound data) {
|
||||
public IClimateState modifyTarget(IClimateContainer container, IClimateState newState, IClimateState previousState, NBTTagCompound data) {
|
||||
Collection<IClimateSource> sources = container.getClimateSources();
|
||||
if (sources.isEmpty()) {
|
||||
data.removeTag("rangeUp");
|
||||
@@ -44,82 +42,41 @@ public class ClimateSourceModifier implements IClimateModifier {
|
||||
data.removeTag("change");
|
||||
return newState;
|
||||
}
|
||||
IClimateHousing housing = container.getParent();
|
||||
double sizeModifier = housing.getSize() / Config.climateSourceRange;
|
||||
sizeModifier = Math.max(sizeModifier, 1.0D);
|
||||
container.recalculateBoundaries();
|
||||
|
||||
IClimateState changeState = ClimateStates.INSTANCE.create(data.getCompoundTag("change"), ClimateStateType.CHANGE);
|
||||
if (!container.canWork()) {
|
||||
IClimateState defaultState = container.getParent().getDefaultClimate();
|
||||
float defaultTemperature = defaultState.getTemperature();
|
||||
float defaultHumidity = defaultState.getHumidity();
|
||||
float temperature = changeState.getTemperature();
|
||||
float humidity = changeState.getHumidity();
|
||||
if (temperature != defaultTemperature) {
|
||||
if (temperature > defaultTemperature) {
|
||||
changeState = changeState.addTemperature((float) -Math.min(CLIMATE_CHANGE / sizeModifier, temperature - defaultTemperature));
|
||||
} else {
|
||||
changeState = changeState.addTemperature((float) Math.min(CLIMATE_CHANGE / sizeModifier, defaultTemperature - temperature));
|
||||
}
|
||||
}
|
||||
if (humidity != defaultHumidity) {
|
||||
if (humidity > defaultHumidity) {
|
||||
changeState = changeState.addHumidity((float) -Math.min(CLIMATE_CHANGE / sizeModifier, humidity - defaultHumidity));
|
||||
} else {
|
||||
changeState = changeState.addHumidity((float) Math.min(CLIMATE_CHANGE / sizeModifier, defaultHumidity - humidity));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
container.recalculateBoundaries(sizeModifier);
|
||||
IClimateState boundaryUp = container.getBoundaryUp();
|
||||
IClimateState boundaryDown = container.getBoundaryDown();
|
||||
|
||||
IClimateState boundaryUp = container.getBoundaryUp();
|
||||
IClimateState boundaryDown = container.getBoundaryDown();
|
||||
//Send the boundaries to the client
|
||||
data.setTag("rangeUp", boundaryUp.writeToNBT(new NBTTagCompound()));
|
||||
data.setTag("rangeDown", boundaryDown.writeToNBT(new NBTTagCompound()));
|
||||
|
||||
data.setTag("rangeUp", boundaryUp.writeToNBT(new NBTTagCompound()));
|
||||
data.setTag("rangeDown", boundaryDown.writeToNBT(new NBTTagCompound()));
|
||||
IClimateState targetedState = container.getTargetedState();
|
||||
if (!targetedState.isPresent()) {
|
||||
return newState;
|
||||
}
|
||||
IClimateState target = getTargetOrBound(previousState, container.getBoundaryDown(), container.getBoundaryUp(), targetedState);
|
||||
IClimateState changeState = ClimateStates.extendedZero();
|
||||
|
||||
IClimateState targetedState = container.getTargetedState();
|
||||
if (!targetedState.isPresent()) {
|
||||
return newState;
|
||||
}
|
||||
int workedSources = 0;
|
||||
IClimateState target = getTargetOrBound(oldState, container.getBoundaryDown(), container.getBoundaryUp(), targetedState);
|
||||
for (IClimateSource source : container.getClimateSources()) {
|
||||
newState = newState.add(source.getState());
|
||||
}
|
||||
|
||||
for (IClimateSource source : container.getClimateSources()) {
|
||||
IClimateState state = source.work(oldState, target);
|
||||
if (state.isPresent()) {
|
||||
boolean hasChange = false;
|
||||
double temperatureChange = state.getTemperature();
|
||||
double humidityChange = state.getHumidity();
|
||||
if (temperatureChange != 0) {
|
||||
temperatureChange /= sizeModifier;
|
||||
hasChange = true;
|
||||
}
|
||||
if (humidityChange != 0) {
|
||||
humidityChange /= sizeModifier;
|
||||
hasChange = true;
|
||||
}
|
||||
if (hasChange) {
|
||||
changeState = changeState.addTemperature((float) temperatureChange);
|
||||
changeState = changeState.addHumidity((float) humidityChange);
|
||||
workedSources++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (workedSources == 0) {
|
||||
return newState.add(changeState);
|
||||
}
|
||||
for (IClimateSource source : container.getClimateSources()) {
|
||||
IClimateState state = source.work(previousState, target, newState, container.getSizeModifier(), container.canWork());
|
||||
changeState = changeState.add(source.getState());
|
||||
newState = newState.add(state);
|
||||
}
|
||||
data.setTag("change", changeState.writeToNBT(new NBTTagCompound()));
|
||||
return newState.add(changeState);
|
||||
return newState;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(IClimateContainer container, NBTTagCompound nbtData, ClimateType type, List<String> lines) {
|
||||
IClimateState rangeDown = ClimateStates.INSTANCE.create(nbtData.getCompoundTag("rangeDown"), ClimateStateType.MUTABLE);
|
||||
IClimateState rangeUp = ClimateStates.INSTANCE.create(nbtData.getCompoundTag("rangeUp"), ClimateStateType.MUTABLE);
|
||||
IClimateState change = ClimateStates.INSTANCE.create(nbtData.getCompoundTag("change"), ClimateStateType.MUTABLE);
|
||||
IClimateState rangeDown = ClimateStates.INSTANCE.create(nbtData.getCompoundTag("rangeDown"), ClimateStateType.DEFAULT);
|
||||
IClimateState rangeUp = ClimateStates.INSTANCE.create(nbtData.getCompoundTag("rangeUp"), ClimateStateType.DEFAULT);
|
||||
IClimateState change = ClimateStates.INSTANCE.create(nbtData.getCompoundTag("change"), ClimateStateType.EXTENDED);
|
||||
if (type == ClimateType.HUMIDITY) {
|
||||
lines.add(Translator.translateToLocalFormatted("for.gui.modifier.sources.range.up", StringUtil.floatAsPercent(rangeUp.getHumidity())));
|
||||
lines.add(Translator.translateToLocalFormatted("for.gui.modifier.sources.range.down", StringUtil.floatAsPercent(rangeDown.getHumidity())));
|
||||
@@ -146,6 +103,9 @@ public class ClimateSourceModifier implements IClimateModifier {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The target if it is within the bounds and the bounds if it is above or below the bounds.
|
||||
*/
|
||||
private IClimateState getTargetOrBound(IClimateState climateState, IClimateState boundaryDown, IClimateState boundaryUp, IClimateState targetedState) {
|
||||
float temperature = climateState.getTemperature();
|
||||
float humidity = climateState.getHumidity();
|
||||
@@ -161,7 +121,7 @@ public class ClimateSourceModifier implements IClimateModifier {
|
||||
} else if (targetHumidity < humidity) {
|
||||
humidity = Math.max(targetHumidity, boundaryDown.getHumidity());
|
||||
}
|
||||
return ClimateStates.immutableOf(temperature, humidity);
|
||||
return ClimateStates.of(temperature, humidity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -72,7 +72,7 @@ public class GuiGreenhouse extends GuiForestryTitled<ContainerGreenhouse> {
|
||||
public void setClimate(IClimateContainer container, float temp, float hum) {
|
||||
temperaturePanel.setValue(temp);
|
||||
humidityPanel.setValue(hum);
|
||||
container.setTargetedState(ClimateStates.immutableOf(temp, hum));
|
||||
container.setTargetedState(ClimateStates.of(temp, hum));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -105,7 +105,7 @@ public class WidgetClimateBar extends Widget {
|
||||
String spriteName;
|
||||
|
||||
EnumClimate(String spriteName, Biome biome) {
|
||||
climateState = ClimateStates.immutableOf(biome.getTemperature(), biome.getRainfall());
|
||||
climateState = ClimateStates.of(biome.getTemperature(), biome.getRainfall());
|
||||
this.spriteName = spriteName;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
@@ -39,6 +40,7 @@ import forestry.core.items.IColoredItem;
|
||||
import forestry.core.items.ItemForestry;
|
||||
import forestry.core.multiblock.MultiblockUtil;
|
||||
import forestry.core.utils.ClimateUtil;
|
||||
import forestry.core.utils.StringUtil;
|
||||
import forestry.core.utils.Translator;
|
||||
import forestry.greenhouse.PluginGreenhouse;
|
||||
import forestry.greenhouse.api.climate.IClimateContainer;
|
||||
@@ -85,7 +87,7 @@ public class ItemGreenhouseScreen extends ItemForestry implements IColoredItem {
|
||||
public static boolean isValid(ItemStack stack, World world) {
|
||||
BlockPos pos = getGreenhousePos(stack);
|
||||
boolean isValid = true;
|
||||
if (pos == null || !world.isBlockLoaded(pos)) {
|
||||
if (pos == null || world == null || !world.isBlockLoaded(pos)) {
|
||||
isValid = false;
|
||||
} else {
|
||||
IGreenhouseControllerInternal controller = MultiblockUtil.getController(world, pos, IGreenhouseComponent.class);
|
||||
@@ -165,7 +167,19 @@ public class ItemGreenhouseScreen extends ItemForestry implements IColoredItem {
|
||||
public void addInformation(ItemStack stack, @Nullable World world, List<String> tooltip, ITooltipFlag flag) {
|
||||
super.addInformation(stack, world, tooltip, flag);
|
||||
boolean previewModeActive = isPreviewModeActive(stack);
|
||||
tooltip.add(Translator.translateToLocal(Translator.translateToLocal("for.greenhouse_screen.mode.name") + ": " + (previewModeActive ? "Active" : "Inactive")));
|
||||
String previewMode = Translator.translateToLocal(previewModeActive ? "for.greenhouse_screen.mode.active" : "for.greenhouse_screen.mode.inactive");
|
||||
tooltip.add(Translator.translateToLocal(Translator.translateToLocalFormatted("for.greenhouse_screen.mode", previewMode)));
|
||||
boolean isValid = isValid(stack, world);
|
||||
BlockPos pos = getGreenhousePos(stack);
|
||||
String state = isValid ? Translator.translateToLocalFormatted("for.greenhouse_screen.state.linked", pos.getX(), pos.getY(), pos.getZ()) : Translator.translateToLocal("for.greenhouse_screen.state.fail");
|
||||
tooltip.add(Translator.translateToLocalFormatted("for.greenhouse_screen.state", state));
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
IGreenhouseControllerInternal controller = MultiblockUtil.getController(world, pos, IGreenhouseComponent.class);
|
||||
IClimateState climateState = controller.getClimateContainer().getState();
|
||||
tooltip.add(Translator.translateToLocalFormatted("for.greenhouse_screen.temperature", TextFormatting.GOLD + StringUtil.floatAsPercent(climateState.getTemperature())));
|
||||
tooltip.add(Translator.translateToLocalFormatted("for.greenhouse_screen.humidity", TextFormatting.BLUE + StringUtil.floatAsPercent(climateState.getHumidity())));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,7 +26,6 @@ import net.minecraft.world.biome.Biome;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.climate.ClimateStateType;
|
||||
import forestry.api.climate.IClimateState;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
@@ -392,7 +391,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
limits = createLimits();
|
||||
if (!climateContainer.getTargetedState().isPresent()) {
|
||||
IClimateState defaultClimate = getDefaultClimate();
|
||||
climateContainer.setState(defaultClimate.toState(ClimateStateType.MUTABLE));
|
||||
climateContainer.setState(defaultClimate.copy());
|
||||
climateContainer.setTargetedState(defaultClimate);
|
||||
}
|
||||
|
||||
@@ -460,7 +459,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
biomes++;
|
||||
}
|
||||
}
|
||||
defaultState = ClimateStates.immutableOf((float) (temperature / biomes), (float) (humidity / biomes));
|
||||
defaultState = ClimateStates.of((float) (temperature / biomes), (float) (humidity / biomes));
|
||||
}
|
||||
|
||||
/* RectangularMultiblockControllerBase */
|
||||
|
||||
@@ -30,8 +30,6 @@ import forestry.api.core.ICamouflageHandler;
|
||||
import forestry.api.core.ICamouflagedTile;
|
||||
import forestry.apiculture.network.packets.PacketActiveUpdate;
|
||||
import forestry.core.circuits.ISocketable;
|
||||
import forestry.core.climate.ClimateSource;
|
||||
import forestry.core.climate.ClimateSourceType;
|
||||
import forestry.core.inventory.InventoryAdapter;
|
||||
import forestry.core.network.IStreamableGui;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
@@ -43,7 +41,9 @@ import forestry.greenhouse.api.climate.IClimateSource;
|
||||
import forestry.greenhouse.api.climate.IClimateSourceOwner;
|
||||
import forestry.greenhouse.blocks.BlockClimatiser;
|
||||
import forestry.greenhouse.camouflage.CamouflageHandlerType;
|
||||
import forestry.greenhouse.climate.ClimateSource;
|
||||
import forestry.greenhouse.climate.ClimateSourceClimatiser;
|
||||
import forestry.greenhouse.climate.ClimateSourceType;
|
||||
import forestry.greenhouse.gui.ContainerClimatiser;
|
||||
import forestry.greenhouse.gui.GuiClimatiser;
|
||||
import forestry.greenhouse.multiblock.GreenhouseController;
|
||||
@@ -164,6 +164,8 @@ public class TileClimatiser extends TileForestry implements IActivatable, IStrea
|
||||
chipset.onLoad(this);
|
||||
}
|
||||
}
|
||||
|
||||
source.readFromNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -177,6 +179,8 @@ public class TileClimatiser extends TileForestry implements IActivatable, IStrea
|
||||
data.setBoolean("Active", active);
|
||||
|
||||
sockets.writeToNBT(data);
|
||||
|
||||
source.writeToNBT(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@@ -116,6 +116,7 @@ public class TileGreenhouseWindow extends TileEntity implements IActivatable, IC
|
||||
if (data.hasKey("Glass")) {
|
||||
glass = data.getString("Glass");
|
||||
}
|
||||
source.readFromNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -126,19 +127,13 @@ public class TileGreenhouseWindow extends TileEntity implements IActivatable, IC
|
||||
if (glass != null) {
|
||||
data.setString("Glass", glass);
|
||||
}
|
||||
source.writeToNBT(data);
|
||||
return super.writeToNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getUpdateTag() {
|
||||
NBTTagCompound data = super.getUpdateTag();
|
||||
if (mode != null) {
|
||||
data.setShort("mode", (short) mode.ordinal());
|
||||
}
|
||||
if (glass != null) {
|
||||
data.setString("Glass", glass);
|
||||
}
|
||||
return data;
|
||||
return writeToNBT(new NBTTagCompound());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user