| 1 | package net.minecraft.core.cauldron;
|
| 2 |
|
| 3 | import java.util.HashMap;
|
| 4 | import java.util.Map;
|
| 5 | import java.util.Map.Entry;
|
| 6 | import net.minecraft.core.BlockPos;
|
| 7 | import net.minecraft.tags.TagKey;
|
| 8 | import net.minecraft.world.InteractionHand;
|
| 9 | import net.minecraft.world.InteractionResult;
|
| 10 | import net.minecraft.world.entity.player.Player;
|
| 11 | import net.minecraft.world.item.Item;
|
| 12 | import net.minecraft.world.item.ItemStack;
|
| 13 | import net.minecraft.world.level.Level;
|
| 14 | import net.minecraft.world.level.block.state.BlockState;
|
| 15 |
|
| 16 | @FunctionalInterface
|
| 17 | public interface CauldronInteraction {
|
| 18 | CauldronInteraction DEFAULT = (var0, var1, var2, var3, var4, var5) -> InteractionResult.TRY_WITH_EMPTY_HAND;
|
| 19 |
|
| 20 | InteractionResult interact(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, ItemStack itemInHand);
|
| 21 |
|
| 22 | class Dispatcher {
|
| 23 | private final Map<TagKey<Item>, CauldronInteraction> tags = new HashMap<>();
|
| 24 | private final Map<Item, CauldronInteraction> items = new HashMap<>();
|
| 25 |
|
| 26 | void put(final Item item, final CauldronInteraction interaction) {
|
| 27 | this.items.put(item, interaction);
|
| 28 | }
|
| 29 |
|
| 30 | void put(final TagKey<Item> tag, final CauldronInteraction interaction) {
|
| 31 | this.tags.put(tag, interaction);
|
| 32 | }
|
| 33 |
|
| 34 | public CauldronInteraction get(final ItemStack itemStack) {
|
| 35 | for (Entry<TagKey<Item>, CauldronInteraction> e : this.tags.entrySet()) {
|
| 36 | if (itemStack.is(e.getKey())) {
|
| 37 | return e.getValue();
|
| 38 | }
|
| 39 | }
|
| 40 |
|
| 41 | return this.items.getOrDefault(itemStack.getItem(), CauldronInteraction.DEFAULT);
|
| 42 | }
|
| 43 | }
|
| 44 | }
|
| 45 |
|