Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add config to only lobotomize if villagers have been traded with
  • Loading branch information
2stinkysocks committed Dec 27, 2023
commit c1bdde90404e59a0750373adb3ce9f7bbfdac2d2
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: 2stinkysocks <zmehall@gmail.com>
Date: Wed, 27 Dec 2023 16:04:52 -0700
Subject: [PATCH] Add config to only lobotomize if villagers have been traded
with


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 68404053233985cb830e95e287c81875a3b86957..15862eb0e3c56d3dac5d7772242a75fbfc8c877a 100644
--- a/src/main/java/net/minecraft/world/entity/npc/Villager.java
+++ b/src/main/java/net/minecraft/world/entity/npc/Villager.java
@@ -204,13 +204,18 @@ public class Villager extends AbstractVillager implements ReputationEventHandler

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));
+ boolean canLobotomize = true;
+ if(shouldCheckForTradeLocked) {
+ canLobotomize = this.getVillagerXp() != 0;
+ }
+ this.isLobotomized = canLobotomize && !canTravelFrom(BlockPos.containing(this.position().x, this.getBoundingBox().minY + 0.0625D, this.position().z));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline the canLobotomize check into the this.isLobotomized = ... line.

this.isLobotomized = (shouldCheckForTradeLocked && this.getVillagerXp() != 0) && ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

condensed the logic, yours was a bit off when I double checked it. here's a truth table I used to check my work:

C = only lobotomize traded with
X = has no xp
E = existing lobotomize condition

F = is lobotomized


(C -> !X) ^ E

(!C v !X) ^ E

!(C ^ X) ^ E


C  X  E    F
0  0  0    0    !(0 ^ 0) ^ 0  0
0  0  1    1    !(0 ^ 0) ^ 1  1
0  1  0    0    !(0 ^ 1) ^ 0  0
0  1  1    1    !(0 ^ 1) ^ 1  1
1  0  0    0    !(1 ^ 0) ^ 0  0
1  0  1    1    !(1 ^ 0) ^ 1  1
1  1  0    0    !(1 ^ 1) ^ 0  0
1  1  1    0    !(1 ^ 1) ^ 1  0


if (this.isLobotomized) {
this.notLobotomizedCount = 0;
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
index bbf371428e343cfad0ae118c387fd2342541fe53..6f921269ab3563618cc4ce780b6e047a16b85a0a 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
@@ -2900,6 +2900,7 @@ public class PurpurWorldConfig {
public int villagerMinimumDemand = 0;
public boolean villagerLobotomizeEnabled = false;
public int villagerLobotomizeCheckInterval = 100;
+ public boolean villagerLobotomizeWaitUntilTradeLocked = false;
public boolean villagerDisplayTradeItem = true;
public int villagerSpawnIronGolemRadius = 0;
public int villagerSpawnIronGolemLimit = 0;
@@ -2935,6 +2936,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);
villagerSpawnIronGolemRadius = getInt("mobs.villager.spawn-iron-golem.radius", villagerSpawnIronGolemRadius);
villagerSpawnIronGolemLimit = getInt("mobs.villager.spawn-iron-golem.limit", villagerSpawnIronGolemLimit);