-
Notifications
You must be signed in to change notification settings - Fork 0
Added Loot Table datagen. Added sticks to the short/tall grass loot table. #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ad2ac0f
7e62858
8caa3d3
f1072ef
195cb1f
a61e73c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||||||||||
| package com.tcm.MineTale.datagen; | ||||||||||||||||||
|
|
||||||||||||||||||
| import com.jcraft.jorbis.Block; | ||||||||||||||||||
| import com.tcm.MineTale.registry.ModBlocks; | ||||||||||||||||||
| import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; | ||||||||||||||||||
| import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider; | ||||||||||||||||||
|
|
@@ -20,14 +21,24 @@ public ModBlockTagProvider(FabricDataOutput output, CompletableFuture<HolderLook | |||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * Populates the BlockTags.LOGS tag with this mod's log blocks. | ||||||||||||||||||
| * Populate block tags with this mod's blocks. | ||||||||||||||||||
| * | ||||||||||||||||||
| * Registers each mod-defined log block so they are included in the game's LOGS tag mapping. | ||||||||||||||||||
| * Adds mod-defined blocks to relevant vanilla block tags (for example | ||||||||||||||||||
| * MINEABLE_WITH_PICKAXE, MINEABLE_WITH_AXE, and LOGS) so they are included | ||||||||||||||||||
| * in the game's tag mappings. | ||||||||||||||||||
| * | ||||||||||||||||||
| * @param provider a registry lookup provider used to resolve holders during tag population | ||||||||||||||||||
| * @param provider registry lookup provider used to resolve holders during tag population | ||||||||||||||||||
| */ | ||||||||||||||||||
| @Override | ||||||||||||||||||
| protected void addTags(HolderLookup.Provider provider) { | ||||||||||||||||||
| valueLookupBuilder(BlockTags.MINEABLE_WITH_PICKAXE) | ||||||||||||||||||
| .add(ModBlocks.FURNACE_WORKBENCH_BLOCK_T1) | ||||||||||||||||||
| .add(ModBlocks.FURNACE_WORKBENCH_BLOCK_T2) | ||||||||||||||||||
| .add(ModBlocks.ARMORERS_WORKBENCH_BLOCK); | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Per the 🐛 Proposed fix valueLookupBuilder(BlockTags.MINEABLE_WITH_PICKAXE)
.add(ModBlocks.FURNACE_WORKBENCH_BLOCK_T1)
- .add(ModBlocks.FURNACE_WORKBENCH_BLOCK_T2)
- .add(ModBlocks.ARMORERS_WORKBENCH_BLOCK);
+ .add(ModBlocks.FURNACE_WORKBENCH_BLOCK_T2);
valueLookupBuilder(BlockTags.MINEABLE_WITH_AXE)
.add(ModBlocks.CAMPFIRE_WORKBENCH_BLOCK)
- .add(ModBlocks.WORKBENCH_WORKBENCH_BLOCK);
+ .add(ModBlocks.WORKBENCH_WORKBENCH_BLOCK)
+ .add(ModBlocks.ARMORERS_WORKBENCH_BLOCK);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| valueLookupBuilder(BlockTags.MINEABLE_WITH_AXE) | ||||||||||||||||||
| .add(ModBlocks.CAMPFIRE_WORKBENCH_BLOCK) | ||||||||||||||||||
| .add(ModBlocks.WORKBENCH_WORKBENCH_BLOCK); | ||||||||||||||||||
|
|
||||||||||||||||||
| valueLookupBuilder(BlockTags.LOGS) | ||||||||||||||||||
| .add(ModBlocks.AMBER_LOG) | ||||||||||||||||||
| .add(ModBlocks.BAMBOO_LOG) | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| package com.tcm.MineTale.datagen; | ||
|
|
||
| import com.tcm.MineTale.block.workbenches.AbstractWorkbench; | ||
| import com.tcm.MineTale.registry.ModBlocks; | ||
| import com.tcm.MineTale.registry.ModItems; | ||
| import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; | ||
| import net.fabricmc.fabric.api.datagen.v1.provider.FabricBlockLootTableProvider; | ||
| import net.minecraft.advancements.criterion.StatePropertiesPredicate; | ||
| import net.minecraft.core.HolderLookup; | ||
| import net.minecraft.core.registries.Registries; | ||
| import net.minecraft.world.item.Item; | ||
| import net.minecraft.world.item.enchantment.Enchantment; | ||
| import net.minecraft.world.item.enchantment.Enchantments; | ||
| import net.minecraft.world.level.block.Block; | ||
| import net.minecraft.world.level.block.state.properties.ChestType; | ||
| 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.entries.LootPoolSingletonContainer; | ||
| import net.minecraft.world.level.storage.loot.functions.ApplyBonusCount; | ||
| 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 net.minecraft.world.level.storage.loot.providers.number.UniformGenerator; | ||
|
|
||
| import java.util.concurrent.CompletableFuture; | ||
|
|
||
| public class ModLootTableProvider extends FabricBlockLootTableProvider { | ||
| /** | ||
| * Creates a ModLootTableProvider used to generate the mod's block loot tables. | ||
| * | ||
| * Initializes the provider with the data output target and a future registry lookup used to resolve game registries during loot table generation. | ||
| * | ||
| * @param dataOutput the data output target for generated data | ||
| * @param registryLookup a future that provides a HolderLookup.Provider for resolving registries needed while generating loot tables | ||
| */ | ||
| public ModLootTableProvider(FabricDataOutput dataOutput, CompletableFuture<HolderLookup.Provider> registryLookup) { | ||
| super(dataOutput, registryLookup); | ||
| } | ||
|
|
||
| /** | ||
| * Registers loot tables for the mod's workbench blocks. | ||
| * | ||
| * Each added loot table causes the block to drop itself (one item) only when the block's state | ||
| * matches the required DoubleBlockHalf (LOWER) and ChestType (LEFT or SINGLE) for that block, | ||
| * and the drop is subject to explosion survival/decay. | ||
| */ | ||
| @Override | ||
| public void generate() { | ||
| ///Block Drops Itself | ||
| this.add(ModBlocks.ARMORERS_WORKBENCH_BLOCK, | ||
| LootTable.lootTable() // Use the static factory method to start the builder | ||
| .withPool(LootPool.lootPool() | ||
| .setRolls(ConstantValue.exactly(1.0F)) | ||
| .add(LootItem.lootTableItem(ModBlocks.ARMORERS_WORKBENCH_BLOCK)) | ||
| .when(LootItemBlockStatePropertyCondition.hasBlockStateProperties(ModBlocks.ARMORERS_WORKBENCH_BLOCK) | ||
| .setProperties(StatePropertiesPredicate.Builder.properties() | ||
| .hasProperty(AbstractWorkbench.HALF, DoubleBlockHalf.LOWER) | ||
| .hasProperty(AbstractWorkbench.TYPE, ChestType.LEFT) | ||
| ) | ||
| ) | ||
| .when(ExplosionCondition.survivesExplosion()) | ||
| ) | ||
| ); | ||
|
|
||
| this.add(ModBlocks.CAMPFIRE_WORKBENCH_BLOCK, | ||
| LootTable.lootTable() // Use the static factory method to start the builder | ||
| .withPool(LootPool.lootPool() | ||
| .setRolls(ConstantValue.exactly(1.0F)) | ||
| .add(LootItem.lootTableItem(ModBlocks.CAMPFIRE_WORKBENCH_BLOCK)) | ||
| .when(LootItemBlockStatePropertyCondition.hasBlockStateProperties(ModBlocks.CAMPFIRE_WORKBENCH_BLOCK) | ||
| .setProperties(StatePropertiesPredicate.Builder.properties() | ||
| .hasProperty(AbstractWorkbench.HALF, DoubleBlockHalf.LOWER) | ||
| .hasProperty(AbstractWorkbench.TYPE, ChestType.SINGLE) | ||
| ) | ||
| ) | ||
| .when(ExplosionCondition.survivesExplosion()) | ||
| ) | ||
| ); | ||
|
|
||
| this.add(ModBlocks.WORKBENCH_WORKBENCH_BLOCK, | ||
| LootTable.lootTable() // Use the static factory method to start the builder | ||
| .withPool(LootPool.lootPool() | ||
| .setRolls(ConstantValue.exactly(1.0F)) | ||
| .add(LootItem.lootTableItem(ModBlocks.WORKBENCH_WORKBENCH_BLOCK)) | ||
| .when(LootItemBlockStatePropertyCondition.hasBlockStateProperties(ModBlocks.WORKBENCH_WORKBENCH_BLOCK) | ||
| .setProperties(StatePropertiesPredicate.Builder.properties() | ||
| .hasProperty(AbstractWorkbench.HALF, DoubleBlockHalf.LOWER) | ||
| .hasProperty(AbstractWorkbench.TYPE, ChestType.LEFT) | ||
| ) | ||
|
Comment on lines
+88
to
+92
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Find and examine AbstractWorkbench to understand HALF property registration
fd -e java "AbstractWorkbench" --type f -exec cat -n {} +Repository: CodeMonkeysMods/MineTale Length of output: 298 🏁 Script executed: # Find WORKBENCH_WORKBENCH_BLOCK definition
fd -e java . | xargs rg -l "WORKBENCH_WORKBENCH_BLOCK" | head -20Repository: CodeMonkeysMods/MineTale Length of output: 535 🏁 Script executed: # Check ModBlocks to see WORKBENCH_WORKBENCH_BLOCK registration
fd -e java "ModBlocks" --type f -exec cat -n {} +Repository: CodeMonkeysMods/MineTale Length of output: 298 🏁 Script executed: # Find AbstractWorkbench file
fd "AbstractWorkbench" --type fRepository: CodeMonkeysMods/MineTale Length of output: 314 🏁 Script executed: # Read ModBlocks.java to see WORKBENCH_WORKBENCH_BLOCK definition
cat src/main/java/com/tcm/MineTale/registry/ModBlocks.javaRepository: CodeMonkeysMods/MineTale Length of output: 30000 🏁 Script executed: # Check the size of ModLootTableProvider to read it properly
wc -l src/client/java/com/tcm/MineTale/datagen/ModLootTableProvider.javaRepository: CodeMonkeysMods/MineTale Length of output: 138 🏁 Script executed: # Read AbstractWorkbench to understand HALF property registration
cat src/main/java/com/tcm/MineTale/block/workbenches/AbstractWorkbench.javaRepository: CodeMonkeysMods/MineTale Length of output: 18822 🏁 Script executed: # Read WorkbenchWorkbench to verify IS_TALL/IS_WIDE configuration
cat src/main/java/com/tcm/MineTale/block/workbenches/WorkbenchWorkbench.javaRepository: CodeMonkeysMods/MineTale Length of output: 4014 🏁 Script executed: # Read ModLootTableProvider fully
cat src/client/java/com/tcm/MineTale/datagen/ModLootTableProvider.javaRepository: CodeMonkeysMods/MineTale Length of output: 7984 Remove spurious While the Suggested cleanup this.add(ModBlocks.WORKBENCH_WORKBENCH_BLOCK,
LootTable.lootTable()
.withPool(LootPool.lootPool()
.setRolls(ConstantValue.exactly(1.0F))
.add(LootItem.lootTableItem(ModBlocks.WORKBENCH_WORKBENCH_BLOCK))
.when(LootItemBlockStatePropertyCondition.hasBlockStateProperties(ModBlocks.WORKBENCH_WORKBENCH_BLOCK)
.setProperties(StatePropertiesPredicate.Builder.properties()
- .hasProperty(AbstractWorkbench.HALF, DoubleBlockHalf.LOWER)
.hasProperty(AbstractWorkbench.TYPE, ChestType.LEFT)
)
)
.when(ExplosionCondition.survivesExplosion())
)
);🤖 Prompt for AI Agents |
||
| ) | ||
| .when(ExplosionCondition.survivesExplosion()) | ||
| ) | ||
| ); | ||
|
|
||
| this.add(ModBlocks.FURNACE_WORKBENCH_BLOCK_T1, | ||
| LootTable.lootTable() // Use the static factory method to start the builder | ||
| .withPool(LootPool.lootPool() | ||
| .setRolls(ConstantValue.exactly(1.0F)) | ||
| .add(LootItem.lootTableItem(ModBlocks.FURNACE_WORKBENCH_BLOCK_T1)) | ||
| .when(LootItemBlockStatePropertyCondition.hasBlockStateProperties(ModBlocks.FURNACE_WORKBENCH_BLOCK_T1) | ||
| .setProperties(StatePropertiesPredicate.Builder.properties() | ||
| .hasProperty(AbstractWorkbench.HALF, DoubleBlockHalf.LOWER) | ||
| .hasProperty(AbstractWorkbench.TYPE, ChestType.LEFT) | ||
| ) | ||
| ) | ||
| .when(ExplosionCondition.survivesExplosion()) | ||
| ) | ||
| ); | ||
|
|
||
| this.add(ModBlocks.FURNACE_WORKBENCH_BLOCK_T2, | ||
| LootTable.lootTable() // Use the static factory method to start the builder | ||
| .withPool(LootPool.lootPool() | ||
| .setRolls(ConstantValue.exactly(1.0F)) | ||
| .add(LootItem.lootTableItem(ModBlocks.FURNACE_WORKBENCH_BLOCK_T2)) | ||
| .when(LootItemBlockStatePropertyCondition.hasBlockStateProperties(ModBlocks.FURNACE_WORKBENCH_BLOCK_T2) | ||
| .setProperties(StatePropertiesPredicate.Builder.properties() | ||
| .hasProperty(AbstractWorkbench.HALF, DoubleBlockHalf.LOWER) | ||
| .hasProperty(AbstractWorkbench.TYPE, ChestType.LEFT) | ||
| ) | ||
| ) | ||
| .when(ExplosionCondition.survivesExplosion()) | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
|
|
||
| /// For Ore Drops | ||
| /** | ||
| * Create a loot table builder that drops the specified item in multiple quantities with Silk Touch, Fortune bonus, and explosion decay applied. | ||
| * | ||
| * @param drop the source block used for Silk Touch dispatch and explosion-decay context | ||
| * @param item the item to drop from the ore | ||
| * @return a LootTable.Builder that drops `item` in a base count between 2 and 5, augmented by the Fortune enchantment, with Silk Touch handling and explosion decay applied | ||
| */ | ||
| public LootTable.Builder AverageOreDrops(Block drop, Item item) { | ||
| HolderLookup.RegistryLookup<Enchantment> impl = this.registries.lookupOrThrow(Registries.ENCHANTMENT); | ||
| return this.createSilkTouchDispatchTable(drop, this.applyExplosionDecay(drop, ((LootPoolSingletonContainer.Builder<?>) | ||
| LootItem.lootTableItem(item).apply(SetItemCountFunction.setCount(UniformGenerator.between(2, 5)))) | ||
| .apply(ApplyBonusCount.addOreBonusCount(impl.getOrThrow(Enchantments.FORTUNE))))); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a loot table builder for an ore that yields the specified item with Silk Touch and Fortune handling. | ||
| * | ||
| * The table gives a base drop count of exactly 1 (before Fortune), increases the count with Fortune, returns the | ||
| * ore block when mined with Silk Touch, and applies explosion decay to the drop. | ||
| * | ||
| * @param drop the ore block (returned when Silk Touch is used) | ||
| * @param item the item to drop when the ore is mined without Silk Touch | ||
| * @return a LootTable.Builder configured to drop the specified item with Fortune bonuses, Silk Touch dispatch, | ||
| * and explosion decay | ||
| */ | ||
| public LootTable.Builder SingleOreDrops(Block drop, Item item) { | ||
| HolderLookup.RegistryLookup<Enchantment> impl = this.registries.lookupOrThrow(Registries.ENCHANTMENT); | ||
| return this.createSilkTouchDispatchTable(drop, this.applyExplosionDecay(drop, ((LootPoolSingletonContainer.Builder<?>) | ||
| LootItem.lootTableItem(item).apply(SetItemCountFunction.setCount(ConstantValue.exactly(1)))) | ||
| .apply(ApplyBonusCount.addOreBonusCount(impl.getOrThrow(Enchantments.FORTUNE))))); | ||
| } | ||
|
|
||
| /** | ||
| * Builds a loot table for a "light" ore block that supports Silk Touch, Fortune bonuses, and explosion decay. | ||
| * | ||
| * @param drop the ore block whose loot table is being created | ||
| * @param item the item to drop from the ore when not Silk Touched | ||
| * @return a LootTable.Builder that drops {@code item} in quantities of 1–2 (before Fortune), applies Fortune bonus, | ||
| * dispatches to Silk Touch drops when applicable, and respects explosion decay | ||
| */ | ||
| public LootTable.Builder LightOreDrops(Block drop, Item item) { | ||
| HolderLookup.RegistryLookup<Enchantment> impl = this.registries.lookupOrThrow(Registries.ENCHANTMENT); | ||
| return this.createSilkTouchDispatchTable(drop, this.applyExplosionDecay(drop, ((LootPoolSingletonContainer.Builder<?>) | ||
| LootItem.lootTableItem(item).apply(SetItemCountFunction.setCount(UniformGenerator.between(1, 2)))) | ||
| .apply(ApplyBonusCount.addOreBonusCount(impl.getOrThrow(Enchantments.FORTUNE))))); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove wrong
com.jcraft.jorbis.Blockimport.com.jcraft.jorbisis an Ogg Vorbis audio decoder library; itsBlockclass is a DSP processing block and has nothing to do with Minecraft blocks. This import is unused in this file and should be removed.🐛 Proposed fix
-import com.jcraft.jorbis.Block; import com.tcm.MineTale.registry.ModBlocks;📝 Committable suggestion
🤖 Prompt for AI Agents