mirror of
https://gitlab.bixilon.de/bixilon/pixlyzer.git
synced 2025-09-27 14:10:01 -04:00
extract fuel
This commit is contained in:
parent
5995cb7a29
commit
befd41203d
@ -7,9 +7,14 @@ import de.bixilon.mbf.MBFDataInfo
|
||||
import de.bixilon.pixlyzer.exceptions.GeneratorSkipException
|
||||
import de.bixilon.pixlyzer.generator.Generators
|
||||
import de.bixilon.pixlyzer.util.ReflectionUtil.getClass
|
||||
import de.bixilon.pixlyzer.util.ReflectionUtil.getField
|
||||
import de.bixilon.pixlyzer.util.ReflectionUtil.getGetter
|
||||
import de.bixilon.pixlyzer.util.ReflectionUtil.invoke
|
||||
import de.bixilon.pixlyzer.util.ReflectionUtil.variable
|
||||
import de.bixilon.pixlyzer.util.Util
|
||||
import net.minecraft.Bootstrap
|
||||
import net.minecraft.tag.ItemTags
|
||||
import net.minecraft.tag.Tag
|
||||
import net.minecraft.util.registry.Registry
|
||||
import java.io.*
|
||||
import java.util.*
|
||||
@ -61,6 +66,12 @@ object PixLyzer {
|
||||
|
||||
Util.forceClassInit(Registry::class.java)
|
||||
|
||||
getField(ItemTags::class.java, "REQUIRED_TAGS")?.get(null)?.variable<Iterable<Any>>("tags")?.let {
|
||||
for (tag in it) {
|
||||
getField(tag::class.java, "delegate")!!.set(tag, Tag::class.java.invoke("of", arrayOf(Set::class.java), arrayOf(setOf<Any>())))
|
||||
}
|
||||
}
|
||||
|
||||
println("Class loading done in ${System.currentTimeMillis() - classesLoadStartTime}ms")
|
||||
|
||||
|
||||
|
@ -4,17 +4,22 @@ import de.bixilon.pixlyzer.generator.Generator
|
||||
import de.bixilon.pixlyzer.util.Util.nullCast
|
||||
import net.minecraft.block.Blocks
|
||||
import net.minecraft.block.FireBlock
|
||||
import net.minecraft.block.entity.AbstractFurnaceBlockEntity
|
||||
import net.minecraft.util.registry.Registry
|
||||
|
||||
object MiscGenerator : Generator(
|
||||
"misc"
|
||||
) {
|
||||
override fun generate() {
|
||||
|
||||
private fun generateBurnChances() {
|
||||
"fire_burn_chances".add {
|
||||
for ((block, chance) in Blocks.FIRE.nullCast<FireBlock>()!!.burnChances) {
|
||||
it[Registry.BLOCK.getRawId(block)] = chance
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun generateSpreadChances() {
|
||||
"fire_spread_chances".add {
|
||||
for ((block, chance) in Blocks.FIRE.nullCast<FireBlock>()!!.spreadChances) {
|
||||
it[Registry.BLOCK.getRawId(block)] = chance
|
||||
@ -22,6 +27,20 @@ object MiscGenerator : Generator(
|
||||
}
|
||||
}
|
||||
|
||||
private fun generateFuelTime() {
|
||||
"fuel_time".add {
|
||||
for ((block, fuelTime) in AbstractFurnaceBlockEntity.createFuelTimeMap()) {
|
||||
it[Registry.ITEM.getRawId(block)] = fuelTime
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun generate() {
|
||||
generateBurnChances()
|
||||
generateSpreadChances()
|
||||
generateFuelTime()
|
||||
}
|
||||
|
||||
|
||||
fun String.add(generator: (json: MutableMap<Any, Any>) -> Unit) {
|
||||
val json: MutableMap<Any, Any> = mutableMapOf()
|
||||
|
@ -62,8 +62,9 @@ object ReflectionUtil {
|
||||
}
|
||||
|
||||
fun <T> Any.invoke(name: String, types: Array<Class<*>> = arrayOf(), parameters: Array<Any> = arrayOf()): T? {
|
||||
val clazz = if (this is Class<*>) this else this::class.java
|
||||
val method = try {
|
||||
this::class.java.getMethod(name, *types)
|
||||
clazz.getMethod(name, *types)
|
||||
} catch (exception: NoSuchMethodException) {
|
||||
return null
|
||||
}
|
||||
@ -73,4 +74,8 @@ object ReflectionUtil {
|
||||
fun <T> Any.variable(vararg names: String): T? {
|
||||
return getField(this::class.java, *names)?.get(this) as T?
|
||||
}
|
||||
|
||||
fun <T> Any.invokeGetter(vararg names: String): T? {
|
||||
return getGetter(this::class.java, *names)?.invoke(this) as T?
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user