Commits
Miles Holder authored and md_5 committed 19c8ef9ae3d
1 1 | --- a/net/minecraft/world/entity/npc/EntityVillagerAbstract.java |
2 2 | +++ b/net/minecraft/world/entity/npc/EntityVillagerAbstract.java |
3 - | |
3 + | |
4 4 | import net.minecraft.world.phys.Vec3D; |
5 5 | import org.slf4j.Logger; |
6 6 | |
7 7 | +// CraftBukkit start |
8 8 | +import org.bukkit.Bukkit; |
9 9 | +import org.bukkit.craftbukkit.inventory.CraftMerchant; |
10 10 | +import org.bukkit.craftbukkit.inventory.CraftMerchantRecipe; |
11 11 | +import org.bukkit.entity.AbstractVillager; |
12 12 | +import org.bukkit.event.entity.VillagerAcquireTradeEvent; |
13 13 | +// CraftBukkit end |
14 14 | + |
15 15 | public abstract class EntityVillagerAbstract extends EntityAgeable implements InventoryCarrier, NPC, IMerchant { |
16 16 | |
17 17 | + // CraftBukkit start |
18 - | + private CraftMerchant craftMerchant; |
19 - | + |
20 18 | + @Override |
21 19 | + public CraftMerchant getCraftMerchant() { |
22 - | + return (craftMerchant == null) ? craftMerchant = new CraftMerchant(this) : craftMerchant; |
20 + | + return (org.bukkit.craftbukkit.entity.CraftAbstractVillager) getBukkitEntity(); |
23 21 | + } |
24 22 | + // CraftBukkit end |
25 23 | private static final DataWatcherObject<Integer> DATA_UNHAPPY_COUNTER = DataWatcher.defineId(EntityVillagerAbstract.class, DataWatcherRegistry.INT); |
26 24 | private static final Logger LOGGER = LogUtils.getLogger(); |
27 25 | public static final int VILLAGER_SLOT_OFFSET = 300; |
28 - | |
26 + | |
29 27 | private EntityHuman tradingPlayer; |
30 28 | @Nullable |
31 29 | protected MerchantRecipeList offers; |
32 30 | - private final InventorySubcontainer inventory = new InventorySubcontainer(8); |
33 31 | + private final InventorySubcontainer inventory = new InventorySubcontainer(8, (org.bukkit.craftbukkit.entity.CraftAbstractVillager) this.getBukkitEntity()); // CraftBukkit add argument |
34 32 | |
35 33 | public EntityVillagerAbstract(EntityTypes<? extends EntityVillagerAbstract> entitytypes, World world) { |
36 34 | super(entitytypes, world); |
37 - | |
35 + | |
38 36 | public void readAdditionalSaveData(NBTTagCompound nbttagcompound) { |
39 37 | super.readAdditionalSaveData(nbttagcompound); |
40 38 | if (nbttagcompound.contains("Offers")) { |
41 39 | - DataResult dataresult = MerchantRecipeList.CODEC.parse(this.registryAccess().createSerializationContext(DynamicOpsNBT.INSTANCE), nbttagcompound.get("Offers")); |
42 40 | + DataResult<MerchantRecipeList> dataresult = MerchantRecipeList.CODEC.parse(this.registryAccess().createSerializationContext(DynamicOpsNBT.INSTANCE), nbttagcompound.get("Offers")); // CraftBukkit - decompile error |
43 41 | Logger logger = EntityVillagerAbstract.LOGGER; |
44 42 | |
45 43 | Objects.requireNonNull(logger); |
46 - | |
44 + | |
47 45 | MerchantRecipe merchantrecipe = ((VillagerTrades.IMerchantRecipeOption) arraylist.remove(this.random.nextInt(arraylist.size()))).getOffer(this, this.random); |
48 46 | |
49 47 | if (merchantrecipe != null) { |
50 48 | - merchantrecipelist.add(merchantrecipe); |
51 49 | + // CraftBukkit start |
52 50 | + VillagerAcquireTradeEvent event = new VillagerAcquireTradeEvent((AbstractVillager) getBukkitEntity(), merchantrecipe.asBukkit()); |
53 51 | + // Suppress during worldgen |
54 52 | + if (this.valid) { |
55 53 | + Bukkit.getPluginManager().callEvent(event); |
56 54 | + } |