allow robot flight height values above 256, close #3515

This commit is contained in:
Adrian Siekierka 2022-09-02 19:41:50 +02:00
parent b381aa5190
commit ae644f3c74
3 changed files with 11 additions and 7 deletions

View File

@ -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

View File

@ -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"
)
)

View File

@ -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 <flightHeight> 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)