Commits

Miles Holder authored and md_5 committed 19c8ef9ae3d
SPIGOT-7867: Merchant instanceof AbstractVillager always returns false
No tags

nms-patches/net/minecraft/world/entity/npc/EntityVillagerAbstract.patch

Modified
1 1 --- a/net/minecraft/world/entity/npc/EntityVillagerAbstract.java
2 2 +++ b/net/minecraft/world/entity/npc/EntityVillagerAbstract.java
3 -@@ -40,8 +40,24 @@
3 +@@ -40,8 +40,22 @@
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 -@@ -50,7 +66,7 @@
26 +@@ -50,7 +64,7 @@
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 -@@ -179,7 +195,7 @@
35 +@@ -179,7 +193,7 @@
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 -@@ -246,7 +262,16 @@
44 +@@ -246,7 +260,16 @@
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 + }

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut