3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 20:40:07 +01:00
Paper/nms-patches/EntityVillager.patch

90 Zeilen
4.3 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/EntityVillager.java
+++ b/net/minecraft/server/EntityVillager.java
2018-12-25 22:00:00 +01:00
@@ -6,6 +6,16 @@
2016-05-10 13:47:39 +02:00
import javax.annotation.Nullable;
2016-11-17 02:41:03 +01:00
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2016-05-10 13:47:39 +02:00
+// CraftBukkit start
2016-02-29 22:32:46 +01:00
+import org.bukkit.Bukkit;
2016-05-10 13:47:39 +02:00
+import org.bukkit.craftbukkit.entity.CraftVillager;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
2016-02-29 22:32:46 +01:00
+import org.bukkit.craftbukkit.inventory.CraftMerchantRecipe;
+import org.bukkit.entity.Villager;
+import org.bukkit.event.entity.EntityTransformEvent;
2016-02-29 22:32:46 +01:00
+import org.bukkit.event.entity.VillagerAcquireTradeEvent;
+import org.bukkit.event.entity.VillagerReplenishTradeEvent;
2016-05-10 13:47:39 +02:00
+// CraftBukkit end
2016-11-17 02:41:03 +01:00
public class EntityVillager extends EntityAgeable implements NPC, IMerchant {
2018-12-25 22:00:00 +01:00
@@ -37,7 +47,7 @@
public EntityVillager(World world, int i) {
2018-07-15 02:00:00 +02:00
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);
2016-02-29 22:32:46 +01:00
this.setSize(0.6F, 1.95F);
((Navigation) this.getNavigation()).a(true);
2018-12-25 22:00:00 +01:00
@@ -119,7 +129,14 @@
2016-02-29 22:32:46 +01:00
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
}
}
2018-12-25 22:00:00 +01:00
@@ -131,7 +148,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
}
}
2018-12-25 22:00:00 +01:00
@@ -433,7 +450,20 @@
2016-11-17 02:41:03 +01:00
for (int l = 0; l < k; ++l) {
EntityVillager.IMerchantRecipeOption entityvillager_imerchantrecipeoption = aentityvillager_imerchantrecipeoption3[l];
2016-02-29 22:32:46 +01:00
2016-11-17 02:41:03 +01:00
- 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());
+ }
2016-02-29 22:32:46 +01:00
+ }
2016-11-17 02:41:03 +01:00
+ // CraftBukkit end
}
2016-02-29 22:32:46 +01:00
}
2018-12-25 22:00:00 +01:00
@@ -568,7 +598,12 @@
entitywitch.setCustomNameVisible(this.getCustomNameVisible());
}
- this.world.addEntity(entitywitch);
+ // CraftBukkit start
+ if (CraftEventFactory.callEntityTransformEvent(this, entitywitch, EntityTransformEvent.TransformReason.LIGHTNING).isCancelled()) {
+ return;
+ }
+ this.world.addEntity(entitywitch, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.LIGHTNING);
+ // CraftBukkit end
this.die();
}
}