electrodynamics/src/main/scala/edx/core/resource/alloy/Alloy.scala

52 lines
1.1 KiB
Scala
Raw Normal View History

2015-01-14 12:06:03 +01:00
package edx.core.resource.alloy
2015-01-12 13:38:11 +01:00
import net.minecraft.nbt.NBTTagCompound
2015-01-26 12:40:32 +01:00
import resonantengine.api.ISave
import resonantengine.lib.wrapper.NBTWrapper._
2015-01-12 13:38:11 +01:00
/**
2015-01-12 16:01:41 +01:00
* A class that stores alloy objects. Alloys are materials that are composed of other materials.
2015-01-12 13:38:11 +01:00
* @author Calclavia
*/
2015-01-26 12:40:32 +01:00
class Alloy(val max: Int) extends ISave
2015-01-12 13:38:11 +01:00
{
2015-01-12 16:01:41 +01:00
var content = Map.empty[String, Int]
2015-01-12 13:38:11 +01:00
2015-01-12 16:01:41 +01:00
def this(nbt: NBTTagCompound, max: Int = 8)
2015-01-12 13:38:11 +01:00
{
2015-01-12 16:01:41 +01:00
this(max)
load(nbt)
2015-01-12 13:38:11 +01:00
}
override def load(nbt: NBTTagCompound)
{
2015-01-12 16:01:41 +01:00
content = nbt.getMap("mixture")
}
def percentage(material: String): Float = content(material) / size.toFloat
2015-01-13 15:53:38 +01:00
def size = content.values.foldLeft(0)(_ + _)
2015-01-14 12:06:03 +01:00
def percentage = size / max.toFloat
2015-01-12 16:01:41 +01:00
/**
* Mixes a dust material into this jar
*/
def mix(material: String): Boolean =
{
if (size < max)
{
content += material -> (content.getOrElse(material, 0) + 1)
return true
}
return false
}
2015-01-12 13:38:11 +01:00
2015-01-12 16:01:41 +01:00
def color = AlloyUtility.mixedColor(content.map(keyVal => (keyVal._1, keyVal._2 / size.toFloat)))
override def save(nbt: NBTTagCompound)
{
nbt.setMap("mixture", content)
2015-01-12 13:38:11 +01:00
}
}