Add more WanderingTrader API

This commit is contained in:
HexedHero 2021-05-06 14:56:43 +01:00
parent 6949e999eb
commit 2329a7b1c8
2 changed files with 43 additions and 5 deletions

View File

@ -1,6 +1,6 @@
--- a/net/minecraft/world/entity/npc/WanderingTrader.java --- a/net/minecraft/world/entity/npc/WanderingTrader.java
+++ b/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 net.minecraft.world.phys.Vec3;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
@ -18,7 +18,11 @@
private static final int NUMBER_OF_TRADE_OFFERS = 5; private static final int NUMBER_OF_TRADE_OFFERS = 5;
@Nullable @Nullable
private BlockPos wanderTarget; 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<? extends WanderingTrader> type, Level world) { public WanderingTrader(EntityType<? extends WanderingTrader> type, Level world) {
super(type, world); super(type, world);
@ -26,7 +30,19 @@
} }
@Override @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); MerchantOffer merchantrecipe = villagertrades_imerchantrecipeoption.getOffer(this, this.random);
if (merchantrecipe != null) { if (merchantrecipe != null) {
@ -44,7 +60,7 @@
} }
} }
@@ -190,7 +208,7 @@ @@ -190,7 +212,7 @@
if (offer.shouldRewardExp()) { if (offer.shouldRewardExp()) {
int i = 3 + this.random.nextInt(4); int i = 3 + this.random.nextInt(4);
@ -53,7 +69,7 @@
} }
} }
@@ -244,7 +262,7 @@ @@ -244,7 +266,7 @@
private void maybeDespawn() { private void maybeDespawn() {
if (this.despawnDelay > 0 && !this.isTrading() && --this.despawnDelay == 0) { if (this.despawnDelay > 0 && !this.isTrading() && --this.despawnDelay == 0) {

View File

@ -28,4 +28,26 @@ public class CraftWanderingTrader extends CraftAbstractVillager implements Wande
public void setDespawnDelay(int despawnDelay) { public void setDespawnDelay(int despawnDelay) {
this.getHandle().setDespawnDelay(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
} }