CraftBukkit/nms-patches/net/minecraft/world/entity/npc/EntityVillagerAbstract.patch
2025-03-26 03:05:00 +11:00

62 lines
3.2 KiB
Diff

--- a/net/minecraft/world/entity/npc/EntityVillagerAbstract.java
+++ b/net/minecraft/world/entity/npc/EntityVillagerAbstract.java
@@ -34,8 +34,22 @@
import net.minecraft.world.level.portal.TeleportTransition;
import net.minecraft.world.phys.Vec3D;
+// 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 InventoryCarrier, NPC, IMerchant {
+ // CraftBukkit start
+ @Override
+ public CraftMerchant getCraftMerchant() {
+ return (org.bukkit.craftbukkit.entity.CraftAbstractVillager) getBukkitEntity();
+ }
+ // CraftBukkit end
private static final DataWatcherObject<Integer> DATA_UNHAPPY_COUNTER = DataWatcher.<Integer>defineId(EntityVillagerAbstract.class, DataWatcherRegistry.INT);
public static final int VILLAGER_SLOT_OFFSET = 300;
private static final int VILLAGER_INVENTORY_SIZE = 8;
@@ -43,7 +57,7 @@
private EntityHuman tradingPlayer;
@Nullable
protected MerchantRecipeList offers;
- 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);
@@ -171,7 +185,7 @@
@Override
public void readAdditionalSaveData(NBTTagCompound nbttagcompound) {
super.readAdditionalSaveData(nbttagcompound);
- this.offers = (MerchantRecipeList) nbttagcompound.read("Offers", MerchantRecipeList.CODEC, this.registryAccess().createSerializationContext(DynamicOpsNBT.INSTANCE)).orElse((Object) null);
+ this.offers = (MerchantRecipeList) nbttagcompound.read("Offers", MerchantRecipeList.CODEC, this.registryAccess().createSerializationContext(DynamicOpsNBT.INSTANCE)).orElse(null); // CraftBukkit - decompile error
this.readInventoryFromTag(nbttagcompound, this.registryAccess());
}
@@ -230,7 +244,16 @@
MerchantRecipe merchantrecipe = ((VillagerTrades.IMerchantRecipeOption) arraylist.remove(this.random.nextInt(arraylist.size()))).getOffer(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
++j;
}
}