-
-
Notifications
You must be signed in to change notification settings - Fork 479
Expand file tree
/
Copy path0014-Option-for-Villager-Clerics-to-farm-Nether-Wart.patch
More file actions
171 lines (159 loc) · 12.6 KB
/
Copy path0014-Option-for-Villager-Clerics-to-farm-Nether-Wart.patch
File metadata and controls
171 lines (159 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
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 de89e45ecd4ac4c6db8b74bbe3dd6b4a7cf21671..f15e4cfd8c0ac5e08779dbe6b9aa40bfe9ce4d8f 100644
--- a/net/minecraft/world/entity/ai/behavior/HarvestFarmland.java
+++ b/net/minecraft/world/entity/ai/behavior/HarvestFarmland.java
@@ -32,6 +32,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(
@@ -50,9 +51,10 @@ public class HarvestFarmland extends Behavior<Villager> {
protected boolean checkExtraStartConditions(ServerLevel level, Villager owner) {
if (!level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) {
return false;
- } else if (!owner.getVillagerData().profession().is(VillagerProfession.FARMER)) {
+ } else if (!owner.getVillagerData().profession().is(VillagerProfession.FARMER) && !(level.purpurConfig.villagerClericsFarmWarts && owner.getVillagerData().profession().is(VillagerProfession.CLERIC))) { // Purpur - Option for Villager Clerics to farm Nether Wart
return false;
} else {
+ if (!this.clericWartFarmer && owner.getVillagerData().profession().is(VillagerProfession.CLERIC)) this.clericWartFarmer = true; // Purpur - Option for Villager Clerics to farm Nether Wart
BlockPos.MutableBlockPos mutableBlockPos = owner.blockPosition().mutable();
this.validFarmlandAroundVillager.clear();
@@ -83,6 +85,7 @@ public class HarvestFarmland extends Behavior<Villager> {
BlockState blockState = serverLevel.getBlockState(pos);
Block block = blockState.getBlock();
Block block1 = serverLevel.getBlockState(pos.below()).getBlock();
+ if (this.clericWartFarmer) return block == net.minecraft.world.level.block.Blocks.NETHER_WART && blockState.getValue(net.minecraft.world.level.block.NetherWartBlock.AGE) == 3 || blockState.isAir() && block1 == net.minecraft.world.level.block.Blocks.SOUL_SAND; // Purpur - Option for Villager Clerics to farm Nether Wart
return block instanceof CropBlock && ((CropBlock)block).isMaxAge(blockState) || blockState.isAir() && block1 instanceof FarmBlock;
}
@@ -109,19 +112,19 @@ public class HarvestFarmland extends Behavior<Villager> {
BlockState blockState = level.getBlockState(this.aboveFarmlandPos);
Block block = blockState.getBlock();
Block block1 = 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(owner, this.aboveFarmlandPos, blockState.getFluidState().createLegacyBlock())) { // CraftBukkit // Paper - fix wrong block state
level.destroyBlock(this.aboveFarmlandPos, true, owner);
} // CraftBukkit
}
- if (blockState.isAir() && block1 instanceof FarmBlock && owner.hasFarmSeeds()) {
+ if (blockState.isAir() && block1 instanceof FarmBlock && !this.clericWartFarmer || this.clericWartFarmer && block1 == net.minecraft.world.level.block.Blocks.SOUL_SAND && owner.hasFarmSeeds()) { // Purpur - Option for Villager Clerics to farm Nether Wart
SimpleContainer inventory = owner.getInventory();
for (int i = 0; i < inventory.getContainerSize(); i++) {
ItemStack item = inventory.getItem(i);
boolean flag = false;
- if (!item.isEmpty() && item.is(ItemTags.VILLAGER_PLANTABLE_SEEDS) && item.getItem() instanceof BlockItem blockItem) {
+ if (!item.isEmpty() && (item.is(ItemTags.VILLAGER_PLANTABLE_SEEDS) || this.clericWartFarmer && item.getItem() == net.minecraft.world.item.Items.NETHER_WART) && item.getItem() instanceof BlockItem blockItem) { // Purpur - Option for Villager Clerics to farm Nether Wart
BlockState blockState1 = blockItem.getBlock().defaultBlockState();
if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(owner, this.aboveFarmlandPos, blockState1)) { // CraftBukkit
level.setBlockAndUpdate(this.aboveFarmlandPos, blockState1);
@@ -136,7 +139,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 623dd33a85cb67ecb835de18e9aac29f3394ce28..72cca4897f9697573fd6987a5f0d2df52761b8c3 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(owner, ImmutableSet.of(Items.WHEAT), villager);
}
+ // Purpur start - Option for Villager Clerics to farm Nether Wart
+ if (level.purpurConfig.villagerClericsFarmWarts && level.purpurConfig.villagerClericFarmersThrowWarts && owner.getVillagerData().profession().is(VillagerProfession.CLERIC) && owner.getInventory().countItem(Items.NETHER_WART) > Items.NETHER_WART.getDefaultMaxStackSize() / 2) {
+ throwHalfStack(owner, ImmutableSet.of(Items.NETHER_WART), villager);
+ }
+ // Purpur end - Option for Villager Clerics to farm Nether Wart
+
if (!this.trades.isEmpty() && owner.getInventory().hasAnyOf(this.trades)) {
throwHalfStack(owner, this.trades, villager);
}
diff --git a/net/minecraft/world/entity/ai/behavior/VillagerGoalPackages.java b/net/minecraft/world/entity/ai/behavior/VillagerGoalPackages.java
index c65f80aadeb27685653f6a4731888c612d4a59d6..bb07aa944ce60ec7db96e2b57bd6c2c862e2f787 100644
--- a/net/minecraft/world/entity/ai/behavior/VillagerGoalPackages.java
+++ b/net/minecraft/world/entity/ai/behavior/VillagerGoalPackages.java
@@ -79,8 +79,13 @@ public class VillagerGoalPackages {
public static ImmutableList<Pair<Integer, ? extends BehaviorControl<? super Villager>>> getWorkPackage(
Holder<VillagerProfession> profession, 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 f0583076ef62189508a392a76c3fb6b741bbdde9..dc4a9ddb8479e9d0c4895b19d7d677cdd8ad3faa 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(ServerLevel level, Villager entity) {
+ // 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 = entity.getBrain();
+ if (!level.purpurConfig.villagerClericsFarmWarts && entity.getVillagerData().profession().is(net.minecraft.world.entity.npc.VillagerProfession.CLERIC)) {
+ brain.eraseMemory(MemoryModuleType.SECONDARY_JOB_SITE);
+ return;
+ }
+ // Purpur end - Option for Villager Clerics to farm Nether Wart
ResourceKey<Level> resourceKey = level.dimension();
BlockPos blockPos = entity.blockPosition();
List<GlobalPos> list = Lists.newArrayList();
@@ -38,7 +45,7 @@ public class SecondaryPoiSensor extends Sensor<Villager> {
}
}
- Brain<?> brain = entity.getBrain();
+ //Brain<?> brain = entity.getBrain(); // Purpur - Option for Villager Clerics to farm Nether Wart - moved up
if (!list.isEmpty()) {
brain.setMemory(MemoryModuleType.SECONDARY_JOB_SITE, list);
} else {
diff --git a/net/minecraft/world/entity/npc/Villager.java b/net/minecraft/world/entity/npc/Villager.java
index 4a68a8124716a57801f2d42a87e4d68c99d2f348..3b78e25de462a6fc393175f7992b9a1d4d08c64b 100644
--- a/net/minecraft/world/entity/npc/Villager.java
+++ b/net/minecraft/world/entity/npc/Villager.java
@@ -315,7 +315,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
villagerBrain.setSchedule(Schedule.VILLAGER_DEFAULT);
villagerBrain.addActivityWithConditions(
Activity.WORK,
- VillagerGoalPackages.getWorkPackage(holder, 0.5F),
+ VillagerGoalPackages.getWorkPackage(holder, 0.5F, this.level().purpurConfig.villagerClericsFarmWarts), // Purpur - Option for Villager Clerics to farm Nether Wart
ImmutableSet.of(Pair.of(MemoryModuleType.JOB_SITE, MemoryStatus.VALUE_PRESENT))
);
}
@@ -966,7 +966,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
}
public boolean hasFarmSeeds() {
- return this.getInventory().hasAnyMatching(stack -> stack.is(ItemTags.VILLAGER_PLANTABLE_SEEDS));
+ return this.getInventory().hasAnyMatching(stack -> this.level().purpurConfig.villagerClericsFarmWarts && this.getVillagerData().profession().is(VillagerProfession.CLERIC) ? stack.is(Items.NETHER_WART) : stack.is(ItemTags.VILLAGER_PLANTABLE_SEEDS)); // Purpur - Option for Villager Clerics to farm Nether Wart
}
@Override
diff --git a/net/minecraft/world/entity/npc/VillagerProfession.java b/net/minecraft/world/entity/npc/VillagerProfession.java
index 0b7fdbc19f8a977be8168bca198c157fbe90044b..abfc2542a486d5a64bf88eac69f7d9587869d3cf 100644
--- a/net/minecraft/world/entity/npc/VillagerProfession.java
+++ b/net/minecraft/world/entity/npc/VillagerProfession.java
@@ -103,7 +103,7 @@ public record VillagerProfession(
register(registry, ARMORER, PoiTypes.ARMORER, SoundEvents.VILLAGER_WORK_ARMORER);
register(registry, BUTCHER, PoiTypes.BUTCHER, SoundEvents.VILLAGER_WORK_BUTCHER);
register(registry, CARTOGRAPHER, PoiTypes.CARTOGRAPHER, SoundEvents.VILLAGER_WORK_CARTOGRAPHER);
- register(registry, CLERIC, PoiTypes.CLERIC, SoundEvents.VILLAGER_WORK_CLERIC);
+ register(registry, CLERIC, PoiTypes.CLERIC, ImmutableSet.of(Items.NETHER_WART), ImmutableSet.of(Blocks.SOUL_SAND), SoundEvents.VILLAGER_WORK_CLERIC); // Purpur - Option for Villager Clerics to farm Nether Wart
register(
registry,
FARMER,