From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Sat, 5 Dec 2020 01:20:16 -0800 Subject: [PATCH] Option for Villager Clerics to farm Nether Wart Adds an option so that Villagers with the Cleric profession are able to farm Nether Wart. Reimplemented based on a feature of the carpet-extra mod. diff --git a/net/minecraft/world/entity/ai/behavior/HarvestFarmland.java b/net/minecraft/world/entity/ai/behavior/HarvestFarmland.java index 5a0d0d1c145c303930769ea27f81d91337a3f1bf..29458d4dc1764b5b7ede94853190a5dd84c1fc36 100644 --- a/net/minecraft/world/entity/ai/behavior/HarvestFarmland.java +++ b/net/minecraft/world/entity/ai/behavior/HarvestFarmland.java @@ -31,6 +31,7 @@ public class HarvestFarmland extends Behavior { private long nextOkStartTime; private int timeWorkedSoFar; private final List validFarmlandAroundVillager = Lists.newArrayList(); + private boolean clericWartFarmer = false; // Purpur - Option for Villager Clerics to farm Nether Wart public HarvestFarmland() { super( @@ -51,10 +52,11 @@ public class HarvestFarmland extends Behavior { return false; } - if (!body.getVillagerData().profession().is(VillagerProfession.FARMER)) { + if (!body.getVillagerData().profession().is(VillagerProfession.FARMER) && !(level.purpurConfig.villagerClericsFarmWarts && body.getVillagerData().profession().is(VillagerProfession.CLERIC))) { // Purpur - Option for Villager Clerics to farm Nether Wart return false; } + if (!this.clericWartFarmer && body.getVillagerData().profession().is(VillagerProfession.CLERIC)) this.clericWartFarmer = true; // Purpur - Option for Villager Clerics to farm Nether Wart BlockPos.MutableBlockPos mutPos = body.blockPosition().mutable(); this.validFarmlandAroundVillager.clear(); @@ -83,6 +85,7 @@ public class HarvestFarmland extends Behavior { BlockState state = level.getBlockState(blockPos); Block block = state.getBlock(); Block blockBelow = level.getBlockState(blockPos.below()).getBlock(); + if (this.clericWartFarmer) return block == net.minecraft.world.level.block.Blocks.NETHER_WART && state.getValue(net.minecraft.world.level.block.NetherWartBlock.AGE) == 3 || state.isAir() && block == net.minecraft.world.level.block.Blocks.SOUL_SAND; // Purpur - Option for Villager Clerics to farm Nether Wart return block instanceof CropBlock cropBlock && cropBlock.isMaxAge(state) || state.isAir() && blockBelow instanceof FarmlandBlock; } @@ -109,19 +112,19 @@ public class HarvestFarmland extends Behavior { BlockState blockState = level.getBlockState(this.aboveFarmlandPos); Block block = blockState.getBlock(); Block blockBelow = level.getBlockState(this.aboveFarmlandPos.below()).getBlock(); - if (block instanceof CropBlock cropBlock && cropBlock.isMaxAge(blockState)) { + if (block instanceof CropBlock cropBlock && cropBlock.isMaxAge(blockState) && !this.clericWartFarmer || this.clericWartFarmer && block == net.minecraft.world.level.block.Blocks.NETHER_WART && blockState.getValue(net.minecraft.world.level.block.NetherWartBlock.AGE) == 3) { // Purpur - Option for Villager Clerics to farm Nether Wart if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(body, this.aboveFarmlandPos, blockState.getFluidState().createLegacyBlock())) { // CraftBukkit // Paper - fix wrong block state level.destroyBlock(this.aboveFarmlandPos, true, body); } // CraftBukkit } - if (blockState.isAir() && blockBelow instanceof FarmlandBlock && body.hasFarmSeeds()) { + if (blockState.isAir() && blockBelow instanceof FarmlandBlock && !this.clericWartFarmer || this.clericWartFarmer && blockBelow == net.minecraft.world.level.block.Blocks.SOUL_SAND && body.hasFarmSeeds()) { // Purpur - Option for Villager Clerics to farm Nether Wart SimpleContainer inventory = body.getInventory(); for (int i = 0; i < inventory.getContainerSize(); i++) { ItemStack itemStack = inventory.getItem(i); boolean ok = false; - if (!itemStack.isEmpty() && itemStack.is(ItemTags.VILLAGER_PLANTABLE_SEEDS) && itemStack.getItem() instanceof BlockItem blockItem) { + if (!itemStack.isEmpty() && (itemStack.is(ItemTags.VILLAGER_PLANTABLE_SEEDS) || this.clericWartFarmer && itemStack.getItem() == net.minecraft.world.item.Items.NETHER_WART) && itemStack.getItem() instanceof BlockItem blockItem) { // Purpur - Option for Villager Clerics to farm Nether Wart BlockState place = blockItem.getBlock().defaultBlockState(); if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(body, this.aboveFarmlandPos, place)) { // CraftBukkit level.setBlockAndUpdate(this.aboveFarmlandPos, place); @@ -136,7 +139,7 @@ public class HarvestFarmland extends Behavior { this.aboveFarmlandPos.getX(), this.aboveFarmlandPos.getY(), this.aboveFarmlandPos.getZ(), - SoundEvents.CROP_PLANTED, + this.clericWartFarmer ? SoundEvents.NETHER_WART_PLANTED : SoundEvents.CROP_PLANTED, // Purpur - Option for Villager Clerics to farm Nether Wart SoundSource.BLOCKS, 1.0F, 1.0F diff --git a/net/minecraft/world/entity/ai/behavior/TradeWithVillager.java b/net/minecraft/world/entity/ai/behavior/TradeWithVillager.java index 736ad21b73a19113c6f0f3bce6aa1cc0a41485a8..ec3541d4f2d39a3fd482063efabeab6478311214 100644 --- a/net/minecraft/world/entity/ai/behavior/TradeWithVillager.java +++ b/net/minecraft/world/entity/ai/behavior/TradeWithVillager.java @@ -59,6 +59,12 @@ public class TradeWithVillager extends Behavior { throwHalfStack(body, ImmutableSet.of(Items.WHEAT), target); } + // Purpur start - Option for Villager Clerics to farm Nether Wart + if (level.purpurConfig.villagerClericsFarmWarts && level.purpurConfig.villagerClericFarmersThrowWarts && body.getVillagerData().profession().is(VillagerProfession.CLERIC) && body.getInventory().countItem(Items.NETHER_WART) > Items.NETHER_WART.getDefaultMaxStackSize() / 2) { + throwHalfStack(body, ImmutableSet.of(Items.NETHER_WART), target); + } + // Purpur end - Option for Villager Clerics to farm Nether Wart + if (!this.trades.isEmpty() && body.getInventory().hasAnyOf(this.trades)) { throwHalfStack(body, this.trades, target); } diff --git a/net/minecraft/world/entity/ai/behavior/VillagerGoalPackages.java b/net/minecraft/world/entity/ai/behavior/VillagerGoalPackages.java index fa9163d1f73eacd110227b6cf95f578c678aa803..bcae1ac0f5acccd4e58fe1cc2a54b3d30b488414 100644 --- a/net/minecraft/world/entity/ai/behavior/VillagerGoalPackages.java +++ b/net/minecraft/world/entity/ai/behavior/VillagerGoalPackages.java @@ -74,8 +74,13 @@ public class VillagerGoalPackages { public static ImmutableList>> getWorkPackage( final Holder profession, final float speedModifier ) { + // Purpur start - Option for Villager Clerics to farm Nether Wart + return getWorkPackage(profession, speedModifier, false); + } + public static ImmutableList>> getWorkPackage(Holder profession, float speedModifier, boolean clericsFarmWarts) { + // Purpur end - Option for Villager Clerics to farm Nether Wart WorkAtPoi workAtPoi; - if (profession.is(VillagerProfession.FARMER)) { + if (profession.is(VillagerProfession.FARMER) || (clericsFarmWarts && profession.is(VillagerProfession.CLERIC))) { // Purpur - Option for Villager Clerics to farm Nether Wart workAtPoi = new WorkAtComposter(); } else { workAtPoi = new WorkAtPoi(); diff --git a/net/minecraft/world/entity/ai/sensing/SecondaryPoiSensor.java b/net/minecraft/world/entity/ai/sensing/SecondaryPoiSensor.java index ec12508c112b1e7748a5d197b73a0d540bed10fc..f2daabad51d565cae11e8bfce8b1bf40a7e56a78 100644 --- a/net/minecraft/world/entity/ai/sensing/SecondaryPoiSensor.java +++ b/net/minecraft/world/entity/ai/sensing/SecondaryPoiSensor.java @@ -22,6 +22,13 @@ public class SecondaryPoiSensor extends Sensor { @Override protected void doTick(final ServerLevel level, final Villager body) { + // Purpur start - Option for Villager Clerics to farm Nether Wart - make sure clerics don't wander to soul sand when the option is off + Brain brain = body.getBrain(); + if (!level.purpurConfig.villagerClericsFarmWarts && body.getVillagerData().profession().is(net.minecraft.world.entity.npc.villager.VillagerProfession.CLERIC)) { + brain.eraseMemory(MemoryModuleType.SECONDARY_JOB_SITE); + return; + } + // Purpur end - Option for Villager Clerics to farm Nether Wart ResourceKey dimensionType = level.dimension(); BlockPos center = body.blockPosition(); List jobSites = Lists.newArrayList(); @@ -38,7 +45,7 @@ public class SecondaryPoiSensor extends Sensor { } } - Brain brain = body.getBrain(); + //Brain brain = body.getBrain(); // Purpur - Option for Villager Clerics to farm Nether Wart - moved up if (!jobSites.isEmpty()) { brain.setMemory(MemoryModuleType.SECONDARY_JOB_SITE, jobSites); } else { diff --git a/net/minecraft/world/entity/npc/villager/Villager.java b/net/minecraft/world/entity/npc/villager/Villager.java index f0ebe6f376a13df2fa34f41ecdcc9bded72dc756..bd9f39efb01f9153db56e6e58b56b76dec3d8cc3 100644 --- a/net/minecraft/world/entity/npc/villager/Villager.java +++ b/net/minecraft/world/entity/npc/villager/Villager.java @@ -148,7 +148,7 @@ public class Villager extends AbstractVillager implements VillagerDataHolder, Re activities.add( ActivityData.create( Activity.WORK, - VillagerGoalPackages.getWorkPackage(profession, 0.5F), + VillagerGoalPackages.getWorkPackage(profession, 0.5F, body.level().purpurConfig.villagerClericsFarmWarts), // Purpur - Option for Villager Clerics to farm Nether Wart ImmutableSet.of(Pair.of(MemoryModuleType.JOB_SITE, MemoryStatus.VALUE_PRESENT)) ) ); @@ -947,7 +947,7 @@ public class Villager extends AbstractVillager implements VillagerDataHolder, Re } public boolean hasFarmSeeds() { - return this.getInventory().hasAnyMatching(item -> item.is(ItemTags.VILLAGER_PLANTABLE_SEEDS)); + return this.getInventory().hasAnyMatching(item -> this.level().purpurConfig.villagerClericsFarmWarts && this.getVillagerData().profession().is(VillagerProfession.CLERIC) ? item.is(Items.NETHER_WART) : item.is(ItemTags.VILLAGER_PLANTABLE_SEEDS)); } @Override diff --git a/net/minecraft/world/entity/npc/villager/VillagerProfession.java b/net/minecraft/world/entity/npc/villager/VillagerProfession.java index 1d779d7a51437581fa3d8da38449916362b25ce9..9d71db9db42e38338afe10b24699dae9cc90fcfa 100644 --- a/net/minecraft/world/entity/npc/villager/VillagerProfession.java +++ b/net/minecraft/world/entity/npc/villager/VillagerProfession.java @@ -165,6 +165,8 @@ public record VillagerProfession( registry, CLERIC, PoiTypes.CLERIC, + ImmutableSet.of(Items.NETHER_WART), // Purpur - Option for Villager Clerics to farm Nether Wart + ImmutableSet.of(Blocks.SOUL_SAND), // Purpur - Option for Villager Clerics to farm Nether Wart SoundEvents.VILLAGER_WORK_CLERIC, Int2ObjectMap.ofEntries( Int2ObjectMap.entry(1, TradeSets.CLERIC_LEVEL_1),