Skip to content

Commit

Permalink
Renaming for heat endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
yuesha-yc committed Jan 2, 2025
1 parent bc3d3a6 commit 577d987
Show file tree
Hide file tree
Showing 21 changed files with 224 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.teammoeg.frostedheart.content.research.inspire.EnergyCore;
import com.teammoeg.frostedheart.content.robotics.logistics.RobotChunk;
import com.teammoeg.frostedheart.content.scenario.runner.ScenarioConductor;
import com.teammoeg.frostedheart.content.steamenergy.capabilities.HeatEndpoint;
import com.teammoeg.frostedheart.content.steamenergy.HeatEndpoint;
import com.teammoeg.frostedheart.content.water.capability.WaterLevelCapability;
import com.teammoeg.frostedheart.content.steamenergy.capabilities.HeatStorageCapability;
import com.teammoeg.frostedheart.content.town.ChunkTownResourceCapability;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.teammoeg.frostedheart.base.team.SpecialDataHolder;
import com.teammoeg.frostedheart.base.team.SpecialDataTypes;
import com.teammoeg.frostedheart.content.research.data.ResearchVariant;
import com.teammoeg.frostedheart.content.steamenergy.capabilities.HeatProviderEndPoint;
import com.teammoeg.frostedheart.content.steamenergy.HeatProviderEndPoint;
import com.teammoeg.frostedheart.util.FHUtils;
import com.teammoeg.frostedheart.util.io.CodecUtil;

Expand Down Expand Up @@ -195,7 +195,7 @@ public void tick(Level w) {
isActive = tickFuelProcess(w);
tickHeatedProcess(w);
if (isActive && power > 0)
ep.setPower((float) (power * getHeatEfficiency()));
ep.setHeat((float) (power * getHeatEfficiency()));
}

