3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-20 21:40:06 +01:00
Paper/nms-patches/EntityVillagerAbstract.patch
2020-08-12 07:00:00 +10:00

53 Zeilen
2.3 KiB
Diff

--- a/net/minecraft/server/EntityVillagerAbstract.java
+++ b/net/minecraft/server/EntityVillagerAbstract.java
@@ -4,15 +4,30 @@
import java.util.Iterator;
import java.util.Set;
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.inventory.CraftMerchant;
+import org.bukkit.craftbukkit.inventory.CraftMerchantRecipe;
+import org.bukkit.entity.AbstractVillager;
+import org.bukkit.event.entity.VillagerAcquireTradeEvent;
+// CraftBukkit end
public abstract class EntityVillagerAbstract extends EntityAgeable implements NPC, IMerchant {
+ // CraftBukkit start
+ private CraftMerchant craftMerchant;
+
+ @Override
+ public CraftMerchant getCraftMerchant() {
+ return (craftMerchant == null) ? craftMerchant = new CraftMerchant(this) : craftMerchant;
+ }
+ // CraftBukkit end
private static final DataWatcherObject<Integer> bp = DataWatcher.a(EntityVillagerAbstract.class, DataWatcherRegistry.b);
@Nullable
private EntityHuman tradingPlayer;
@Nullable
protected MerchantRecipeList trades;
- private final InventorySubcontainer inventory = new InventorySubcontainer(8);
+ private final InventorySubcontainer inventory = new InventorySubcontainer(8, (org.bukkit.craftbukkit.entity.CraftAbstractVillager) this.getBukkitEntity()); // CraftBukkit add argument
public EntityVillagerAbstract(EntityTypes<? extends EntityVillagerAbstract> entitytypes, World world) {
super(entitytypes, world);
@@ -213,7 +228,16 @@
MerchantRecipe merchantrecipe = villagertrades_imerchantrecipeoption.a(this, this.random);
if (merchantrecipe != null) {
- merchantrecipelist.add(merchantrecipe);
+ // CraftBukkit start
+ VillagerAcquireTradeEvent event = new VillagerAcquireTradeEvent((AbstractVillager) getBukkitEntity(), merchantrecipe.asBukkit());
+ // Suppress during worldgen
+ if (this.valid) {
+ Bukkit.getPluginManager().callEvent(event);
+ }
+ if (!event.isCancelled()) {
+ merchantrecipelist.add(CraftMerchantRecipe.fromBukkit(event.getRecipe()).toMinecraft());
+ }
+ // CraftBukkit end
}
}