From 2329a7b1c8125bc8c7da320eea928ee9024164e7 Mon Sep 17 00:00:00 2001 From: HexedHero <6012891+HexedHero@users.noreply.github.com> Date: Thu, 6 May 2021 14:56:43 +0100 Subject: [PATCH] Add more WanderingTrader API --- .../entity/npc/WanderingTrader.java.patch | 26 +++++++++++++++---- .../entity/CraftWanderingTrader.java | 22 ++++++++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/world/entity/npc/WanderingTrader.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/npc/WanderingTrader.java.patch index 4e58fee721..e48584e0ab 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/npc/WanderingTrader.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/npc/WanderingTrader.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/npc/WanderingTrader.java +++ b/net/minecraft/world/entity/npc/WanderingTrader.java -@@ -48,8 +48,16 @@ +@@ -48,25 +48,38 @@ import net.minecraft.world.phys.Vec3; import org.apache.commons.lang3.tuple.Pair; @@ -18,7 +18,11 @@ private static final int NUMBER_OF_TRADE_OFFERS = 5; @Nullable private BlockPos wanderTarget; -@@ -57,6 +65,7 @@ + private int despawnDelay; ++ // Paper start - Add more WanderingTrader API ++ public boolean canDrinkPotion = true; ++ public boolean canDrinkMilk = true; ++ // Paper end - Add more WanderingTrader API public WanderingTrader(EntityType type, Level world) { super(type, world); @@ -26,7 +30,19 @@ } @Override -@@ -137,7 +146,16 @@ + protected void registerGoals() { + this.goalSelector.addGoal(0, new FloatGoal(this)); + this.goalSelector.addGoal(0, new UseItemGoal<>(this, PotionContents.createItemStack(Items.POTION, Potions.INVISIBILITY), SoundEvents.WANDERING_TRADER_DISAPPEARED, (entityvillagertrader) -> { +- return this.level().isNight() && !entityvillagertrader.isInvisible(); ++ return this.canDrinkPotion && this.level().isNight() && !entityvillagertrader.isInvisible(); // Paper - Add more WanderingTrader API + })); + this.goalSelector.addGoal(0, new UseItemGoal<>(this, new ItemStack(Items.MILK_BUCKET), SoundEvents.WANDERING_TRADER_REAPPEARED, (entityvillagertrader) -> { +- return this.level().isDay() && entityvillagertrader.isInvisible(); ++ return this.canDrinkMilk && this.level().isDay() && entityvillagertrader.isInvisible(); // Paper - Add more WanderingTrader API + })); + this.goalSelector.addGoal(1, new TradeWithPlayerGoal(this)); + this.goalSelector.addGoal(1, new AvoidEntityGoal<>(this, Zombie.class, 8.0F, 0.5D, 0.5D)); +@@ -137,7 +150,16 @@ MerchantOffer merchantrecipe = villagertrades_imerchantrecipeoption.getOffer(this, this.random); if (merchantrecipe != null) { @@ -44,7 +60,7 @@ } } -@@ -190,7 +208,7 @@ +@@ -190,7 +212,7 @@ if (offer.shouldRewardExp()) { int i = 3 + this.random.nextInt(4); @@ -53,7 +69,7 @@ } } -@@ -244,7 +262,7 @@ +@@ -244,7 +266,7 @@ private void maybeDespawn() { if (this.despawnDelay > 0 && !this.isTrading() && --this.despawnDelay == 0) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWanderingTrader.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWanderingTrader.java index 08194a78c2..0e597394a3 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWanderingTrader.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWanderingTrader.java @@ -28,4 +28,26 @@ public class CraftWanderingTrader extends CraftAbstractVillager implements Wande public void setDespawnDelay(int despawnDelay) { this.getHandle().setDespawnDelay(despawnDelay); } + + // Paper start - Add more WanderingTrader API + @Override + public void setCanDrinkPotion(boolean bool) { + getHandle().canDrinkPotion = bool; + } + + @Override + public boolean canDrinkPotion() { + return getHandle().canDrinkPotion; + } + + @Override + public void setCanDrinkMilk(boolean bool) { + getHandle().canDrinkMilk = bool; + } + + @Override + public boolean canDrinkMilk() { + return getHandle().canDrinkMilk; + } + // Paper end }