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 # 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. # to make use of here, since they will all be disabled by default.
potionWhitelist: [ potionWhitelist: [
"potion.moveSpeed", "speed",
"potion.digSpeed", "haste",
"potion.damageBoost", "strength",
"potion.jump", "jump_boost",
"potion.resistance", "resistance",
"potion.fireResistance", "fire_resistance",
"potion.waterBreathing", "water_breathing",
"potion.nightVision", "night_vision",
"potion.absorption", "absorption",
"potion.blindness", "blindness",
"potion.confusion", "nausea",
"potion.digSlowDown", "mining_fatigue",
"potion.harm", "instant_damage",
"potion.hunger", "hunger",
"potion.moveSlowdown", "slowness",
"potion.poison", "poison",
"potion.weakness", "weakness",
"potion.wither" "wither"
] ]
# How much damage the hungry behavior should deal to the player when the # 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 nanomachinesCommandRange = config.getDouble("nanomachines.commandRange") max 0
val nanomachineMagnetRange = config.getDouble("nanomachines.magnetRange") max 0 val nanomachineMagnetRange = config.getDouble("nanomachines.magnetRange") max 0
val nanomachineDisintegrationRange = config.getInt("nanomachines.disintegrationRange") 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 nanomachinesHungryDamage = config.getDouble("nanomachines.hungryDamage").toFloat max 0
val nanomachinesHungryEnergyRestored = config.getDouble("nanomachines.hungryEnergyRestored") 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. // Upgrading to version 1.5.20, changed relay delay default.
VersionRange.createFromVersionSpec("[0.0, 1.5.20)") -> Array( VersionRange.createFromVersionSpec("[0.0, 1.5.20)") -> Array(
"switch.relayDelayUpgrade" "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 to give other mods a chance to register their potions.
lazy val PotionWhitelist = filterPotions(Settings.get.nanomachinePotionWhitelist) 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) 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 = { override def writeBehaviorToNBT(behavior: Behavior, nbt: NBTTagCompound): Unit = {
behavior match { behavior match {
case potionBehavior: PotionBehavior => case potionBehavior: PotionBehavior =>
nbt.setInteger("potionId", Potion.getIdFromPotion(potionBehavior.potion)) nbt.setString("potionId", Potion.REGISTRY.getNameForObject(potionBehavior.potion).toString)
case _ => // Shouldn't happen, ever. case _ => // Shouldn't happen, ever.
} }
} }
override def readBehaviorFromNBT(player: EntityPlayer, nbt: NBTTagCompound) = { override def readBehaviorFromNBT(player: EntityPlayer, nbt: NBTTagCompound) = {
val potionId = nbt.getInteger("potionId") val potionId = nbt.getString("potionId")
new PotionBehavior(Potion.getPotionById(potionId), player) new PotionBehavior(Potion.getPotionFromResourceLocation(potionId), player)
} }
class PotionBehavior(val potion: Potion, player: EntityPlayer) extends AbstractBehavior(player) { class PotionBehavior(val potion: Potion, player: EntityPlayer) extends AbstractBehavior(player) {