Files
Purpur/purpur-server/minecraft-patches/features/0014-Option-for-Villager-Clerics-to-farm-Nether-Wart.patch

172 lines
12 KiB
Diff

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 6f7af24143421cac84d9c1175acd88a776d8652d..d3f88e3274abc5904544a84a6f1e1d10a441b1e7 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<Villager> {
private long nextOkStartTime;
private int timeWorkedSoFar;
private final List<BlockPos> validFarmlandAroundVillager = Lists.newArrayList();
+ private boolean clericWartFarmer = false; // Purpur - Option for Villager Clerics to farm Nether Wart
public HarvestFarmland() {
super(
@@ -49,9 +50,10 @@ public class HarvestFarmland extends Behavior<Villager> {
protected boolean checkExtraStartConditions(final ServerLevel level, final Villager body) {
if (!level.getGameRules().get(GameRules.MOB_GRIEFING)) {
return false;
- } else if (!body.getVillagerData().profession().is(VillagerProfession.FARMER)) {
+ } else 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;
} else {
+ 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();
@@ -81,6 +83,7 @@ public class HarvestFarmland extends Behavior<Villager> {
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)block).isMaxAge(state) || state.isAir() && blockBelow instanceof FarmlandBlock;
}
@@ -107,19 +110,19 @@ public class HarvestFarmland extends Behavior<Villager> {
BlockState blockState = level.getBlockState(this.aboveFarmlandPos);
Block block = blockState.getBlock();
Block blockBelow = level.getBlockState(this.aboveFarmlandPos.below()).getBlock();
- if (block instanceof CropBlock && ((CropBlock)block).isMaxAge(blockState)) {
+ if (block instanceof CropBlock && ((CropBlock)block).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);
@@ -134,7 +137,7 @@ public class HarvestFarmland extends Behavior<Villager> {
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 1d405a77c4cf70bd818a4f59163e5b319808d5f3..6a7b51acfc2cd157ce81c3a92d2633375cb1a6a7 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<Villager> {
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 e70ada99503e9df863e0f1e17dcafe85b5e4efd5..ebd320fa575fbf955f900f7ec0bbf6e17aa73b05 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<Pair<Integer, ? extends BehaviorControl<? super Villager>>> getWorkPackage(
final Holder<VillagerProfession> profession, final float speedModifier
) {
+ // Purpur start - Option for Villager Clerics to farm Nether Wart
+ return getWorkPackage(profession, speedModifier, false);
+ }
+ public static ImmutableList<Pair<Integer, ? extends BehaviorControl<? super Villager>>> getWorkPackage(Holder<VillagerProfession> 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<Villager> {
@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<Level> dimensionType = level.dimension();
BlockPos center = body.blockPosition();
List<GlobalPos> jobSites = Lists.newArrayList();
@@ -38,7 +45,7 @@ public class SecondaryPoiSensor extends Sensor<Villager> {
}
}
- 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 19bba23d87543574d5d8a4139ac93e751fe690d9..27b2675059795b54b7d217442065bd50618ac7ae 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))
)
);
@@ -945,7 +945,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),