Move tritanium loot tables to datagen
This commit is contained in:
parent
6f9132ee8c
commit
e88c2ba9b0
@ -6,6 +6,7 @@ package ru.dbotthepony.mc.otm.datagen.loot
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectArrayMap
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectFunction
|
||||
import net.minecraft.advancements.critereon.StatePropertiesPredicate
|
||||
import net.minecraft.core.HolderLookup
|
||||
import net.minecraft.core.WritableRegistry
|
||||
import net.minecraft.data.DataGenerator
|
||||
import net.minecraft.data.loot.LootTableProvider
|
||||
@ -29,9 +30,11 @@ import net.minecraft.world.level.storage.loot.providers.number.ConstantValue
|
||||
import net.neoforged.neoforge.data.event.GatherDataEvent
|
||||
import ru.dbotthepony.mc.otm.core.stream
|
||||
import ru.dbotthepony.mc.otm.data.loot.CopyTileNbtFunction
|
||||
import java.util.concurrent.CompletableFuture
|
||||
|
||||
class LootTables(generator: GatherDataEvent) : LootTableProvider(generator.generator.packOutput, setOf() /* because we don't fucking validate you fuck */, listOf() /* because we attach everything after class is constructed duh */, generator.lookupProvider) {
|
||||
private val providersTable = Reference2ObjectArrayMap<LootContextParamSet, HashMap<ResourceKey<LootTable>, () -> LootTable.Builder>>()
|
||||
val registry: CompletableFuture<HolderLookup.Provider> = generator.lookupProvider
|
||||
|
||||
fun builder(context: LootContextParamSet, id: ResourceKey<LootTable>, provider: LootTable.Builder.() -> Unit) {
|
||||
provider(context, id) {
|
||||
@ -39,6 +42,10 @@ class LootTables(generator: GatherDataEvent) : LootTableProvider(generator.gener
|
||||
}
|
||||
}
|
||||
|
||||
fun builder(block: Block, provider: LootPool.Builder.() -> Unit) {
|
||||
singleLootPool(LootContextParamSets.BLOCK, block.lootTable, provider)
|
||||
}
|
||||
|
||||
fun provider(context: LootContextParamSet, id: ResourceKey<LootTable>, provider: () -> LootTable.Builder) {
|
||||
check(providersTable
|
||||
.computeIfAbsent(context, Reference2ObjectFunction { HashMap() })
|
||||
@ -101,6 +108,7 @@ class LootTables(generator: GatherDataEvent) : LootTableProvider(generator.gener
|
||||
fun singleLootPool(context: LootContextParamSet, id: ResourceKey<LootTable>, block: LootPool.Builder.() -> Unit) {
|
||||
builder(context, id) {
|
||||
withPool(LootPool.lootPool().also(block))
|
||||
setRandomSequence(id.location())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,50 @@
|
||||
package ru.dbotthepony.mc.otm.datagen.loot
|
||||
|
||||
import net.minecraft.advancements.critereon.EnchantmentPredicate
|
||||
import net.minecraft.advancements.critereon.ItemEnchantmentsPredicate
|
||||
import net.minecraft.advancements.critereon.ItemPredicate
|
||||
import net.minecraft.advancements.critereon.ItemSubPredicates
|
||||
import net.minecraft.advancements.critereon.MinMaxBounds
|
||||
import net.minecraft.world.item.Items
|
||||
import net.minecraft.world.item.enchantment.Enchantments
|
||||
import net.minecraft.world.level.ItemLike
|
||||
import net.minecraft.world.level.block.Block
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties
|
||||
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf
|
||||
import net.minecraft.world.level.storage.loot.entries.AlternativesEntry
|
||||
import net.minecraft.world.level.storage.loot.entries.LootItem
|
||||
import net.minecraft.world.level.storage.loot.functions.ApplyBonusCount
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets
|
||||
import net.minecraft.world.level.storage.loot.predicates.ExplosionCondition
|
||||
import ru.dbotthepony.mc.otm.datagen.modLocation
|
||||
import net.minecraft.world.level.storage.loot.predicates.MatchTool
|
||||
import ru.dbotthepony.mc.otm.core.lookupOrThrow
|
||||
import ru.dbotthepony.mc.otm.datagen.modLootTable
|
||||
import ru.dbotthepony.mc.otm.registry.MBlocks
|
||||
import ru.dbotthepony.mc.otm.registry.MItems
|
||||
import ru.dbotthepony.mc.otm.registry.MRegistry
|
||||
|
||||
private fun ore(lootTables: LootTables, ore: Block, clump: ItemLike) {
|
||||
lootTables.builder(ore) {
|
||||
add(AlternativesEntry.alternatives(
|
||||
LootItem.lootTableItem(ore).also {
|
||||
it.condition(MatchTool.toolMatches(
|
||||
ItemPredicate.Builder.item().withSubPredicate(
|
||||
ItemSubPredicates.ENCHANTMENTS,
|
||||
ItemEnchantmentsPredicate.enchantments(listOf(EnchantmentPredicate(
|
||||
lootTables.registry.get().lookupOrThrow(Enchantments.SILK_TOUCH), MinMaxBounds.Ints.atLeast(1)
|
||||
)))
|
||||
)
|
||||
))
|
||||
},
|
||||
|
||||
LootItem.lootTableItem(clump).also {
|
||||
it.apply(ApplyBonusCount.addOreBonusCount(lootTables.registry.get().lookupOrThrow(Enchantments.FORTUNE)))
|
||||
it.condition(ExplosionCondition.survivesExplosion())
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fun addLootTables(lootTables: LootTables) {
|
||||
lootTables.dropsSelf(MRegistry.DECORATIVE_CRATE.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }
|
||||
|
||||
@ -54,6 +87,9 @@ fun addLootTables(lootTables: LootTables) {
|
||||
lootTables.dropsSelf(MBlocks.TRITANIUM_BARS) { condition(ExplosionCondition.survivesExplosion()) }
|
||||
lootTables.dropsSelf(MBlocks.ENERGY_CABLES.values) { condition(ExplosionCondition.survivesExplosion()) }
|
||||
|
||||
ore(lootTables, MBlocks.TRITANIUM_ORE, MItems.TRITANIUM_ORE_CLUMP)
|
||||
ore(lootTables, MBlocks.DEEPSLATE_TRITANIUM_ORE, MItems.TRITANIUM_ORE_CLUMP)
|
||||
|
||||
lootTables.dropsSelf(MBlocks.INFINITE_WATER_SOURCE) { condition(ExplosionCondition.survivesExplosion()) }
|
||||
|
||||
lootTables.dropsSelf(MBlocks.ENGINE) { condition(ExplosionCondition.survivesExplosion()) }
|
||||
|
@ -1,52 +0,0 @@
|
||||
{
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"bonus_rolls": 0.0,
|
||||
"entries": [
|
||||
{
|
||||
"type": "minecraft:alternatives",
|
||||
"children": [
|
||||
{
|
||||
"type": "minecraft:item",
|
||||
"conditions": [
|
||||
{
|
||||
"condition": "minecraft:match_tool",
|
||||
"predicate": {
|
||||
"predicates": {
|
||||
"minecraft:enchantments": [
|
||||
{
|
||||
"enchantments": "minecraft:silk_touch",
|
||||
"levels": {
|
||||
"min": 1
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"name": "overdrive_that_matters:deepslate_tritanium_ore"
|
||||
},
|
||||
{
|
||||
"type": "minecraft:item",
|
||||
"functions": [
|
||||
{
|
||||
"enchantment": "minecraft:fortune",
|
||||
"formula": "minecraft:ore_drops",
|
||||
"function": "minecraft:apply_bonus"
|
||||
},
|
||||
{
|
||||
"function": "minecraft:explosion_decay"
|
||||
}
|
||||
],
|
||||
"name": "overdrive_that_matters:tritanium_ore_clump"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"rolls": 1.0
|
||||
}
|
||||
],
|
||||
"random_sequence": "overdrive_that_matters:blocks/deepslate_tritanium_ore"
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
{
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"bonus_rolls": 0.0,
|
||||
"entries": [
|
||||
{
|
||||
"type": "minecraft:alternatives",
|
||||
"children": [
|
||||
{
|
||||
"type": "minecraft:item",
|
||||
"conditions": [
|
||||
{
|
||||
"condition": "minecraft:match_tool",
|
||||
"predicate": {
|
||||
"predicates": {
|
||||
"minecraft:enchantments": [
|
||||
{
|
||||
"enchantments": "minecraft:silk_touch",
|
||||
"levels": {
|
||||
"min": 1
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"name": "overdrive_that_matters:tritanium_ore"
|
||||
},
|
||||
{
|
||||
"type": "minecraft:item",
|
||||
"functions": [
|
||||
{
|
||||
"enchantment": "minecraft:fortune",
|
||||
"formula": "minecraft:ore_drops",
|
||||
"function": "minecraft:apply_bonus"
|
||||
},
|
||||
{
|
||||
"function": "minecraft:explosion_decay"
|
||||
}
|
||||
],
|
||||
"name": "overdrive_that_matters:tritanium_ore_clump"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"rolls": 1.0
|
||||
}
|
||||
],
|
||||
"random_sequence": "overdrive_that_matters:blocks/deepslate_tritanium_ore"
|
||||
}
|
Loading…
Reference in New Issue
Block a user