using 'smelting dictionary' for smelter recipes

This commit is contained in:
minjaesong
2024-03-10 00:46:46 +09:00
parent c6999e0794
commit 247cf9bd33
14 changed files with 681 additions and 111 deletions

View File

@@ -41,12 +41,12 @@
"75";"item@basegame:171";"item@basegame:171";"BLOCK_TRUNK_ROSEWOOD";"0.0312";"0.0312";"0.0312";"0.0312";"17";"900";"WOOD";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"TREE,TREETRUNK,TREELARGE,NATURAL" "75";"item@basegame:171";"item@basegame:171";"BLOCK_TRUNK_ROSEWOOD";"0.0312";"0.0312";"0.0312";"0.0312";"17";"900";"WOOD";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"TREE,TREETRUNK,TREELARGE,NATURAL"
# sabulous # sabulous
"80";"80";"80";"BLOCK_SAND";"0.1252";"0.1252";"0.1252";"0.1252";"12";"1600";"SAND";"1";"0";"0";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"SAND,NATURAL,WARM" "80";"80";"80";"BLOCK_SAND";"0.1252";"0.1252";"0.1252";"0.1252";"12";"1600";"SAND";"1";"0";"0";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"SAND,NATURAL,WARM,SMELTABLE"
"81";"81";"81";"BLOCK_SAND_WHITE";"0.1252";"0.1252";"0.1252";"0.1252";"12";"1600";"SAND";"1";"0";"0";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"SAND,NATURAL,WARM" "81";"81";"81";"BLOCK_SAND_WHITE";"0.1252";"0.1252";"0.1252";"0.1252";"12";"1600";"SAND";"1";"0";"0";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"SAND,NATURAL,WARM,SMELTABLE"
"82";"82";"82";"BLOCK_SAND_RED";"0.1252";"0.1252";"0.1252";"0.1252";"12";"1600";"SAND";"1";"0";"0";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"SAND,NATURAL,WARM" "82";"82";"82";"BLOCK_SAND_RED";"0.1252";"0.1252";"0.1252";"0.1252";"12";"1600";"SAND";"1";"0";"0";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"SAND,NATURAL,WARM,SMELTABLE"
"83";"83";"83";"BLOCK_SAND_DESERT";"0.1252";"0.1252";"0.1252";"0.1252";"12";"1600";"SAND";"1";"0";"0";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"SAND,NATURAL,WARM" "83";"83";"83";"BLOCK_SAND_DESERT";"0.1252";"0.1252";"0.1252";"0.1252";"12";"1600";"SAND";"1";"0";"0";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"SAND,NATURAL,WARM,SMELTABLE"
"84";"84";"84";"BLOCK_SAND_BLACK";"0.1252";"0.1252";"0.1252";"0.1252";"12";"1600";"SAND";"1";"0";"0";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"SAND,NATURAL,WARM" "84";"84";"84";"BLOCK_SAND_BLACK";"0.1252";"0.1252";"0.1252";"0.1252";"12";"1600";"SAND";"1";"0";"0";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"SAND,NATURAL,WARM,SMELTABLE"
"85";"85";"85";"BLOCK_SAND_GREEN";"0.1252";"0.1252";"0.1252";"0.1252";"12";"1600";"SAND";"1";"0";"0";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"SAND,NATURAL,WARM" "85";"85";"85";"BLOCK_SAND_GREEN";"0.1252";"0.1252";"0.1252";"0.1252";"12";"1600";"SAND";"1";"0";"0";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"SAND,NATURAL,WARM,SMELTABLE"
"96";"96";"96";"BLOCK_GRAVEL";"0.1252";"0.1252";"0.1252";"0.1252";"12";"1700";"GRVL";"1";"0";"0";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"GRAVEL,NATURAL" "96";"96";"96";"BLOCK_GRAVEL";"0.1252";"0.1252";"0.1252";"0.1252";"12";"1700";"GRVL";"1";"0";"0";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"GRAVEL,NATURAL"
"97";"97";"97";"BLOCK_GRAVEL_GREY";"0.1252";"0.1252";"0.1252";"0.1252";"12";"1700";"GRVL";"1";"0";"0";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"GRAVEL,NATURAL" "97";"97";"97";"BLOCK_GRAVEL_GREY";"0.1252";"0.1252";"0.1252";"0.1252";"12";"1700";"GRVL";"1";"0";"0";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"GRAVEL,NATURAL"
Can't render this file because it contains an unexpected character in line 18 and column 2.

View File

@@ -10,6 +10,7 @@ GetAV
GetFaction GetFaction
GetLocale GetLocale
GetTime GetTime
HasItem
ImportLayerData ImportLayerData
ImportWorld ImportWorld
Inventory Inventory
1 CatStdout
10 GetFaction
11 GetLocale
12 GetTime
13 HasItem
14 ImportLayerData
15 ImportWorld
16 Inventory

View File

