Add more Wandering Trader API (#5020)

This commit is contained in:
HexedHero 2021-05-06 15:26:50 +01:00 committed by GitHub
parent 8cec462a5f
commit 48aa061063
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 106 additions and 0 deletions

View file

@ -0,0 +1,41 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: HexedHero <6012891+HexedHero@users.noreply.github.com>
Date: Thu, 6 May 2021 14:56:26 +0100
Subject: [PATCH] Add more WanderingTrader API
diff --git a/src/main/java/org/bukkit/entity/WanderingTrader.java b/src/main/java/org/bukkit/entity/WanderingTrader.java
index 55394ed5c68cb0bf4333fc918e3b4c8c4e3db0c6..da76e1ed5406322073dd8c7a89ca55aa68620ac4 100644
--- a/src/main/java/org/bukkit/entity/WanderingTrader.java
+++ b/src/main/java/org/bukkit/entity/WanderingTrader.java
@@ -28,4 +28,30 @@ public interface WanderingTrader extends AbstractVillager {
* {@link WanderingTrader} is forcibly despawned
*/
public void setDespawnDelay(int despawnDelay);
+
+ // Paper start - Add more WanderingTrader API
+ /**
+ * Set if the Wandering Trader can and will drink an invisibility potion.
+ * @param bool whether the mob will drink
+ */
+ public void setCanDrinkPotion(boolean bool);
+
+ /**
+ * Get if the Wandering Trader can and will drink an invisibility potion.
+ * @return whether the mob will drink
+ */
+ public boolean canDrinkPotion();
+
+ /**
+ * Set if the Wandering Trader can and will drink milk.
+ * @param bool whether the mob will drink
+ */
+ public void setCanDrinkMilk(boolean bool);
+
+ /**
+ * Get if the Wandering Trader can and will drink milk.
+ * @return whether the mob will drink
+ */
+ public boolean canDrinkMilk();
+ // Paper end
}

View file

@ -0,0 +1,65 @@
From 0000000000000000000000000000000000000000 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
diff --git a/src/main/java/net/minecraft/world/entity/npc/EntityVillagerTrader.java b/src/main/java/net/minecraft/world/entity/npc/EntityVillagerTrader.java
index 37e1b2bf33510c3603efadf219b462e667f573c2..69044827ed6b34924ffd89a977afa06df0dcefc3 100644
--- a/src/main/java/net/minecraft/world/entity/npc/EntityVillagerTrader.java
+++ b/src/main/java/net/minecraft/world/entity/npc/EntityVillagerTrader.java
@@ -58,6 +58,10 @@ public class EntityVillagerTrader extends EntityVillagerAbstract {
@Nullable
private BlockPosition bp;
private int despawnDelay;
+ // Paper start - Add more WanderingTrader API
+ public boolean canDrinkPotion = true;
+ public boolean canDrinkMilk = true;
+ // Paper end
public EntityVillagerTrader(EntityTypes<? extends EntityVillagerTrader> entitytypes, World world) {
super(entitytypes, world);
@@ -69,10 +73,10 @@ public class EntityVillagerTrader extends EntityVillagerAbstract {
protected void initPathfinder() {
this.goalSelector.a(0, new PathfinderGoalFloat(this));
this.goalSelector.a(0, new PathfinderGoalUseItem<>(this, PotionUtil.a(new ItemStack(Items.POTION), Potions.INVISIBILITY), SoundEffects.ENTITY_WANDERING_TRADER_DISAPPEARED, (entityvillagertrader) -> {
- return this.world.isNight() && !entityvillagertrader.isInvisible();
+ return canDrinkPotion && this.world.isNight() && !entityvillagertrader.isInvisible(); // Paper - Add more WanderingTrader API
}));
this.goalSelector.a(0, new PathfinderGoalUseItem<>(this, new ItemStack(Items.MILK_BUCKET), SoundEffects.ENTITY_WANDERING_TRADER_REAPPEARED, (entityvillagertrader) -> {
- return this.world.isDay() && entityvillagertrader.isInvisible();
+ return canDrinkMilk && this.world.isDay() && entityvillagertrader.isInvisible(); // Paper - Add more WanderingTrader API
}));
this.goalSelector.a(1, new PathfinderGoalTradeWithPlayer(this));
this.goalSelector.a(1, new PathfinderGoalAvoidTarget<>(this, EntityZombie.class, 8.0F, 0.5D, 0.5D));
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftWanderingTrader.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftWanderingTrader.java
index c8344ce0a85030b12139d0b2bbe45acdcd33e1e7..6dad8ca649a2fa0a80a4b88c8a3e284fe218f31f 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftWanderingTrader.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftWanderingTrader.java
@@ -35,4 +35,26 @@ public class CraftWanderingTrader extends CraftAbstractVillager implements Wande
public void setDespawnDelay(int despawnDelay) {
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
}