diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index 03f49658c8..1617157f9e 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -412,6 +412,9 @@ opencomputers { # two real experience points, redstone is worth 5. oreXpRate: 4.0 + # This determines how much experience a robot gets for each suck. + suckXpRate: 1.0 + # This is the amount of additional energy that fits into a robots # internal buffer for each level it gains. So with the default values, # at maximum level (30) a robot will have an internal buffer size of @@ -1003,6 +1006,10 @@ opencomputers { "allow default" ] + whitelist: [] + + blacklist: [] + # The time in seconds to wait for a response to a request before timing # out and returning an error message. If this is zero (the default) the # request will never time out. @@ -1400,6 +1407,10 @@ opencomputers { # be performed by the trading upgrade tradingRange: 8.0 + # The maximum range between the drone/robot and a experience orb for a suck to + # be performed by the experience upgrade + suckXpRange: 8.0 + # Radius the MFU is able to operate in mfuRange: 3 @@ -1645,7 +1656,7 @@ opencomputers { # This setting assigns the budget call cost to invoke bitblt to write vram # to a screen. Video ram can bitblit to a screen which can cause real life - # network laod the defaults settings put bitblit network impact close to gpu.set + # network load the defaults settings put bitblit network impact close to gpu.set # Increase these values to throttle bitblt more. The cost tier N is bitbltCost * 2^(tier) # default is .5, which gives: .5, 1, 4 bitbltCost: 0.5 diff --git a/src/main/scala/li/cil/oc/Settings.scala b/src/main/scala/li/cil/oc/Settings.scala index d44e4643e0..9b7dc3f1fe 100644 --- a/src/main/scala/li/cil/oc/Settings.scala +++ b/src/main/scala/li/cil/oc/Settings.scala @@ -124,6 +124,7 @@ class Settings(val config: Config) { val robotActionXp = config.getDouble("robot.xp.actionXp") max 0 val robotExhaustionXpRate = config.getDouble("robot.xp.exhaustionXpRate") max 0 val robotOreXpRate = config.getDouble("robot.xp.oreXpRate") max 0 + val robotSuckXpRate = config.getDouble("robot.xp.suckXpRate") max 0 val bufferPerLevel = config.getDouble("robot.xp.bufferPerLevel") max 0 val toolEfficiencyPerLevel = config.getDouble("robot.xp.toolEfficiencyPerLevel") max 0 val harvestSpeedBoostPerLevel = config.getDouble("robot.xp.harvestSpeedBoostPerLevel") max 0 @@ -387,6 +388,7 @@ class Settings(val config: Config) { val serverRackSwitchTier = (config.getInt("misc.serverRackSwitchTier") - 1) max Tier.None min Tier.Three val redstoneDelay = config.getDouble("misc.redstoneDelay") max 0 val tradingRange = config.getDouble("misc.tradingRange") max 0 + val suckXpRange = config.getDouble("misc.suckXpRange") max 0 val mfuRange = config.getInt("misc.mfuRange") max 0 min 128 // ----------------------------------------------------------------------- // diff --git a/src/main/scala/li/cil/oc/server/component/UpgradeExperience.scala b/src/main/scala/li/cil/oc/server/component/UpgradeExperience.scala index 6f2c7f4546..5593b1d187 100644 --- a/src/main/scala/li/cil/oc/server/component/UpgradeExperience.scala +++ b/src/main/scala/li/cil/oc/server/component/UpgradeExperience.scala @@ -1,7 +1,6 @@ package li.cil.oc.server.component import java.util - import li.cil.oc.Constants import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute import li.cil.oc.api.driver.DeviceInfo.DeviceClass @@ -15,7 +14,7 @@ import li.cil.oc.api.machine.Callback import li.cil.oc.api.machine.Context import li.cil.oc.api.network.Visibility import li.cil.oc.api.prefab.AbstractManagedEnvironment -import li.cil.oc.util.UpgradeExperience +import li.cil.oc.util.{BlockPosition, UpgradeExperience} import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.entity.item.EntityXPOrb import net.minecraft.init.Items @@ -24,7 +23,7 @@ import net.minecraft.nbt.NBTTagCompound import scala.collection.convert.WrapAsJava._ import scala.collection.convert.WrapAsScala._ -class UpgradeExperience(val host: EnvironmentHost with internal.Agent) extends AbstractManagedEnvironment with DeviceInfo { +class UpgradeExperience(val host: EnvironmentHost with internal.Agent) extends AbstractManagedEnvironment with traits.WorldAware with DeviceInfo { final val MaxLevel = 30 override val node = api.Network.newNode(this, Visibility.Network). @@ -42,6 +41,8 @@ class UpgradeExperience(val host: EnvironmentHost with internal.Agent) extends A override def getDeviceInfo: util.Map[String, String] = deviceInfo + override def position: BlockPosition = BlockPosition(host) + var experience = 0.0 var level = 0 @@ -110,6 +111,28 @@ class UpgradeExperience(val host: EnvironmentHost with internal.Agent) extends A result(true) } + @Callback(doc = """function():number -- suck experience from nearby. return the amount of sucked experience""") + def suck(context: Context, args: Arguments): Array[AnyRef] = { + val nearBounds = position.bounds + val farBounds = nearBounds.offset(Settings.get.suckXpRange, Settings.get.suckXpRange, Settings.get.suckXpRange) + val bounds = nearBounds.union(farBounds) + var gained = 0D + entitiesInBounds[EntityXPOrb](classOf[EntityXPOrb], bounds).foreach(orb => { + + if (!orb.isDead && orb.xpValue > 0) { + val copy = experience.toDouble + addExperience(orb.xpValue * Settings.get.robotSuckXpRate) + val added = (experience.toDouble - copy) / Settings.get.robotSuckXpRate + gained += added + orb.xpValue = (orb.xpValue - added.toInt) + if (orb.xpValue <= 0) { + orb.setDead() + } + } + }) + result(gained) + } + private def updateClient() = host match { case robot: internal.Robot => robot.synchronizeSlot(robot.componentSlot(node.address)) case _ =>