@@ -48,7 +48,6 @@ id;classname;tags
47;net.torvald.terrarum.modulebasegame.gameitems.ItemWrench;TOOL,WRENCH 47;net.torvald.terrarum.modulebasegame.gameitems.ItemWrench;TOOL,WRENCH
# ingots # ingots
26;net.torvald.terrarum.modulebasegame.gameitems.IngotSteel;INGOT
112;net.torvald.terrarum.modulebasegame.gameitems.IngotCopper;INGOT 112;net.torvald.terrarum.modulebasegame.gameitems.IngotCopper;INGOT
113;net.torvald.terrarum.modulebasegame.gameitems.IngotIron;INGOT 113;net.torvald.terrarum.modulebasegame.gameitems.IngotIron;INGOT
114;net.torvald.terrarum.modulebasegame.gameitems.ItemCoalCoke;COMBUSTIBLE 114;net.torvald.terrarum.modulebasegame.gameitems.ItemCoalCoke;COMBUSTIBLE
@@ -58,6 +57,15 @@ id;classname;tags
118;net.torvald.terrarum.modulebasegame.gameitems.IngotSilver;INGOT 118;net.torvald.terrarum.modulebasegame.gameitems.IngotSilver;INGOT
119;net.torvald.terrarum.modulebasegame.gameitems.IngotLead;INGOT 119;net.torvald.terrarum.modulebasegame.gameitems.IngotLead;INGOT
# alloys
26;net.torvald.terrarum.modulebasegame.gameitems.IngotSteel;INGOT,ALLOY
176;net.torvald.terrarum.modulebasegame.gameitems.IngotBronze;INGOT,ALLOY
177;net.torvald.terrarum.modulebasegame.gameitems.IngotBrass;INGOT,ALLOY
178;net.torvald.terrarum.modulebasegame.gameitems.IngotElectrum;INGOT,ALLOY
179;net.torvald.terrarum.modulebasegame.gameitems.IngotSilverBillon;INGOT,ALLOY
180;net.torvald.terrarum.modulebasegame.gameitems.IngotRosegold;INGOT,ALLOY
181;net.torvald.terrarum.modulebasegame.gameitems.IngotSolder;INGOT,ALLOY
# ores # ores
128;net.torvald.terrarum.modulebasegame.gameitems.OreCopper;SMELTABLE 128;net.torvald.terrarum.modulebasegame.gameitems.OreCopper;SMELTABLE
129;net.torvald.terrarum.modulebasegame.gameitems.OreIron;SMELTABLE 129;net.torvald.terrarum.modulebasegame.gameitems.OreIron;SMELTABLE
@@ -82,10 +90,10 @@ id;classname;tags
163;net.torvald.terrarum.modulebasegame.gameitems.ItemSeedRosewood;SEEDLING 163;net.torvald.terrarum.modulebasegame.gameitems.ItemSeedRosewood;SEEDLING
# tree logs # tree logs
168;net.torvald.terrarum.modulebasegame.gameitems.ItemLogsOak;COMBUSTIBLE,SMELTABLE 168;net.torvald.terrarum.modulebasegame.gameitems.ItemLogsOak;COMBUSTIBLE,SMELTABLE,LOGS
169;net.torvald.terrarum.modulebasegame.gameitems.ItemLogsEbony;COMBUSTIBLE,SMELTABLE 169;net.torvald.terrarum.modulebasegame.gameitems.ItemLogsEbony;COMBUSTIBLE,SMELTABLE,LOGS
170;net.torvald.terrarum.modulebasegame.gameitems.ItemLogsBirch;COMBUSTIBLE,SMELTABLE 170;net.torvald.terrarum.modulebasegame.gameitems.ItemLogsBirch;COMBUSTIBLE,SMELTABLE,LOGS
171;net.torvald.terrarum.modulebasegame.gameitems.ItemLogsRosewood;COMBUSTIBLE,SMELTABLE 171;net.torvald.terrarum.modulebasegame.gameitems.ItemLogsRosewood;COMBUSTIBLE,SMELTABLE,LOGS
256;net.torvald.terrarum.modulebasegame.gameitems.ItemSwingingDoorOak;FIXTURE 256;net.torvald.terrarum.modulebasegame.gameitems.ItemSwingingDoorOak;FIXTURE
1 id classname tags
48 # ingots
49 26 112 net.torvald.terrarum.modulebasegame.gameitems.IngotSteel net.torvald.terrarum.modulebasegame.gameitems.IngotCopper INGOT
50 112 113 net.torvald.terrarum.modulebasegame.gameitems.IngotCopper net.torvald.terrarum.modulebasegame.gameitems.IngotIron INGOT
113 net.torvald.terrarum.modulebasegame.gameitems.IngotIron INGOT
51 114 net.torvald.terrarum.modulebasegame.gameitems.ItemCoalCoke COMBUSTIBLE
52 115 net.torvald.terrarum.modulebasegame.gameitems.IngotZinc INGOT
53 116 net.torvald.terrarum.modulebasegame.gameitems.IngotTin INGOT
57 # ores # alloys
58 128 26 net.torvald.terrarum.modulebasegame.gameitems.OreCopper net.torvald.terrarum.modulebasegame.gameitems.IngotSteel SMELTABLE INGOT,ALLOY
59 129 176 net.torvald.terrarum.modulebasegame.gameitems.OreIron net.torvald.terrarum.modulebasegame.gameitems.IngotBronze SMELTABLE INGOT,ALLOY
60 177 net.torvald.terrarum.modulebasegame.gameitems.IngotBrass INGOT,ALLOY
61 178 net.torvald.terrarum.modulebasegame.gameitems.IngotElectrum INGOT,ALLOY
62 179 net.torvald.terrarum.modulebasegame.gameitems.IngotSilverBillon INGOT,ALLOY
63 180 net.torvald.terrarum.modulebasegame.gameitems.IngotRosegold INGOT,ALLOY
64 181 net.torvald.terrarum.modulebasegame.gameitems.IngotSolder INGOT,ALLOY
65 # ores
66 128 net.torvald.terrarum.modulebasegame.gameitems.OreCopper SMELTABLE
67 129 net.torvald.terrarum.modulebasegame.gameitems.OreIron SMELTABLE
68 130 net.torvald.terrarum.modulebasegame.gameitems.OreCoal SMELTABLE,COMBUSTIBLE
69 130 131 net.torvald.terrarum.modulebasegame.gameitems.OreCoal net.torvald.terrarum.modulebasegame.gameitems.OreZinc SMELTABLE,COMBUSTIBLE SMELTABLE
70 131 132 net.torvald.terrarum.modulebasegame.gameitems.OreZinc net.torvald.terrarum.modulebasegame.gameitems.OreTin SMELTABLE
71 132 133 net.torvald.terrarum.modulebasegame.gameitems.OreTin net.torvald.terrarum.modulebasegame.gameitems.OreGold SMELTABLE
90 256 257 net.torvald.terrarum.modulebasegame.gameitems.ItemSwingingDoorOak net.torvald.terrarum.modulebasegame.gameitems.ItemSwingingDoorEbony FIXTURE
91 257 258 net.torvald.terrarum.modulebasegame.gameitems.ItemSwingingDoorEbony net.torvald.terrarum.modulebasegame.gameitems.ItemSwingingDoorBirch FIXTURE
92 258 259 net.torvald.terrarum.modulebasegame.gameitems.ItemSwingingDoorBirch net.torvald.terrarum.modulebasegame.gameitems.ItemSwingingDoorRosewood FIXTURE
93 259 320 net.torvald.terrarum.modulebasegame.gameitems.ItemSwingingDoorRosewood net.torvald.terrarum.modulebasegame.gameitems.ItemWorldPortal FIXTURE FIXTURE,STATION
94 320 # data storage (discs net.torvald.terrarum.modulebasegame.gameitems.ItemWorldPortal 256)
95 # data storage (discs # 32768 is a reserved number for a blank disc
96 # 32768 is a reserved number for a blank disc 32769 net.torvald.terrarum.modulebasegame.gameitems.MusicDisc01 MUSIC,PHONO
97 32769 32770 net.torvald.terrarum.modulebasegame.gameitems.MusicDisc01 net.torvald.terrarum.modulebasegame.gameitems.MusicDisc02 MUSIC,PHONO
98 32770 32771 net.torvald.terrarum.modulebasegame.gameitems.MusicDisc02 net.torvald.terrarum.modulebasegame.gameitems.MusicDisc03 MUSIC,PHONO
99 32771 32772 net.torvald.terrarum.modulebasegame.gameitems.MusicDisc03 net.torvald.terrarum.modulebasegame.gameitems.MusicDisc04 MUSIC,PHONO

View File

@@ -0,0 +1,27 @@
{
/* as for the plus operator, the itemIDs must be sorted lexicographically and first word should come left */
"item@basegame:112+item@basegame:116": { /* copper + tin -> bronze */
"difficulty": 1.0,
"product": [1, "item@basegame:176"]
},
"item@basegame:112+item@basegame:115": { /* copper + zinc -> brass */
"difficulty": 1.0,
"product": [1, "item@basegame:177"]
},
"item@basegame:117+item@basegame:118": { /* gold + silver -> electrum */
"difficulty": 1.0,
"product": [1, "item@basegame:178"]
},
"item@basegame:112+item@basegame:118": { /* copper + silver -> silver billon */
"difficulty": 1.0,
"product": [1, "item@basegame:179"]
},
"item@basegame:112+item@basegame:117": { /* copper + gold -> rose gold */
"difficulty": 1.0,
"product": [1, "item@basegame:180"]
},
"item@basegame:116+item@basegame:119": { /* tin + lead -> solder */
"difficulty": 1.0,
"product": [1, "item@basegame:181"]
}
}

View File

@@ -0,0 +1,48 @@
{
"$SAND": { /* sand -> crude glass */
"difficulty": 1.0,
"product": [1, "basegame:148"]
},
"item@basegame:144": { /* quartz -> clean glass */
"difficulty": 1.0,
"product": [1, "basegame:149"]
},
"$LOGS": { /* logs -> charcoal */
"difficulty": 1.0,
"product": [1, "item@basegame:29"]
},
"item@basegame:128": { /* copper ore -> ingot */
"difficulty": 1.0,
"product": [1, "item@basegame:112"]
},
"item@basegame:129": { /* iron ore -> ingot */
"difficulty": 1.0,
"product": [1, "item@basegame:113"]
},
"item@basegame:130": { /* coal -> coke */
"difficulty": 1.0,
"product": [1, "item@basegame:114"]
},
"item@basegame:131": { /* zinc ore -> ingot */
"difficulty": 1.0,
"product": [1, "item@basegame:115"]
},
"item@basegame:132": { /* tin ore -> ingot */
"difficulty": 1.0,
"product": [1, "item@basegame:116"]
},
"item@basegame:133": { /* gold ore -> ingot */
"difficulty": 1.0,
"product": [1, "item@basegame:117"]
},
"item@basegame:134": { /* silver ore -> ingot */
"difficulty": 1.0,
"product": [1, "item@basegame:118"]
},
"item@basegame:135": { /* lead ore -> ingot */
"difficulty": 1.0,
"product": [1, "item@basegame:119"]
}
}

View File

