mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 20:14:05 +09:00
pickaxe to drop ores when they were mined
This commit is contained in:
@@ -4,6 +4,7 @@ import net.torvald.gdx.graphics.Cvec
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.ReferencingRanges.PREFIX_VIRTUALTILE
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
import net.torvald.terrarum.gameitems.isWall
|
||||
import net.torvald.terrarum.utils.CSVFetcher
|
||||
import net.torvald.util.SortedArrayList
|
||||
import org.apache.commons.csv.CSVRecord
|
||||
@@ -63,7 +64,7 @@ class BlockCodex {
|
||||
}
|
||||
|
||||
fun fromCSV(module: String, csvString: String) {
|
||||
printdbg(this, "Building wire properties table for module $module")
|
||||
printdbg(this, "Building block properties table for module $module")
|
||||
|
||||
val csvParser = org.apache.commons.csv.CSVParser.parse(
|
||||
csvString,
|
||||
@@ -144,7 +145,7 @@ class BlockCodex {
|
||||
}
|
||||
|
||||
try {
|
||||
return if (blockID.startsWith("wall@"))
|
||||
return if (blockID.isWall())
|
||||
blockProps[blockID.substring(5)]!!
|
||||
else
|
||||
blockProps[blockID]!!
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.torvald.terrarum.blockproperties
|
||||
|
||||
import net.torvald.gdx.graphics.Cvec
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
|
||||
/**
|
||||
@@ -28,4 +29,13 @@ class FluidCodex {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
class FluidProp {
|
||||
val opacity: Cvec = Cvec()
|
||||
val lumCol: Cvec = Cvec()
|
||||
var id: ItemID = ""
|
||||
var nameKey: String = ""
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package net.torvald.terrarum.blockproperties
|
||||
|
||||
import net.torvald.gdx.graphics.Cvec
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2023-10-09.
|
||||
*/
|
||||
class FluidProp {
|
||||
|
||||
val opacity: Cvec = Cvec()
|
||||
val lumCol: Cvec = Cvec()
|
||||
var id: ItemID = ""
|
||||
var nameKey: String = ""
|
||||
|
||||
|
||||
}
|
||||
84
src/net/torvald/terrarum/blockproperties/OreCodex.kt
Normal file
84
src/net/torvald/terrarum/blockproperties/OreCodex.kt
Normal file
@@ -0,0 +1,84 @@
|
||||
package net.torvald.terrarum.blockproperties
|
||||
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
import net.torvald.terrarum.utils.CSVFetcher
|
||||
import org.apache.commons.csv.CSVRecord
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2023-10-11.
|
||||
*/
|
||||
class OreCodex {
|
||||
|
||||
@Transient val oreProps = HashMap<ItemID, OreProp>()
|
||||
@Transient private val nullProp = OreProp()
|
||||
|
||||
internal constructor()
|
||||
|
||||
/**
|
||||
* Later entry (possible from other modules) will replace older ones
|
||||
*/
|
||||
fun fromModule(module: String, path: String) {
|
||||
App.printdbg(this, "Building ore properties table")
|
||||
try {
|
||||
register(module, CSVFetcher.readFromModule(module, path))
|
||||
}
|
||||
catch (e: IOException) { e.printStackTrace() }
|
||||
}
|
||||
|
||||
fun fromCSV(module: String, csvString: String) {
|
||||
App.printdbg(this, "Building ore properties table for module $module")
|
||||
|
||||
val csvParser = org.apache.commons.csv.CSVParser.parse(
|
||||
csvString,
|
||||
CSVFetcher.terrarumCSVFormat
|
||||
)
|
||||
val csvRecordList = csvParser.records
|
||||
csvParser.close()
|
||||
|
||||
register(module, csvRecordList)
|
||||
}
|
||||
|
||||
private fun register(module: String, records: List<CSVRecord>) {
|
||||
records.forEach {
|
||||
setProp(module, it.intVal("id"), it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setProp(modname: String, key: Int, record: CSVRecord) {
|
||||
val prop = OreProp()
|
||||
prop.id = "ores@$modname:$key"
|
||||
prop.tags = record.get("tags").split(',').map { it.trim() }.toHashSet()
|
||||
prop.item = record.get("item").let { if (it == null) "" else if (it.contains(':')) it else "$modname:$it" }
|
||||
|
||||
oreProps[prop.id] = prop
|
||||
|
||||
App.printdbg(this, "Setting prop ${prop.id}")
|
||||
}
|
||||
|
||||
fun getAll() = oreProps.values
|
||||
|
||||
operator fun get(oreID: ItemID?): OreProp {
|
||||
if (oreID == null || oreID == Block.NULL) {
|
||||
return nullProp
|
||||
}
|
||||
|
||||
try {
|
||||
return oreProps[oreID]!!
|
||||
}
|
||||
catch (e: NullPointerException) {
|
||||
throw NullPointerException("Oreprop with id $oreID does not exist.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class OreProp {
|
||||
var id: String = ""
|
||||
var item: ItemID = ""
|
||||
var tags = HashSet<String>()
|
||||
|
||||
fun hasTag(s: String) = tags.contains(s)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user