|
| 1 | +package net.kaupenjoe.tutorialmod.util; |
| 2 | + |
| 3 | +import net.fabricmc.fabric.api.loot.v3.LootTableEvents; |
| 4 | +import net.kaupenjoe.tutorialmod.item.ModItems; |
| 5 | +import net.minecraft.loot.LootPool; |
| 6 | +import net.minecraft.loot.LootTables; |
| 7 | +import net.minecraft.loot.condition.RandomChanceLootCondition; |
| 8 | +import net.minecraft.loot.entry.ItemEntry; |
| 9 | +import net.minecraft.loot.function.SetCountLootFunction; |
| 10 | +import net.minecraft.loot.provider.number.ConstantLootNumberProvider; |
| 11 | +import net.minecraft.loot.provider.number.UniformLootNumberProvider; |
| 12 | +import net.minecraft.util.Identifier; |
| 13 | + |
| 14 | +public class ModLootTableModifiers { |
| 15 | + private static final Identifier GRASS_BLOCK_ID |
| 16 | + = Identifier.of("minecraft", "blocks/short_grass"); |
| 17 | + private static final Identifier CREEPER_ID |
| 18 | + = Identifier.of("minecraft", "entities/creeper"); |
| 19 | + |
| 20 | + public static void modifyLootTables() { |
| 21 | + LootTableEvents.MODIFY.register((key, tableBuilder, source, registry) -> { |
| 22 | + if(GRASS_BLOCK_ID.equals(key.getValue())) { |
| 23 | + LootPool.Builder poolBuilder = LootPool.builder() |
| 24 | + .rolls(ConstantLootNumberProvider.create(1)) |
| 25 | + .conditionally(RandomChanceLootCondition.builder(0.25f)) // Drops 25% of the time |
| 26 | + .with(ItemEntry.builder(ModItems.CAULIFLOWER_SEEDS)) |
| 27 | + .apply(SetCountLootFunction.builder(UniformLootNumberProvider.create(1.0f, 2.0f)).build()); |
| 28 | + |
| 29 | + tableBuilder.pool(poolBuilder.build()); |
| 30 | + } |
| 31 | + |
| 32 | + if(LootTables.IGLOO_CHEST_CHEST.equals(key)) { |
| 33 | + LootPool.Builder poolBuilder = LootPool.builder() |
| 34 | + .rolls(ConstantLootNumberProvider.create(1)) |
| 35 | + .conditionally(RandomChanceLootCondition.builder(1.0f)) // Drops 100% of the time |
| 36 | + .with(ItemEntry.builder(ModItems.CHISEL)) |
| 37 | + .apply(SetCountLootFunction.builder(UniformLootNumberProvider.create(1.0f, 2.0f)).build()); |
| 38 | + |
| 39 | + tableBuilder.pool(poolBuilder.build()); |
| 40 | + } |
| 41 | + |
| 42 | + if(CREEPER_ID.equals(key.getValue())) { |
| 43 | + LootPool.Builder poolBuilder = LootPool.builder() |
| 44 | + .rolls(ConstantLootNumberProvider.create(1)) |
| 45 | + .conditionally(RandomChanceLootCondition.builder(0.75f)) // Drops 75% of the time |
| 46 | + .with(ItemEntry.builder(ModItems.CAULIFLOWER)) |
| 47 | + .apply(SetCountLootFunction.builder(UniformLootNumberProvider.create(1.0f, 2.0f)).build()); |
| 48 | + |
| 49 | + tableBuilder.pool(poolBuilder.build()); |
| 50 | + } |
| 51 | + }); |
| 52 | + } |
| 53 | +} |
0 commit comments