MerchantResultSlot .java

net.minecraft.world.inventory.MerchantResultSlot (class): members: merchant, removeCount, checkTakeAchievements, onQuickCraft, mayPickup, onTake, mayPlace.

net.minecraft.world.inventoryclass78 linescommonextends Slot2.2 KB

API Surface (6)

boolean mayPlace(final ItemStack itemStack)
ItemStack remove(final int amount)
void onQuickCraft(final ItemStack picked, final int count)
void checkTakeAchievements(final ItemStack carried)
boolean mayPickup(final Player player)
void onTake(final Player player, final ItemStack carried)

Fields & Constants (4)

slots
player
removeCount
merchant

Code Graph: Dependencies (7)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

MerchantResultSlot.java78 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.inventory;
2
3
import net.minecraft.stats.Stats;
4
import net.minecraft.world.entity.player.Player;
5
import net.minecraft.world.item.ItemStack;
6
import net.minecraft.world.item.trading.Merchant;
7
import net.minecraft.world.item.trading.MerchantOffer;
8
9
public class MerchantResultSlot extends Slot {
10
	private final MerchantContainer slots;
11
	private final Player player;
12
	private int removeCount;
13
	private final Merchant merchant;
14
15
	public MerchantResultSlot(final Player player, final Merchant merchant, final MerchantContainer slots, final int id, final int x, final int y) {
16
		super(slots, id, x, y);
17
		this.player = player;
18
		this.merchant = merchant;
19
		this.slots = slots;
20
	}
21
22
	@Override
23
	public boolean mayPlace(final ItemStack itemStack) {
24
		return false;
25
	}
26
27
	@Override
28
	public ItemStack remove(final int amount) {
29
		if (this.hasItem()) {
30
			this.removeCount = this.removeCount + Math.min(amount, this.getItem().getCount());
31
		}
32
33
		return super.remove(amount);
34
	}
35
36
	@Override
37
	protected void onQuickCraft(final ItemStack picked, final int count) {
38
		this.removeCount += count;
39
		this.checkTakeAchievements(picked);
40
	}
41
42
	@Override
43
	protected void checkTakeAchievements(final ItemStack carried) {
44
		carried.onCraftedBy(this.player, this.removeCount);
45
		this.removeCount = 0;
46
	}
47
48
	@Override
49
	public boolean mayPickup(final Player player) {
50
		MerchantOffer offer = this.slots.getActiveOffer();
51
		if (offer == null) {
52
			return false;
53
		}
54
55
		ItemStack buyA = this.slots.getItem(0);
56
		ItemStack buyB = this.slots.getItem(1);
57
		return (offer.satisfiedBy(buyA, buyB) || offer.satisfiedBy(buyB, buyA)) && super.mayPickup(player);
58
	}
59
60
	@Override
61
	public void onTake(final Player player, final ItemStack carried) {
62
		this.checkTakeAchievements(carried);
63
		MerchantOffer offer = this.slots.getActiveOffer();
64
		if (offer != null) {
65
			ItemStack buyA = this.slots.getItem(0);
66
			ItemStack buyB = this.slots.getItem(1);
67
			if (offer.take(buyA, buyB) || offer.take(buyB, buyA)) {
68
				this.merchant.notifyTrade(offer);
69
				player.awardStat(Stats.TRADED_WITH_VILLAGER);
70
				this.slots.setItem(0, buyA);
71
				this.slots.setItem(1, buyB);
72
			}
73
74
			this.merchant.overrideXp(this.merchant.getVillagerXp() + offer.getXp());
75
		}
76
	}
77
}
78

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