aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower/net/minecraft/world/entity/npc/WanderingTrader.java.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/world/entity/npc/WanderingTrader.java.patch')
-rw-r--r--patch-remap/mache-vineflower/net/minecraft/world/entity/npc/WanderingTrader.java.patch295
1 files changed, 295 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/world/entity/npc/WanderingTrader.java.patch b/patch-remap/mache-vineflower/net/minecraft/world/entity/npc/WanderingTrader.java.patch
new file mode 100644
index 0000000000..d3d01aa735
--- /dev/null
+++ b/patch-remap/mache-vineflower/net/minecraft/world/entity/npc/WanderingTrader.java.patch
@@ -0,0 +1,295 @@
+--- a/net/minecraft/world/entity/npc/WanderingTrader.java
++++ b/net/minecraft/world/entity/npc/WanderingTrader.java
+@@ -1,6 +1,7 @@
+ package net.minecraft.world.entity.npc;
+
+ import java.util.EnumSet;
++import java.util.Iterator;
+ import javax.annotation.Nullable;
+ import net.minecraft.core.BlockPos;
+ import net.minecraft.nbt.CompoundTag;
+@@ -9,7 +10,7 @@
+ import net.minecraft.sounds.SoundEvent;
+ import net.minecraft.sounds.SoundEvents;
+ import net.minecraft.stats.Stats;
+-import net.minecraft.world.InteractionHand;
++import net.minecraft.world.EnumHand;
+ import net.minecraft.world.InteractionResult;
+ import net.minecraft.world.damagesource.DamageSource;
+ import net.minecraft.world.entity.AgeableMob;
+@@ -19,11 +20,11 @@
+ import net.minecraft.world.entity.ai.goal.AvoidEntityGoal;
+ import net.minecraft.world.entity.ai.goal.FloatGoal;
+ import net.minecraft.world.entity.ai.goal.Goal;
+-import net.minecraft.world.entity.ai.goal.InteractGoal;
+ import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal;
+ import net.minecraft.world.entity.ai.goal.LookAtTradingPlayerGoal;
+ import net.minecraft.world.entity.ai.goal.MoveTowardsRestrictionGoal;
+ import net.minecraft.world.entity.ai.goal.PanicGoal;
++import net.minecraft.world.entity.ai.goal.PathfinderGoalInteract;
+ import net.minecraft.world.entity.ai.goal.TradeWithPlayerGoal;
+ import net.minecraft.world.entity.ai.goal.UseItemGoal;
+ import net.minecraft.world.entity.ai.goal.WaterAvoidingRandomStrollGoal;
+@@ -46,7 +47,15 @@
+ import net.minecraft.world.phys.Vec3;
+ import org.apache.commons.lang3.tuple.Pair;
+
+-public class WanderingTrader extends AbstractVillager {
++// CraftBukkit start
++import org.bukkit.Bukkit;
++import org.bukkit.craftbukkit.inventory.CraftMerchantRecipe;
++import org.bukkit.entity.AbstractVillager;
++import org.bukkit.event.entity.VillagerAcquireTradeEvent;
++// CraftBukkit end
++
++public class WanderingTrader extends net.minecraft.world.entity.npc.AbstractVillager {
++
+ private static final int NUMBER_OF_TRADE_OFFERS = 5;
+ @Nullable
+ private BlockPos wanderTarget;
+@@ -54,45 +63,32 @@
+
+ public WanderingTrader(EntityType<? extends WanderingTrader> entityType, Level level) {
+ super(entityType, level);
++ this.setDespawnDelay(48000); // CraftBukkit - set default from MobSpawnerTrader
+ }
+
+ @Override
+ protected void registerGoals() {
+ this.goalSelector.addGoal(0, new FloatGoal(this));
+- this.goalSelector
+- .addGoal(
+- 0,
+- new UseItemGoal<>(
+- this,
+- PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.INVISIBILITY),
+- SoundEvents.WANDERING_TRADER_DISAPPEARED,
+- wanderingTrader -> this.level().isNight() && !wanderingTrader.isInvisible()
+- )
+- );
+- this.goalSelector
+- .addGoal(
+- 0,
+- new UseItemGoal<>(
+- this,
+- new ItemStack(Items.MILK_BUCKET),
+- SoundEvents.WANDERING_TRADER_REAPPEARED,
+- wanderingTrader -> this.level().isDay() && wanderingTrader.isInvisible()
+- )
+- );
++ this.goalSelector.addGoal(0, new UseItemGoal<>(this, PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.INVISIBILITY), SoundEvents.WANDERING_TRADER_DISAPPEARED, (entityvillagertrader) -> {
++ return this.level().isNight() && !entityvillagertrader.isInvisible();
++ }));
++ this.goalSelector.addGoal(0, new UseItemGoal<>(this, new ItemStack(Items.MILK_BUCKET), SoundEvents.WANDERING_TRADER_REAPPEARED, (entityvillagertrader) -> {
++ return this.level().isDay() && entityvillagertrader.isInvisible();
++ }));
+ this.goalSelector.addGoal(1, new TradeWithPlayerGoal(this));
+- this.goalSelector.addGoal(1, new AvoidEntityGoal<>(this, Zombie.class, 8.0F, 0.5, 0.5));
+- this.goalSelector.addGoal(1, new AvoidEntityGoal<>(this, Evoker.class, 12.0F, 0.5, 0.5));
+- this.goalSelector.addGoal(1, new AvoidEntityGoal<>(this, Vindicator.class, 8.0F, 0.5, 0.5));
+- this.goalSelector.addGoal(1, new AvoidEntityGoal<>(this, Vex.class, 8.0F, 0.5, 0.5));
+- this.goalSelector.addGoal(1, new AvoidEntityGoal<>(this, Pillager.class, 15.0F, 0.5, 0.5));
+- this.goalSelector.addGoal(1, new AvoidEntityGoal<>(this, Illusioner.class, 12.0F, 0.5, 0.5));
+- this.goalSelector.addGoal(1, new AvoidEntityGoal<>(this, Zoglin.class, 10.0F, 0.5, 0.5));
+- this.goalSelector.addGoal(1, new PanicGoal(this, 0.5));
++ this.goalSelector.addGoal(1, new AvoidEntityGoal<>(this, Zombie.class, 8.0F, 0.5D, 0.5D));
++ this.goalSelector.addGoal(1, new AvoidEntityGoal<>(this, Evoker.class, 12.0F, 0.5D, 0.5D));
++ this.goalSelector.addGoal(1, new AvoidEntityGoal<>(this, Vindicator.class, 8.0F, 0.5D, 0.5D));
++ this.goalSelector.addGoal(1, new AvoidEntityGoal<>(this, Vex.class, 8.0F, 0.5D, 0.5D));
++ this.goalSelector.addGoal(1, new AvoidEntityGoal<>(this, Pillager.class, 15.0F, 0.5D, 0.5D));
++ this.goalSelector.addGoal(1, new AvoidEntityGoal<>(this, Illusioner.class, 12.0F, 0.5D, 0.5D));
++ this.goalSelector.addGoal(1, new AvoidEntityGoal<>(this, Zoglin.class, 10.0F, 0.5D, 0.5D));
++ this.goalSelector.addGoal(1, new PanicGoal(this, 0.5D));
+ this.goalSelector.addGoal(1, new LookAtTradingPlayerGoal(this));
+- this.goalSelector.addGoal(2, new WanderingTrader.WanderToPositionGoal(this, 2.0, 0.35));
+- this.goalSelector.addGoal(4, new MoveTowardsRestrictionGoal(this, 0.35));
+- this.goalSelector.addGoal(8, new WaterAvoidingRandomStrollGoal(this, 0.35));
+- this.goalSelector.addGoal(9, new InteractGoal(this, Player.class, 3.0F, 1.0F));
++ this.goalSelector.addGoal(2, new WanderingTrader.WanderToPositionGoal(this, 2.0D, 0.35D));
++ this.goalSelector.addGoal(4, new MoveTowardsRestrictionGoal(this, 0.35D));
++ this.goalSelector.addGoal(8, new WaterAvoidingRandomStrollGoal(this, 0.35D));
++ this.goalSelector.addGoal(9, new PathfinderGoalInteract(this, Player.class, 3.0F, 1.0F));
+ this.goalSelector.addGoal(10, new LookAtPlayerGoal(this, Mob.class, 8.0F));
+ }
+
+@@ -108,10 +104,11 @@
+ }
+
+ @Override
+- public InteractionResult mobInteract(Player player, InteractionHand hand) {
+- ItemStack itemInHand = player.getItemInHand(hand);
+- if (!itemInHand.is(Items.VILLAGER_SPAWN_EGG) && this.isAlive() && !this.isTrading() && !this.isBaby()) {
+- if (hand == InteractionHand.MAIN_HAND) {
++ public InteractionResult mobInteract(Player player, EnumHand hand) {
++ ItemStack itemstack = player.getItemInHand(hand);
++
++ if (!itemstack.is(Items.VILLAGER_SPAWN_EGG) && this.isAlive() && !this.isTrading() && !this.isBaby()) {
++ if (hand == EnumHand.MAIN_HAND) {
+ player.awardStat(Stats.TALKED_TO_VILLAGER);
+ }
+
+@@ -135,28 +132,45 @@
+ if (this.level().enabledFeatures().contains(FeatureFlags.TRADE_REBALANCE)) {
+ this.experimentalUpdateTrades();
+ } else {
+- VillagerTrades.ItemListing[] itemListings = VillagerTrades.WANDERING_TRADER_TRADES.get(1);
+- VillagerTrades.ItemListing[] itemListings1 = VillagerTrades.WANDERING_TRADER_TRADES.get(2);
+- if (itemListings != null && itemListings1 != null) {
+- MerchantOffers offers = this.getOffers();
+- this.addOffersFromItemListings(offers, itemListings, 5);
+- int randomInt = this.random.nextInt(itemListings1.length);
+- VillagerTrades.ItemListing itemListing = itemListings1[randomInt];
+- MerchantOffer offer = itemListing.getOffer(this, this.random);
+- if (offer != null) {
+- offers.add(offer);
++ VillagerTrades.ItemListing[] avillagertrades_imerchantrecipeoption = (VillagerTrades.ItemListing[]) VillagerTrades.WANDERING_TRADER_TRADES.get(1);
++ VillagerTrades.ItemListing[] avillagertrades_imerchantrecipeoption1 = (VillagerTrades.ItemListing[]) VillagerTrades.WANDERING_TRADER_TRADES.get(2);
++
++ if (avillagertrades_imerchantrecipeoption != null && avillagertrades_imerchantrecipeoption1 != null) {
++ MerchantOffers merchantrecipelist = this.getOffers();
++
++ this.addOffersFromItemListings(merchantrecipelist, avillagertrades_imerchantrecipeoption, 5);
++ int i = this.random.nextInt(avillagertrades_imerchantrecipeoption1.length);
++ VillagerTrades.ItemListing villagertrades_imerchantrecipeoption = avillagertrades_imerchantrecipeoption1[i];
++ MerchantOffer merchantrecipe = villagertrades_imerchantrecipeoption.getOffer(this, this.random);
++
++ if (merchantrecipe != null) {
++ // CraftBukkit start
++ VillagerAcquireTradeEvent event = new VillagerAcquireTradeEvent((AbstractVillager) getBukkitEntity(), merchantrecipe.asBukkit());
++ // Suppress during worldgen
++ if (this.valid) {
++ Bukkit.getPluginManager().callEvent(event);
++ }
++ if (!event.isCancelled()) {
++ merchantrecipelist.add(CraftMerchantRecipe.fromBukkit(event.getRecipe()).toMinecraft());
++ }
++ // CraftBukkit end
+ }
++
+ }
+ }
+ }
+
+ private void experimentalUpdateTrades() {
+- MerchantOffers offers = this.getOffers();
++ MerchantOffers merchantrecipelist = this.getOffers();
++ Iterator iterator = VillagerTrades.EXPERIMENTAL_WANDERING_TRADER_TRADES.iterator();
+
+- for (Pair<VillagerTrades.ItemListing[], Integer> pair : VillagerTrades.EXPERIMENTAL_WANDERING_TRADER_TRADES) {
+- VillagerTrades.ItemListing[] itemListings = pair.getLeft();
+- this.addOffersFromItemListings(offers, itemListings, pair.getRight());
++ while (iterator.hasNext()) {
++ Pair<VillagerTrades.ItemListing[], Integer> pair = (Pair) iterator.next();
++ VillagerTrades.ItemListing[] avillagertrades_imerchantrecipeoption = (VillagerTrades.ItemListing[]) pair.getLeft();
++
++ this.addOffersFromItemListings(merchantrecipelist, avillagertrades_imerchantrecipeoption, (Integer) pair.getRight());
+ }
++
+ }
+
+ @Override
+@@ -166,6 +180,7 @@
+ if (this.wanderTarget != null) {
+ compound.put("WanderTarget", NbtUtils.writeBlockPos(this.wanderTarget));
+ }
++
+ }
+
+ @Override
+@@ -191,8 +206,10 @@
+ protected void rewardTradeXp(MerchantOffer offer) {
+ if (offer.shouldRewardExp()) {
+ int i = 3 + this.random.nextInt(4);
+- this.level().addFreshEntity(new ExperienceOrb(this.level(), this.getX(), this.getY() + 0.5, this.getZ(), i));
++
++ this.level().addFreshEntity(new ExperienceOrb(this.level(), this.getX(), this.getY() + 0.5D, this.getZ(), i));
+ }
++
+ }
+
+ @Override
+@@ -239,12 +256,14 @@
+ if (!this.level().isClientSide) {
+ this.maybeDespawn();
+ }
++
+ }
+
+ private void maybeDespawn() {
+ if (this.despawnDelay > 0 && !this.isTrading() && --this.despawnDelay == 0) {
+ this.discard();
+ }
++
+ }
+
+ public void setWanderTarget(@Nullable BlockPos wanderTarget) {
+@@ -256,48 +275,47 @@
+ return this.wanderTarget;
+ }
+
+- class WanderToPositionGoal extends Goal {
++ private class WanderToPositionGoal extends Goal {
++
+ final WanderingTrader trader;
+ final double stopDistance;
+ final double speedModifier;
+
+- WanderToPositionGoal(WanderingTrader trader, double stopDistance, double speedModifier) {
+- this.trader = trader;
+- this.stopDistance = stopDistance;
+- this.speedModifier = speedModifier;
+- this.setFlags(EnumSet.of(Goal.Flag.MOVE));
++ WanderToPositionGoal(WanderingTrader entityvillagertrader, double d0, double d1) {
++ this.trader = entityvillagertrader;
++ this.stopDistance = d0;
++ this.speedModifier = d1;
++ this.setFlags(EnumSet.of(Goal.Type.MOVE));
+ }
+
+ @Override
+ public void stop() {
+- this.trader.setWanderTarget(null);
++ this.trader.setWanderTarget((BlockPos) null);
+ WanderingTrader.this.navigation.stop();
+ }
+
+ @Override
+ public boolean canUse() {
+- BlockPos wanderTarget = this.trader.getWanderTarget();
+- return wanderTarget != null && this.isTooFarAway(wanderTarget, this.stopDistance);
++ BlockPos blockposition = this.trader.getWanderTarget();
++
++ return blockposition != null && this.isTooFarAway(blockposition, this.stopDistance);
+ }
+
+ @Override
+ public void tick() {
+- BlockPos wanderTarget = this.trader.getWanderTarget();
+- if (wanderTarget != null && WanderingTrader.this.navigation.isDone()) {
+- if (this.isTooFarAway(wanderTarget, 10.0)) {
+- Vec3 vec3 = new Vec3(
+- (double)wanderTarget.getX() - this.trader.getX(),
+- (double)wanderTarget.getY() - this.trader.getY(),
+- (double)wanderTarget.getZ() - this.trader.getZ()
+- )
+- .normalize();
+- Vec3 vec31 = vec3.scale(10.0).add(this.trader.getX(), this.trader.getY(), this.trader.getZ());
+- WanderingTrader.this.navigation.moveTo(vec31.x, vec31.y, vec31.z, this.speedModifier);
++ BlockPos blockposition = this.trader.getWanderTarget();
++
++ if (blockposition != null && WanderingTrader.this.navigation.isDone()) {
++ if (this.isTooFarAway(blockposition, 10.0D)) {
++ Vec3 vec3d = (new Vec3((double) blockposition.getX() - this.trader.getX(), (double) blockposition.getY() - this.trader.getY(), (double) blockposition.getZ() - this.trader.getZ())).normalize();
++ Vec3 vec3d1 = vec3d.scale(10.0D).add(this.trader.getX(), this.trader.getY(), this.trader.getZ());
++
++ WanderingTrader.this.navigation.moveTo(vec3d1.x, vec3d1.y, vec3d1.z, this.speedModifier);
+ } else {
+- WanderingTrader.this.navigation
+- .moveTo((double)wanderTarget.getX(), (double)wanderTarget.getY(), (double)wanderTarget.getZ(), this.speedModifier);
++ WanderingTrader.this.navigation.moveTo((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), this.speedModifier);
+ }
+ }
++
+ }
+
+ private boolean isTooFarAway(BlockPos pos, double distance) {