Added robot.uuidFormat setting to control UUIDs assigned to robots' fake players. See comment in config for usage. Disclaimer: relatively untested.

This commit is contained in:
Florian Nücke 2014-12-05 14:12:11 +01:00
parent 2947ded770
commit 8cccc17ace
5 changed files with 25 additions and 2 deletions

View File

@ -304,6 +304,16 @@ opencomputers {
# block from another mod, the name will default to 'OpenComputers'.
nameFormat: "$player$.robot"
# Controls the UUID robots are given. You can either specify a fixed UUID
# here or use the two provided variables:
# - $random$, which will assign each robot a random UUID.
# - $player$, which assigns to each placed robot the UUID of the player
# that placed it (note: if robots are placed by fake players, i.e.
# other mods' blocks, they will get that mods' fake player's profile!)
# Note that if no player UUID is available this will be the same as
# $random$.
uuidFormat: "$player$"
# This controls how fast robots gain experience, and how that experience
# alters the stats.
xp {

View File

@ -96,6 +96,7 @@ class Settings(val config: Config) {
val useAndPlaceRange = config.getDouble("robot.useAndPlaceRange")
val itemDamageRate = config.getDouble("robot.itemDamageRate") max 0 min 1
val nameFormat = config.getString("robot.nameFormat")
val uuidFormat = config.getString("robot.uuidFormat")
// robot.xp
val baseXpToLevel = config.getDouble("robot.xp.baseValue") max 0

View File

@ -185,7 +185,7 @@ class RobotProxy extends RedstoneAware with traits.SpecialBlock {
}) match {
case Some((robot, owner, uuid)) =>
robot.owner = owner
robot.ownerUuid = uuid
robot.ownerUuid = Option(robot.determineUUID(uuid))
robot.info.load(stack)
robot.bot.node.changeBuffer(robot.info.robotEnergy - robot.bot.node.localBuffer)
robot.updateInventorySize()

View File

@ -124,6 +124,18 @@ class Robot extends traits.Computer with traits.PowerInformation with IFluidHand
private lazy val player_ = new robot.Player(this)
def determineUUID(playerUUID: Option[UUID] = None) = {
val format = Settings.get.uuidFormat
val randomUUID = UUID.randomUUID()
try UUID.fromString(format.
replaceAllLiterally("$random$", randomUUID.toString).
replaceAllLiterally("$player$", playerUUID.map(_.toString).getOrElse(randomUUID.toString))) catch {
case t: Throwable =>
OpenComputers.log.warn("Failed determining robot UUID, check your config's `uuidFormat` entry!", t)
randomUUID
}
}
// ----------------------------------------------------------------------- //
def name = info.name

View File

@ -49,7 +49,7 @@ import scala.reflect._
object Player {
def profileFor(robot: tileentity.Robot) = {
val uuid = robot.ownerUuid.getOrElse(UUID.randomUUID())
val uuid = robot.ownerUuid.getOrElse(robot.determineUUID())
val randomId = (robot.world.rand.nextInt(0xFFFFFF) + 1).toString
val name = Settings.get.nameFormat.
replace("$player$", robot.owner).