Skip to content

Commit

Permalink
Fixed thermal heat exchangers
Browse files Browse the repository at this point in the history
  • Loading branch information
jrddunbr committed Jan 10, 2021
1 parent 2834df4 commit 6ff5919
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 108 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MAJORVERSION = 1
MINORVERSION = 16
REVISION = 16
REVISION = 17

GROUP = 'net.electricalage.eln'
ARCHIVE_NAME = 'ElectricalAge-jrddunbr'
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/mods/eln/Eln.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@

import java.util.*;

import static jdk.nashorn.internal.objects.NativeMath.max;
import static mods.eln.i18n.I18N.*;

@SuppressWarnings({"SameParameterValue", "PointlessArithmeticExpression"})
Expand Down Expand Up @@ -338,6 +339,8 @@ public class Eln {

public static boolean verticalIronCableCrafting = false;

public static Double flywheelMass = 0.0;

@EventHandler
public void preInit(FMLPreInitializationEvent event) {

Expand Down Expand Up @@ -423,10 +426,9 @@ public void preInit(FMLPreInitializationEvent event) {
fuelHeatFurnacePowerFactor = config.get("balancing", "fuelHeatFurnacePowerFactor", 1.0).getDouble();
autominerRange = config.get("balancing", "autominerRange", 10, "Maximum horizontal distance from autominer that will be mined").getInt(10);

Other.ElnToIc2ConversionRatio = config.get("balancing", "ElnToIndustrialCraftConversionRatio", 1.0 / 3.0).getDouble(1.0 / 3.0);
Other.ElnToOcConversionRatio = config.get("balancing", "ElnToOpenComputerConversionRatio", 1.0 / 3.0 / 2.5).getDouble(1.0 / 3.0 / 2.5);
Other.ElnToTeConversionRatio = config.get("balancing", "ElnToThermalExpansionConversionRatio", 1.0 / 3.0 * 4).getDouble(1.0 / 3.0 * 4);
// Other.ElnToBuildcraftConversionRatio = config.get("balancing", "ElnToBuildcraftConversionRatio", 1.0 / 3.0 / 5 * 2).getDouble(1.0 / 3.0 / 5 * 2);
Other.wattsToEu = config.get("balancing", "ElnToIndustrialCraftConversionRatio", 1.0 / 3.0).getDouble(1.0 / 3.0);
Other.wattsToOC = config.get("balancing", "ElnToOpenComputerConversionRatio", 1.0 / 3.0 / 2.5).getDouble(1.0 / 3.0 / 2.5);
Other.wattsToRf = config.get("balancing", "ElnToThermalExpansionConversionRatio", 1.0 / 3.0 * 4).getDouble(1.0 / 3.0 * 4);
plateConversionRatio = config.get("balancing", "platesPerIngot", 1).getInt(1);
shaftEnergyFactor = config.get("balancing", "shaftEnergyFactor", 0.05).getDouble(0.05);

Expand All @@ -436,7 +438,7 @@ public void preInit(FMLPreInitializationEvent event) {
ComputerProbeEnable = config.get("compatibility", "ComputerProbeEnable", true).getBoolean(true);
ElnToOtherEnergyConverterEnable = config.get("compatibility", "ElnToOtherEnergyConverterEnable", true).getBoolean(true);

replicatorPop = config.get("entity", "replicatorPop", true).getBoolean(true);
replicatorPop = config.get("entity", "replicatorPop", false).getBoolean(false);
ReplicatorPopProcess.popPerSecondPerPlayer = config.get("entity", "replicatorPopWhenThunderPerSecond", 1.0 / 120).getDouble(1.0 / 120);
replicatorRegistrationId = config.get("entity", "replicatorId", -1).getInt(-1);
killMonstersAroundLamps = config.get("entity", "killMonstersAroundLamps", true).getBoolean(true);
Expand Down Expand Up @@ -501,6 +503,8 @@ public void preInit(FMLPreInitializationEvent event) {

Eln.maxSoundDistance = config.get("debug", "maxSoundDistance", 16.0).getDouble();

Eln.flywheelMass = Math.min(Math.max(config.get("balancing", "flywheelMass", 50.0).getDouble(), 1.0), 1000.0);

config.save();

eventChannel = NetworkRegistry.INSTANCE.newEventDrivenChannel(channelName);
Expand Down Expand Up @@ -587,7 +591,7 @@ public void preInit(FMLPreInitializationEvent event) {
SixNode.sixNodeCacheList.add(new SixNodeCacheStd());

registerTestBlock();
//registerEnergyConverter();
registerEnergyConverter();
registerComputer();

registerArmor();
Expand Down Expand Up @@ -833,7 +837,7 @@ public void load(FMLInitializationEvent event) {
registerReplicator();
//

//recipeEnergyConverter();
recipeEnergyConverter();
recipeComputerProbe();

recipeArmor();
Expand Down Expand Up @@ -957,7 +961,7 @@ private void registerEnergyConverter() {
new EnergyConverterElnToOtherDescriptor("EnergyConverterElnToOtherLVU", ELN_CONVERTER_MAX_POWER);
elnToOtherBlockConverter = new EnergyConverterElnToOtherBlock(desc);
elnToOtherBlockConverter.setCreativeTab(creativeTab).setBlockName(blockName);
//GameRegistry.registerBlock(elnToOtherBlockConverter, SimpleNodeItem.class, blockName);
GameRegistry.registerBlock(elnToOtherBlockConverter, SimpleNodeItem.class, blockName);
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/mods/eln/Other.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public class Other {
public static boolean ccLoaded = false;
public static boolean teLoaded = false;

public static double ElnToIc2ConversionRatio;
public static double ElnToOcConversionRatio;
public static double ElnToTeConversionRatio;
public static double wattsToEu;
public static double wattsToOC;
public static double wattsToRf;

public static final String modIdIc2 = "IC2";
public static final String modIdOc = "OpenComputers";
Expand All @@ -25,15 +25,15 @@ public static void check() {
teLoaded = Loader.isModLoaded(modIdTe);
}

public static double getElnToIc2ConversionRatio() {
return ElnToIc2ConversionRatio;
public static double getWattsToEu() {
return wattsToEu;
}

public static double getElnToOcConversionRatio() {
return ElnToOcConversionRatio;
public static double getWattsToOC() {
return wattsToOC;
}

public static double getElnToTeConversionRatio() {
return ElnToTeConversionRatio;
public static double getWattsToRf() {
return wattsToRf;
}
}
3 changes: 2 additions & 1 deletion src/main/java/mods/eln/mechanical/Flywheel.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mods.eln.mechanical

import mods.eln.Eln
import mods.eln.misc.Direction
import mods.eln.misc.LinearFunction
import mods.eln.misc.Obj3D
Expand All @@ -21,7 +22,7 @@ class FlywheelDescriptor(baseName: String, obj: Obj3D) : SimpleShaftDescriptor(b
}

class FlyWheelElement(node: TransparentNode, desc_: TransparentNodeDescriptor) : StraightJointElement(node, desc_) {
override val shaftMass = 10.0
override val shaftMass = Eln.flywheelMass?: 50.0

inner class FlyWheelFlingProcess : IProcess {
val interval = 0.05
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import net.minecraft.tileentity.TileEntity
import net.minecraftforge.common.util.ForgeDirection
import java.io.DataInputStream
import java.io.IOException
import kotlin.math.min

@InterfaceList(Optional.Interface(iface = "ic2.api.energy.tile.IEnergySource", modid = Other.modIdIc2), Optional.Interface(iface = "cofh.api.energy.IEnergyHandler", modid = Other.modIdTe), Optional.Interface(iface = "li.cil.oc.api.network.Environment", modid = Other.modIdOc))
class EnergyConverterElnToOtherEntity : SimpleNodeEntity(), IEnergySource, Environment, IEnergyHandler {
Expand All @@ -30,6 +29,7 @@ class EnergyConverterElnToOtherEntity : SimpleNodeEntity(), IEnergySource, Envir
var ocEnergy: EnergyConverterElnToOtherFireWallOc? = null
@JvmField
var addedToEnet = false
var ic2tier = 1

@SideOnly(Side.CLIENT)
override fun newGuiDraw(side: Direction, player: EntityPlayer): GuiScreen {
Expand All @@ -40,6 +40,7 @@ class EnergyConverterElnToOtherEntity : SimpleNodeEntity(), IEnergySource, Envir
super.serverPublishUnserialize(stream)
try {
selectorPower = stream.readDouble()
ic2tier = stream.readInt()
hasChanges = true
} catch (e: IOException) {
e.printStackTrace()
Expand All @@ -63,19 +64,15 @@ class EnergyConverterElnToOtherEntity : SimpleNodeEntity(), IEnergySource, Envir
if (worldObj.isRemote) return 0.0
if (node == null) return 0.0
val node = node as EnergyConverterElnToOtherNode
//val offered = node.getOtherModEnergyBuffer(Other.ElnToIc2ConversionRatio)
val offered = node.getOtherModOutMax(node.energyBuffer, Other.getElnToIc2ConversionRatio())
println("offering: $offered of ${node.energyBuffer}")
return offered
return node.availableEnergyInModUnitsWithLimit(IC2Tiers.values().first { it.tier == node.ic2tier }.euPerTick.toDouble(), Other.getWattsToEu())
}

@Optional.Method(modid = Other.modIdIc2)
override fun drawEnergy(amount: Double) {
if (worldObj.isRemote) return
if (node == null) return
val node = node as EnergyConverterElnToOtherNode
val draw = node.drawEnergy(amount, Other.getElnToIc2ConversionRatio())
println("drawing $draw")
node.drawEnergy(amount, Other.getWattsToEu())
}

@Optional.Method(modid = Other.modIdIc2)
Expand Down Expand Up @@ -146,8 +143,8 @@ class EnergyConverterElnToOtherEntity : SimpleNodeEntity(), IEnergySource, Envir
if (worldObj.isRemote) return 0
if (node == null) return 0
val node = node as EnergyConverterElnToOtherNode
val extract = Math.max(0, Math.min(maxExtract, node.getOtherModEnergyBuffer(Other.getElnToTeConversionRatio()).toInt()))
if (!simulate) node.drawEnergy(extract.toDouble(), Other.getElnToTeConversionRatio())
val extract = Math.max(0, Math.min(maxExtract, node.availableEnergyInModUnits(Other.getWattsToRf()).toInt()))
if (!simulate) node.drawEnergy(extract.toDouble(), Other.getWattsToRf())
return extract
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class EnergyConverterElnToOtherFireWallOc(var e: EnergyConverterElnToOtherEntity
if (e.node == null) return
val c = node as Connector
val node = e.node as EnergyConverterElnToOtherNode
var eMax = node.getOtherModEnergyBuffer(Other.getElnToOcConversionRatio())
var eMax = node.availableEnergyInModUnits(Other.getWattsToOC())
eMax = Math.min(Math.min(eMax, c.globalBufferSize() - c.globalBuffer()), node.descriptor!!.maxPower)
if (c.tryChangeBuffer(eMax)) {
node.drawEnergy(eMax, Other.getElnToOcConversionRatio())
node.drawEnergy(eMax, Other.getWattsToOC())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package mods.eln.simplenode.energyconverter
import cofh.api.energy.IEnergyHandler
import mods.eln.Other
import mods.eln.misc.Direction
import mods.eln.node.simple.SimpleNode

object EnergyConverterElnToOtherFireWallRf {

Expand All @@ -17,11 +16,12 @@ object EnergyConverterElnToOtherFireWallRf {
.filter{ it.first is IEnergyHandler }
.map { Pair(it.first as IEnergyHandler, it.second) }
if (energySinkList.isEmpty()) return
val pMax = node.getOtherModEnergyBuffer(Other.getElnToTeConversionRatio())

val energyUsed = energySinkList.map {
it.first.receiveEnergy(it.second.toForge(), pMax.toInt() / energySinkList.size, false).toDouble()
val rfUsed = energySinkList.map {
val rfAvailable = (node.availableEnergyInModUnits(Other.getWattsToRf()) / energySinkList.size)
// receiveEnergy takes RF in, gives out RF
val rfUsed = it.first.receiveEnergy(it.second.toForge(), rfAvailable.toInt(), false).toDouble()
rfUsed
}.sum()
node.drawEnergy(energyUsed, Other.getElnToTeConversionRatio())
node.drawEnergy(rfUsed, Other.getWattsToRf())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,42 @@ import mods.eln.gui.GuiTextFieldEln
import mods.eln.gui.GuiVerticalTrackBar
import mods.eln.gui.IGuiObject
import mods.eln.i18n.I18N
import java.lang.Math.pow
import java.text.DecimalFormat
import kotlin.math.log
import kotlin.math.max
import kotlin.math.pow
import kotlin.math.roundToInt

class EnergyConverterElnToOtherGui(var render: EnergyConverterElnToOtherEntity) : GuiScreenEln() {

var powerSelector: GuiVerticalTrackBar? = null
//var ic2tier1: GuiButtonEln? = null
//var ic2tier2: GuiButtonEln? = null
//var ic2tier3: GuiButtonEln? = null
//var ic2tier4: GuiButtonEln? = null
//var ic2tier5: GuiButtonEln? = null
var ic2tier1: GuiButtonEln? = null
var ic2tier2: GuiButtonEln? = null
var ic2tier3: GuiButtonEln? = null
var ic2tier4: GuiButtonEln? = null
var powerEntry: GuiTextFieldEln? = null

val maxPower = Eln.instance.ELN_CONVERTER_MAX_POWER
private val maxPower = Eln.instance.ELN_CONVERTER_MAX_POWER

//var ic2tierList: List<GuiButtonEln>? = null
var ic2tierList: List<GuiButtonEln>? = null

override fun initGui() {
super.initGui()
powerSelector = newGuiVerticalTrackBar(6, 6 + 2, 20, 100)
powerSelector = newGuiVerticalTrackBar(6, 6 + 2, 20, 82)
powerSelector!!.setStepIdMax(100)
powerSelector!!.setEnable(true)
powerSelector!!.setRange(0f, 1f)
//ic2tier1 = newGuiButton(35, 6, 40,"IC2 T1")
//ic2tier2 = newGuiButton(35, 28, 40,"IC2 T2")
//ic2tier3 = newGuiButton(35, 50, 40,"IC2 T3")
//ic2tier4 = newGuiButton(35, 72, 40,"IC2 T4")
//ic2tier5 = newGuiButton(35, 94, 40, "IC2 T5")
//ic2tierList = listOfNotNull(ic2tier1, ic2tier2, ic2tier3, ic2tier4, ic2tier5)
//ic2tier1!!.enabled = true
//ic2tier1!!.setComment(0, "Set output to 32 EU/t max")
//ic2tier2!!.enabled = true
//ic2tier2!!.setComment(0, "Set output to 128 EU/t max")
//ic2tier3!!.enabled = true
//ic2tier3!!.setComment(0, "Set output to 512 EU/t max")
//ic2tier4!!.enabled = true
//ic2tier4!!.setComment(0, "Set output to 2048 EU/t max")
//ic2tier5!!.enabled = true
//ic2tier5!!.setComment(0, "Set output to 8192 EU/t max")
powerEntry = newGuiTextField(6, 112, 55)
ic2tier1 = newGuiButton(30, 6, 47,"IC2 T1")
ic2tier2 = newGuiButton(30, 28, 47,"IC2 T2")
ic2tier3 = newGuiButton(30, 50, 47,"IC2 T3")
ic2tier4 = newGuiButton(30, 72, 47,"IC2 T4")
ic2tierList = listOfNotNull(ic2tier1, ic2tier2, ic2tier3, ic2tier4)
ic2tier1!!.enabled = true
ic2tier1!!.setComment(0, "Set output to 32 EU/t max")
ic2tier2!!.enabled = true
ic2tier2!!.setComment(0, "Set output to 128 EU/t max")
ic2tier3!!.enabled = true
ic2tier3!!.setComment(0, "Set output to 512 EU/t max")
ic2tier4!!.enabled = true
ic2tier4!!.setComment(0, "Set output to 2048 EU/t max")
powerEntry = newGuiTextField(6, 96, 70)
powerEntry!!.enabled
powerEntry!!.setComment(listOf("Select the maximum export power").toTypedArray())
syncVoltage()
Expand All @@ -60,19 +52,24 @@ class EnergyConverterElnToOtherGui(var render: EnergyConverterElnToOtherEntity)
fun syncVoltage() {
powerSelector!!.value = selectedPowerToSlider(render.selectorPower)
powerEntry!!.text = render.selectorPower.toInt().toString()
ic2tierList!!.forEachIndexed {
index, button ->
val tier = index + 1
button.displayString = if (tier == render.ic2tier) {
"[IC2 T$tier]"
} else {
"IC2 T$tier"
}
}
render.hasChanges = false
}

fun selectedPowerToSlider(selectedPower: Double): Float {
return log(selectedPower / 100 + 1, (maxPower / 100) + 1).toFloat()
//return log(selectedPower + 1, Eln.instance.ELN_CONVERTER_MAX_POWER + 1).toFloat()
//return log(selectedPower, Eln.instance.ELN_CONVERTER_MAX_POWER).toFloat()
}

fun sliderToSelectedPower(slider: Float): Double {
return 100 * (pow((maxPower / 100) + 1, slider.toDouble()) - 1)
//return pow(Eln.instance.ELN_CONVERTER_MAX_POWER + 1, slider.toDouble()) - 1
//return Eln.instance.ELN_CONVERTER_MAX_POWER.pow(slider.toDouble())
return 100 * (((maxPower / 100) + 1).pow(slider.toDouble()) - 1)
}

override fun guiObjectEvent(guiObject: IGuiObject) {
Expand All @@ -86,26 +83,24 @@ class EnergyConverterElnToOtherGui(var render: EnergyConverterElnToOtherEntity)
render.selectorPower = powerEntry!!.text.toDoubleOrNull()?: render.selectorPower
render.sender.clientSendDouble(NetworkType.SET_POWER.id, render.selectorPower)
}
//guiObject === ic2tier1 ->
// render.sender.clientSendInt(NetworkType.SET_IC2_TIER.id, 1)
//guiObject === ic2tier2 ->
// render.sender.clientSendInt(NetworkType.SET_IC2_TIER.id, 2)
//guiObject === ic2tier3 ->
// render.sender.clientSendInt(NetworkType.SET_IC2_TIER.id, 3)
//guiObject === ic2tier4 ->
// render.sender.clientSendInt(NetworkType.SET_IC2_TIER.id, 4)
//guiObject === ic2tier5 ->
// render.sender.clientSendInt(NetworkType.SET_IC2_TIER.id, 5)
guiObject === ic2tier1 ->
render.sender.clientSendInt(NetworkType.SET_IC2_TIER.id, 1)
guiObject === ic2tier2 ->
render.sender.clientSendInt(NetworkType.SET_IC2_TIER.id, 2)
guiObject === ic2tier3 ->
render.sender.clientSendInt(NetworkType.SET_IC2_TIER.id, 3)
guiObject === ic2tier4 ->
render.sender.clientSendInt(NetworkType.SET_IC2_TIER.id, 4)
}
}

override fun preDraw(f: Float, x: Int, y: Int) {
super.preDraw(f, x, y)
if (render.hasChanges) syncVoltage()
powerSelector!!.setComment(0, I18N.tr("Input power is limited to %1\$W", sliderToSelectedPower(powerSelector!!.value).toInt()))
powerSelector!!.setComment(0, I18N.tr("Input power is limited to %1\$W", render.selectorPower))
}

override fun newHelper(): GuiHelper {
return GuiHelper(this, 67, 140)
return GuiHelper(this, 82, 115)
}
}
Loading

0 comments on commit 6ff5919

Please sign in to comment.