Made it possible to define colors for loot disks.

This commit is contained in:
Florian Nücke 2014-07-11 16:48:14 +02:00
parent c9e441caba
commit 539ceb83a1
3 changed files with 31 additions and 18 deletions

View File

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

View File

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

View File

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