EmptyMapItem .java

net.minecraft.world.item.EmptyMapItem (class, 39 lines): extends Item. members: use. imports: Prediction, Stats, InteractionHand, InteractionResult.

net.minecraft.world.itemclass39 linescommonextends Item1.3 KB

API Surface (1)

InteractionResult use(final Level level, final Player player, final InteractionHand hand)

Full Source

EmptyMapItem.java39 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.item;
2
3
import net.minecraft.server.level.ServerLevel;
4
import net.minecraft.sounds.SoundEvents;
5
import net.minecraft.stats.Stats;
6
import net.minecraft.util.Prediction;
7
import net.minecraft.world.InteractionHand;
8
import net.minecraft.world.InteractionResult;
9
import net.minecraft.world.entity.player.Player;
10
import net.minecraft.world.level.Level;
11
12
public class EmptyMapItem extends Item {
13
	public EmptyMapItem(final Item.Properties properties) {
14
		super(properties);
15
	}
16
17
	@Override
18
	public InteractionResult use(final Level level, final Player player, final InteractionHand hand) {
19
		ItemStack itemStack = player.getItemInHand(hand);
20
		if (level instanceof ServerLevel serverLevel) {
21
			itemStack.consume(1, player);
22
			player.awardStat(Stats.ITEM_USED.get(this));
23
			serverLevel.playSound(null, player, SoundEvents.UI_CARTOGRAPHY_TABLE_TAKE_RESULT, player.getSoundSource(), 1.0F, 1.0F);
24
			ItemStack map = MapItem.create(serverLevel, player.getBlockX(), player.getBlockZ(), (byte)0, true, false);
25
			if (itemStack.isEmpty()) {
26
				return InteractionResult.SUCCESS.heldItemTransformedTo(map);
27
			}
28
29
			if (!player.getInventory().add(map.copy())) {
30
				player.drop(map, false, Prediction.SERVER_ONLY);
31
			}
32
33
			return InteractionResult.SUCCESS;
34
		} else {
35
			return InteractionResult.SUCCESS;
36
		}
37
	}
38
}
39

Decompiled Minecraft 26.3 source of EmptyMapItem (net/minecraft/world/item/EmptyMapItem.java) with Mojang official mappings, stored verbatim on the site.