mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-20 12:09:39 +00:00
Fix Targeted state
This commit is contained in:
1 parent
d8c8aec2ee
commit
66f0da433e
11 files changed
+65
-29
No files matched your search
@@ -62,7 +62,6 @@ public class ClimateContainer implements IClimateContainer, IStreamable {
|
||||
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,7 +164,9 @@ public class ClimateContainer implements IClimateContainer, IStreamable {
|
||||
@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;
|
||||
}
|
||||
@@ -173,7 +174,9 @@ public class ClimateContainer implements IClimateContainer, IStreamable {
|
||||
@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 class ClimateContainer implements IClimateContainer, IStreamable {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ImmutableClimateState getTargetedState() {
|
||||
return targetedState;
|
||||
}
|
||||
@@ -234,8 +238,13 @@ public class ClimateContainer implements IClimateContainer, IStreamable {
|
||||
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 class ClimateContainer implements IClimateContainer, IStreamable {
|
||||
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 class ClimateContainer implements IClimateContainer, IStreamable {
|
||||
}
|
||||
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 @@ public enum EnumErrorCode implements IErrorState {
|
||||
|
||||
// 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 class MultiblockEventHandlerClient {
|
||||
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 class GreenhouseEventHandler {
|
||||
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 @@ public interface IClimateContainer extends INbtReadable, INbtWritable, IClimateS
|
||||
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 class ClimateSourceModifier extends BlankClimateModifier {
|
||||
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.entity.player.EntityPlayer;
|
||||
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 class GuiGreenhouse extends GuiForestryTitled<ContainerGreenhouse> {
|
||||
|
||||
//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 class WidgetClimatePanel extends Widget {
|
||||
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 class FakeGreenhouseController extends FakeMultiblockController implement
|
||||
|
||||
@Override
|
||||
public void setCenterCoordinates(BlockPos cordinates) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -242,6 +242,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
@Override
|
||||
protected void onMachinePaused() {
|
||||
provider.clear(true);
|
||||
provider.getStorage().removeProviderFromChunks();
|
||||
this.centerPos = BlockPos.ORIGIN;
|
||||
}
|
||||
|
||||
@@ -250,6 +251,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
super.onMachineDisassembled();
|
||||
|
||||
provider.clear(false);
|
||||
provider.getStorage().removeProviderFromChunks();
|
||||
|
||||
this.centerPos = BlockPos.ORIGIN;
|
||||
|
||||
@@ -395,7 +397,11 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
|
||||
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();
|
||||
|
||||
+5
-1
@@ -153,7 +153,7 @@ public class GreenhouseProviderServer extends GreenhouseProvider {
|
||||
|| 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 @@ public class GreenhouseProviderServer extends GreenhouseProvider {
|
||||
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();
|
||||
|
||||
Reference in new issue
Block a user