From ae644f3c74002a4d22ac4efeef5d9914deb09cad Mon Sep 17 00:00:00 2001 From: Adrian Siekierka Date: Fri, 2 Sep 2022 19:41:50 +0200 Subject: [PATCH] allow robot flight height values above 256, close #3515 --- src/main/resources/application.conf | 2 +- src/main/scala/li/cil/oc/Settings.scala | 10 ++++++---- .../li/cil/oc/common/event/RobotCommonHandler.scala | 6 ++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index 70b8432c5..46cffac1c 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -309,7 +309,7 @@ opencomputers { # flight capabilities). # - Any position that has an adjacent block with a solid face towards the # position is valid (robots can "climb"). - # Set this to 256 to allow robots to fly whereever, as was the case + # Set this to -1 to allow robots to fly whereever, as was the case # before the 1.5 update. Consider using drones for cases where you need # unlimited flight capabilities instead! limitFlightHeight: 8 diff --git a/src/main/scala/li/cil/oc/Settings.scala b/src/main/scala/li/cil/oc/Settings.scala index f0206da1f..67e0d29ae 100644 --- a/src/main/scala/li/cil/oc/Settings.scala +++ b/src/main/scala/li/cil/oc/Settings.scala @@ -6,13 +6,11 @@ import java.net.InetAddress import java.nio.charset.StandardCharsets import java.security.SecureRandom import java.util.UUID - import com.google.common.net.InetAddresses import com.mojang.authlib.GameProfile import com.typesafe.config._ import cpw.mods.fml.common.Loader -import cpw.mods.fml.common.versioning.DefaultArtifactVersion -import cpw.mods.fml.common.versioning.VersionRange +import cpw.mods.fml.common.versioning.{DefaultArtifactVersion, VersionRange} import li.cil.oc.Settings.DebugCardAccess import li.cil.oc.common.Tier import li.cil.oc.integration.Mods @@ -101,7 +99,7 @@ class Settings(val config: Config) { val allowActivateBlocks = config.getBoolean("robot.allowActivateBlocks") val allowUseItemsWithDuration = config.getBoolean("robot.allowUseItemsWithDuration") val canAttackPlayers = config.getBoolean("robot.canAttackPlayers") - val limitFlightHeight = config.getInt("robot.limitFlightHeight") max 0 + val limitFlightHeight = config.getInt("robot.limitFlightHeight") max -1 val screwCobwebs = config.getBoolean("robot.notAfraidOfSpiders") val swingRange = config.getDouble("robot.swingRange") val useAndPlaceRange = config.getDouble("robot.useAndPlaceRange") @@ -568,6 +566,10 @@ object Settings { "misc.maxWirelessRange", "misc.maxOpenPorts", "computer.cpuComponentCount" + ), + // Upgrading to version 1.8.0, changed meaning of limitFlightHeight value. + VersionRange.createFromVersionSpec("[0.0, 1.8.0)") -> Array( + "computer.robot.limitFlightHeight" ) ) diff --git a/src/main/scala/li/cil/oc/common/event/RobotCommonHandler.scala b/src/main/scala/li/cil/oc/common/event/RobotCommonHandler.scala index a61eed9e1..9cafacd0d 100644 --- a/src/main/scala/li/cil/oc/common/event/RobotCommonHandler.scala +++ b/src/main/scala/li/cil/oc/common/event/RobotCommonHandler.scala @@ -26,7 +26,7 @@ object RobotCommonHandler { @SubscribeEvent def onRobotMove(e: RobotMoveEvent.Pre): Unit = { - if (Settings.get.limitFlightHeight < 256) e.agent match { + if (Settings.get.limitFlightHeight >= 0) e.agent match { case robot: Robot => val world = robot.world var maxFlyingHeight = Settings.get.limitFlightHeight @@ -43,8 +43,9 @@ object RobotCommonHandler { collect { case Some(item: UpgradeHover) => maxFlyingHeight = math.max(maxFlyingHeight, Settings.get.upgradeFlightHeight(item.tier)) } def isMovingDown = e.direction == ForgeDirection.DOWN + def bypassesFlightLimit = maxFlyingHeight >= world.getHeight def hasAdjacentBlock(pos: BlockPosition) = ForgeDirection.VALID_DIRECTIONS.exists(side => world.isSideSolid(pos.offset(side), side.getOpposite)) - def isWithinFlyingHeight(pos: BlockPosition) = maxFlyingHeight >= world.getHeight || (1 to maxFlyingHeight).exists(n => !world.isAirBlock(pos.offset(ForgeDirection.DOWN, n))) + def isWithinFlyingHeight(pos: BlockPosition) = (1 to maxFlyingHeight).exists(n => !world.isAirBlock(pos.offset(ForgeDirection.DOWN, n))) val startPos = BlockPosition(robot) val targetPos = startPos.offset(e.direction) // New movement rules as of 1.5: @@ -53,6 +54,7 @@ object RobotCommonHandler { // 3. Positions up to above a block are valid (limited flight capabilities). // 4. Any position that has an adjacent block with a solid face towards the position is valid (robots can "climb"). val validMove = isMovingDown || + bypassesFlightLimit || hasAdjacentBlock(startPos) || hasAdjacentBlock(targetPos) || isWithinFlyingHeight(startPos)