1
0
mirror of https://github.com/chylex/Hardcore-Ender-Expansion-2.git synced 2025-04-14 12:15:44 +02:00

Separate loot table and loot pool configuration to fix weirdness

This commit is contained in:
chylex 2019-03-30 09:20:30 +01:00
parent 7cd00e9c4a
commit 4a191ee98e
4 changed files with 57 additions and 21 deletions
src/main

View File

@ -55,34 +55,21 @@ object ModLoot{
}
val LootTable.pools
get() = LootTable::class.java.declaredFields.first { it.type === List::class.java }.also { it.isAccessible = true }.get(this) as List<LootPool>
get() = LootTable::class.java.declaredFields.first { it.type === List::class.java }.also { it.isAccessible = true }.get(this) as ArrayList<LootPool>
@JvmStatic
@SubscribeEvent
fun onLootTableLoad(e: LootTableLoadEvent){
if (e.name.namespace == HEE.ID){
var table = e.table
var pools = table.pools
val table = reconfigureLootTable(e.table)
for(index in pools.indices){
val pool = pools[index]
val name = pool.name
if (!name.contains('#')){
for(pool in table.pools){
if (!pool.name.contains('#')){
continue
}
val split = name.splitToSequence('#').drop(1).map { it.split('=').let { (k, v) -> Pair(k, v) } }
for((key, value) in split){
for((key, value) in parseParameters(pool)){
when(key){
"stack_splitting" -> {
if (value == "off"){
table = NoStackSplittingLootTable(table)
pools = table.pools
}
}
"rolls_bias" -> {
val (highestChanceValue, biasSoftener) = value.split('~')
pool.rolls = RandomBiasedValueRange(pool.rolls, highestChanceValue.toFloat(), biasSoftener.toFloat())
@ -96,4 +83,35 @@ object ModLoot{
e.table = table
}
}
private fun reconfigureLootTable(table: LootTable): LootTable{
val pools = table.pools
val configurationPool = pools.find { it.name.startsWith("table#") }
if (configurationPool == null){
return table
}
pools.remove(configurationPool)
var newTable = table
for((key, value) in parseParameters(configurationPool)){
when(key){
"stack_splitting" -> {
if (value == "off"){
newTable = NoStackSplittingLootTable(table)
}
}
else -> throw UnsupportedOperationException(key)
}
}
return newTable
}
private fun parseParameters(pool: LootPool): Sequence<Pair<String, String>>{
return pool.name.splitToSequence('#').drop(1).map { it.split('=').let { (k, v) -> Pair(k, v) } }
}
}

View File

@ -1,9 +1,15 @@
{
"pools": [
{
"rolls": 0,
"name": "table#stack_splitting=off",
"entries": []
},
{
"rolls": { "min": 3, "max": 10 },
"name": "pool#stack_splitting=off#rolls_bias=6.5~3",
"name": "pool#rolls_bias=6.5~3",
"entries": [
{ "type": "item", "name": "minecraft:iron_ingot", "weight": 100, "functions": [{ "function": "set_count", "count": { "min": 1, "max": 5 } }], "entryName": "iron_ingot" },
{ "type": "item", "name": "hee:ethereum", "weight": 95, "functions": [{ "function": "set_count", "count": { "min": 1, "max": 2 } }], "entryName": "ethereum" },

View File

@ -1,9 +1,15 @@
{
"pools": [
{
"rolls": 0,
"name": "table#stack_splitting=off",
"entries": []
},
{
"rolls": { "min": 9, "max": 11 },
"name": "pool#stack_splitting=off#rolls_bias=10~5",
"name": "pool#rolls_bias=10~5",
"entries": [
{ "type": "item", "name": "minecraft:paper", "weight": 50, "functions": [{ "function": "set_count", "count": { "min": 1, "max": 3 } }], "entryName": "paper" },
{ "type": "item", "name": "minecraft:book", "weight": 45, "functions": [{ "function": "set_count", "count": { "min": 1, "max": 2 } }], "entryName": "book" },

View File

@ -1,9 +1,15 @@
{
"pools": [
{
"rolls": 0,
"name": "table#stack_splitting=off",
"entries": []
},
{
"rolls": { "min": 4, "max": 6 },
"name": "pool#stack_splitting=off#rolls_bias=5~5",
"name": "pool#rolls_bias=5~5",
"entries": [
{ "type": "item", "name": "minecraft:paper", "weight": 50, "functions": [{ "function": "set_count", "count": { "min": 1, "max": 3 } }], "entryName": "paper" },
{ "type": "item", "name": "minecraft:book", "weight": 45, "functions": [{ "function": "set_count", "count": { "min": 1, "max": 2 } }], "entryName": "book" },