summaryrefslogtreecommitdiffstats
path: root/nms-patches/EntityVillager.patch
blob: 8693d0ff097c33ce5d767bda6a9c023e3debd85d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
--- a/net/minecraft/server/EntityVillager.java
+++ b/net/minecraft/server/EntityVillager.java
@@ -6,6 +6,14 @@
 import javax.annotation.Nullable;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.entity.CraftVillager;
+import org.bukkit.craftbukkit.inventory.CraftMerchantRecipe;
+import org.bukkit.entity.Villager;
+import org.bukkit.event.entity.VillagerAcquireTradeEvent;
+import org.bukkit.event.entity.VillagerReplenishTradeEvent;
+// CraftBukkit end
 
 public class EntityVillager extends EntityAgeable implements NPC, IMerchant {
 
@@ -18,13 +26,13 @@
     @Nullable
     private EntityHuman tradingPlayer;
     @Nullable
-    private MerchantRecipeList trades;
+    public MerchantRecipeList trades; // PAIL private -> public
     private int bF;
     private boolean bG;
     private boolean bH;
     public int riches;
     private String bJ;
-    private int bK;
+    public int bK; // PAIL private -> public // PAIL rename careerID
     private int bL;
     private boolean bM;
     private boolean bN;
@@ -37,7 +45,7 @@
 
     public EntityVillager(World world, int i) {
         super(world);
-        this.inventory = new InventorySubcontainer("Items", false, 8);
+        this.inventory = new InventorySubcontainer("Items", false, 8, (CraftVillager) this.getBukkitEntity()); // CraftBukkit add argument
         this.setProfession(i);
         this.setSize(0.6F, 1.95F);
         ((Navigation) this.getNavigation()).a(true);
@@ -119,7 +127,14 @@
                         MerchantRecipe merchantrecipe = (MerchantRecipe) iterator.next();
 
                         if (merchantrecipe.h()) {
-                            merchantrecipe.a(this.random.nextInt(6) + this.random.nextInt(6) + 2);
+                            // CraftBukkit start
+                            int bonus = this.random.nextInt(6) + this.random.nextInt(6) + 2;
+                            VillagerReplenishTradeEvent event = new VillagerReplenishTradeEvent((Villager) this.getBukkitEntity(), merchantrecipe.asBukkit(), bonus);
+                            Bukkit.getPluginManager().callEvent(event);
+                            if (!event.isCancelled()) {
+                                merchantrecipe.a(event.getBonus());
+                            }
+                            // CraftBukkit end
                         }
                     }
 
@@ -432,7 +447,7 @@
         return this.trades;
     }
 
-    private void dx() {
+    public void dx() { // CraftBukkit private -> public // PAIL rename populateTrades
         EntityVillager.IMerchantRecipeOption[][][] aentityvillager_imerchantrecipeoption = EntityVillager.bP[this.getProfession()];
 
         if (this.bK != 0 && this.bL != 0) {
@@ -460,7 +475,20 @@
                 for (int l = 0; l < k; ++l) {
                     EntityVillager.IMerchantRecipeOption entityvillager_imerchantrecipeoption = aentityvillager_imerchantrecipeoption3[l];
 
-                    entityvillager_imerchantrecipeoption.a(this, this.trades, this.random);
+                    // CraftBukkit start
+                    // this is a hack. this must be done because otherwise, if
+                    // mojang adds a new type of villager merchant option, it will need to
+                    // have event handling added manually. this is better than having to do that.
+                    MerchantRecipeList list = new MerchantRecipeList();
+                    entityvillager_imerchantrecipeoption.a(this, list, this.random);
+                    for (MerchantRecipe recipe : list) {
+                        VillagerAcquireTradeEvent event = new VillagerAcquireTradeEvent((Villager) getBukkitEntity(), recipe.asBukkit());
+                        Bukkit.getPluginManager().callEvent(event);
+                        if (!event.isCancelled()) {
+                            this.trades.add(CraftMerchantRecipe.fromBukkit(event.getRecipe()).toMinecraft());
+                        }
+                    }
+                    // CraftBukkit end
                 }
             }