Check for "survives explosion"

Fixes #161
This commit is contained in:
DBotThePony 2022-10-27 16:13:57 +07:00
parent 4dc132a8ec
commit 2b50109fd5
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 56 additions and 38 deletions

View File

@ -18,6 +18,7 @@ import net.minecraft.world.level.storage.loot.LootPool
import net.minecraft.world.level.storage.loot.LootTable import net.minecraft.world.level.storage.loot.LootTable
import net.minecraft.world.level.storage.loot.ValidationContext import net.minecraft.world.level.storage.loot.ValidationContext
import net.minecraft.world.level.storage.loot.entries.LootItem import net.minecraft.world.level.storage.loot.entries.LootItem
import net.minecraft.world.level.storage.loot.entries.LootPoolSingletonContainer
import net.minecraft.world.level.storage.loot.functions.CopyNbtFunction import net.minecraft.world.level.storage.loot.functions.CopyNbtFunction
import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction 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.LootContextParamSet
@ -93,7 +94,7 @@ class LootTables(generator: DataGenerator) : LootTableProvider(generator) {
override fun validate(map: MutableMap<ResourceLocation, LootTable>, validationtracker: ValidationContext) {} override fun validate(map: MutableMap<ResourceLocation, LootTable>, validationtracker: ValidationContext) {}
fun createSlabItemTable(block: Block) { fun createSlabItemTable(block: Block, configurator: LootPoolSingletonContainer.Builder<*>.() -> Unit = {}) {
builder(LootContextParamSets.BLOCK, block.lootTable) { builder(LootContextParamSets.BLOCK, block.lootTable) {
withPool( withPool(
LootPool.lootPool().setRolls(ConstantValue.exactly(1.0f)).add( LootPool.lootPool().setRolls(ConstantValue.exactly(1.0f)).add(
@ -106,14 +107,16 @@ class LootTables(generator: DataGenerator) : LootTableProvider(generator) {
.hasProperty(SlabBlock.TYPE, SlabType.DOUBLE) .hasProperty(SlabBlock.TYPE, SlabType.DOUBLE)
) )
) )
) ).also(configurator)
) )
) )
} }
} }
fun createSlabItemTable(block: Collection<Block>) { fun createSlabItemTable(blocks: Collection<Block>, configurator: LootPoolSingletonContainer.Builder<*>.() -> Unit = {}) {
block.forEach(this::createSlabItemTable) for (block in blocks) {
createSlabItemTable(block, configurator)
}
} }
fun blockProvider(block: Block, provider: () -> LootTable.Builder) { fun blockProvider(block: Block, provider: () -> LootTable.Builder) {
@ -141,13 +144,23 @@ class LootTables(generator: DataGenerator) : LootTableProvider(generator) {
fun dropsSelf(vararg blocks: Block) { fun dropsSelf(vararg blocks: Block) {
for (block in blocks) { for (block in blocks) {
singleLootPool(LootContextParamSets.BLOCK, block.lootTable) { singleLootPool(LootContextParamSets.BLOCK, block.lootTable) {
add(LootItem.lootTableItem(block)) item(block) {}
} }
} }
} }
fun dropsSelf(blocks: Collection<Block>) { fun dropsSelf(block: Block, configurator: LootPoolSingletonContainer.Builder<*>.() -> Unit = {}) {
blocks.forEach(this::dropsSelf) singleLootPool(LootContextParamSets.BLOCK, block.lootTable) {
item(block, configurator)
}
}
fun dropsSelf(blocks: Collection<Block>, configurator: LootPoolSingletonContainer.Builder<*>.() -> Unit = {}) {
for (block in blocks) {
singleLootPool(LootContextParamSets.BLOCK, block.lootTable) {
item(block, configurator)
}
}
} }
fun tile(block: Block, f: (CopyNbtFunction.Builder) -> Unit = {}) { fun tile(block: Block, f: (CopyNbtFunction.Builder) -> Unit = {}) {

View File

@ -7,6 +7,7 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf 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.entries.LootItem
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets
import net.minecraft.world.level.storage.loot.predicates.ExplosionCondition
import ru.dbotthepony.mc.otm.block.entity.ChemicalGeneratorBlockEntity import ru.dbotthepony.mc.otm.block.entity.ChemicalGeneratorBlockEntity
import ru.dbotthepony.mc.otm.block.entity.EnergyCounterBlockEntity import ru.dbotthepony.mc.otm.block.entity.EnergyCounterBlockEntity
import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity.Companion.ENERGY_KEY import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity.Companion.ENERGY_KEY
@ -22,45 +23,45 @@ import ru.dbotthepony.mc.otm.registry.MItems
import ru.dbotthepony.mc.otm.registry.MRegistry import ru.dbotthepony.mc.otm.registry.MRegistry
fun addLootTables(lootTables: LootTables) { fun addLootTables(lootTables: LootTables) {
lootTables.dropsSelf(MRegistry.DECORATIVE_CRATE.allBlocks.values) lootTables.dropsSelf(MRegistry.DECORATIVE_CRATE.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MRegistry.CARGO_CRATES.allBlocks.values) lootTables.dropsSelf(MRegistry.CARGO_CRATES.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MRegistry.INDUSTRIAL_GLASS.allBlocks.values) lootTables.dropsSelf(MRegistry.INDUSTRIAL_GLASS.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MRegistry.INDUSTRIAL_GLASS_PANE.allBlocks.values) lootTables.dropsSelf(MRegistry.INDUSTRIAL_GLASS_PANE.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MRegistry.TRITANIUM_BLOCK.allBlocks.values) lootTables.dropsSelf(MRegistry.TRITANIUM_BLOCK.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MRegistry.TRITANIUM_WALL.allBlocks.values) lootTables.dropsSelf(MRegistry.TRITANIUM_WALL.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MRegistry.TRITANIUM_STAIRS.allBlocks.values) lootTables.dropsSelf(MRegistry.TRITANIUM_STAIRS.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.createSlabItemTable(MRegistry.TRITANIUM_SLAB.allBlocks.values) lootTables.createSlabItemTable(MRegistry.TRITANIUM_SLAB.allBlocks.values)
lootTables.dropsSelf(MRegistry.VENT.allBlocks.values) lootTables.dropsSelf(MRegistry.VENT.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MRegistry.VENT_ALTERNATIVE.allBlocks.values) lootTables.dropsSelf(MRegistry.VENT_ALTERNATIVE.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MRegistry.FLOOR_TILES.blocks.values) lootTables.dropsSelf(MRegistry.FLOOR_TILES.blocks.values) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MRegistry.UNREFINED_FLOOR_TILES.blocks.values) lootTables.dropsSelf(MRegistry.UNREFINED_FLOOR_TILES.blocks.values) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MRegistry.TRITANIUM_STRIPED_BLOCK.flatBlocks) lootTables.dropsSelf(MRegistry.TRITANIUM_STRIPED_BLOCK.flatBlocks) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MRegistry.TRITANIUM_STRIPED_STAIRS.flatBlocks) lootTables.dropsSelf(MRegistry.TRITANIUM_STRIPED_STAIRS.flatBlocks) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MRegistry.TRITANIUM_STRIPED_WALL.flatBlocks) lootTables.dropsSelf(MRegistry.TRITANIUM_STRIPED_WALL.flatBlocks) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.createSlabItemTable(MRegistry.TRITANIUM_STRIPED_SLAB.flatBlocks) lootTables.createSlabItemTable(MRegistry.TRITANIUM_STRIPED_SLAB.flatBlocks) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MRegistry.FLOOR_TILES_STAIRS.blocks.values) lootTables.dropsSelf(MRegistry.FLOOR_TILES_STAIRS.blocks.values) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.createSlabItemTable(MRegistry.FLOOR_TILES_SLAB.blocks.values) lootTables.createSlabItemTable(MRegistry.FLOOR_TILES_SLAB.blocks.values) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MBlocks.CARBON_FIBRE_BLOCK) lootTables.dropsSelf(MBlocks.CARBON_FIBRE_BLOCK) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MBlocks.TRITANIUM_RAW_BLOCK) lootTables.dropsSelf(MBlocks.TRITANIUM_RAW_BLOCK) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MBlocks.TRITANIUM_STRIPED_BLOCK) lootTables.dropsSelf(MBlocks.TRITANIUM_STRIPED_BLOCK) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MBlocks.TRITANIUM_STRIPED_WALL) lootTables.dropsSelf(MBlocks.TRITANIUM_STRIPED_WALL) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MBlocks.TRITANIUM_STRIPED_STAIRS) lootTables.dropsSelf(MBlocks.TRITANIUM_STRIPED_STAIRS) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.createSlabItemTable(MBlocks.TRITANIUM_STRIPED_SLAB) lootTables.createSlabItemTable(MBlocks.TRITANIUM_STRIPED_SLAB) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MBlocks.MATTER_CABLE) lootTables.dropsSelf(MBlocks.MATTER_CABLE) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MBlocks.GRAVITATION_STABILIZER) lootTables.dropsSelf(MBlocks.GRAVITATION_STABILIZER)
lootTables.dropsOther(MBlocks.GRAVITATION_STABILIZER_LENS, MBlocks.GRAVITATION_STABILIZER) lootTables.dropsOther(MBlocks.GRAVITATION_STABILIZER_LENS, MBlocks.GRAVITATION_STABILIZER)
lootTables.dropsSelf(MBlocks.LABORATORY_LAMP) lootTables.dropsSelf(MBlocks.LABORATORY_LAMP) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MBlocks.LABORATORY_LAMP_INVERTED) lootTables.dropsSelf(MBlocks.LABORATORY_LAMP_INVERTED) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MBlocks.DANGER_STRIPE_BLOCK) lootTables.dropsSelf(MBlocks.DANGER_STRIPE_BLOCK) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MBlocks.METAL_BEAM) lootTables.dropsSelf(MBlocks.METAL_BEAM) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MBlocks.TRITANIUM_INGOT_BLOCK) lootTables.dropsSelf(MBlocks.TRITANIUM_INGOT_BLOCK) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MBlocks.TRITANIUM_TRAPDOOR) lootTables.dropsSelf(MBlocks.TRITANIUM_TRAPDOOR) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.dropsSelf(MRegistry.TRITANIUM_PRESSURE_PLATE.allBlocks.values) lootTables.dropsSelf(MRegistry.TRITANIUM_PRESSURE_PLATE.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }
lootTables.block(MBlocks.PHANTOM_ATTRACTOR) { lootTables.block(MBlocks.PHANTOM_ATTRACTOR) {
item(MBlocks.PHANTOM_ATTRACTOR) { item(MBlocks.PHANTOM_ATTRACTOR) {
@ -68,6 +69,8 @@ fun addLootTables(lootTables: LootTables) {
this[BlockStateProperties.DOUBLE_BLOCK_HALF] = DoubleBlockHalf.LOWER this[BlockStateProperties.DOUBLE_BLOCK_HALF] = DoubleBlockHalf.LOWER
} }
} }
condition(ExplosionCondition.survivesExplosion())
} }
lootTables.block(MBlocks.TRITANIUM_DOOR) { lootTables.block(MBlocks.TRITANIUM_DOOR) {
@ -76,6 +79,8 @@ fun addLootTables(lootTables: LootTables) {
this[BlockStateProperties.DOUBLE_BLOCK_HALF] = DoubleBlockHalf.LOWER this[BlockStateProperties.DOUBLE_BLOCK_HALF] = DoubleBlockHalf.LOWER
} }
} }
condition(ExplosionCondition.survivesExplosion())
} }
lootTables.builder(LootContextParamSets.ADVANCEMENT_ENTITY, modLocation("research_all_android")) { lootTables.builder(LootContextParamSets.ADVANCEMENT_ENTITY, modLocation("research_all_android")) {