From 539ceb83a116bd50a36863bc243bf26ba813597c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Fri, 11 Jul 2014 16:48:14 +0200 Subject: [PATCH] Made it possible to define colors for loot disks. --- .../assets/opencomputers/loot/loot.properties | 18 +++++++----- src/main/scala/li/cil/oc/Items.scala | 2 ++ src/main/scala/li/cil/oc/common/Loot.scala | 29 ++++++++++++------- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/main/resources/assets/opencomputers/loot/loot.properties b/src/main/resources/assets/opencomputers/loot/loot.properties index 10d45b4a5..3ddab9ce5 100644 --- a/src/main/resources/assets/opencomputers/loot/loot.properties +++ b/src/main/resources/assets/opencomputers/loot/loot.properties @@ -1,12 +1,16 @@ # This file contains the list of floppy disks that can be found as loot. -# Each entry is a mapping of folder name to disk label. +# Each entry is a mapping of folder name to disk label. Parameters are +# the 'weight' of an item in the random generation process and the color +# of the floppy. The default weight is one. For example, a disk with +# weight 2 is two times as likely to be generated than an item with +# weight 1. The color defaults to gray. It must be a dye's ore-dict name. BetterShell=besh -Builder=build -OpenIRC=irc -OpenOS=openos -MazeGen=maze -OPPM=oppm +Builder=build:1:dyeCyan +OpenIRC=irc:1:dyeRed +OpenOS=openos:1:dyeGreen +MazeGen=maze:1:dyeBrown +OPPM=oppm:1:dyeLime # Higher chance to find the dig program, because it has the most immediate # use - OpenOS is craftable and IRC can be downloaded once an internet card # is available - which one needs anyway, to use the program... -TheDig=dig:3 +TheDig=dig:3:dyeBlue diff --git a/src/main/scala/li/cil/oc/Items.scala b/src/main/scala/li/cil/oc/Items.scala index b56d1602c..fcf04a2bd 100644 --- a/src/main/scala/li/cil/oc/Items.scala +++ b/src/main/scala/li/cil/oc/Items.scala @@ -5,6 +5,7 @@ import li.cil.oc.api.detail.{ItemAPI, ItemInfo} import li.cil.oc.common.InventorySlots.Tier import li.cil.oc.common.recipe.Recipes import li.cil.oc.common.{Loot, item} +import li.cil.oc.util.Color import li.cil.oc.util.mods.Mods import net.minecraft.block.Block import net.minecraft.creativetab.CreativeTabs @@ -215,6 +216,7 @@ object Items extends ItemAPI { val nbt = new NBTTagCompound("tag") nbt.setTag(Settings.namespace + "data", data) nbt.setString(Settings.namespace + "lootPath", "OpenOS") + nbt.setInteger(Settings.namespace + "color", Color.dyes.indexOf("dyeGreen")) val stack = super.createItemStack(amount) stack.setTagCompound(nbt) diff --git a/src/main/scala/li/cil/oc/common/Loot.scala b/src/main/scala/li/cil/oc/common/Loot.scala index 1660de8ba..af3ecd610 100644 --- a/src/main/scala/li/cil/oc/common/Loot.scala +++ b/src/main/scala/li/cil/oc/common/Loot.scala @@ -2,8 +2,10 @@ package li.cil.oc.common import java.io import java.util.Random +import java.util.logging.Level import li.cil.oc.common.recipe.Recipes +import li.cil.oc.util.Color import li.cil.oc.{OpenComputers, Settings, api} import net.minecraft.inventory.IInventory import net.minecraft.item.ItemStack @@ -78,21 +80,21 @@ object Loot extends WeightedRandomChestContent(api.Items.get("openOS").createIte private def parseLootDisks(list: java.util.Properties, acc: mutable.Map[String, (ItemStack, Int)]) { for (key <- list.stringPropertyNames if key != "OpenOS") { val value = list.getProperty(key) - val splitAt = value.lastIndexOf(':') - if (splitAt >= 0) { - val (name, count) = value.splitAt(splitAt) - try { - acc += key ->(createLootDisk(name, key), count.substring(1).toInt) - } - catch { - case _: Throwable => OpenComputers.log.warning("Bad loot descriptor: " + value) - } + try value.split(":") match { + case Array(name, count, color) => + acc += key -> ((createLootDisk(name, key, Some(color)), count.toInt)) + case Array(name, count) => + acc += key -> ((createLootDisk(name, key), count.toInt)) + case _ => + acc += key -> ((createLootDisk(value, key), 1)) + } + catch { + case t: Throwable => OpenComputers.log.log(Level.WARNING, "Bad loot descriptor: " + value, t) } - else acc += key ->(createLootDisk(value, key), 1) } } - private def createLootDisk(name: String, path: String) = { + private def createLootDisk(name: String, path: String, color: Option[String] = None) = { val data = new NBTTagCompound() data.setString(Settings.namespace + "fs.label", name) @@ -100,6 +102,11 @@ object Loot extends WeightedRandomChestContent(api.Items.get("openOS").createIte tag.setTag(Settings.namespace + "data", data) // Store this top level, so it won't get wiped on save. tag.setString(Settings.namespace + "lootPath", path) + color match { + case Some(oreDictName) => + tag.setInteger(Settings.namespace + "color", Color.dyes.indexOf(oreDictName)) + case _ => + } val disk = api.Items.get("lootDisk").createItemStack(1) disk.setTagCompound(tag)