mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 11:06:29 +01:00
83 lines
3.9 KiB
Diff
83 lines
3.9 KiB
Diff
--- a/net/minecraft/server/EntityVillager.java
|
|
+++ b/net/minecraft/server/EntityVillager.java
|
|
@@ -7,6 +7,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 {
|
|
|
|
@@ -26,7 +34,7 @@
|
|
public int riches;
|
|
private String bO;
|
|
public int careerId;
|
|
- private int bQ;
|
|
+ public int bQ; // PAIL private->public
|
|
private boolean bR;
|
|
private boolean bS;
|
|
public final InventorySubcontainer inventory;
|
|
@@ -38,7 +46,7 @@
|
|
|
|
public EntityVillager(World world, int i) {
|
|
super(EntityTypes.VILLAGER, world);
|
|
- this.inventory = new InventorySubcontainer(new ChatComponentText("Items"), 8);
|
|
+ this.inventory = new InventorySubcontainer(new ChatComponentText("Items"), 8, (CraftVillager) this.getBukkitEntity()); // CraftBukkit add argument
|
|
this.setProfession(i);
|
|
this.setSize(0.6F, 1.95F);
|
|
((Navigation) this.getNavigation()).a(true);
|
|
@@ -120,7 +128,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
|
|
}
|
|
}
|
|
|
|
@@ -132,7 +147,7 @@
|
|
}
|
|
}
|
|
|
|
- this.addEffect(new MobEffect(MobEffects.REGENERATION, 200, 0));
|
|
+ this.addEffect(new MobEffect(MobEffects.REGENERATION, 200, 0), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.VILLAGER_TRADE); // CraftBukkit
|
|
}
|
|
}
|
|
|
|
@@ -434,7 +449,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
|
|
}
|
|
}
|
|
|