1
0
mirror of https://github.com/chylex/Hardcore-Ender-Expansion-2.git synced 2025-04-11 03:15:44 +02:00

Add a base generator for Energy Cluster properties and color

This commit is contained in:
chylex 2018-09-10 15:37:45 +02:00
parent 998b94bc5b
commit c8379d86ca
3 changed files with 64 additions and 8 deletions
src/main/java/chylex/hee/game

View File

@ -18,7 +18,6 @@ import chylex.hee.system.util.FLAG_SYNC_CLIENT
import chylex.hee.system.util.breakBlock
import chylex.hee.system.util.ceilToInt
import chylex.hee.system.util.isAnyPlayerWithinRange
import chylex.hee.system.util.nextItem
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.util.ITickable
import kotlin.math.pow
@ -92,16 +91,20 @@ class TileEntityEnergyCluster : TileEntityBase(), ITickable{
color = this.color
)
fun loadClusterSnapshot(data: ClusterSnapshot){
energyLevel = data.energyLevel
energyBaseCapacity = data.energyCapacity
internalHealthStatus = data.healthStatus
internalHealthOverride = data.healthOverride
color = data.color
fun loadClusterSnapshot(snapshot: ClusterSnapshot){
energyLevel = snapshot.energyLevel
energyBaseCapacity = snapshot.energyCapacity
internalHealthStatus = snapshot.healthStatus
internalHealthOverride = snapshot.healthOverride
color = snapshot.color
ticksToRegen = 40
}
fun setInactive(){
isInactive = true
}
// Overrides
override fun update(){
@ -141,7 +144,10 @@ class TileEntityEnergyCluster : TileEntityBase(), ITickable{
override fun readNBT(nbt: NBTTagCompound, context: Context) = with(nbt){
loadClusterSnapshot(ClusterSnapshot(nbt.getCompoundTag(SNAPSHOT_TAG)))
isInactive = getBoolean(INACTIVE_TAG)
if (getBoolean(INACTIVE_TAG)){
setInactive()
}
}
override fun hasFastRenderer(): Boolean = true

View File

@ -1,8 +1,17 @@
package chylex.hee.game.mechanics.energy
import chylex.hee.game.render.util.HCL
import chylex.hee.game.render.util.IColor
import java.util.Random
class ClusterColor(val primaryHue: Short, val secondaryHue: Short){
val forReceptacle: IColor
get() = HCL(primaryHue.toDouble(), 75, 80)
companion object{
fun generate(rand: Random): ClusterColor{
val primary = rand.nextInt(360)
val secondary = (primary + 30 + rand.nextInt(300)) % 360
return ClusterColor(primary.toShort(), secondary.toShort())
}
}
}

View File

@ -0,0 +1,41 @@
package chylex.hee.game.mechanics.energy
import chylex.hee.game.mechanics.energy.IClusterHealth.HealthStatus
import chylex.hee.game.mechanics.energy.IClusterHealth.HealthStatus.DAMAGED
import chylex.hee.game.mechanics.energy.IClusterHealth.HealthStatus.HEALTHY
import chylex.hee.game.mechanics.energy.IClusterHealth.HealthStatus.TIRED
import chylex.hee.game.mechanics.energy.IClusterHealth.HealthStatus.WEAKENED
import chylex.hee.game.mechanics.energy.IEnergyQuantity.Floating
import chylex.hee.game.mechanics.energy.IEnergyQuantity.Units
import chylex.hee.system.collection.WeightedList
import chylex.hee.system.collection.WeightedList.Companion.weightedListOf
import chylex.hee.system.util.nextFloat
import java.util.Random
interface IClusterGenerator{
fun generate(rand: Random): ClusterSnapshot
companion object{ // TODO make generators static fields in kotlin 1.3
private class SimpleGenerator(level: Pair<Int, Int>, capacity: Pair<Int, Int>, private val health: (Random) -> HealthStatus) : IClusterGenerator{
constructor(level: Pair<Int, Int>, capacity: Pair<Int, Int>, health: WeightedList<HealthStatus>) : this(level, capacity, health::generateItem)
private val levelMin = Units(level.first).floating.value
private val levelMax = Units(level.second).floating.value
private val capacityMin = Units(capacity.first).floating.value
private val capacityMax = Units(capacity.second).floating.value
override fun generate(rand: Random): ClusterSnapshot{
val generatedLevel = Floating(rand.nextFloat(levelMin, levelMax))
val generatedCapacity = Floating(rand.nextFloat(capacityMin, capacityMax))
return ClusterSnapshot(
energyLevel = minOf(generatedLevel, generatedCapacity),
energyCapacity = generatedCapacity,
healthStatus = health(rand),
healthOverride = null,
color = ClusterColor.generate(rand)
)
}
}
}
}