Files
Purpur/patches/server/0148-Option-for-Villager-Clerics-to-farm-Nether-Wart.patch
2021-02-13 14:26:41 -06:00

258 lines
18 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/server/BehaviorFarm.java b/src/main/java/net/minecraft/server/BehaviorFarm.java
index 0ff202c0d77681f7e0d55d57c69dd0e455336eba..b9c6011c8dcab1a328260871f46d0216bce1818f 100644
--- a/src/main/java/net/minecraft/server/BehaviorFarm.java
+++ b/src/main/java/net/minecraft/server/BehaviorFarm.java
@@ -12,6 +12,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));
@@ -20,9 +21,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();
@@ -53,6 +59,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;
}
@@ -78,7 +89,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);
@@ -86,7 +97,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) {
@@ -109,6 +120,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);
@@ -119,7 +136,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/server/BehaviorTradeVillager.java b/src/main/java/net/minecraft/server/BehaviorTradeVillager.java
index ad26ecd7fe6b6eedc743f2fab687bd0c6a62a46a..6d8b6951c3c07f71dc89131842d815099c62030f 100644
--- a/src/main/java/net/minecraft/server/BehaviorTradeVillager.java
+++ b/src/main/java/net/minecraft/server/BehaviorTradeVillager.java
@@ -41,6 +41,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);
@@ -62,6 +67,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/server/Behaviors.java b/src/main/java/net/minecraft/server/Behaviors.java
index 2d91869660c36b4cd7bfe887956a26802cce7f8a..e376306bc2555620d1a61af2296f3dd8abc6ce0e 100644
--- a/src/main/java/net/minecraft/server/Behaviors.java
+++ b/src/main/java/net/minecraft/server/Behaviors.java
@@ -12,10 +12,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/server/EntityVillager.java b/src/main/java/net/minecraft/server/EntityVillager.java
index b3f71c9dcada0ae14172c5694564a9f54a6e556e..60962553e4f374b38de82f2cd4d72cef3d956c72 100644
--- a/src/main/java/net/minecraft/server/EntityVillager.java
+++ b/src/main/java/net/minecraft/server/EntityVillager.java
@@ -131,7 +131,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));
@@ -845,6 +845,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);
}
@@ -866,6 +871,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/server/IInventory.java b/src/main/java/net/minecraft/server/IInventory.java
index 46b88056b852a7f91d32862dea7bd3a7ea4a1226..64f1767f66a5a91833225faa1b1444e62c6a0205 100644
--- a/src/main/java/net/minecraft/server/IInventory.java
+++ b/src/main/java/net/minecraft/server/IInventory.java
@@ -31,6 +31,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;
@@ -45,6 +46,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/server/SensorSecondaryPlaces.java b/src/main/java/net/minecraft/server/SensorSecondaryPlaces.java
index 24173f0d3a6c2c9a4a564de6cd828bdef9afec90..2d8e3e77710b59967b7b18006194d73761df6c56 100644
--- a/src/main/java/net/minecraft/server/SensorSecondaryPlaces.java
+++ b/src/main/java/net/minecraft/server/SensorSecondaryPlaces.java
@@ -12,6 +12,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();
@@ -29,10 +36,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/server/VillagerProfession.java b/src/main/java/net/minecraft/server/VillagerProfession.java
index 3c60da7ac6faebe9d964e893974e42613c59b4c1..6493f220a0cf627e82e5f3f3c85e9934d9a9ebae 100644
--- a/src/main/java/net/minecraft/server/VillagerProfession.java
+++ b/src/main/java/net/minecraft/server/VillagerProfession.java
@@ -9,7 +9,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 c42b76c449c55ece8ca08e596253e20aab3ecb09..c690238bb16d7172ba53321f9512a7bb9c5683fd 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -1077,6 +1077,8 @@ public class PurpurWorldConfig {
public boolean villagerCanBreed = true;
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);
@@ -1095,6 +1097,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;