public void tickHeatedProcess(Level world) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected boolean tickFuel(IMultiblockContext<RadiatorState> ctx) {
RadiatorState state = ctx.getState();
boolean hasFuel;
if (state.network.tryDrainHeat(4)) {
state.setTempLevel(state.network.getTemperatureLevel());
state.setTempLevel(state.network.getTempLevel());
state.setRangeLevel(0.5f);
state.setActive(true);
hasFuel = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package com.teammoeg.frostedheart.content.climate.heatdevice.radiator;

import com.teammoeg.frostedheart.content.climate.heatdevice.generator.HeatingState;
import com.teammoeg.frostedheart.content.steamenergy.capabilities.HeatConsumerEndpoint;
import com.teammoeg.frostedheart.content.steamenergy.HeatConsumerEndpoint;
import net.minecraft.nbt.CompoundTag;
import net.minecraftforge.common.util.LazyOptional;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import com.teammoeg.frostedheart.bootstrap.common.FHBlockEntityTypes;
import com.teammoeg.frostedheart.bootstrap.common.FHCapabilities;
import com.teammoeg.frostedheart.content.steamenergy.capabilities.HeatConsumerEndpoint;
import com.teammoeg.frostedheart.content.steamenergy.HeatConsumerEndpoint;

import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public void drawContainerBackgroundPre(@Nonnull GuiGraphics transform, float par
int w = (int) (14 * (tile.process / (float) tile.processMax));
transform.blit(TEXTURE, leftPos + 107, topPos + 28, 176, 0, 14 - w, 29);
}
if (tile.network.getPower() > 0) {
float v = tile.network.getPower() / tile.network.getMaxPower();
if (tile.network.getHeat() > 0) {
float v = tile.network.getHeat() / tile.network.getCapacity();
boolean a = false, b = false;
if (v > 0.75) {
a = b = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.teammoeg.frostedheart.content.steamenergy;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import net.minecraft.nbt.CompoundTag;

/**
* Defines a HeatEndpoint with a capacity to store, provide, and receive heat.
*/
@Getter
@ToString(callSuper = true)
public abstract class HeatCapacityEndpoint extends HeatEndpoint {
/** The max capacity to store heat. */
protected final float capacity;
/**
* Detach priority.
* Consumer priority, if power is low, endpoint with lower priority would detach first
*/
protected final int priority;
/** Current heat stored. */
@Setter
protected float heat;

public HeatCapacityEndpoint(int priority, float capacity) {
this.capacity = capacity;
this.priority = priority;
}

public void load(CompoundTag nbt,boolean isPacket) {
heat = nbt.getFloat("net_power");
}

public void save(CompoundTag nbt,boolean isPacket) {
nbt.putFloat("net_power", heat);
}

@Override
public boolean canReceiveHeat() {
return heat < capacity;
}

@Override
public boolean canProvideHeat() {
return heat > 0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@
*
*/

package com.teammoeg.frostedheart.content.steamenergy.capabilities;
package com.teammoeg.frostedheart.content.steamenergy;

import lombok.ToString;

/**
* Class SteamNetworkConsumer.
* <p>
* Integrated power cache manager for power devices
* A device should properly "request" power from the network
*/
public class HeatConsumerEndpoint extends HeatPowerEndpoint{
@ToString(callSuper = true)
public class HeatConsumerEndpoint extends HeatCapacityEndpoint {
/**
* The max intake value.<br>
*/
Expand All @@ -44,8 +47,7 @@ public HeatConsumerEndpoint(int priority, float maxPower, float maxIntake) {
}
/**
* Instantiates a new SteamNetworkConsumer with recommended cache value.<br>
* MaxIntake defaults 4 times maxIntake. <br>
* @param priority consumer priority, if power is low, endpoint with lower priority would detach first
* maxPower defaults to four times maxIntake. <br>
* @param maxIntake the max heat requested from network<br>
*/
public HeatConsumerEndpoint(float maxIntake) {
Expand All @@ -60,21 +62,21 @@ public HeatConsumerEndpoint(float maxIntake) {
* @return the heat actually drain
*/
public float drainHeat(float val) {
float drained = Math.min(power, val);
power -= drained;
float drained = Math.min(heat, val);
heat -= drained;
return drained;
}

public float sendHeat(float filled,int level) {
float required=Math.min(maxIntake, maxPower-power);
public float receiveHeat(float filled, int level) {
float required=Math.min(maxIntake, capacity - heat);
tempLevel=level;
if(required>0) {
if(filled>=required) {
filled-=required;
power+=required;
heat +=required;
return filled;
}
power+=filled;
heat +=filled;
return 0;
}
return filled;
Expand All @@ -89,19 +91,16 @@ public float sendHeat(float filled,int level) {
* @return true, if the heat value can all drained
*/
public boolean tryDrainHeat(float val) {
if (power >= val) {
power -= val;
if (heat >= val) {
heat -= val;
return true;
}
return false;
}
public boolean canProvideHeat() {
return false;
}
@Override
public String toString() {
return "SteamNetworkConsumer [maxPower=" + maxPower + ", maxIntake=" + maxIntake + ", power=" + power + ", persist=" + persist + ", dist=" + distance + "]";
}

@Override
public float provideHeat() {
return 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.teammoeg.frostedheart.content.steamenergy.capabilities;
package com.teammoeg.frostedheart.content.steamenergy;

import com.teammoeg.frostedheart.content.steamenergy.HeatEnergyNetwork;
import com.teammoeg.frostedheart.util.io.NBTSerializable;

import lombok.Getter;
import lombok.ToString;
import net.minecraft.core.Direction;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
Expand All @@ -11,48 +12,29 @@
* The Endpoint base for heat network.
*
*/
public abstract class HeatEndpoint implements NBTSerializable{
@Getter
@ToString()
public abstract class HeatEndpoint implements NBTSerializable {

/**
* The main network.<br>
* The main network.
*/
@ToString.Exclude
protected HeatEnergyNetwork network;

@Override
public String toString() {
return "HeatEndpoint [distance=" + distance + ", tempLevel=" + tempLevel + "]";
}

/**
* The distance.<br>
* The distance to center.
*/
protected int distance=-1;

/** The temp level. */
protected int tempLevel;

/** Is constant supply even unload. */
public boolean persist;

/**
* Gets the whole network.
/**
* Temperature level of the network.
*
* @return the network
* This is normally defined by the Generator, or a Heat Debugger.
*/
public HeatEnergyNetwork getNetwork() {
return network;
}
protected int tempLevel;

/**
* Gets the distance to central.
*
* @return the distance
*/
public int getDistance() {
return distance;
}

/**
* Recive connection from network.
*
* @param w current world
Expand Down Expand Up @@ -86,69 +68,72 @@ public void clearConnection() {
}

/**
* Can receive heat from network.
* Can receive heat from the network.
* <p>
* The network would call this to check if this is a consumer.
* If this returns true, this endpoint would be added to the consumer list with or without actually consume.
* The network may also put heat into this network.
* This should only called by network, You should not call this method.
* <p>
* This should be only called by the network, You should not call this method.
*
* @return true, if successful
*/
public abstract boolean canSendHeat();
protected abstract boolean canReceiveHeat();

/**
* The network calls this to put heat into this endpoint.
* Receive heat from the network.
* <p>
* If the heat provided lesser than max intake then the heat statistics would show red
* This should only called by network, You should not call this method.
* <p>
* This should be only called by the network, You should not call this method.
*
* @param filled the network fills heat to this endpoint
* @param level the actual heat level
* @return the heat actually filled
* @param filled the amount of heat that the network fills to this endpoint
* @param level the actual temperature level, which my differ from HeatEndpoint#tempLevel
* @return the amount of heat actually filled
*/
public abstract float sendHeat(float filled,int level);

/**
* Get the temperature level.
*
* @return the temperature level
*/
public int getTemperatureLevel() {
return tempLevel;
}
protected abstract float receiveHeat(float filled, int level);

/**
* Can draw heat from network.
* Whether this endpoint can provide heat to the network.
* <p>
* The network would call this to check if this is a provider.
* If this returns true, this endpoint would be added to the generator list with or without actually generate.
* This should only called by network, You should not call this method.
* <p>
* This should be only called by the network, You should not call this method.
*
* @return true, if successful
*/
public abstract boolean canProvideHeat();
protected abstract boolean canProvideHeat();

/**
* Provide heat to the network.
* This should only called by network, You should not call this method.
* <p>
* This should be only called by the network, You should not call this method.
*
* @return heat provided to the network
* @return the amount of heat actually provided
*/
public abstract float provideHeat();
protected abstract float provideHeat();

/**
* Checks if the network valid.
*
* @return true, if successful
*/
public boolean hasValidNetwork() {
return network!=null;
return network != null;
}

/**
* Gets the max intake.
* The maximum heat to receive from the network.
*
* @return the max intake
*/
public abstract float getMaxIntake();

/**
* Gets the detach priority.
*
* @return the priority to detatch
*/
public abstract int getPriority();
}
Loading

0 comments on commit 577d987

Please sign in to comment.