Files
Purpur/patches/server/0145-Option-for-Villager-Clerics-to-farm-Nether-Wart.patch
BillyGalbreath 1362f49b24 Updated Upstream (Paper, Tuinity, & Airplane)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
bca97a8f7 replace spaces in world key (touches #5397)
de94f6485 Refactor chat message composition (#5396)
e27f334bb [CI-SKIP] Fix makemcdevsrc.sh for nms relocations (#5389)
ae15e85da Updated Upstream (CraftBukkit)
26fe0ac5a Only set despawnTimer for Wandering Traders spawned by MobSpawnerTrader (#5391)
b748eb7b8 Fix VanillaMobGoalTest#testBukkitMap (#5390)
18dbbb578 [Auto] Updated Upstream (CraftBukkit)
fac9cc5d5 [CI-SKIP] Ignore .gitignore
087aa70e7 Deprecate ItemStack#setLore(List<String>) and ItemStack#getLore, add Component based alternatives
9889c651c apply fixup
c310f0a61 Updated Upstream (Bukkit/CraftBukkit)
f17560ab0 wtf is this t file -jmp
347f3a9b8 fix compile
700e9e6a5 rebase
cf4dc464a Revert de5f4e469...c270abe96
6870db613 script & POM fix
743c6533c Replace ** with * (BSD/macOS)
376d7b097 Don't remove the .java
fcb3fd42a Fix macOS/BSD support
8cfc05249 Link correctly
ba1031ca7 Rename work dir
c8d844ab7 Actually fix preloading this time
e62aa5e3e Fix class preloading
1c03cf898 It's mojang math, not minecraft math
1034873df Apply fixups
39b125771 Use revision file
956150da7 Welcome to 1.16.5-R0.2
ccb217c01 Change cache keys
0d217001c more work
f6d820f07 It compiles
0f78e9525 More work
1718f61bf Updated Upstream (CraftBukkit/Spigot)
b28d46114 Update scripts for NMS repackaging

Tuinity Changes:
9bdcb9b8e Delete work dir when running jar
6351d7ca7 Update Upstream (Paper)
932c199a6 Generate md-dev correctly
bf3e73778 Make packet limiter work from IDE
1686f3861 Fix packet limiter config
f40f7b425 Update README.md styling (#264)
da1c3ace5 GH Actions Changes (#213)
5f325ecf1 Update Upstream (Paper)
0f83fe48d Update Upstream (Paper)

Airplane Changes:
f94d39947 Merge pull request #18 from notOM3GA/upstream/nms-repackage
0fc622631 Force build for Flare update
08439d6a9 Update Upstream (Tuinity)
2021-03-21 23:00:01 -05:00

274 lines
20 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: jmp <jasonpenilla2@me.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/src/main/java/net/minecraft/world/IInventory.java b/src/main/java/net/minecraft/world/IInventory.java
index 774ba6a923f7e329f6af5efc17e1c46e87ed2d77..b8c73cd0ba916b7bf166a6d2f6b7ab68cd9c939b 100644
--- a/src/main/java/net/minecraft/world/IInventory.java
+++ b/src/main/java/net/minecraft/world/IInventory.java
@@ -38,6 +38,7 @@ public interface IInventory extends Clearable {
return true;
}
+ default int getAmount(Item item) { return this.a(item); } // Purpur - OBFHELPER
default int a(Item item) {
int i = 0;
@@ -52,6 +53,7 @@ public interface IInventory extends Clearable {
return i;
}
+ default boolean containsAny(Set<Item> itemSet) { return a(itemSet); } // Purpur - OBFHELPER
default boolean a(Set<Item> set) {
for (int i = 0; i < this.getSize(); ++i) {
ItemStack itemstack = this.getItem(i);
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorFarm.java b/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorFarm.java
index 42c70a6c2972ac38e889a6d42fe2d7d4f6017d57..751f2b2f7d0e87212a6bd813d4f85cefd5bb2b50 100644
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorFarm.java
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorFarm.java
@@ -21,6 +21,7 @@ import net.minecraft.world.item.Items;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.BlockCrops;
+import net.minecraft.world.level.block.BlockNetherWart;
import net.minecraft.world.level.block.BlockSoil;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.IBlockData;
@@ -32,6 +33,7 @@ public class BehaviorFarm extends Behavior<EntityVillager> {
private long c;
private int d;
private final List<BlockPosition> e = Lists.newArrayList();
+ private boolean clericWartFarmer = false; // Purpur
public BehaviorFarm() {
super(ImmutableMap.of(MemoryModuleType.LOOK_TARGET, MemoryStatus.VALUE_ABSENT, MemoryModuleType.WALK_TARGET, MemoryStatus.VALUE_ABSENT, MemoryModuleType.SECONDARY_JOB_SITE, MemoryStatus.VALUE_PRESENT));
@@ -40,9 +42,14 @@ public class BehaviorFarm extends Behavior<EntityVillager> {
protected boolean a(WorldServer worldserver, EntityVillager entityvillager) {
if (!worldserver.getGameRules().getBoolean(GameRules.MOB_GRIEFING) && !worldserver.purpurConfig.villagerFarmingBypassMobGriefing) { // Purpur
return false;
- } else if (entityvillager.getVillagerData().getProfession() != VillagerProfession.FARMER) {
+ } else if (entityvillager.getVillagerData().getProfession() != VillagerProfession.FARMER && !(worldserver.purpurConfig.villagerClericsFarmWarts && entityvillager.getVillagerData().getProfession() == VillagerProfession.CLERIC)) { // Purpur
return false;
} else {
+ // Purpur start
+ if (!this.clericWartFarmer && entityvillager.getVillagerData().getProfession() == VillagerProfession.CLERIC) {
+ this.clericWartFarmer = true;
+ }
+ // Purpur end
BlockPosition.MutableBlockPosition blockposition_mutableblockposition = entityvillager.getChunkCoordinates().i();
this.e.clear();
@@ -73,6 +80,11 @@ public class BehaviorFarm extends Behavior<EntityVillager> {
Block block = iblockdata.getBlock();
Block block1 = worldserver.getType(blockposition.down()).getBlock();
+ // Purpur start
+ if (this.clericWartFarmer) {
+ return block == Blocks.NETHER_WART && iblockdata.get(BlockNetherWart.AGE) == 3 || iblockdata.isAir() && block1 == Blocks.SOUL_SAND;
+ }
+ // Purpur end
return block instanceof BlockCrops && ((BlockCrops) block).isRipe(iblockdata) || iblockdata.isAir() && block1 instanceof BlockSoil;
}
@@ -98,7 +110,7 @@ public class BehaviorFarm extends Behavior<EntityVillager> {
Block block = iblockdata.getBlock();
Block block1 = worldserver.getType(this.farmBlock.down()).getBlock();
- if (block instanceof BlockCrops && ((BlockCrops) block).isRipe(iblockdata)) {
+ if (block instanceof BlockCrops && ((BlockCrops) block).isRipe(iblockdata) || this.clericWartFarmer && block == Blocks.NETHER_WART && iblockdata.get(BlockNetherWart.AGE) == 3) { // Purpur
// CraftBukkit start
if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entityvillager, this.farmBlock, Blocks.AIR.getBlockData()).isCancelled()) {
worldserver.a(this.farmBlock, true, entityvillager);
@@ -106,7 +118,7 @@ public class BehaviorFarm extends Behavior<EntityVillager> {
// CraftBukkit end
}
- if (iblockdata.isAir() && block1 instanceof BlockSoil && entityvillager.canPlant()) {
+ if (iblockdata.isAir() && (block1 instanceof BlockSoil || this.clericWartFarmer && block1 == Blocks.SOUL_SAND) && entityvillager.canPlant()) { // Purpur
InventorySubcontainer inventorysubcontainer = entityvillager.getInventory();
for (int j = 0; j < inventorysubcontainer.getSize(); ++j) {
@@ -129,6 +141,12 @@ public class BehaviorFarm extends Behavior<EntityVillager> {
planted = Blocks.BEETROOTS;
flag = true;
}
+ // Purpur start
+ else if (itemstack.getItem() == Items.NETHER_WART) {
+ planted = Blocks.NETHER_WART;
+ flag = true;
+ }
+ // Purpur end
if (planted != null && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entityvillager, this.farmBlock, planted.getBlockData()).isCancelled()) {
worldserver.setTypeAndData(this.farmBlock, planted.getBlockData(), 3);
@@ -139,7 +157,7 @@ public class BehaviorFarm extends Behavior<EntityVillager> {
}
if (flag) {
- worldserver.playSound((EntityHuman) null, (double) this.farmBlock.getX(), (double) this.farmBlock.getY(), (double) this.farmBlock.getZ(), SoundEffects.ITEM_CROP_PLANT, SoundCategory.BLOCKS, 1.0F, 1.0F);
+ worldserver.playSound((EntityHuman) null, (double) this.farmBlock.getX(), (double) this.farmBlock.getY(), (double) this.farmBlock.getZ(), this.clericWartFarmer ? SoundEffects.ITEM_NETHER_WART_PLANT : SoundEffects.ITEM_CROP_PLANT, SoundCategory.BLOCKS, 1.0F, 1.0F); // Purpur
itemstack.subtract(1);
if (itemstack.isEmpty()) {
inventorysubcontainer.setItem(j, ItemStack.b);
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorTradeVillager.java b/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorTradeVillager.java
index 71ea6c43d76bf1abe6b08dadb20ea4708b0ecfc7..c73b4475182541fa8261bec44f1eeeef21c22f42 100644
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorTradeVillager.java
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorTradeVillager.java
@@ -53,6 +53,11 @@ public class BehaviorTradeVillager extends Behavior<EntityVillager> {
if (entityvillager1.getVillagerData().getProfession() == VillagerProfession.FARMER && entityvillager.getInventory().a(Items.WHEAT) > Items.WHEAT.getMaxStackSize() / 2) {
a(entityvillager, ImmutableSet.of(Items.WHEAT), entityvillager1);
}
+ // Purpur start
+ if (worldserver.purpurConfig.villagerClericsFarmWarts && worldserver.purpurConfig.villagerClericFarmersThrowWarts && entityvillager.getVillagerData().getProfession() == VillagerProfession.CLERIC && entityvillager.getInventory().getAmount(Items.NETHER_WART) > Items.NETHER_WART.getMaxStackSize() / 2) {
+ tryThrowingItems(entityvillager, ImmutableSet.of(Items.NETHER_WART), entityvillager1);
+ }
+ // Purpur end
if (!this.b.isEmpty() && entityvillager.getInventory().a(this.b)) {
a(entityvillager, this.b, entityvillager1);
@@ -74,6 +79,7 @@ public class BehaviorTradeVillager extends Behavior<EntityVillager> {
}).collect(Collectors.toSet());
}
+ private static void tryThrowingItems(EntityVillager entityVillager, Set<Item> acceptableItems, EntityLiving targetEntity) { a(entityVillager, acceptableItems, targetEntity); } // Purpur - OBFHELPER
private static void a(EntityVillager entityvillager, Set<Item> set, EntityLiving entityliving) {
InventorySubcontainer inventorysubcontainer = entityvillager.getInventory();
ItemStack itemstack = ItemStack.b;
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/Behaviors.java b/src/main/java/net/minecraft/world/entity/ai/behavior/Behaviors.java
index df12193e1a2e449193a3feab53fc684a2571ae3a..4a8217862a98488ce71ce577b5fa9d6a0f9c898a 100644
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/Behaviors.java
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/Behaviors.java
@@ -21,10 +21,13 @@ public class Behaviors {
return ImmutableList.of(Pair.of(0, new BehaviorSwim(0.8F)), Pair.of(0, new BehaviorInteractDoor()), Pair.of(0, new BehaviorLook(45, 90)), Pair.of(0, new BehaviorPanic()), Pair.of(0, new BehaviorWake()), Pair.of(0, new BehaviorBellAlert()), Pair.of(0, new BehaviorRaid()), Pair.of(0, new BehaviorPositionValidate(villagerprofession.b(), MemoryModuleType.JOB_SITE)), Pair.of(0, new BehaviorPositionValidate(villagerprofession.b(), MemoryModuleType.POTENTIAL_JOB_SITE)), Pair.of(1, new BehavorMove()), Pair.of(2, new BehaviorBetterJob(villagerprofession)), Pair.of(3, new BehaviorInteractPlayer(f)), new Pair[]{Pair.of(5, new BehaviorFindAdmirableItem<>(f, false, 4)), Pair.of(6, new BehaviorFindPosition(villagerprofession.b(), MemoryModuleType.JOB_SITE, MemoryModuleType.POTENTIAL_JOB_SITE, true, Optional.empty())), Pair.of(7, new BehaviorPotentialJobSite(f)), Pair.of(8, new BehaviorLeaveJob(f)), Pair.of(10, new BehaviorFindPosition(VillagePlaceType.r, MemoryModuleType.HOME, false, Optional.of((byte) 14))), Pair.of(10, new BehaviorFindPosition(VillagePlaceType.s, MemoryModuleType.MEETING_POINT, true, Optional.of((byte) 14))), Pair.of(10, new BehaviorCareer()), Pair.of(10, new BehaviorProfession())});
}
- public static ImmutableList<Pair<Integer, ? extends Behavior<? super EntityVillager>>> b(VillagerProfession villagerprofession, float f) {
- Object object;
+ // Purpur start - OBFHELPER, add clericsFarmWarts param
+ public static ImmutableList<Pair<Integer, ? extends Behavior<? super EntityVillager>>> b(VillagerProfession villagerprofession, float f) { return createWorkTask(villagerprofession, f, false); }
+ public static ImmutableList<Pair<Integer, ? extends Behavior<? super EntityVillager>>> createWorkTask(VillagerProfession villagerprofession, float f, boolean clericsFarmWarts) {
+ BehaviorWork object; // Purpur - decompile fix
- if (villagerprofession == VillagerProfession.FARMER) {
+ if (villagerprofession == VillagerProfession.FARMER || (clericsFarmWarts && villagerprofession == VillagerProfession.CLERIC)) {
+ // Purpur end
object = new BehaviorWorkComposter();
} else {
object = new BehaviorWork();
diff --git a/src/main/java/net/minecraft/world/entity/ai/sensing/SensorSecondaryPlaces.java b/src/main/java/net/minecraft/world/entity/ai/sensing/SensorSecondaryPlaces.java
index 25c10973c74f98224dd1d2ae5e7178b9781374aa..78df1ded72a625c676faf4d704e9e44cec2bc054 100644
--- a/src/main/java/net/minecraft/world/entity/ai/sensing/SensorSecondaryPlaces.java
+++ b/src/main/java/net/minecraft/world/entity/ai/sensing/SensorSecondaryPlaces.java
@@ -11,6 +11,7 @@ import net.minecraft.server.level.WorldServer;
import net.minecraft.world.entity.ai.BehaviorController;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.world.entity.npc.EntityVillager;
+import net.minecraft.world.entity.npc.VillagerProfession;
import net.minecraft.world.level.World;
public class SensorSecondaryPlaces extends Sensor<EntityVillager> {
@@ -20,6 +21,13 @@ public class SensorSecondaryPlaces extends Sensor<EntityVillager> {
}
protected void a(WorldServer worldserver, EntityVillager entityvillager) {
+ // Purpur start - make sure clerics don't wander to soul sand when the option is off
+ BehaviorController<?> behaviorcontroller = entityvillager.getBehaviorController();
+ if (!worldserver.purpurConfig.villagerClericsFarmWarts && entityvillager.getVillagerData().getProfession() == VillagerProfession.CLERIC) {
+ behaviorcontroller.removeMemory(MemoryModuleType.SECONDARY_JOB_SITE);
+ return;
+ }
+ // Purpur end
ResourceKey<World> resourcekey = worldserver.getDimensionKey();
BlockPosition blockposition = entityvillager.getChunkCoordinates();
List<GlobalPos> list = Lists.newArrayList();
@@ -37,10 +45,10 @@ public class SensorSecondaryPlaces extends Sensor<EntityVillager> {
}
}
- BehaviorController<?> behaviorcontroller = entityvillager.getBehaviorController();
+ //BehaviorController<?> behaviorcontroller = entityvillager.getBehaviorController(); // Purpur - move up
if (!list.isEmpty()) {
- behaviorcontroller.setMemory(MemoryModuleType.SECONDARY_JOB_SITE, (Object) list);
+ behaviorcontroller.setMemory(MemoryModuleType.SECONDARY_JOB_SITE, list); // Purpur - decompile fix
} else {
behaviorcontroller.removeMemory(MemoryModuleType.SECONDARY_JOB_SITE);
}
diff --git a/src/main/java/net/minecraft/world/entity/npc/EntityVillager.java b/src/main/java/net/minecraft/world/entity/npc/EntityVillager.java
index bc14e242f97f9f6d8e581d12319c95ae5f70f250..77a5be6f5fc51689a74f853b5dfcef5e772e2c84 100644
--- a/src/main/java/net/minecraft/world/entity/npc/EntityVillager.java
+++ b/src/main/java/net/minecraft/world/entity/npc/EntityVillager.java
@@ -203,7 +203,7 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
behaviorcontroller.a(Activity.PLAY, Behaviors.a(0.5F));
} else {
behaviorcontroller.setSchedule(Schedule.VILLAGER_DEFAULT);
- behaviorcontroller.a(Activity.WORK, Behaviors.b(villagerprofession, 0.5F), (Set) ImmutableSet.of(Pair.of(MemoryModuleType.JOB_SITE, MemoryStatus.VALUE_PRESENT)));
+ behaviorcontroller.a(Activity.WORK, Behaviors.createWorkTask(villagerprofession, 0.5F, this.world.purpurConfig.villagerClericsFarmWarts), (Set) ImmutableSet.of(Pair.of(MemoryModuleType.JOB_SITE, MemoryStatus.VALUE_PRESENT))); // Purpur
}
behaviorcontroller.a(Activity.CORE, Behaviors.a(villagerprofession, 0.5F));
@@ -923,6 +923,11 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
@Override
public boolean i(ItemStack itemstack) {
Item item = itemstack.getItem();
+ // Purpur start
+ if (this.world.purpurConfig.villagerClericsFarmWarts && item.getItem() == Items.NETHER_WART && this.getVillagerData().getProfession() == VillagerProfession.CLERIC) {
+ return true;
+ }
+ // Purpur end
return (EntityVillager.bs.contains(item) || this.getVillagerData().getProfession().c().contains(item)) && this.getInventory().b(itemstack);
}
@@ -944,6 +949,11 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
}
public boolean canPlant() {
+ // Purpur start
+ if (this.world.purpurConfig.villagerClericsFarmWarts && this.getVillagerData().getProfession() == VillagerProfession.CLERIC) {
+ return this.getInventory().containsAny(ImmutableSet.of(Items.NETHER_WART));
+ }
+ // Purpur end
return this.getInventory().a((Set) ImmutableSet.of(Items.WHEAT_SEEDS, Items.POTATO, Items.CARROT, Items.BEETROOT_SEEDS));
}
diff --git a/src/main/java/net/minecraft/world/entity/npc/VillagerProfession.java b/src/main/java/net/minecraft/world/entity/npc/VillagerProfession.java
index 69de7588eebba7557cdaec129f19ec1fc2c675c5..dd9b678481620856fb7eaaa04c3b812c861e892a 100644
--- a/src/main/java/net/minecraft/world/entity/npc/VillagerProfession.java
+++ b/src/main/java/net/minecraft/world/entity/npc/VillagerProfession.java
@@ -18,7 +18,7 @@ public class VillagerProfession {
public static final VillagerProfession ARMORER = a("armorer", VillagePlaceType.d, SoundEffects.ENTITY_VILLAGER_WORK_ARMORER);
public static final VillagerProfession BUTCHER = a("butcher", VillagePlaceType.e, SoundEffects.ENTITY_VILLAGER_WORK_BUTCHER);
public static final VillagerProfession CARTOGRAPHER = a("cartographer", VillagePlaceType.f, SoundEffects.ENTITY_VILLAGER_WORK_CARTOGRAPHER);
- public static final VillagerProfession CLERIC = a("cleric", VillagePlaceType.g, SoundEffects.ENTITY_VILLAGER_WORK_CLERIC);
+ public static final VillagerProfession CLERIC = a("cleric", VillagePlaceType.g, ImmutableSet.of(Items.NETHER_WART), ImmutableSet.of(Blocks.SOUL_SAND), SoundEffects.ENTITY_VILLAGER_WORK_CLERIC); // Purpur
public static final VillagerProfession FARMER = a("farmer", VillagePlaceType.h, ImmutableSet.of(Items.WHEAT, Items.WHEAT_SEEDS, Items.BEETROOT_SEEDS, Items.BONE_MEAL), ImmutableSet.of(Blocks.FARMLAND), SoundEffects.ENTITY_VILLAGER_WORK_FARMER);
public static final VillagerProfession FISHERMAN = a("fisherman", VillagePlaceType.i, SoundEffects.ENTITY_VILLAGER_WORK_FISHERMAN);
public static final VillagerProfession FLETCHER = a("fletcher", VillagePlaceType.j, SoundEffects.ENTITY_VILLAGER_WORK_FLETCHER);
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index b2e4404e05ba304423803779321321292b306255..6f0fa3d581fcb1897bc8e591d596a7e1388a667d 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -1078,6 +1078,8 @@ public class PurpurWorldConfig {
public int villagerBreedingTicks = 6000;
public boolean villagerLobotomizeEnabled = false;
public int villagerLobotomizeCheck = 60;
+ public boolean villagerClericsFarmWarts = false;
+ public boolean villagerClericFarmersThrowWarts = true;
private void villagerSettings() {
villagerRidable = getBoolean("mobs.villager.ridable", villagerRidable);
villagerRidableInWater = getBoolean("mobs.villager.ridable-in-water", villagerRidableInWater);
@@ -1097,6 +1099,8 @@ public class PurpurWorldConfig {
}
villagerLobotomizeEnabled = getBoolean("mobs.villager.lobotomize.enabled", villagerLobotomizeEnabled);
villagerLobotomizeCheck = getInt("mobs.villager.lobotomize.check-interval", villagerLobotomizeCheck);
+ villagerClericsFarmWarts = getBoolean("mobs.villager.clerics-farm-warts", villagerClericsFarmWarts);
+ villagerClericFarmersThrowWarts = getBoolean("mobs.villager.cleric-wart-farmers-throw-warts-at-villagers", villagerClericFarmersThrowWarts);
}
public boolean villagerTraderRidable = false;