diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/loot/LootTables.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/loot/LootTables.kt index 6aa8d0f4f..b6e1d1965 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/loot/LootTables.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/loot/LootTables.kt @@ -10,9 +10,11 @@ import net.minecraft.advancements.critereon.StatePropertiesPredicate import net.minecraft.data.DataGenerator import net.minecraft.data.loot.LootTableProvider import net.minecraft.resources.ResourceLocation +import net.minecraft.util.StringRepresentable import net.minecraft.world.level.ItemLike import net.minecraft.world.level.block.Block import net.minecraft.world.level.block.SlabBlock +import net.minecraft.world.level.block.state.properties.Property import net.minecraft.world.level.block.state.properties.SlabType import net.minecraft.world.level.storage.loot.LootPool import net.minecraft.world.level.storage.loot.LootTable @@ -24,6 +26,7 @@ import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction import net.minecraft.world.level.storage.loot.parameters.LootContextParamSet import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets import net.minecraft.world.level.storage.loot.predicates.LootItemBlockStatePropertyCondition +import net.minecraft.world.level.storage.loot.predicates.LootItemCondition import net.minecraft.world.level.storage.loot.providers.nbt.ContextNbtProvider import net.minecraft.world.level.storage.loot.providers.number.ConstantValue import net.minecraft.world.level.storage.loot.providers.number.UniformGenerator @@ -33,6 +36,7 @@ import ru.dbotthepony.mc.otm.core.registryName import java.util.function.BiConsumer import java.util.function.Consumer import java.util.function.Supplier +import kotlin.reflect.full.isSubclassOf private typealias LootTableSaver = BiConsumer private typealias LootTableCallback = Consumer @@ -65,6 +69,27 @@ fun > T.setCount(minimal: Float, maxim return this } +fun > T.condition(condition: LootItemCondition.Builder): T { + `when`(condition) + return this +} + +inline fun > T.blockStateCondition(block: Block, configurator: StatePropertiesPredicate.Builder.() -> Unit): T { + condition(LootItemBlockStatePropertyCondition.hasBlockStateProperties(block).setProperties(StatePropertiesPredicate.Builder.properties().also(configurator))) + return this +} + +operator fun StatePropertiesPredicate.Builder.set(property: Property<*>, value: String): StatePropertiesPredicate.Builder = hasProperty(property, value) +operator fun StatePropertiesPredicate.Builder.set(property: Property, value: Int): StatePropertiesPredicate.Builder = hasProperty(property, value) +operator fun StatePropertiesPredicate.Builder.set(property: Property, value: Boolean): StatePropertiesPredicate.Builder = hasProperty(property, value) +operator fun > StatePropertiesPredicate.Builder.set(property: Property, value: T): StatePropertiesPredicate.Builder { + if (value !is StringRepresentable) { + throw ClassCastException("Provided type ${value::class.qualifiedName} is not a subtype of ${StringRepresentable::class.qualifiedName}") + } + + return hasProperty(property, value.serializedName) +} + data class NbtCopy(val source: String, val destination: String, val strategy: CopyNbtFunction.MergeStrategy = CopyNbtFunction.MergeStrategy.REPLACE) fun TileNbtCopy(source: String, strategy: CopyNbtFunction.MergeStrategy = CopyNbtFunction.MergeStrategy.REPLACE): NbtCopy { diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/loot/LootTablesData.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/loot/LootTablesData.kt index c728e0a1d..caedabcc7 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/loot/LootTablesData.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/loot/LootTablesData.kt @@ -7,7 +7,6 @@ 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.LootItem import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets -import net.minecraft.world.level.storage.loot.predicates.LootItemBlockStatePropertyCondition import ru.dbotthepony.mc.otm.block.entity.ChemicalGeneratorBlockEntity import ru.dbotthepony.mc.otm.block.entity.EnergyCounterBlockEntity import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity.Companion.ENERGY_KEY @@ -64,11 +63,19 @@ fun addLootTables(lootTables: LootTables) { lootTables.dropsSelf(MRegistry.TRITANIUM_PRESSURE_PLATE.allBlocks.values) lootTables.block(MBlocks.PHANTOM_ATTRACTOR) { - add(LootItem.lootTableItem(MBlocks.PHANTOM_ATTRACTOR) - .`when`(LootItemBlockStatePropertyCondition - .hasBlockStateProperties(MBlocks.PHANTOM_ATTRACTOR) - .setProperties(StatePropertiesPredicate.Builder.properties() - .hasProperty(BlockStateProperties.DOUBLE_BLOCK_HALF, DoubleBlockHalf.LOWER)))) + item(MBlocks.PHANTOM_ATTRACTOR) { + blockStateCondition(MBlocks.PHANTOM_ATTRACTOR) { + this[BlockStateProperties.DOUBLE_BLOCK_HALF] = DoubleBlockHalf.LOWER + } + } + } + + lootTables.block(MBlocks.TRITANIUM_DOOR) { + item(MBlocks.TRITANIUM_DOOR) { + blockStateCondition(MBlocks.TRITANIUM_DOOR) { + this[BlockStateProperties.DOUBLE_BLOCK_HALF] = DoubleBlockHalf.LOWER + } + } } lootTables.builder(LootContextParamSets.ADVANCEMENT_ENTITY, modLocation("research_all_android")) { @@ -151,8 +158,4 @@ fun addLootTables(lootTables: LootTables) { lootTables.basicTile(MBlocks.MATTER_CAPACITOR_BANK) lootTables.poweredTile(MBlocks.MATTER_BOTTLER, TileNbtCopy(MATTER_STORAGE_KEY), TileNbtCopy(MatterBottlerBlockEntity.IS_BOTTLING_KEY)) - - lootTables.blockProvider(MBlocks.TRITANIUM_DOOR) { - BlockLoot.createDoorTable(MBlocks.TRITANIUM_DOOR) - } }