From 71a6a3484e3492fe8d9c8ceca03c2db79392d2de Mon Sep 17 00:00:00 2001 From: LatvianModder Date: Thu, 22 Aug 2024 10:31:30 +0300 Subject: [PATCH] Fixed door loot table --- .../kubejs/block/custom/DoorBlockBuilder.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/main/java/dev/latvian/mods/kubejs/block/custom/DoorBlockBuilder.java b/src/main/java/dev/latvian/mods/kubejs/block/custom/DoorBlockBuilder.java index f5dfc4fc2..e46e8b0e6 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/custom/DoorBlockBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/custom/DoorBlockBuilder.java @@ -1,10 +1,12 @@ package dev.latvian.mods.kubejs.block.custom; import dev.latvian.mods.kubejs.block.BlockRenderType; +import dev.latvian.mods.kubejs.block.drop.BlockDrops; import dev.latvian.mods.kubejs.client.ModelGenerator; import dev.latvian.mods.kubejs.client.VariantBlockStateGenerator; import dev.latvian.mods.kubejs.generator.KubeAssetGenerator; import dev.latvian.mods.rhino.util.ReturnsSelf; +import net.minecraft.advancements.critereon.StatePropertiesPredicate; import net.minecraft.core.Direction; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.BlockTags; @@ -14,6 +16,15 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.DoorHingeSide; import net.minecraft.world.level.block.state.properties.DoubleBlockHalf; +import net.minecraft.world.level.storage.loot.LootPool; +import net.minecraft.world.level.storage.loot.LootTable; +import net.minecraft.world.level.storage.loot.entries.LootItem; +import net.minecraft.world.level.storage.loot.functions.LootItemConditionalFunction; +import net.minecraft.world.level.storage.loot.functions.SetComponentsFunction; +import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction; +import net.minecraft.world.level.storage.loot.predicates.ExplosionCondition; +import net.minecraft.world.level.storage.loot.predicates.LootItemBlockStatePropertyCondition; +import net.minecraft.world.level.storage.loot.providers.number.ConstantValue; import java.util.List; import java.util.Map; @@ -157,6 +168,41 @@ protected void generateBlockModelJsons(KubeAssetGenerator generator) { } } + @Override + public LootTable generateLootTable() { + var blockDrops = drops == null ? BlockDrops.createDefault(get().asItem().getDefaultInstance()) : drops.get(); + + if (blockDrops.items().length == 0) { + return null; + } + + var pool = new LootPool.Builder(); + + if (blockDrops.rolls() != null) { + pool.setRolls(blockDrops.rolls()); + } + + pool.when(ExplosionCondition.survivesExplosion()); + + for (var drop : blockDrops.items()) { + var item = LootItem.lootTableItem(drop.getItem()); + + item.when(new LootItemBlockStatePropertyCondition.Builder(get()).setProperties(StatePropertiesPredicate.Builder.properties().hasProperty(DoorBlock.HALF, DoubleBlockHalf.LOWER))); + + if (drop.getCount() > 1) { + item.apply(SetItemCountFunction.setCount(ConstantValue.exactly(drop.getCount()))); + } + + if (!drop.isComponentsPatchEmpty()) { + item.apply(LootItemConditionalFunction.simpleBuilder(c -> new SetComponentsFunction(c, drop.getComponentsPatch()))); + } + + pool.add(item); + } + + return new LootTable.Builder().withPool(pool).build(); + } + @Override protected void generateItemModelJson(ModelGenerator m) { m.parent("minecraft:item/generated");