Fix missing potion effects in nanomachines.

Closes #1885.
This commit is contained in:
Vexatos 2017-01-29 11:46:22 +01:00
parent 723883b9d9
commit 85a6c5b8c7
3 changed files with 35 additions and 23 deletions

View File

@ -1063,25 +1063,25 @@ opencomputers {
# in case of a number it has to be the potion ID. Add any potion effects
# to make use of here, since they will all be disabled by default.
potionWhitelist: [
"potion.moveSpeed",
"potion.digSpeed",
"potion.damageBoost",
"potion.jump",
"potion.resistance",
"potion.fireResistance",
"potion.waterBreathing",
"potion.nightVision",
"potion.absorption",
"speed",
"haste",
"strength",
"jump_boost",
"resistance",
"fire_resistance",
"water_breathing",
"night_vision",
"absorption",
"potion.blindness",
"potion.confusion",
"potion.digSlowDown",
"potion.harm",
"potion.hunger",
"potion.moveSlowdown",
"potion.poison",
"potion.weakness",
"potion.wither"
"blindness",
"nausea",
"mining_fatigue",
"instant_damage",
"hunger",
"slowness",
"poison",
"weakness",
"wither"
]
# How much damage the hungry behavior should deal to the player when the

View File

@ -372,7 +372,7 @@ class Settings(val config: Config) {
val nanomachinesCommandRange = config.getDouble("nanomachines.commandRange") max 0
val nanomachineMagnetRange = config.getDouble("nanomachines.magnetRange") max 0
val nanomachineDisintegrationRange = config.getInt("nanomachines.disintegrationRange") max 0
val nanomachinePotionWhitelist = config.getStringList("nanomachines.potionWhitelist")
val nanomachinePotionWhitelist = config.getAnyRefList("nanomachines.potionWhitelist")
val nanomachinesHungryDamage = config.getDouble("nanomachines.hungryDamage").toFloat max 0
val nanomachinesHungryEnergyRestored = config.getDouble("nanomachines.hungryEnergyRestored") max 0
@ -513,6 +513,10 @@ object Settings {
// Upgrading to version 1.5.20, changed relay delay default.
VersionRange.createFromVersionSpec("[0.0, 1.5.20)") -> Array(
"switch.relayDelayUpgrade"
),
// Potion whitelist was fixed in 1.6.2.
VersionRange.createFromVersionSpec("[0.0, 1.6.2)") -> Array(
"nanomachines.potionWhitelist"
)
)

View File

@ -16,7 +16,15 @@ object PotionProvider extends ScalaProvider("c29e4eec-5a46-479a-9b3d-ad0f06da784
// Lazy to give other mods a chance to register their potions.
lazy val PotionWhitelist = filterPotions(Settings.get.nanomachinePotionWhitelist)
def filterPotions(list: Iterable[String]) = list.map(Potion.getPotionFromResourceLocation).filter(_ != null).toSet
def filterPotions[T](list: Iterable[T]) = {
list.map {
case name: String => Option(Potion.getPotionFromResourceLocation(name))
case id: java.lang.Number => Option(Potion.getPotionById(id.intValue()))
case _ => None
}.collect {
case Some(potion) => potion
}.toSet
}
def isPotionEligible(potion: Potion) = potion != null && PotionWhitelist.contains(potion)
@ -27,14 +35,14 @@ object PotionProvider extends ScalaProvider("c29e4eec-5a46-479a-9b3d-ad0f06da784
override def writeBehaviorToNBT(behavior: Behavior, nbt: NBTTagCompound): Unit = {
behavior match {
case potionBehavior: PotionBehavior =>
nbt.setInteger("potionId", Potion.getIdFromPotion(potionBehavior.potion))
nbt.setString("potionId", Potion.REGISTRY.getNameForObject(potionBehavior.potion).toString)
case _ => // Shouldn't happen, ever.
}
}
override def readBehaviorFromNBT(player: EntityPlayer, nbt: NBTTagCompound) = {
val potionId = nbt.getInteger("potionId")
new PotionBehavior(Potion.getPotionById(potionId), player)
val potionId = nbt.getString("potionId")
new PotionBehavior(Potion.getPotionFromResourceLocation(potionId), player)
}
class PotionBehavior(val potion: Potion, player: EntityPlayer) extends AbstractBehavior(player) {