@@ -846,11 +846,16 @@ object ModMgr {
object GameCraftingRecipeLoader { object GameCraftingRecipeLoader {
const val recipePath = "crafting/" const val recipePath = "crafting/"
const val smeltingPath = "smelting/"
@JvmStatic operator fun invoke(module: String) { @JvmStatic operator fun invoke(module: String) {
getFile(module, recipePath).listFiles { it: File -> it.name.lowercase().endsWith(".json") }?.forEach { jsonFile -> getFile(module, recipePath).listFiles { it: File -> it.name.lowercase().endsWith(".json") }?.forEach { jsonFile ->
Terrarum.craftingCodex.addFromJson(JsonFetcher(jsonFile), module, jsonFile.name) Terrarum.craftingCodex.addFromJson(JsonFetcher(jsonFile), module, jsonFile.name)
} }
getFile(module, smeltingPath).listFiles { it: File -> it.name.lowercase().endsWith(".json") }?.forEach { jsonFile ->
Terrarum.craftingCodex.addSmeltingFromJson(JsonFetcher(jsonFile), module, jsonFile.name)
}
} }
} }

View File

@@ -47,8 +47,6 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
*/ */
@Transient open var smokiness = Float.POSITIVE_INFINITY @Transient open var smokiness = Float.POSITIVE_INFINITY
@Transient open var smeltingProduct: ItemID? = null
open var dynamicID: ItemID = originalID open var dynamicID: ItemID = originalID
/** /**
* if the ID is a Actor range, it's an actor contained in a pocket. * if the ID is a Actor range, it's an actor contained in a pocket.

View File

@@ -1,13 +1,11 @@
package net.torvald.terrarum.itemproperties package net.torvald.terrarum.itemproperties
import com.badlogic.gdx.utils.JsonValue import com.badlogic.gdx.utils.JsonValue
import net.torvald.terrarum.INGAME import net.torvald.terrarum.ItemCodex
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameitems.ItemID import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameitems.isBlock import net.torvald.terrarum.gameitems.isBlock
import net.torvald.terrarum.gameitems.isWall import net.torvald.terrarum.gameitems.isWall
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
import net.torvald.terrarum.utils.forEachSiblings import net.torvald.terrarum.utils.forEachSiblings
import net.torvald.terrarum.utils.forEachSiblingsIndexed import net.torvald.terrarum.utils.forEachSiblingsIndexed
@@ -22,6 +20,8 @@ class CraftingCodex {
*/ */
@Transient internal val props = HashMap<ItemID, ArrayList<CraftingRecipe>>() // the key ItemID and value.product must be equal @Transient internal val props = HashMap<ItemID, ArrayList<CraftingRecipe>>() // the key ItemID and value.product must be equal
@Transient internal val smeltingProps = HashMap<String, SmeltingRecipe>()
fun addRecipe(recipe: CraftingRecipe) { fun addRecipe(recipe: CraftingRecipe) {
val product = recipe.product val product = recipe.product
if (props.containsKey(product)) { if (props.containsKey(product)) {
@@ -88,6 +88,27 @@ class CraftingCodex {
} }
} }
fun addSmeltingFromJson(json: JsonValue, moduleName: String, fileName:String) {
if (moduleName.filter { it.code in 33..127 } .length < 5)
throw IllegalStateException("Invalid module name: ${moduleName}")
json.forEachSiblings { key0, details ->
val key = key0.split('+').map { it.trim() }.sorted().joinToString("+")
val difficulty = details["difficulty"].asFloat()
val recipes = ArrayList<SmeltingRecipe>()
val moq = details["product"][0].asLong()
val product = details["product"][1].asString()
// sanity check
if (moq !in 1..1000) {
throw IllegalStateException("Smelting Recipe for item '$product' has invalid moq of ${moq}")
}
// register to the main props
smeltingProps[key] = SmeltingRecipe(difficulty, key.split('+').toTypedArray(), moq, product, "$moduleName/$fileName")
}
}
/** /**
* Returns list of all possible recipes for the item; null if there is no recipe * Returns list of all possible recipes for the item; null if there is no recipe
* *
@@ -98,6 +119,55 @@ class CraftingCodex {
return it.ifEmpty { null } return it.ifEmpty { null }
} }
private fun getCombinations0(data: List<List<String>>): List<List<String>> {
if (data.isEmpty()) {
return listOf(emptyList())
}
val first = data.first()
val rest = data.subList(1, data.size)
val combinations = mutableListOf<List<String>>()
for (sublist in getCombinations0(rest)) {
for (item in first) {
combinations.add(listOf(item) + sublist)
}
}
return combinations
}
private fun getCombinations(data: List<List<String>>): List<String> {
val r = mutableListOf<String>()
val l = getCombinations0(data)
l.forEach {
r.add(it.sorted().joinToString("+"))
}
return r
}
/**
* @return Null if:
* - at least one of the vararg contains null
* - a smelting product of given items does not exist
* - Otherwise, a smelting product of the given items are returned
*/
fun getSmeltingProductOf(vararg item: ItemID?): SmeltingRecipe? {
if (item.contains(null)) return null
val keysPossible0: List<List<String>> =
(item.map { listOf(it!!) + (ItemCodex[it]?.tags?.toList()?.map { "\$" + it } ?: emptyList()) })
val keysPossible = getCombinations(keysPossible0)
// iterate through all the combinations of keys
var found: SmeltingRecipe? = null
var i = 0
while (found == null && i < keysPossible.size) {
found = smeltingProps[keysPossible[i]]
i += 1
}
return found
}
/** /**
* Returns list of items that uses the given `item`. * Returns list of items that uses the given `item`.
* *
@@ -118,6 +188,7 @@ class CraftingCodex {
} }
} }
/** /**
* @return list of itemIDs and corresponding recipes * @return list of itemIDs and corresponding recipes
*/ */
@@ -128,6 +199,7 @@ class CraftingCodex {
data class SmeltingRecipe(val difficulty: Float, val ingredients: Array<ItemID>, val moq: Long, val item: ItemID, val addedBy: String)
data class CraftingRecipe(val workbench: String, val ingredients: Array<CraftingIngredients>, val moq: Long, val product: ItemID, val addedBy: String) data class CraftingRecipe(val workbench: String, val ingredients: Array<CraftingIngredients>, val moq: Long, val product: ItemID, val addedBy: String)
data class CraftingIngredients(val key: String, val keyMode: CraftingItemKeyMode, val qty: Long) { data class CraftingIngredients(val key: String, val keyMode: CraftingItemKeyMode, val qty: Long) {
override fun toString() = "$qty ${if (keyMode == CraftingItemKeyMode.TAG) "\$$key" else "$key"}" override fun toString() = "$qty ${if (keyMode == CraftingItemKeyMode.TAG) "\$$key" else "$key"}"

View File

@@ -50,8 +50,7 @@ class EntryPoint : ModuleEntryPoint() {
// add smelting recipe for sands // add smelting recipe for sands
BlockCodex.filter { it.hasTag("SAND") }.forEach { (itemID, _) -> BlockCodex.filter { it.hasTag("SAND") }.forEach { (itemID, _) ->
ItemCodex[itemID]!!.tags.add("SMELTABLE") // ItemCodex[itemID]!!.tags.add("SMELTABLE")
ItemCodex[itemID]!!.smeltingProduct = "basegame:148"
} }
println("\n[Basegame.EntryPoint] Welcome back!") println("\n[Basegame.EntryPoint] Welcome back!")

View File

@@ -0,0 +1,40 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.*
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
/**
* Created by minjaesong on 2024-03-10.
*/
object HasItem : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size != 2)
printUsage()
else {
val it = args[1]
val hasBlock = BlockCodex.getOrNull(it) != null
val blockTags = BlockCodex.getOrNull(it)?.tags?.toList()?.sorted()?.joinToString()?.let { "($it)" } ?: ""
val hasItem = ItemCodex[it] != null
val itemTags = ItemCodex[it]?.tags?.toList()?.sorted()?.joinToString()?.let { "($it)" } ?: ""
val hasWire = WireCodex.getOrNull(it) != null
val wireTags = WireCodex.getOrNull(it)?.tags?.toList()?.sorted()?.joinToString()?.let { "($it)" } ?: ""
val hasOre = OreCodex.getOrNull(it) != null
val oreTags = OreCodex.getOrNull(it)?.tags?.toList()?.sorted()?.joinToString()?.let { "($it)" } ?: ""
Echo("${ccY}hasBlock? $ccG$hasBlock $ccO$blockTags")
Echo("${ccY}hasWire? $ccG$hasWire $ccO$wireTags")
Echo("${ccY}hasOre? $ccG$hasOre $ccO$oreTags")
Echo("${ccM}hasItem? $ccG$hasItem $ccO$itemTags")
}
}
override fun printUsage() {
Echo("Usage: hasitem itemid")
Echo("Prints the information if the item exists in the game")
}
}

View File

@@ -0,0 +1,389 @@
package net.torvald.terrarum.modulebasegame.gameactors
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.gdx.graphics.Cvec
import net.torvald.random.HQRNG
import net.torvald.spriteanimation.SheetSpriteAnimation
import net.torvald.terrarum.*
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
import net.torvald.terrarum.audio.MusicContainer
import net.torvald.terrarum.audio.dsp.Gain
import net.torvald.terrarum.audio.dsp.NullFilter
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.Hitbox
import net.torvald.terrarum.gameactors.Lightbox
import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameparticles.ParticleVanishingSprite
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.ui.UISmelterBasic
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/**
* Created by minjaesong on 2024-03-09.
*/
class FixtureAlloyingCrucible : FixtureBase {
var fuelCaloriesNow = 0.0 // arbitrary number, may as well be watts or joules
var fuelCaloriesMax: Double? = null
var temperature = 0f // 0f..1f
var progress = 0f // 0f..1f
internal var oreItem1: InventoryPair? = null
internal var oreItem2: InventoryPair? = null
internal var fireboxItem: InventoryPair? = null
internal var productItem: InventoryPair? = null
@Transient val oreItem1Status = object : SmelterItemStatus {
override fun set(itm: ItemID, qty: Long) {
if (oreItem1 != null) oreItem1!!.set(itm, qty)
else oreItem1 = InventoryPair(itm, qty)
}
override fun changeCount(delta: Long) {
oreItem1!!.qty += delta
if (oreItem1!!.qty <= 0L) {
oreItem1 = null
}
}
override fun nullify() {
oreItem1 = null
}
override fun isNull(): Boolean {
return oreItem1 == null
}
override val itm: ItemID?
get() = oreItem1?.itm
override val qty: Long?
get() = oreItem1?.qty
}
@Transient val oreItem2Status = object : SmelterItemStatus {
override fun set(itm: ItemID, qty: Long) {
if (oreItem2 != null) oreItem2!!.set(itm, qty)
else oreItem2 = InventoryPair(itm, qty)
}
override fun changeCount(delta: Long) {
oreItem2!!.qty += delta
if (oreItem2!!.qty <= 0L) {
oreItem2 = null
}
}
override fun nullify() {
oreItem2 = null
}
override fun isNull(): Boolean {
return oreItem2 == null
}
override val itm: ItemID?
get() = oreItem2?.itm
override val qty: Long?
get() = oreItem2?.qty
}
@Transient val fireboxItemStatus = object : SmelterItemStatus {
override fun set(itm: ItemID, qty: Long) {
if (fireboxItem != null) fireboxItem!!.set(itm, qty)
else fireboxItem = InventoryPair(itm, qty)
}
override fun changeCount(delta: Long) {
fireboxItem!!.qty += delta
if (fireboxItem!!.qty <= 0L) {
fireboxItem = null
}
}
override fun nullify() {
fireboxItem = null
}
override fun isNull(): Boolean {
return fireboxItem == null
}
override val itm: ItemID?
get() = fireboxItem?.itm
override val qty: Long?
get() = fireboxItem?.qty
}
@Transient val productItemStatus = object : SmelterItemStatus {
override fun set(itm: ItemID, qty: Long) {
if (productItem != null) productItem!!.set(itm, qty)
else productItem = InventoryPair(itm, qty)
}
override fun changeCount(delta: Long) {
productItem!!.qty += delta
if (productItem!!.qty <= 0L) {
productItem = null
}
}
override fun nullify() {
productItem = null
}
override fun isNull(): Boolean {
return productItem == null
}
override val itm: ItemID?
get() = productItem?.itm
override val qty: Long?
get() = productItem?.qty
}
override val canBeDespawned: Boolean
get() = oreItem1 == null && oreItem2 == null && fireboxItem == null && productItem == null
init {
CommonResourcePool.addToLoadingList("basegame/sprites/fixtures/alloying_furnace.tga") {
TextureRegionPack(ModMgr.getGdxFile("basegame", "sprites/fixtures/alloying_furnace.tga"), 32, 32)
}
CommonResourcePool.addToLoadingList("basegame/sprites/fixtures/alloying_furnace_emsv.tga") {
TextureRegionPack(ModMgr.getGdxFile("basegame", "sprites/fixtures/alloying_furnace_emsv.tga"), 32, 32)
}
CommonResourcePool.loadAll()
}
constructor() : super(
BlockBox(BlockBox.NO_COLLISION, 2, 2), // temporary value, will be overwritten by spawn()
nameFun = { Lang["ITEM_ALLOYING_SMELTER"] },
) {
CommonResourcePool.addToLoadingList("particles-tiki_smoke.tga") {
TextureRegionPack(ModMgr.getGdxFile("basegame", "particles/bigger_smoke.tga"), 16, 16)
}
CommonResourcePool.loadAll()
density = BlockCodex[Block.STONE].density.toDouble()
setHitboxDimension(32, 32, 0, 0)
makeNewSprite(CommonResourcePool.getAsTextureRegionPack("basegame/sprites/fixtures/alloying_furnace.tga")).let {
it.setRowsAndFrames(1,1)
}
makeNewSpriteEmissive(CommonResourcePool.getAsTextureRegionPack("basegame/sprites/fixtures/alloying_furnace_emsv.tga")).let {
it.setRowsAndFrames(1,1)
}
actorValue[AVKey.BASEMASS] = 100.0
// this.mainUI = UIAlloyingCrucible(this)
}
@Transient val static = MusicContainer("bonfire", ModMgr.getFile("basegame", "audio/effects/static/bonfire.ogg"), true)
@Transient val light = Cvec(0.5f, 0.18f, 0f, 0f)
@Transient override var lightBoxList = arrayListOf(Lightbox(Hitbox(0.0, 0.0, TILE_SIZED * 2, TILE_SIZED * 2), light))
@Transient private val actorBlocks = arrayOf(
arrayOf(Block.ACTORBLOCK_NO_COLLISION, null),
arrayOf(Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION),
)
override fun placeActorBlocks() {
forEachBlockbox { x, y, ox, oy ->
val tile = actorBlocks[oy][ox]
if (tile != null) {
world!!.setTileTerrain(x, y, tile, true)
}
}
}
private var nextDelayBase = 0.25f // use smokiness value of the item
private var nextDelay = 0.25f // use smokiness value of the item
private var spawnTimer = 0f
@Transient private val RNG = HQRNG()
override fun drawEmissive(frameDelta: Float, batch: SpriteBatch) {
if (isVisible && spriteEmissive != null) {
BlendMode.resolve(drawMode, batch)
(spriteEmissive as SheetSpriteAnimation).currentFrame = 1 // unlit
drawSpriteInGoodPosition(frameDelta, spriteEmissive!!, batch, 2, Color.WHITE)
(spriteEmissive as SheetSpriteAnimation).currentFrame = 0 // lit
val r = 1f - (temperature - 1f).sqr()
val g = (2f * temperature - 1f).coerceIn(0f, 1f)
drawSpriteInGoodPosition(frameDelta, spriteEmissive!!, batch, 2, Color(r, g, g, 1f))
}
// debug display of hIntTilewiseHitbox
if (KeyToggler.isOn(Input.Keys.F9)) {
val blockMark = CommonResourcePool.getAsTextureRegionPack("blockmarkings_common").get(0, 0)
for (y in 0..intTilewiseHitbox.height.toInt() + 1) {
batch.color = if (y == intTilewiseHitbox.height.toInt() + 1) HITBOX_COLOURS1 else HITBOX_COLOURS0
for (x in 0..intTilewiseHitbox.width.toInt()) {
batch.draw(blockMark,
(intTilewiseHitbox.startX.toFloat() + x) * TerrarumAppConfiguration.TILE_SIZEF,
(intTilewiseHitbox.startY.toFloat() + y) * TerrarumAppConfiguration.TILE_SIZEF
)
}
}
batch.color = Color.WHITE
}
}
override fun drawBody(frameDelta: Float, batch: SpriteBatch) {
if (isVisible && sprite != null) {
BlendMode.resolve(drawMode, batch)
(sprite as SheetSpriteAnimation).currentFrame = 1 // unlit
drawSpriteInGoodPosition(frameDelta, sprite!!, batch, forcedColourFilter = Color.WHITE)
(sprite as SheetSpriteAnimation).currentFrame = 2 // lit overlay
val r = 1f - (temperature - 1f).sqr()
val g = (2f * temperature - 1f).coerceIn(0f, 1f)
drawSpriteInGoodPosition(frameDelta, sprite!!, batch, forcedColourFilter = Color(1f, g, g, r))
}
// debug display of hIntTilewiseHitbox
if (KeyToggler.isOn(Input.Keys.F9)) {
val blockMark = CommonResourcePool.getAsTextureRegionPack("blockmarkings_common").get(0, 0)
for (y in 0..intTilewiseHitbox.height.toInt() + 1) {
batch.color = if (y == intTilewiseHitbox.height.toInt() + 1) HITBOX_COLOURS1 else HITBOX_COLOURS0
for (x in 0..intTilewiseHitbox.width.toInt()) {
batch.draw(blockMark,
(intTilewiseHitbox.startX.toFloat() + x) * TerrarumAppConfiguration.TILE_SIZEF,
(intTilewiseHitbox.startY.toFloat() + y) * TerrarumAppConfiguration.TILE_SIZEF
)
}
}
batch.color = Color.WHITE
}
}
override fun updateImpl(delta: Float) {
super.updateImpl(delta)
val fuelItemProp = ItemCodex[fireboxItem?.itm]
// consume fuel
if (fuelCaloriesNow > 0f) {
fuelCaloriesNow -= FixtureSmelterBasic.FUEL_CONSUMPTION
// raise temperature
temperature += 1f /2048f
}
// take fuel from the item slot
else if (fuelCaloriesNow <= 0f && fuelItemProp?.calories != null && fireboxItem!!.qty > 0L) {
fuelCaloriesNow = fuelItemProp.calories
fuelCaloriesMax = fuelItemProp.calories
nextDelayBase = fuelItemProp.smokiness
nextDelay = (nextDelayBase * (1.0 + RNG.nextTriangularBal() * 0.1)).toFloat()
fireboxItemStatus.changeCount(-1)
}
// no item on the slot
else if (fuelCaloriesNow <= 0f && fireboxItem == null) {
nextDelayBase = Float.POSITIVE_INFINITY
nextDelay = Float.POSITIVE_INFINITY
}
// tick a thermal loss
temperature -= 1f / 4096f
temperature = temperature.coerceIn(0f, 1f)
// emit smokes only when there is something burning
if (spawnTimer >= nextDelay) {
(Terrarum.ingame as TerrarumIngame).addParticle(
ParticleVanishingSprite(
CommonResourcePool.getAsTextureRegionPack("particles-tiki_smoke.tga"),
25f, true, hitbox.startX + TILE_SIZED, hitbox.startY + 16, false, (Math.random() * 256).toInt()
)
)
spawnTimer -= nextDelay
nextDelay = (nextDelayBase * (1.0 + RNG.nextTriangularBal() * 0.1)).toFloat()
(sprite as? SheetSpriteAnimation)?.delays?.set(0, Math.random().toFloat() * 0.4f + 0.1f)
}
val smeltingProduct = CraftingRecipeCodex.getSmeltingProductOf(oreItem1?.itm, oreItem2?.itm)
// roast items
if (oreItem1 != null &&
oreItem2 != null &&
temperature > 0f &&
smeltingProduct != null &&
(productItem == null || smeltingProduct.item == productItem!!.itm)
) {
progress += temperature
if (progress >= FixtureSmelterBasic.CALORIES_PER_ROASTING) {
val smeltingProduct = smeltingProduct.item
// check if the item even exists
if (ItemCodex[smeltingProduct] == null) throw NullPointerException("No item prop for $smeltingProduct")
if (productItem == null)
productItem = InventoryPair(smeltingProduct, 1L)
else
productItemStatus.changeCount(1)
// take the ore item
oreItem1Status.changeCount(-1)
oreItem2Status.changeCount(-1)
progress = 0f
}
}
else if (oreItem1 == null || oreItem2 == null) {
progress = 0f
}
// update lightbox
lightBoxList.forEach {
it.light = light.cpy().mul(temperature)
}
if (temperature > 0.001f)
spawnTimer += delta
else
spawnTimer = 0f
// update sound randomiser
volRand.update(delta)
// manage audio
// FIXME this code is also killing the audio played by the other fixture (FixtureFurnaceAndAnvil)
getTrackByAudio(static).let {
if (it == null || (temperature > 0f && !it.isPlaying && !it.playRequested.get())) {
startAudio(static) {
it.filters[filterIndex] = Gain(0f)
}
}
else if (it != null && it.isPlaying && temperature <= 0f) {
stopAudio(static) {
it.filters[filterIndex] = NullFilter
}
}
if (it != null) {
if (it.filters[filterIndex] !is Gain) // just in case...
it.filters[filterIndex] = Gain(0f)
(it.filters[filterIndex] as Gain).gain = (it.maxVolume * temperature * volRand.get()).toFloat()
}
}
}
@Transient private val filterIndex = 0
@Transient private val volRand = ParamRandomiser(0.8f, 0.4f)
override fun dispose() {
super.dispose()
static.dispose()
}
}

View File

@@ -1,10 +1,8 @@
package net.torvald.terrarum.modulebasegame.gameactors package net.torvald.terrarum.modulebasegame.gameactors
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.jme3.math.FastMath
import net.torvald.gdx.graphics.Cvec import net.torvald.gdx.graphics.Cvec
import net.torvald.random.HQRNG import net.torvald.random.HQRNG
import net.torvald.spriteanimation.SheetSpriteAnimation import net.torvald.spriteanimation.SheetSpriteAnimation
@@ -38,11 +36,10 @@ interface SmelterItemStatus {
val qty: Long? val qty: Long?
} }
/** /**
* Created by minjaesong on 2023-12-04. * Created by minjaesong on 2023-12-04.
*/ */
class FixtureSmelterBasic : FixtureBase, CraftingStation { class FixtureSmelterBasic : FixtureBase {
var fuelCaloriesNow = 0.0 // arbitrary number, may as well be watts or joules var fuelCaloriesNow = 0.0 // arbitrary number, may as well be watts or joules
var fuelCaloriesMax: Double? = null var fuelCaloriesMax: Double? = null
@@ -123,8 +120,6 @@ class FixtureSmelterBasic : FixtureBase, CraftingStation {
override val canBeDespawned: Boolean override val canBeDespawned: Boolean
get() = oreItem == null && fireboxItem == null && productItem == null get() = oreItem == null && fireboxItem == null && productItem == null
@Transient override val tags = listOf("basicsmelter")
init { init {
CommonResourcePool.addToLoadingList("basegame/sprites/fixtures/smelter_tall.tga") { CommonResourcePool.addToLoadingList("basegame/sprites/fixtures/smelter_tall.tga") {
TextureRegionPack(ModMgr.getGdxFile("basegame", "sprites/fixtures/smelter_tall.tga"), 48, 64) TextureRegionPack(ModMgr.getGdxFile("basegame", "sprites/fixtures/smelter_tall.tga"), 48, 64)
@@ -164,7 +159,7 @@ class FixtureSmelterBasic : FixtureBase, CraftingStation {
@Transient val static = MusicContainer("bonfire", ModMgr.getFile("basegame", "audio/effects/static/bonfire.ogg"), true) @Transient val static = MusicContainer("bonfire", ModMgr.getFile("basegame", "audio/effects/static/bonfire.ogg"), true)
@Transient val light = Cvec(0.5f, 0.18f, 0f, 0f) @Transient val light = Cvec(0.5f, 0.18f, 0f, 0f)
@Transient override var lightBoxList = arrayListOf(Lightbox(Hitbox(0.0, 2*TILE_SIZED, TILE_SIZED * 2, TILE_SIZED * 2), Cvec(0.5f, 0.18f, 0f, 0f))) @Transient override var lightBoxList = arrayListOf(Lightbox(Hitbox(0.0, 2*TILE_SIZED, TILE_SIZED * 2, TILE_SIZED * 2), light))
@Transient private val actorBlocks = arrayOf( @Transient private val actorBlocks = arrayOf(
arrayOf(Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION, null), arrayOf(Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION, null),
@@ -257,7 +252,6 @@ class FixtureSmelterBasic : FixtureBase, CraftingStation {
override fun updateImpl(delta: Float) { override fun updateImpl(delta: Float) {
super.updateImpl(delta) super.updateImpl(delta)
val oreItemProp = ItemCodex[oreItem?.itm]
val fuelItemProp = ItemCodex[fireboxItem?.itm] val fuelItemProp = ItemCodex[fireboxItem?.itm]
// consume fuel // consume fuel
@@ -302,23 +296,25 @@ class FixtureSmelterBasic : FixtureBase, CraftingStation {
(sprite as? SheetSpriteAnimation)?.delays?.set(0, Math.random().toFloat() * 0.4f + 0.1f) (sprite as? SheetSpriteAnimation)?.delays?.set(0, Math.random().toFloat() * 0.4f + 0.1f)
} }
val smeltingProduct = CraftingRecipeCodex.getSmeltingProductOf(oreItem?.itm)
// roast items // roast items
if (oreItem != null && if (oreItem != null &&
temperature > 0f && temperature > 0f &&
oreItemProp?.smeltingProduct != null && smeltingProduct != null &&
(productItem == null || oreItemProp.smeltingProduct == productItem!!.itm) (productItem == null || smeltingProduct.item == productItem!!.itm)
) { ) {
progress += temperature progress += temperature
if (progress >= CALORIES_PER_ROASTING) { if (progress >= CALORIES_PER_ROASTING) {
val smeltingProduct = oreItemProp.smeltingProduct!! val smeltingProductItem = smeltingProduct.item
// check if the item even exists // check if the item even exists
if (ItemCodex[smeltingProduct] == null) throw NullPointerException("No item prop for $smeltingProduct") if (ItemCodex[smeltingProductItem] == null) throw NullPointerException("No item prop for $smeltingProductItem")
if (productItem == null) if (productItem == null)
productItem = InventoryPair(smeltingProduct, 1L) productItem = InventoryPair(smeltingProductItem, 1L)
else else
productItemStatus.changeCount(1) productItemStatus.changeCount(1)

View File

@@ -38,7 +38,6 @@ class ItemLogsOak(originalID: ItemID) : OreItemBase(originalID) {
override val materialId = "WOOD" override val materialId = "WOOD"
override var calories = 1920.0 override var calories = 1920.0
override var smokiness = 0.2f override var smokiness = 0.2f
override var smeltingProduct: ItemID? = "item@basegame:29"
override val itemImage: TextureRegion override val itemImage: TextureRegion
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(0,10) get() = CommonResourcePool.getAsItemSheet("basegame.items").get(0,10)
@@ -52,7 +51,6 @@ class ItemLogsEbony(originalID: ItemID) : OreItemBase(originalID) {
override val materialId = "WOOD" override val materialId = "WOOD"
override var calories = 1920.0 override var calories = 1920.0
override var smokiness = 0.2f override var smokiness = 0.2f
override var smeltingProduct: ItemID? = "item@basegame:29"
override val itemImage: TextureRegion override val itemImage: TextureRegion
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(1,10) get() = CommonResourcePool.getAsItemSheet("basegame.items").get(1,10)
@@ -66,7 +64,6 @@ class ItemLogsBirch(originalID: ItemID) : OreItemBase(originalID) {
override val materialId = "WOOD" override val materialId = "WOOD"
override var calories = 1920.0 override var calories = 1920.0
override var smokiness = 0.2f override var smokiness = 0.2f
override var smeltingProduct: ItemID? = "item@basegame:29"
override val itemImage: TextureRegion override val itemImage: TextureRegion
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(2,10) get() = CommonResourcePool.getAsItemSheet("basegame.items").get(2,10)
@@ -80,7 +77,6 @@ class ItemLogsRosewood(originalID: ItemID) : OreItemBase(originalID) {
override val materialId = "WOOD" override val materialId = "WOOD"
override var calories = 1920.0 override var calories = 1920.0
override var smokiness = 0.2f override var smokiness = 0.2f
override var smeltingProduct: ItemID? = "item@basegame:29"
override val itemImage: TextureRegion override val itemImage: TextureRegion
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(3,10) get() = CommonResourcePool.getAsItemSheet("basegame.items").get(3,10)
@@ -94,19 +90,16 @@ class ItemLogsRosewood(originalID: ItemID) : OreItemBase(originalID) {
class OreCopper(originalID: ItemID) : OreItemBase(originalID, true) { class OreCopper(originalID: ItemID) : OreItemBase(originalID, true) {
override var originalName = "ITEM_ORE_MALACHITE" override var originalName = "ITEM_ORE_MALACHITE"
override var smeltingProduct: ItemID? = "item@basegame:112"
override val itemImage: TextureRegion override val itemImage: TextureRegion
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(1,6) get() = CommonResourcePool.getAsItemSheet("basegame.items").get(1,6)
} }
class OreIron(originalID: ItemID) : OreItemBase(originalID, true) { class OreIron(originalID: ItemID) : OreItemBase(originalID, true) {
override var originalName = "ITEM_ORE_HAEMATITE" override var originalName = "ITEM_ORE_HAEMATITE"
override var smeltingProduct: ItemID? = "item@basegame:113"
override val itemImage: TextureRegion override val itemImage: TextureRegion
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(2,6) get() = CommonResourcePool.getAsItemSheet("basegame.items").get(2,6)
} }
class OreCoal(originalID: ItemID) : OreItemBase(originalID, true) { class OreCoal(originalID: ItemID) : OreItemBase(originalID, true) {
override var originalName = "ITEM_ORE_COAL" override var originalName = "ITEM_ORE_COAL"
override var smeltingProduct: ItemID? = "item@basegame:114"
override var calories = 4800.0 override var calories = 4800.0
override var smokiness = 0.3f override var smokiness = 0.3f
override val itemImage: TextureRegion override val itemImage: TextureRegion
@@ -114,40 +107,34 @@ class OreCoal(originalID: ItemID) : OreItemBase(originalID, true) {
} }
class OreZinc(originalID: ItemID) : OreItemBase(originalID, true) { class OreZinc(originalID: ItemID) : OreItemBase(originalID, true) {
override var originalName = "ITEM_ORE_SPHALERITE" override var originalName = "ITEM_ORE_SPHALERITE"
override var smeltingProduct: ItemID? = "item@basegame:115"
override val itemImage: TextureRegion override val itemImage: TextureRegion
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(4,6) get() = CommonResourcePool.getAsItemSheet("basegame.items").get(4,6)
} }
class OreTin(originalID: ItemID) : OreItemBase(originalID, true) { class OreTin(originalID: ItemID) : OreItemBase(originalID, true) {
override var originalName = "ITEM_ORE_CASSITERITE" override var originalName = "ITEM_ORE_CASSITERITE"
override var smeltingProduct: ItemID? = "item@basegame:116"
override val itemImage: TextureRegion override val itemImage: TextureRegion
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(5,6) get() = CommonResourcePool.getAsItemSheet("basegame.items").get(5,6)
} }
class OreGold(originalID: ItemID) : OreItemBase(originalID, true) { class OreGold(originalID: ItemID) : OreItemBase(originalID, true) {
override var originalName = "ITEM_ORE_NATURAL_GOLD" override var originalName = "ITEM_ORE_NATURAL_GOLD"
override var smeltingProduct: ItemID? = "item@basegame:117"
override val materialId: String = "AURM" override val materialId: String = "AURM"
override val itemImage: TextureRegion override val itemImage: TextureRegion
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(6, 6) get() = CommonResourcePool.getAsItemSheet("basegame.items").get(6, 6)
} }
class OreSilver(originalID: ItemID) : OreItemBase(originalID, true) { class OreSilver(originalID: ItemID) : OreItemBase(originalID, true) {
override var originalName = "ITEM_ORE_NATURAL_SILVER" override var originalName = "ITEM_ORE_NATURAL_SILVER"
override var smeltingProduct: ItemID? = "item@basegame:118"
override val materialId: String = "ARGN" override val materialId: String = "ARGN"
override val itemImage: TextureRegion override val itemImage: TextureRegion
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(7,6) get() = CommonResourcePool.getAsItemSheet("basegame.items").get(7,6)
} }
class OreLead(originalID: ItemID) : OreItemBase(originalID, true) { class OreLead(originalID: ItemID) : OreItemBase(originalID, true) {
override var originalName = "ITEM_ORE_GALENA" override var originalName = "ITEM_ORE_GALENA"
override var smeltingProduct: ItemID? = "item@basegame:119"
override val itemImage: TextureRegion override val itemImage: TextureRegion
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(8,6) get() = CommonResourcePool.getAsItemSheet("basegame.items").get(8,6)
} }
class GemQuartz(originalID: ItemID) : OreItemBase(originalID, true) { class GemQuartz(originalID: ItemID) : OreItemBase(originalID, true) {
override var originalName = "ITEM_GEM_QUARTZ" override var originalName = "ITEM_GEM_QUARTZ"
override var smeltingProduct: ItemID? = "basegame:149"
override val itemImage: TextureRegion override val itemImage: TextureRegion
get() = CommonResourcePool.getAsItemSheet("basegame.items").get(13,6) get() = CommonResourcePool.getAsItemSheet("basegame.items").get(13,6)
} }

View File

@@ -24,8 +24,8 @@ object SmelterGuiEventBuilder {
fun getPlayerSlotTouchDownFun( fun getPlayerSlotTouchDownFun(
clickedOnState: AtomicInteger, clickedOnState: AtomicInteger,
fireboxItem: SmelterItemStatus, fireboxItemStatus: SmelterItemStatus,
oreItem: SmelterItemStatus, oreItemStatus: SmelterItemStatus,
getPlayerInventory: () -> ActorInventory, getPlayerInventory: () -> ActorInventory,
@@ -43,24 +43,24 @@ object SmelterGuiEventBuilder {
// oreslot // oreslot
if (amount != null && gameItem != null) { if (amount != null && gameItem != null) {
if (clickedOnState.get() == ORE_SLOT_FIRST) { if (clickedOnState.get() == ORE_SLOT_FIRST) {
if (oreItem.itm == gameItem.dynamicID) { if (oreItemStatus.itm == gameItem.dynamicID) {
playerInventory.remove(gameItem.dynamicID, amount) playerInventory.remove(gameItem.dynamicID, amount)
oreItem.changeCount(amount) oreItemStatus.changeCount(amount)
} }
else { else {
playerInventory.remove(gameItem.dynamicID, amount) playerInventory.remove(gameItem.dynamicID, amount)
oreItem.set(gameItem.dynamicID, amount) oreItemStatus.set(gameItem.dynamicID, amount)
} }
} }
// firebox // firebox
else if (clickedOnState.get() == FIRE_SLOT_FIRST) { else if (clickedOnState.get() == FIRE_SLOT_FIRST) {
if (fireboxItem.isNull()) { if (fireboxItemStatus.isNull()) {
playerInventory.remove(gameItem.dynamicID, amount) playerInventory.remove(gameItem.dynamicID, amount)
fireboxItem.set(gameItem.dynamicID, amount) fireboxItemStatus.set(gameItem.dynamicID, amount)
} }
else if (fireboxItem.itm == gameItem.dynamicID) { else if (fireboxItemStatus.itm == gameItem.dynamicID) {
playerInventory.remove(gameItem.dynamicID, amount) playerInventory.remove(gameItem.dynamicID, amount)
fireboxItem.changeCount(amount) fireboxItemStatus.changeCount(amount)
} }
} }
} }
@@ -72,8 +72,8 @@ object SmelterGuiEventBuilder {
fun getPlayerSlotWheelFun( fun getPlayerSlotWheelFun(
clickedOnState: AtomicInteger, clickedOnState: AtomicInteger,
fireboxItem: SmelterItemStatus, fireboxItemStatus: SmelterItemStatus,
oreItem: SmelterItemStatus, oreItemStatus: SmelterItemStatus,
getPlayerInventory: () -> ActorInventory, getPlayerInventory: () -> ActorInventory,
@@ -84,51 +84,51 @@ object SmelterGuiEventBuilder {
if (gameItem != null) { if (gameItem != null) {
val addCount1 = scrollY.toLong() val addCount1 = scrollY.toLong()
if (clickedOnState.get() == ORE_SLOT_FIRST && (oreItem.isNull() || oreItem.itm == gameItem.dynamicID)) { if (clickedOnState.get() == ORE_SLOT_FIRST && (oreItemStatus.isNull() || oreItemStatus.itm == gameItem.dynamicID)) {
val itemToUse = oreItem.itm ?: gameItem.dynamicID val itemToUse = oreItemStatus.itm ?: gameItem.dynamicID
val addCount2 = scrollY.toLong().coerceIn( val addCount2 = scrollY.toLong().coerceIn(
-(playerInventory.searchByID(itemToUse)?.qty ?: 0L), -(playerInventory.searchByID(itemToUse)?.qty ?: 0L),
oreItem.qty ?: 0L, oreItemStatus.qty ?: 0L,
) )
// add to the inventory slot // add to the inventory slot
if (oreItem.isNotNull() && addCount1 >= 1L) { if (oreItemStatus.isNotNull() && addCount1 >= 1L) {
playerInventory.add(oreItem.itm!!, addCount2) playerInventory.add(oreItemStatus.itm!!, addCount2)
oreItem.changeCount(-addCount2) oreItemStatus.changeCount(-addCount2)
} }
// remove from the inventory slot // remove from the inventory slot
else if (addCount1 <= -1L) { else if (addCount1 <= -1L) {
playerInventory.remove(itemToUse, -addCount2) playerInventory.remove(itemToUse, -addCount2)
if (oreItem.isNull()) if (oreItemStatus.isNull())
oreItem.set(itemToUse, -addCount2) oreItemStatus.set(itemToUse, -addCount2)
else else
oreItem.changeCount(-addCount2) oreItemStatus.changeCount(-addCount2)
} }
if (oreItem.qty == 0L) oreItem.nullify() if (oreItemStatus.qty == 0L) oreItemStatus.nullify()
else if (oreItem.isNotNull() && oreItem.qty!! < 0L) throw Error("Item removal count is larger than what was on the slot") else if (oreItemStatus.isNotNull() && oreItemStatus.qty!! < 0L) throw Error("Item removal count is larger than what was on the slot")
itemListUpdateKeepCurrentFilter() itemListUpdateKeepCurrentFilter()
} }
else if (clickedOnState.get() == FIRE_SLOT_FIRST && (fireboxItem.isNull() || fireboxItem.itm == gameItem.dynamicID)) { else if (clickedOnState.get() == FIRE_SLOT_FIRST && (fireboxItemStatus.isNull() || fireboxItemStatus.itm == gameItem.dynamicID)) {
val itemToUse = fireboxItem.itm ?: gameItem.dynamicID val itemToUse = fireboxItemStatus.itm ?: gameItem.dynamicID
val addCount2 = scrollY.toLong().coerceIn( val addCount2 = scrollY.toLong().coerceIn(
-(playerInventory.searchByID(itemToUse)?.qty ?: 0L), -(playerInventory.searchByID(itemToUse)?.qty ?: 0L),
fireboxItem.qty ?: 0L, fireboxItemStatus.qty ?: 0L,
) )
// add to the inventory slot // add to the inventory slot
if (fireboxItem.isNotNull() && addCount1 >= 1L) { if (fireboxItemStatus.isNotNull() && addCount1 >= 1L) {
playerInventory.add(fireboxItem.itm!!, addCount2) playerInventory.add(fireboxItemStatus.itm!!, addCount2)
fireboxItem.changeCount(-addCount2) fireboxItemStatus.changeCount(-addCount2)
} }
// remove from the inventory slot // remove from the inventory slot
else if (addCount1 <= -1L) { else if (addCount1 <= -1L) {
playerInventory.remove(itemToUse, -addCount2) playerInventory.remove(itemToUse, -addCount2)
if (fireboxItem.isNull()) if (fireboxItemStatus.isNull())
fireboxItem.set(itemToUse, -addCount2) fireboxItemStatus.set(itemToUse, -addCount2)
else else
fireboxItem.changeCount(-addCount2) fireboxItemStatus.changeCount(-addCount2)
} }
itemListUpdateKeepCurrentFilter() itemListUpdateKeepCurrentFilter()
} }
@@ -149,7 +149,7 @@ object SmelterGuiEventBuilder {
playerThings: UITemplateHalfInventory, playerThings: UITemplateHalfInventory,
oreItem: SmelterItemStatus, oreItemStatus: SmelterItemStatus,
getPlayerInventory: () -> ActorInventory, getPlayerInventory: () -> ActorInventory,
@@ -164,17 +164,17 @@ object SmelterGuiEventBuilder {
playerThings.itemList.itemPage = 0 playerThings.itemList.itemPage = 0
itemListUpdate { ItemCodex.hasTag(it.itm, "SMELTABLE") } itemListUpdate { ItemCodex.hasTag(it.itm, "SMELTABLE") }
} }
else if (oreItem.isNotNull()) { else if (oreItemStatus.isNotNull()) {
val removeCount = if (mouseButton == App.getConfigInt("config_mouseprimary")) val removeCount = if (mouseButton == App.getConfigInt("config_mouseprimary"))
oreItem.qty oreItemStatus.qty
else if (mouseButton == App.getConfigInt("config_mousesecondary")) else if (mouseButton == App.getConfigInt("config_mousesecondary"))
1L 1L
else else
null null
if (removeCount != null) { if (removeCount != null) {
getPlayerInventory().add(oreItem.itm!!, removeCount) getPlayerInventory().add(oreItemStatus.itm!!, removeCount)
oreItem.changeCount(-removeCount) oreItemStatus.changeCount(-removeCount)
} }
itemListUpdateKeepCurrentFilter() itemListUpdateKeepCurrentFilter()
} }
@@ -186,7 +186,7 @@ object SmelterGuiEventBuilder {
fun getOreItemSlotWheelFun( fun getOreItemSlotWheelFun(
clickedOnState: AtomicInteger, clickedOnState: AtomicInteger,
oreItem: SmelterItemStatus, oreItemStatus: SmelterItemStatus,
getPlayerInventory: () -> ActorInventory, getPlayerInventory: () -> ActorInventory,
@@ -195,22 +195,22 @@ object SmelterGuiEventBuilder {
): (GameItem?, Long, Float, Float, Any?, UIItemInventoryCellBase) -> Unit { return { gameItem: GameItem?, amount: Long, scrollX: Float, scrollY: Float, itemExtraInfo: Any?, theButton: UIItemInventoryCellBase -> ): (GameItem?, Long, Float, Float, Any?, UIItemInventoryCellBase) -> Unit { return { gameItem: GameItem?, amount: Long, scrollX: Float, scrollY: Float, itemExtraInfo: Any?, theButton: UIItemInventoryCellBase ->
val playerInventory = getPlayerInventory() val playerInventory = getPlayerInventory()
val scrollY = -scrollY val scrollY = -scrollY
if (clickedOnState.get() == ORE_SLOT_FIRST && oreItem.isNotNull()) { if (clickedOnState.get() == ORE_SLOT_FIRST && oreItemStatus.isNotNull()) {
val removeCount1 = scrollY.toLong() val removeCount1 = scrollY.toLong()
val removeCount2 = scrollY.toLong().coerceIn( val removeCount2 = scrollY.toLong().coerceIn(
-oreItem.qty!!, -oreItemStatus.qty!!,
playerInventory.searchByID(oreItem.itm)?.qty ?: 0L, playerInventory.searchByID(oreItemStatus.itm)?.qty ?: 0L,
) )
// add to the slot // add to the slot
if (removeCount1 >= 1L) { if (removeCount1 >= 1L) {
playerInventory.remove(oreItem.itm!!, removeCount2) playerInventory.remove(oreItemStatus.itm!!, removeCount2)
oreItem.changeCount(removeCount2) oreItemStatus.changeCount(removeCount2)
} }
// remove from the slot // remove from the slot
else if (removeCount1 <= -1L) { else if (removeCount1 <= -1L) {
playerInventory.add(oreItem.itm!!, -removeCount2) playerInventory.add(oreItemStatus.itm!!, -removeCount2)
oreItem.changeCount(removeCount2) oreItemStatus.changeCount(removeCount2)
} }
itemListUpdateKeepCurrentFilter() itemListUpdateKeepCurrentFilter()
} }
@@ -228,7 +228,7 @@ object SmelterGuiEventBuilder {
playerThings: UITemplateHalfInventory, playerThings: UITemplateHalfInventory,
fireboxItem: SmelterItemStatus, fireboxItemStatus: SmelterItemStatus,
getPlayerInventory: () -> ActorInventory, getPlayerInventory: () -> ActorInventory,
@@ -243,17 +243,17 @@ object SmelterGuiEventBuilder {
playerThings.itemList.itemPage = 0 playerThings.itemList.itemPage = 0
itemListUpdate { ItemCodex.hasTag(it.itm, "COMBUSTIBLE") } itemListUpdate { ItemCodex.hasTag(it.itm, "COMBUSTIBLE") }
} }
else if (fireboxItem.isNotNull()) { else if (fireboxItemStatus.isNotNull()) {
val removeCount = if (mouseButton == App.getConfigInt("config_mouseprimary")) val removeCount = if (mouseButton == App.getConfigInt("config_mouseprimary"))
fireboxItem.qty fireboxItemStatus.qty
else if (mouseButton == App.getConfigInt("config_mousesecondary")) else if (mouseButton == App.getConfigInt("config_mousesecondary"))
1L 1L
else else
null null
if (removeCount != null) { if (removeCount != null) {
getPlayerInventory().add(fireboxItem.itm!!, removeCount) getPlayerInventory().add(fireboxItemStatus.itm!!, removeCount)
fireboxItem.changeCount(-removeCount) fireboxItemStatus.changeCount(-removeCount)
} }
itemListUpdateKeepCurrentFilter() itemListUpdateKeepCurrentFilter()
} }
@@ -265,7 +265,7 @@ object SmelterGuiEventBuilder {
fun getFireboxItemSlotWheelFun( fun getFireboxItemSlotWheelFun(
clickedOnState: AtomicInteger, clickedOnState: AtomicInteger,
fireboxItem: SmelterItemStatus, fireboxItemStatus: SmelterItemStatus,
getPlayerInventory: () -> ActorInventory, getPlayerInventory: () -> ActorInventory,
@@ -274,22 +274,22 @@ object SmelterGuiEventBuilder {
): (GameItem?, Long, Float, Float, Any?, UIItemInventoryCellBase) -> Unit { return { gameItem: GameItem?, amount: Long, scrollX: Float, scrollY: Float, itemExtraInfo: Any?, theButton: UIItemInventoryCellBase -> ): (GameItem?, Long, Float, Float, Any?, UIItemInventoryCellBase) -> Unit { return { gameItem: GameItem?, amount: Long, scrollX: Float, scrollY: Float, itemExtraInfo: Any?, theButton: UIItemInventoryCellBase ->
val playerInventory = getPlayerInventory() val playerInventory = getPlayerInventory()
val scrollY = -scrollY val scrollY = -scrollY
if (clickedOnState.get() == FIRE_SLOT_FIRST && fireboxItem.isNotNull()) { if (clickedOnState.get() == FIRE_SLOT_FIRST && fireboxItemStatus.isNotNull()) {
val removeCount1 = scrollY.toLong() val removeCount1 = scrollY.toLong()
val removeCount2 = scrollY.toLong().coerceIn( val removeCount2 = scrollY.toLong().coerceIn(
-fireboxItem.qty!!, -fireboxItemStatus.qty!!,
playerInventory.searchByID(fireboxItem.itm)?.qty ?: 0L, playerInventory.searchByID(fireboxItemStatus.itm)?.qty ?: 0L,
) )
// add to the slot // add to the slot
if (removeCount1 >= 1L) { if (removeCount1 >= 1L) {
playerInventory.remove(fireboxItem.itm!!, removeCount2) playerInventory.remove(fireboxItemStatus.itm!!, removeCount2)
fireboxItem.changeCount(removeCount2) fireboxItemStatus.changeCount(removeCount2)
} }
// remove from the slot // remove from the slot
else if (removeCount1 <= -1L) { else if (removeCount1 <= -1L) {
playerInventory.add(fireboxItem.itm!!, -removeCount2) playerInventory.add(fireboxItemStatus.itm!!, -removeCount2)
fireboxItem.changeCount(removeCount2) fireboxItemStatus.changeCount(removeCount2)
} }
itemListUpdateKeepCurrentFilter() itemListUpdateKeepCurrentFilter()
} }
@@ -307,7 +307,7 @@ object SmelterGuiEventBuilder {
playerThings: UITemplateHalfInventory, playerThings: UITemplateHalfInventory,
productItem: SmelterItemStatus, productItemStatus: SmelterItemStatus,
getPlayerInventory: () -> ActorInventory, getPlayerInventory: () -> ActorInventory,
@@ -322,24 +322,24 @@ object SmelterGuiEventBuilder {
itemListUpdate() itemListUpdate()
} }
if (productItem.isNotNull()) { if (productItemStatus.isNotNull()) {
val removeCount = if (mouseButton == App.getConfigInt("config_mouseprimary")) val removeCount = if (mouseButton == App.getConfigInt("config_mouseprimary"))
productItem.qty productItemStatus.qty
else if (mouseButton == App.getConfigInt("config_mousesecondary")) else if (mouseButton == App.getConfigInt("config_mousesecondary"))
1L 1L
else else
null null
if (removeCount != null) { if (removeCount != null) {
getPlayerInventory().add(productItem.itm!!, removeCount) getPlayerInventory().add(productItemStatus.itm!!, removeCount)
productItem.changeCount(-removeCount) productItemStatus.changeCount(-removeCount)
} }
itemListUpdateKeepCurrentFilter() itemListUpdateKeepCurrentFilter()
} }
} } } }
fun getProductItemSlotWheelFun( fun getProductItemSlotWheelFun(
productItem: SmelterItemStatus, productItemStatus: SmelterItemStatus,
getPlayerInventory: () -> ActorInventory, getPlayerInventory: () -> ActorInventory,
@@ -347,17 +347,17 @@ object SmelterGuiEventBuilder {
): (GameItem?, Long, Float, Float, Any?, UIItemInventoryCellBase) -> Unit { return { gameItem: GameItem?, amount: Long, scrollX: Float, scrollY: Float, itemExtraInfo: Any?, theButton: UIItemInventoryCellBase -> ): (GameItem?, Long, Float, Float, Any?, UIItemInventoryCellBase) -> Unit { return { gameItem: GameItem?, amount: Long, scrollX: Float, scrollY: Float, itemExtraInfo: Any?, theButton: UIItemInventoryCellBase ->
val scrollY = -scrollY val scrollY = -scrollY
if (productItem.isNotNull()) { if (productItemStatus.isNotNull()) {
val removeCount1 = scrollY.toLong() val removeCount1 = scrollY.toLong()
val removeCount2 = scrollY.toLong().coerceIn( val removeCount2 = scrollY.toLong().coerceIn(
-productItem.qty!!, -productItemStatus.qty!!,
0L, 0L,
) )
// remove from the slot // remove from the slot
if (removeCount1 <= -1L) { if (removeCount1 <= -1L) {
getPlayerInventory().add(productItem.itm!!, -removeCount2) getPlayerInventory().add(productItemStatus.itm!!, -removeCount2)
productItem.changeCount(removeCount2) productItemStatus.changeCount(removeCount2)
} }
itemListUpdateKeepCurrentFilter() itemListUpdateKeepCurrentFilter()
} }