Skip to content

Commit

Permalink
Added config for pause behaviour for engine (#262)
Browse files Browse the repository at this point in the history
pause behaviour like how it used to work.
  • Loading branch information
millennIumAMbiguity authored Oct 11, 2023
1 parent b21c05e commit a0b9076
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ object EurekaConfig {
@JsonSchema(description = "Increases heat gained at low heat level, and increased heat decreases when at high heat and not consuming fuel")
val engineHeatChangeExponent = 0.1f

@JsonSchema(description = "Pause fuel consumption and power when block is powered")
val engineRedstoneBehaviorPause = false

@JsonSchema(description = "Avoids consuming fuel when heat is 100%")
val engineFuelSaving = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,59 +52,62 @@ class EngineBlockEntity(pos: BlockPos, state: BlockState) :

private var heat = 0f
fun tick() {
if (!this.level!!.isClientSide) {
// Disable engine feeding when they are receiving a redstone signal
if (!level!!.hasNeighborSignal(blockPos)) {
if (fuelLeft > 0) {

if (EurekaConfig.SERVER.engineFuelSaving) {
if (heat <= maxEffectiveFuel) {
heat += scaleEngineHeating(EurekaConfig.SERVER.engineHeatGain)
fuelLeft--
}
} else {
fuelLeft--
if (this.level!!.isClientSide) return

val isPowered = level!!.hasNeighborSignal(blockPos)
if (EurekaConfig.SERVER.engineRedstoneBehaviorPause && isPowered) return

if (heat <= maxEffectiveFuel) {
heat += scaleEngineHeating(EurekaConfig.SERVER.engineHeatGain)
}
// Disable engine feeding when they are receiving a redstone signal
if (!isPowered) {
if (fuelLeft > 0) {

if (EurekaConfig.SERVER.engineFuelSaving) {
if (heat <= maxEffectiveFuel) {
heat += scaleEngineHeating(EurekaConfig.SERVER.engineHeatGain)
fuelLeft--
}
} else {
fuelLeft--

// Refill while burning
if (!fuel.isEmpty && lastFuelValue <= EurekaConfig.SERVER.engineMinCapacity - fuelLeft) {
consumeFuel()
if (heat <= maxEffectiveFuel) {
heat += scaleEngineHeating(EurekaConfig.SERVER.engineHeatGain)
}
} else if (!fuel.isEmpty) {
consumeFuel()
}
}

val prevHeatLevel = heatLevel
heatLevel = min(ceil(heat * 4f / 100f).toInt(), 4)
if (prevHeatLevel != heatLevel) {
level!!.setBlock(blockPos, this.blockState.setValue(HEAT, heatLevel), 11)
// Refill while burning
if (!fuel.isEmpty && lastFuelValue <= EurekaConfig.SERVER.engineMinCapacity - fuelLeft) {
consumeFuel()
}
} else if (!fuel.isEmpty) {
consumeFuel()
}
}

if (heat > 0) {
val eurekaShipControl = ship?.getAttachment(EurekaShipControl::class.java)
if (ship != null && eurekaShipControl != null && !level!!.hasNeighborSignal(blockPos)) {
// Avoid fluctuations in speed
var effectiveHeat = 1f
if (heat < maxEffectiveFuel) {
effectiveHeat = heat / 100f
}

eurekaShipControl.power += lerp(
EurekaConfig.SERVER.minEnginePower,
EurekaConfig.SERVER.enginePower,
effectiveHeat,
)
val prevHeatLevel = heatLevel
heatLevel = min(ceil(heat * 4f / 100f).toInt(), 4)
if (prevHeatLevel != heatLevel) {
level!!.setBlock(blockPos, this.blockState.setValue(HEAT, heatLevel), 11)
}

heat -= eurekaShipControl.consumed
if (heat > 0) {
val eurekaShipControl = ship?.getAttachment(EurekaShipControl::class.java)
if (ship != null && eurekaShipControl != null) {
// Avoid fluctuations in speed
var effectiveHeat = 1f
if (heat < maxEffectiveFuel) {
effectiveHeat = heat / 100f
}

heat = max(heat - scaleEngineCooling(EurekaConfig.SERVER.engineHeatLoss), 0f)
eurekaShipControl.power += lerp(
EurekaConfig.SERVER.minEnginePower,
EurekaConfig.SERVER.enginePower,
effectiveHeat,
)

heat -= eurekaShipControl.consumed
}

heat = max(heat - scaleEngineCooling(EurekaConfig.SERVER.engineHeatLoss), 0f)
}
}

Expand Down

0 comments on commit a0b9076

Please sign in to comment.