aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower/net/minecraft/world/entity/npc/AbstractVillager.java.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/world/entity/npc/AbstractVillager.java.patch')
-rw-r--r--patch-remap/mache-vineflower/net/minecraft/world/entity/npc/AbstractVillager.java.patch228
1 files changed, 228 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/world/entity/npc/AbstractVillager.java.patch b/patch-remap/mache-vineflower/net/minecraft/world/entity/npc/AbstractVillager.java.patch
new file mode 100644
index 0000000000..80869a4e93
--- /dev/null
+++ b/patch-remap/mache-vineflower/net/minecraft/world/entity/npc/AbstractVillager.java.patch
@@ -0,0 +1,228 @@
+--- a/net/minecraft/world/entity/npc/AbstractVillager.java
++++ b/net/minecraft/world/entity/npc/AbstractVillager.java
+@@ -20,11 +20,11 @@
+ import net.minecraft.world.entity.AgeableMob;
+ import net.minecraft.world.entity.Entity;
+ import net.minecraft.world.entity.EntityDimensions;
++import net.minecraft.world.entity.EntityPose;
+ import net.minecraft.world.entity.EntityType;
+-import net.minecraft.world.entity.MobSpawnType;
+-import net.minecraft.world.entity.Pose;
++import net.minecraft.world.entity.EnumMobSpawn;
++import net.minecraft.world.entity.GroupDataEntity;
+ import net.minecraft.world.entity.SlotAccess;
+-import net.minecraft.world.entity.SpawnGroupData;
+ import net.minecraft.world.entity.player.Player;
+ import net.minecraft.world.item.ItemStack;
+ import net.minecraft.world.item.trading.Merchant;
+@@ -34,8 +34,23 @@
+ import net.minecraft.world.level.ServerLevelAccessor;
+ import net.minecraft.world.level.pathfinder.BlockPathTypes;
+ import net.minecraft.world.phys.Vec3;
++// CraftBukkit start
++import org.bukkit.Bukkit;
++import org.bukkit.craftbukkit.inventory.CraftMerchant;
++import org.bukkit.craftbukkit.inventory.CraftMerchantRecipe;
++import org.bukkit.event.entity.VillagerAcquireTradeEvent;
++// CraftBukkit end
+
+-public abstract class AbstractVillager extends AgeableMob implements InventoryCarrier, Npc, Merchant {
++public abstract class AbstractVillager extends AgeableMob implements InventoryCarrier, NPC, Merchant {
++
++ // CraftBukkit start
++ private CraftMerchant craftMerchant;
++
++ @Override
++ public CraftMerchant getCraftMerchant() {
++ return (craftMerchant == null) ? craftMerchant = new CraftMerchant(this) : craftMerchant;
++ }
++ // CraftBukkit end
+ private static final EntityDataAccessor<Integer> DATA_UNHAPPY_COUNTER = SynchedEntityData.defineId(AbstractVillager.class, EntityDataSerializers.INT);
+ public static final int VILLAGER_SLOT_OFFSET = 300;
+ private static final int VILLAGER_INVENTORY_SIZE = 8;
+@@ -43,7 +58,7 @@
+ private Player tradingPlayer;
+ @Nullable
+ protected MerchantOffers offers;
+- private final SimpleContainer inventory = new SimpleContainer(8);
++ private final SimpleContainer inventory = new SimpleContainer(8, (org.bukkit.craftbukkit.entity.CraftAbstractVillager) this.getBukkitEntity()); // CraftBukkit add argument
+
+ public AbstractVillager(EntityType<? extends AbstractVillager> entityType, Level level) {
+ super(entityType, level);
+@@ -52,22 +67,20 @@
+ }
+
+ @Override
+- public SpawnGroupData finalizeSpawn(
+- ServerLevelAccessor level, DifficultyInstance difficulty, MobSpawnType reason, @Nullable SpawnGroupData spawnData, @Nullable CompoundTag dataTag
+- ) {
++ public GroupDataEntity finalizeSpawn(ServerLevelAccessor level, DifficultyInstance difficulty, EnumMobSpawn reason, @Nullable GroupDataEntity spawnData, @Nullable CompoundTag dataTag) {
+ if (spawnData == null) {
+ spawnData = new AgeableMob.AgeableMobGroupData(false);
+ }
+
+- return super.finalizeSpawn(level, difficulty, reason, spawnData, dataTag);
++ return super.finalizeSpawn(level, difficulty, reason, (GroupDataEntity) spawnData, dataTag);
+ }
+
+ public int getUnhappyCounter() {
+- return this.entityData.get(DATA_UNHAPPY_COUNTER);
++ return (Integer) this.entityData.get(AbstractVillager.DATA_UNHAPPY_COUNTER);
+ }
+
+ public void setUnhappyCounter(int unhappyCounter) {
+- this.entityData.set(DATA_UNHAPPY_COUNTER, unhappyCounter);
++ this.entityData.set(AbstractVillager.DATA_UNHAPPY_COUNTER, unhappyCounter);
+ }
+
+ @Override
+@@ -76,14 +89,14 @@
+ }
+
+ @Override
+- protected float getStandingEyeHeight(Pose pose, EntityDimensions size) {
++ protected float getStandingEyeHeight(EntityPose pose, EntityDimensions size) {
+ return this.isBaby() ? 0.81F : 1.62F;
+ }
+
+ @Override
+ protected void defineSynchedData() {
+ super.defineSynchedData();
+- this.entityData.define(DATA_UNHAPPY_COUNTER, 0);
++ this.entityData.define(AbstractVillager.DATA_UNHAPPY_COUNTER, 0);
+ }
+
+ @Override
+@@ -112,12 +125,10 @@
+ }
+
+ @Override
+- public void overrideOffers(@Nullable MerchantOffers offers) {
+- }
++ public void overrideOffers(@Nullable MerchantOffers offers) {}
+
+ @Override
+- public void overrideXp(int xp) {
+- }
++ public void overrideXp(int xp) {}
+
+ @Override
+ public void notifyTrade(MerchantOffer offer) {
+@@ -125,8 +136,9 @@
+ this.ambientSoundTime = -this.getAmbientSoundInterval();
+ this.rewardTradeXp(offer);
+ if (this.tradingPlayer instanceof ServerPlayer) {
+- CriteriaTriggers.TRADE.trigger((ServerPlayer)this.tradingPlayer, this, offer.getResult());
++ CriteriaTriggers.TRADE.trigger((ServerPlayer) this.tradingPlayer, this, offer.getResult());
+ }
++
+ }
+
+ protected abstract void rewardTradeXp(MerchantOffer offer);
+@@ -142,6 +154,7 @@
+ this.ambientSoundTime = -this.getAmbientSoundInterval();
+ this.playSound(this.getTradeUpdatedSound(!stack.isEmpty()), this.getSoundVolume(), this.getVoicePitch());
+ }
++
+ }
+
+ @Override
+@@ -160,9 +173,10 @@
+ @Override
+ public void addAdditionalSaveData(CompoundTag compound) {
+ super.addAdditionalSaveData(compound);
+- MerchantOffers offers = this.getOffers();
+- if (!offers.isEmpty()) {
+- compound.put("Offers", offers.createTag());
++ MerchantOffers merchantrecipelist = this.getOffers();
++
++ if (!merchantrecipelist.isEmpty()) {
++ compound.put("Offers", merchantrecipelist.createTag());
+ }
+
+ this.writeInventoryToTag(compound);
+@@ -186,7 +200,7 @@
+ }
+
+ protected void stopTrading() {
+- this.setTradingPlayer(null);
++ this.setTradingPlayer((Player) null);
+ }
+
+ @Override
+@@ -196,12 +210,14 @@
+ }
+
+ protected void addParticlesAroundSelf(ParticleOptions particleOption) {
+- for (int i = 0; i < 5; i++) {
+- double d = this.random.nextGaussian() * 0.02;
+- double d1 = this.random.nextGaussian() * 0.02;
+- double d2 = this.random.nextGaussian() * 0.02;
+- this.level().addParticle(particleOption, this.getRandomX(1.0), this.getRandomY() + 1.0, this.getRandomZ(1.0), d, d1, d2);
++ for (int i = 0; i < 5; ++i) {
++ double d0 = this.random.nextGaussian() * 0.02D;
++ double d1 = this.random.nextGaussian() * 0.02D;
++ double d2 = this.random.nextGaussian() * 0.02D;
++
++ this.level().addParticle(particleOption, this.getRandomX(1.0D), this.getRandomY() + 1.0D, this.getRandomZ(1.0D), d0, d1, d2);
+ }
++
+ }
+
+ @Override
+@@ -216,30 +232,43 @@
+
+ @Override
+ public SlotAccess getSlot(int slot) {
+- int i = slot - 300;
+- return i >= 0 && i < this.inventory.getContainerSize() ? SlotAccess.forContainer(this.inventory, i) : super.getSlot(slot);
++ int j = slot - 300;
++
++ return j >= 0 && j < this.inventory.getContainerSize() ? SlotAccess.forContainer(this.inventory, j) : super.getSlot(slot);
+ }
+
+ protected abstract void updateTrades();
+
+ protected void addOffersFromItemListings(MerchantOffers givenMerchantOffers, VillagerTrades.ItemListing[] newTrades, int maxNumbers) {
+- ArrayList<VillagerTrades.ItemListing> list = Lists.newArrayList(newTrades);
+- int i = 0;
++ ArrayList<VillagerTrades.ItemListing> arraylist = Lists.newArrayList(newTrades);
++ int j = 0;
+
+- while (i < maxNumbers && !list.isEmpty()) {
+- MerchantOffer offer = list.remove(this.random.nextInt(list.size())).getOffer(this, this.random);
+- if (offer != null) {
+- givenMerchantOffers.add(offer);
+- i++;
++ while (j < maxNumbers && !arraylist.isEmpty()) {
++ MerchantOffer merchantrecipe = ((VillagerTrades.ItemListing) arraylist.remove(this.random.nextInt(arraylist.size()))).getOffer(this, this.random);
++
++ if (merchantrecipe != null) {
++ // CraftBukkit start
++ VillagerAcquireTradeEvent event = new VillagerAcquireTradeEvent((org.bukkit.entity.AbstractVillager) getBukkitEntity(), merchantrecipe.asBukkit());
++ // Suppress during worldgen
++ if (this.valid) {
++ Bukkit.getPluginManager().callEvent(event);
++ }
++ if (!event.isCancelled()) {
++ givenMerchantOffers.add(CraftMerchantRecipe.fromBukkit(event.getRecipe()).toMinecraft());
++ }
++ // CraftBukkit end
++ ++j;
+ }
+ }
++
+ }
+
+ @Override
+ public Vec3 getRopeHoldPosition(float partialTicks) {
+- float f = Mth.lerp(partialTicks, this.yBodyRotO, this.yBodyRot) * (float) (Math.PI / 180.0);
+- Vec3 vec3 = new Vec3(0.0, this.getBoundingBox().getYsize() - 1.0, 0.2);
+- return this.getPosition(partialTicks).add(vec3.yRot(-f));
++ float f1 = Mth.lerp(partialTicks, this.yBodyRotO, this.yBodyRot) * 0.017453292F;
++ Vec3 vec3d = new Vec3(0.0D, this.getBoundingBox().getYsize() - 1.0D, 0.2D);
++
++ return this.getPosition(partialTicks).add(vec3d.yRot(-f1));
+ }
+
+ @Override