2021-03-15 23:00:00 +01:00
|
|
|
--- a/net/minecraft/world/entity/npc/EntityVillagerAbstract.java
|
|
|
|
+++ b/net/minecraft/world/entity/npc/EntityVillagerAbstract.java
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -40,8 +40,24 @@
|
2021-06-11 07:00:00 +02:00
|
|
|
import net.minecraft.world.phys.Vec3D;
|
2024-04-23 17:15:00 +02:00
|
|
|
import org.slf4j.Logger;
|
2021-03-08 22:47:33 +01:00
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
+// CraftBukkit start
|
|
|
|
+import org.bukkit.Bukkit;
|
2019-04-28 04:35:28 +02:00
|
|
|
+import org.bukkit.craftbukkit.inventory.CraftMerchant;
|
2019-04-23 04:00:00 +02:00
|
|
|
+import org.bukkit.craftbukkit.inventory.CraftMerchantRecipe;
|
|
|
|
+import org.bukkit.entity.AbstractVillager;
|
|
|
|
+import org.bukkit.event.entity.VillagerAcquireTradeEvent;
|
|
|
|
+// CraftBukkit end
|
2021-03-08 22:47:33 +01:00
|
|
|
+
|
2021-06-11 07:00:00 +02:00
|
|
|
public abstract class EntityVillagerAbstract extends EntityAgeable implements InventoryCarrier, NPC, IMerchant {
|
2019-04-23 04:00:00 +02:00
|
|
|
|
2019-04-28 04:35:28 +02:00
|
|
|
+ // CraftBukkit start
|
|
|
|
+ private CraftMerchant craftMerchant;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public CraftMerchant getCraftMerchant() {
|
|
|
|
+ return (craftMerchant == null) ? craftMerchant = new CraftMerchant(this) : craftMerchant;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2021-11-21 23:00:00 +01:00
|
|
|
private static final DataWatcherObject<Integer> DATA_UNHAPPY_COUNTER = DataWatcher.defineId(EntityVillagerAbstract.class, DataWatcherRegistry.INT);
|
2024-04-23 17:15:00 +02:00
|
|
|
private static final Logger LOGGER = LogUtils.getLogger();
|
2021-06-11 07:00:00 +02:00
|
|
|
public static final int VILLAGER_SLOT_OFFSET = 300;
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -50,7 +66,7 @@
|
2019-04-23 04:00:00 +02:00
|
|
|
private EntityHuman tradingPlayer;
|
|
|
|
@Nullable
|
2021-06-11 07:00:00 +02:00
|
|
|
protected MerchantRecipeList offers;
|
2019-04-23 04:00:00 +02:00
|
|
|
- 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) {
|
2019-05-14 02:00:00 +02:00
|
|
|
super(entitytypes, world);
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -173,7 +189,7 @@
|
|
|
|
public void readAdditionalSaveData(NBTTagCompound nbttagcompound) {
|
|
|
|
super.readAdditionalSaveData(nbttagcompound);
|
|
|
|
if (nbttagcompound.contains("Offers")) {
|
|
|
|
- DataResult dataresult = MerchantRecipeList.CODEC.parse(this.registryAccess().createSerializationContext(DynamicOpsNBT.INSTANCE), nbttagcompound.get("Offers"));
|
|
|
|
+ DataResult<MerchantRecipeList> dataresult = MerchantRecipeList.CODEC.parse(this.registryAccess().createSerializationContext(DynamicOpsNBT.INSTANCE), nbttagcompound.get("Offers")); // CraftBukkit - decompile error
|
|
|
|
Logger logger = EntityVillagerAbstract.LOGGER;
|
|
|
|
|
|
|
|
Objects.requireNonNull(logger);
|
|
|
|
@@ -240,7 +256,16 @@
|
2023-09-21 18:40:00 +02:00
|
|
|
MerchantRecipe merchantrecipe = ((VillagerTrades.IMerchantRecipeOption) arraylist.remove(this.random.nextInt(arraylist.size()))).getOffer(this, this.random);
|
2019-04-23 04:00:00 +02:00
|
|
|
|
|
|
|
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
|
2023-09-21 18:40:00 +02:00
|
|
|
++j;
|
2019-04-23 04:00:00 +02:00
|
|
|
}
|
|
|
|
}
|