| 1 | package net.minecraft.world.level.storage.loot.predicates;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.advancements.predicates.BlockPredicate;
|
| 5 | import net.minecraft.advancements.predicates.DataComponentMatchers;
|
| 6 | import net.minecraft.advancements.predicates.EnchantmentPredicate;
|
| 7 | import net.minecraft.advancements.predicates.ItemPredicate;
|
| 8 | import net.minecraft.advancements.predicates.MinMaxBounds;
|
| 9 | import net.minecraft.core.HolderGetter;
|
| 10 | import net.minecraft.core.component.predicates.DataComponentPredicates;
|
| 11 | import net.minecraft.core.component.predicates.EnchantmentsPredicate;
|
| 12 | import net.minecraft.core.registries.Registries;
|
| 13 | import net.minecraft.data.worldgen.BootstrapContext;
|
| 14 | import net.minecraft.resources.Identifier;
|
| 15 | import net.minecraft.resources.ResourceKey;
|
| 16 | import net.minecraft.world.item.Item;
|
| 17 | import net.minecraft.world.item.Items;
|
| 18 | import net.minecraft.world.item.enchantment.Enchantment;
|
| 19 | import net.minecraft.world.item.enchantment.Enchantments;
|
| 20 | import net.minecraft.world.level.block.Block;
|
| 21 | import net.minecraft.world.level.block.Blocks;
|
| 22 |
|
| 23 | public class LootPredicates {
|
| 24 | public static final ResourceKey<LootItemCondition> TOOL_CAN_SILK_TOUCH = createKey("tool/can_silk_touch");
|
| 25 | public static final ResourceKey<LootItemCondition> TOOL_CAN_SHEAR = createKey("tool/can_shear");
|
| 26 | public static final ResourceKey<LootItemCondition> FAST_FURNACE = createKey("block/fast_cooking");
|
| 27 |
|
| 28 | private static ResourceKey<LootItemCondition> createKey(final String name) {
|
| 29 | return ResourceKey.create(Registries.PREDICATE, Identifier.withDefaultNamespace(name));
|
| 30 | }
|
| 31 |
|
| 32 | public static void bootstrap(final BootstrapContext<LootItemCondition> context) {
|
| 33 | HolderGetter<Enchantment> enchantments = context.lookup(Registries.ENCHANTMENT);
|
| 34 | HolderGetter<Item> items = context.lookup(Registries.ITEM);
|
| 35 | HolderGetter<Block> blocks = context.lookup(Registries.BLOCK);
|
| 36 | context.register(
|
| 37 | TOOL_CAN_SILK_TOUCH,
|
| 38 | MatchTool.toolMatches(
|
| 39 | ItemPredicate.Builder.item()
|
| 40 | .withComponents(
|
| 41 | DataComponentMatchers.Builder.components()
|
| 42 | .partial(
|
| 43 | DataComponentPredicates.ENCHANTMENTS,
|
| 44 | EnchantmentsPredicate.enchantments(List.of(new EnchantmentPredicate(enchantments.getOrThrow(Enchantments.SILK_TOUCH), MinMaxBounds.Ints.atLeast(1))))
|
| 45 | )
|
| 46 | .build()
|
| 47 | )
|
| 48 | )
|
| 49 | .build()
|
| 50 | );
|
| 51 | context.register(TOOL_CAN_SHEAR, MatchTool.toolMatches(ItemPredicate.Builder.item().of(items, Items.SHEARS)).build());
|
| 52 | context.register(FAST_FURNACE, MatchBlock.blockMatches(BlockPredicate.Builder.block().of(blocks, Blocks.SMOKER, Blocks.BLAST_FURNACE)).build());
|
| 53 | }
|
| 54 | }
|
| 55 |
|