mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 08:27:43 +01:00
Add config to only lobotomize villagers that have been traded with (#1466)
This commit is contained in:
@@ -5,7 +5,7 @@ Subject: [PATCH] Lobotomize stuck villagers
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/npc/Villager.java b/src/main/java/net/minecraft/world/entity/npc/Villager.java
|
||||
index cb6ca99d429b395c0c79b57b1709eb1b8899da82..27e8f8bbaa25227c19399fab2bce8953d098e612 100644
|
||||
index af3af49f2965dbc3da7749bd9c6ae5e2d6b94cbe..fed066980b17d7c7fa773a00b314535c92fc53fd 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/npc/Villager.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/npc/Villager.java
|
||||
@@ -141,6 +141,8 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
|
||||
@@ -17,19 +17,20 @@ index cb6ca99d429b395c0c79b57b1709eb1b8899da82..27e8f8bbaa25227c19399fab2bce8953
|
||||
|
||||
public long nextGolemPanic = -1; // Pufferfish
|
||||
|
||||
@@ -200,6 +202,47 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
|
||||
@@ -200,6 +202,48 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
|
||||
return this.level().purpurConfig.villagerAlwaysDropExp;
|
||||
}
|
||||
|
||||
+ private boolean checkLobotomized() {
|
||||
+ int interval = this.level().purpurConfig.villagerLobotomizeCheckInterval;
|
||||
+ boolean shouldCheckForTradeLocked = this.level().purpurConfig.villagerLobotomizeWaitUntilTradeLocked;
|
||||
+ if (this.notLobotomizedCount > 3) {
|
||||
+ // check half as often if not lobotomized for the last 3+ consecutive checks
|
||||
+ interval *= 2;
|
||||
+ }
|
||||
+ if (this.level().getGameTime() % interval == 0) {
|
||||
+ // offset Y for short blocks like dirt_path/farmland
|
||||
+ this.isLobotomized = !canTravelFrom(BlockPos.containing(this.position().x, this.getBoundingBox().minY + 0.0625D, this.position().z));
|
||||
+ this.isLobotomized = !(shouldCheckForTradeLocked && this.getVillagerXp() == 0) && !canTravelFrom(BlockPos.containing(this.position().x, this.getBoundingBox().minY + 0.0625D, this.position().z));
|
||||
+
|
||||
+ if (this.isLobotomized) {
|
||||
+ this.notLobotomizedCount = 0;
|
||||
@@ -65,7 +66,7 @@ index cb6ca99d429b395c0c79b57b1709eb1b8899da82..27e8f8bbaa25227c19399fab2bce8953
|
||||
@Override
|
||||
public Brain<Villager> getBrain() {
|
||||
return (Brain<Villager>) super.getBrain(); // CraftBukkit - decompile error
|
||||
@@ -297,13 +340,19 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
|
||||
@@ -297,13 +341,19 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
|
||||
// Paper start
|
||||
this.customServerAiStep(false);
|
||||
}
|
||||
@@ -104,19 +105,20 @@ index 6c15d40979fd3e3d246a447c432b321fbf29ada3..6ace76a829c88e2e747dbbcce0a6582c
|
||||
+ // Purpur end
|
||||
}
|
||||
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
index e320196cc5f7302377916d5402579632374de09c..39f373cfbe0228d2040a9e7616a0491b11ee67a1 100644
|
||||
index e320196cc5f7302377916d5402579632374de09c..26351f5ba9fd4f2e231481cfdd52341e0f4d96a4 100644
|
||||
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
@@ -2795,6 +2795,8 @@ public class PurpurWorldConfig {
|
||||
@@ -2795,6 +2795,9 @@ public class PurpurWorldConfig {
|
||||
public boolean villagerAllowTrading = true;
|
||||
public boolean villagerAlwaysDropExp = false;
|
||||
public int villagerMinimumDemand = 0;
|
||||
+ public boolean villagerLobotomizeEnabled = false;
|
||||
+ public int villagerLobotomizeCheckInterval = 100;
|
||||
+ public boolean villagerLobotomizeWaitUntilTradeLocked = false;
|
||||
private void villagerSettings() {
|
||||
villagerRidable = getBoolean("mobs.villager.ridable", villagerRidable);
|
||||
villagerRidableInWater = getBoolean("mobs.villager.ridable-in-water", villagerRidableInWater);
|
||||
@@ -2816,6 +2818,17 @@ public class PurpurWorldConfig {
|
||||
@@ -2816,6 +2819,18 @@ public class PurpurWorldConfig {
|
||||
villagerAllowTrading = getBoolean("mobs.villager.allow-trading", villagerAllowTrading);
|
||||
villagerAlwaysDropExp = getBoolean("mobs.villager.always-drop-exp", villagerAlwaysDropExp);
|
||||
villagerMinimumDemand = getInt("mobs.villager.minimum-demand", villagerMinimumDemand);
|
||||
@@ -131,6 +133,7 @@ index e320196cc5f7302377916d5402579632374de09c..39f373cfbe0228d2040a9e7616a0491b
|
||||
+ }
|
||||
+ villagerLobotomizeEnabled = getBoolean("mobs.villager.lobotomize.enabled", villagerLobotomizeEnabled);
|
||||
+ villagerLobotomizeCheckInterval = getInt("mobs.villager.lobotomize.check-interval", villagerLobotomizeCheckInterval);
|
||||
+ villagerLobotomizeWaitUntilTradeLocked = getBoolean("mobs.villager.lobotomize.wait-until-trade-locked", villagerLobotomizeWaitUntilTradeLocked);
|
||||
}
|
||||
|
||||
public boolean vindicatorRidable = false;
|
||||
|
||||
@@ -17,21 +17,21 @@ index c3e0b1f11b58668f9f24eb421abc340e1b49dfac..d809fa4f96e2c528075f544355397903
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
index 39f373cfbe0228d2040a9e7616a0491b11ee67a1..7f91d3d56f6c4077e773c82da0f96103c892b82b 100644
|
||||
index 26351f5ba9fd4f2e231481cfdd52341e0f4d96a4..38ebf581f6abc16b7556057c05cead5c2bfaa0f7 100644
|
||||
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
@@ -2797,6 +2797,7 @@ public class PurpurWorldConfig {
|
||||
public int villagerMinimumDemand = 0;
|
||||
@@ -2798,6 +2798,7 @@ public class PurpurWorldConfig {
|
||||
public boolean villagerLobotomizeEnabled = false;
|
||||
public int villagerLobotomizeCheckInterval = 100;
|
||||
public boolean villagerLobotomizeWaitUntilTradeLocked = false;
|
||||
+ public boolean villagerDisplayTradeItem = true;
|
||||
private void villagerSettings() {
|
||||
villagerRidable = getBoolean("mobs.villager.ridable", villagerRidable);
|
||||
villagerRidableInWater = getBoolean("mobs.villager.ridable-in-water", villagerRidableInWater);
|
||||
@@ -2829,6 +2830,7 @@ public class PurpurWorldConfig {
|
||||
}
|
||||
@@ -2831,6 +2832,7 @@ public class PurpurWorldConfig {
|
||||
villagerLobotomizeEnabled = getBoolean("mobs.villager.lobotomize.enabled", villagerLobotomizeEnabled);
|
||||
villagerLobotomizeCheckInterval = getInt("mobs.villager.lobotomize.check-interval", villagerLobotomizeCheckInterval);
|
||||
villagerLobotomizeWaitUntilTradeLocked = getBoolean("mobs.villager.lobotomize.wait-until-trade-locked", villagerLobotomizeWaitUntilTradeLocked);
|
||||
+ villagerDisplayTradeItem = getBoolean("mobs.villager.display-trade-item", villagerDisplayTradeItem);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@ Subject: [PATCH] Implement configurable search radius for villagers to spawn
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/npc/Villager.java b/src/main/java/net/minecraft/world/entity/npc/Villager.java
|
||||
index 27e8f8bbaa25227c19399fab2bce8953d098e612..576ac084a97a59f2bd3a1be3d70515649091e593 100644
|
||||
index fed066980b17d7c7fa773a00b314535c92fc53fd..857d1d80afd35d30a2947b0a6f953e5af1516048 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/npc/Villager.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/npc/Villager.java
|
||||
@@ -1100,6 +1100,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
|
||||
@@ -1101,6 +1101,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
|
||||
}
|
||||
|
||||
public void spawnGolemIfNeeded(ServerLevel world, long time, int requiredCount) {
|
||||
@@ -18,21 +18,21 @@ index 27e8f8bbaa25227c19399fab2bce8953d098e612..576ac084a97a59f2bd3a1be3d7051564
|
||||
AABB axisalignedbb = this.getBoundingBox().inflate(10.0D, 10.0D, 10.0D);
|
||||
List<Villager> list = world.getEntitiesOfClass(Villager.class, axisalignedbb);
|
||||
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
index 2a898817bff68402631fbcf9318bed76548c9e21..05d82f9555b8836b48d076ec38f3aab6c070e58b 100644
|
||||
index 1beb9285414e3c178c95ef9ea404fcf34f9cdcac..a0b5c0819541a2924bf29ded4d1842b0e19b4e7b 100644
|
||||
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
@@ -2808,6 +2808,8 @@ public class PurpurWorldConfig {
|
||||
public boolean villagerLobotomizeEnabled = false;
|
||||
@@ -2809,6 +2809,8 @@ public class PurpurWorldConfig {
|
||||
public int villagerLobotomizeCheckInterval = 100;
|
||||
public boolean villagerLobotomizeWaitUntilTradeLocked = false;
|
||||
public boolean villagerDisplayTradeItem = true;
|
||||
+ public int villagerSpawnIronGolemRadius = 0;
|
||||
+ public int villagerSpawnIronGolemLimit = 0;
|
||||
private void villagerSettings() {
|
||||
villagerRidable = getBoolean("mobs.villager.ridable", villagerRidable);
|
||||
villagerRidableInWater = getBoolean("mobs.villager.ridable-in-water", villagerRidableInWater);
|
||||
@@ -2841,6 +2843,8 @@ public class PurpurWorldConfig {
|
||||
villagerLobotomizeEnabled = getBoolean("mobs.villager.lobotomize.enabled", villagerLobotomizeEnabled);
|
||||
@@ -2843,6 +2845,8 @@ public class PurpurWorldConfig {
|
||||
villagerLobotomizeCheckInterval = getInt("mobs.villager.lobotomize.check-interval", villagerLobotomizeCheckInterval);
|
||||
villagerLobotomizeWaitUntilTradeLocked = getBoolean("mobs.villager.lobotomize.wait-until-trade-locked", villagerLobotomizeWaitUntilTradeLocked);
|
||||
villagerDisplayTradeItem = getBoolean("mobs.villager.display-trade-item", villagerDisplayTradeItem);
|
||||
+ villagerSpawnIronGolemRadius = getInt("mobs.villager.spawn-iron-golem.radius", villagerSpawnIronGolemRadius);
|
||||
+ villagerSpawnIronGolemLimit = getInt("mobs.villager.spawn-iron-golem.limit", villagerSpawnIronGolemLimit);
|
||||
|
||||
@@ -1777,10 +1777,10 @@ index 384e7b29215cadfa40af07a183a9c9c6a5b4a80a..bf7ef72a7d92db8f11789a6958327064
|
||||
if ((this.tickCount + this.getId()) % 120 == 0) {
|
||||
Warden.applyDarknessAround(worldserver, this.position(), this, 20);
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/npc/Villager.java b/src/main/java/net/minecraft/world/entity/npc/Villager.java
|
||||
index ceda40e0246830155d13f36073b0ba45a5146de6..795a91cf05dc4f5fba84eaa501e8163fd99bf2c5 100644
|
||||
index 857d1d80afd35d30a2947b0a6f953e5af1516048..18f92478f07de7c941ff8bbe0ec2ef2fe3617fd7 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/npc/Villager.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/npc/Villager.java
|
||||
@@ -342,7 +342,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
|
||||
@@ -343,7 +343,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
|
||||
}
|
||||
protected void customServerAiStep(boolean inactive) { // Purpur - not final
|
||||
// Paper end
|
||||
@@ -1789,7 +1789,7 @@ index ceda40e0246830155d13f36073b0ba45a5146de6..795a91cf05dc4f5fba84eaa501e8163f
|
||||
// Purpur start
|
||||
if (this.level().purpurConfig.villagerLobotomizeEnabled) {
|
||||
// treat as inactive if lobotomized
|
||||
@@ -354,7 +354,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
|
||||
@@ -355,7 +355,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
|
||||
this.getBrain().tick((ServerLevel) this.level(), this); // Paper
|
||||
} else if (this.isLobotomized && shouldRestock()) restock();
|
||||
// Purpur end
|
||||
|
||||
@@ -42,10 +42,10 @@ index cd7b955754b809826048b80723e2e9055b373a4a..b929bef749397797203eb6fb7a7e817d
|
||||
+ // Purpur end - Shears can defuse TNT
|
||||
}
|
||||
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
index 4fa20bdc2a9ca0906f4fd32d7b1d2590da6094a3..4d6679eba841dc6d9b2d227d99ab5842adb1caeb 100644
|
||||
index 51540ca96e7ce0706afbb0644f5b8e699fb79cfc..d7b7e3adb55224adec5f11a98d77e93ebdbb5c2d 100644
|
||||
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
@@ -3284,4 +3284,11 @@ public class PurpurWorldConfig {
|
||||
@@ -3286,4 +3286,11 @@ public class PurpurWorldConfig {
|
||||
cauldronDripstoneWaterFillChance = (float) getDouble("blocks.cauldron.fill-chances.dripstone-water", cauldronDripstoneWaterFillChance);
|
||||
cauldronDripstoneLavaFillChance = (float) getDouble("blocks.cauldron.fill-chances.dripstone-lava", cauldronDripstoneLavaFillChance);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user