Skip to content
Permalink
Browse files

Fix Targeted state

  • Loading branch information
Nedelosk committed Aug 29, 2017
1 parent d8c8aec commit 66f0da433ef99649bc6d27190de5de7a4e323c64
@@ -62,7 +62,6 @@ public ClimateContainer(IClimateHousing parent) {
this.listeners = new ClimateContainerListeners();
this.sources = new HashSet<>();
this.delay = 20;
this.targetedState = parent.getDefaultClimate();
this.state = parent.getDefaultClimate().toMutable();
this.modifierData = new NBTTagCompound();
this.boundaryUp = ImmutableClimateState.MIN;
@@ -165,15 +164,19 @@ public IClimateState getBoundaryUp() {
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
state.writeToNBT(nbt);
nbt.setTag("Target", targetedState.writeToNBT(new NBTTagCompound()));
if(targetedState != null) {
nbt.setTag("Target", targetedState.writeToNBT(new NBTTagCompound()));
}
nbt.setTag("modifierData", modifierData);
return nbt;
}

@Override
public void readFromNBT(NBTTagCompound nbt) {
state.readFromNBT(nbt);
targetedState = new ImmutableClimateState(nbt.getCompoundTag("Target"));
if(nbt.hasKey("Target")) {
targetedState = new ImmutableClimateState(nbt.getCompoundTag("Target"));
}
modifierData = nbt.getCompoundTag("modifierData");
}

@@ -183,6 +186,7 @@ public void setTargetedState(ImmutableClimateState state) {
}

@Override
@Nullable
public ImmutableClimateState getTargetedState() {
return targetedState;
}
@@ -234,8 +238,13 @@ public void writeData(PacketBufferForestry data) {
data.writeFloat(boundaryUp.getHumidity());
data.writeFloat(boundaryDown.getTemperature());
data.writeFloat(boundaryDown.getHumidity());
data.writeFloat(targetedState.getTemperature());
data.writeFloat(targetedState.getHumidity());
if(targetedState != null) {
data.writeBoolean(true);
data.writeFloat(targetedState.getTemperature());
data.writeFloat(targetedState.getHumidity());
}else{
data.writeBoolean(false);
}
data.writeCompoundTag(modifierData);
}

@@ -245,7 +254,11 @@ public void readData(PacketBufferForestry data) throws IOException {
state.setHumidity(data.readFloat());
boundaryUp = new ImmutableClimateState(data.readFloat(), data.readFloat());
boundaryDown = new ImmutableClimateState(data.readFloat(), data.readFloat());
targetedState = new ImmutableClimateState(data.readFloat(), data.readFloat());
if(data.readBoolean()) {
targetedState = new ImmutableClimateState(data.readFloat(), data.readFloat());
}else{
targetedState = null;
}
modifierData = data.readCompoundTag();
}

@@ -276,7 +289,7 @@ public boolean equals(Object obj) {
}
IClimateContainer container = (IClimateContainer) obj;
IClimateHousing parent = container.getParent();
if(parent == null || this.parent == null){
if(parent.getCoordinates() == null || this.parent.getCoordinates() == null){
return false;
}
return this.parent.getCoordinates().equals(parent.getCoordinates());
@@ -86,8 +86,8 @@

// Greenhouse
NOT_LOADED("not_loaded"), // One chunk of the greenhouse is not loaded.
NOT_CLOSED("not_closed"), // The greenhouse is not closed.
TOO_LARGE("too_large") // The greenhouse is too large.
NOT_CLOSED("not_closed"), // The roof of the greenhouse is not closed.
TOO_LARGE("too_large") //The greenhouse is too large for its controller or it is not closed at a position.
;

private final String name;
@@ -90,7 +90,7 @@ public void onWorldRenderLast(RenderWorldLastEvent event){
GlStateManager.popMatrix();
}
}catch(Exception e){
Log.error("Failed to render the position of a multiblock exeption.", e);
Log.error("Failed to render the position of a multiblock exception.", e);
}
}
}
@@ -96,15 +96,15 @@ public void onWorldRenderLast(RenderWorldLastEvent event) {
GlStateManager.glLineWidth(2.5F);
IGreenhouseLimits limits = provider.getUsedLimits();
if (limits != null) {
BlockPos offset = provider.getCenterPos();
Position2D minEdge = limits.getMinimumCoordinates();
Position2D maxEdge = limits.getMaximumCoordinates();
AxisAlignedBB greenhouseBB = new AxisAlignedBB(minEdge.getX(), limits.getDepth(), minEdge.getZ(), maxEdge.getX() + 1, limits.getHeight() + 1, maxEdge.getZ() + 1);
AxisAlignedBB testBlockBB = Block.FULL_BLOCK_AABB;
testBlockBB = testBlockBB.offset(offset);
RenderGlobal.drawSelectionBoundingBox(testBlockBB, 0.0F, 0.0F, 0.0F, 0.5F);
RenderGlobal.drawSelectionBoundingBox(greenhouseBB, 0.0F, 0.0F, 0.0F, 0.5F);
}
//Draw center position
BlockPos offset = provider.getCenterPos();
AxisAlignedBB testBlockBB = Block.FULL_BLOCK_AABB.offset(offset);
RenderGlobal.drawSelectionBoundingBox(testBlockBB, 0.0F, 0.0F, 0.0F, 0.5F);
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
GlStateManager.popMatrix();
@@ -54,8 +54,9 @@
Collection<IClimateContainerListener> getListeners();

/**
* @return the state that the container targets to get his climate state to.
* @return only null if the controller never was assembled.
*/
@Nullable
ImmutableClimateState getTargetedState();

void setTargetedState(ImmutableClimateState state);
@@ -54,8 +54,12 @@ public IClimateState modifyTarget(IClimateContainer container, IClimateState new
data.setTag("rangeUp", boundaryUp.writeToNBT(new NBTTagCompound()));
data.setTag("rangeDown", boundaryDown.writeToNBT(new NBTTagCompound()));

ImmutableClimateState targetedState = container.getTargetedState();
if(targetedState == null){
return newState;
}
int workedSources = 0;
ImmutableClimateState target = getTargetOrBound(oldState, container.getBoundaryDown(), container.getBoundaryUp(), container.getTargetedState());
ImmutableClimateState target = getTargetOrBound(oldState, container.getBoundaryDown(), container.getBoundaryUp(), targetedState);
ClimateChange changeState = new ClimateChange(data.getCompoundTag("change"));

for (IClimateSource source : container.getClimateSources()) {
@@ -16,16 +16,16 @@
import net.minecraft.util.math.BlockPos;

import forestry.api.climate.ClimateType;
import forestry.greenhouse.api.climate.IClimateContainer;
import forestry.greenhouse.api.climate.IClimateData;
import forestry.api.climate.ImmutableClimateState;
import forestry.core.config.Constants;
import forestry.core.gui.GuiForestryTitled;
import forestry.core.gui.TextLayoutHelper;
import forestry.core.utils.NetworkUtil;
import forestry.greenhouse.api.climate.IClimateContainer;
import forestry.greenhouse.api.climate.IClimateData;
import forestry.greenhouse.gui.widgets.WidgetCamouflageTab;
import forestry.greenhouse.gui.widgets.WidgetClimatePanel;
import forestry.greenhouse.gui.widgets.WidgetClimateBar;
import forestry.greenhouse.gui.widgets.WidgetClimatePanel;
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
import forestry.greenhouse.network.packets.PacketSelectClimateTargeted;
import forestry.greenhouse.tiles.TileGreenhouse;
@@ -53,17 +53,21 @@ public GuiGreenhouse(EntityPlayer player, TileGreenhouse tile) {

//Add the camouflage tab
widgetManager.add(new WidgetCamouflageTab(widgetManager, xSize / 4 - WidgetCamouflageTab.WIDTH / 2, -WidgetCamouflageTab.HEIGHT, controller, tile));
widgetManager.add(new WidgetClimateBar(widgetManager, xSize / 3 + WidgetClimateBar.WIDTH / 3, -WidgetClimateBar.HEIGHT));
if(container.getTargetedState() != null) {
widgetManager.add(new WidgetClimateBar(widgetManager, xSize / 3 + WidgetClimateBar.WIDTH / 3, -WidgetClimateBar.HEIGHT));
}
widgetManager.add(temperaturePanel = new WidgetClimatePanel(widgetManager, this, 9, 18, ClimateType.TEMPERATURE, data));
widgetManager.add(humidityPanel = new WidgetClimatePanel(widgetManager, this, 102, 18, ClimateType.HUMIDITY, data));
}

public void sendNetworkUpdate() {
BlockPos pos = controller.getCoordinates();
float temp = temperaturePanel.parseValue();
float hum = humidityPanel.parseValue();
setClimate(container, temp, hum);
NetworkUtil.sendToServer(new PacketSelectClimateTargeted(pos, container.getTargetedState()));
if(container.getTargetedState() != null) {
BlockPos pos = controller.getCoordinates();
float temp = temperaturePanel.parseValue();
float hum = humidityPanel.parseValue();
setClimate(container, temp, hum);
NetworkUtil.sendToServer(new PacketSelectClimateTargeted(pos, container.getTargetedState()));
}
}

public void setClimate(IClimateContainer container, float temp, float hum) {
@@ -67,7 +67,12 @@ public WidgetClimatePanel(WidgetManager manager, GuiGreenhouse gui, int xPos, in
textField = new GuiTextField(0, Minecraft.getMinecraft().fontRenderer, xPos + width / 2 - textFieldLength / 2, yPos + 14, textFieldLength, 10);
textField.setValidator(NUMBER_FILTER);
textField.setEnableBackgroundDrawing(false);
textField.setText(Float.toString(gui.container.getTargetedState().get(type)));
if(gui.container.getTargetedState() != null) {
textField.setText(Float.toString(gui.container.getTargetedState().get(type)));
}else{
textField.setVisible(false);
textField.setEnabled(false);
}
table = new Table();
for (Map.Entry<String, Float> entry : data.getData(type).entrySet()) {
table.addValueEntry(entry.getKey(), StringUtil.floatAsPercent(entry.getValue()));
@@ -108,6 +108,5 @@ public BlockPos getCenterCoordinates() {

@Override
public void setCenterCoordinates(BlockPos cordinates) {

}
}
@@ -242,6 +242,7 @@ protected void onMachineRestored() {
@Override
protected void onMachinePaused() {
provider.clear(true);
provider.getStorage().removeProviderFromChunks();
this.centerPos = BlockPos.ORIGIN;
}

@@ -250,6 +251,7 @@ protected void onMachineDisassembled() {
super.onMachineDisassembled();

provider.clear(false);
provider.getStorage().removeProviderFromChunks();

this.centerPos = BlockPos.ORIGIN;

@@ -395,7 +397,11 @@ protected void onMachineAssembled() {

createDefaultState();
limits = createLimits();
climateContainer.setState(getDefaultClimate().toMutable());
if(climateContainer.getTargetedState() == null) {
ImmutableClimateState defaultClimate = getDefaultClimate();
climateContainer.setState(defaultClimate.toMutable());
climateContainer.setTargetedState(defaultClimate);
}

provider.init(centerPos, limits);
assembleTickCount = getTickCount();
@@ -153,7 +153,7 @@ public IErrorState checkPosition(BlockPos position) {
|| maxSize.getZ() < position.getZ()
|| minSize.getX() > position.getX()
|| minSize.getZ() > position.getZ()) {
return EnumErrorCode.NOT_CLOSED;
return EnumErrorCode.TOO_LARGE;
}

if (!world.isBlockLoaded(position)) {
@@ -256,6 +256,10 @@ private GreenhouseState checkBlocks(Collection<IGreenhouseBlock> blocks) {
return GreenhouseState.UNLOADED_CHUNK;
}
if(errorLogic.hasErrors()){
//Remove the state NOT_CLOSED if the logic has the state TOO_LARGE because the state NOT_CLOSED can be caused by the TOO_LARGE state
if(errorLogic.getErrorStates().contains(EnumErrorCode.TOO_LARGE)){
errorLogic.setCondition(false, EnumErrorCode.NOT_CLOSED);
}
return GreenhouseState.OPEN;
}
this.size = height + depth + storage.getBlockCount();

0 comments on commit 66f0da4

Please sign in to comment.
You can’t perform that action at this time.