From 21db6007119ee8d65aa3cd295143070bfe7a0f53 Mon Sep 17 00:00:00 2001 From: Ivan Pekov Date: Sun, 13 Sep 2020 08:22:23 +0300 Subject: [PATCH] Villager stuff Fixes #152 There is still the issue with doors which I will try to fix later on, but the new option should make them more "vanilla". See the description of the new patch for more information. --- .gitignore | 2 +- PATCHES.md | 2 +- .../server/0030-Optimize-Villagers.patch | 0 .../server/0001-Yatopia-Server-Fixes.patch | 53 ++++- ...ck-distance-in-portal-search-radius.patch} | 12 ++ ... => 0031-Add-timings-for-Pathfinder.patch} | 0 ... 0032-Send-more-packets-immediately.patch} | 0 ...033-Use-offline-uuids-if-we-need-to.patch} | 0 ...034-lithium-collision-optimizations.patch} | 0 ...ch => 0035-lithium-VoxelShapesMixin.patch} | 0 ...h => 0036-lithium-MixinChunkSection.patch} | 0 ...rash.patch => 0037-Fix-recipe-crash.patch} | 0 ...he-chunk-that-you-re-teleporting-to.patch} | 0 ...hly-optimize-VillagePlace-filtering.patch} | 22 +- ...0040-Nuke-streams-off-BlockPosition.patch} | 0 ...41-Nuke-streams-off-SectionPosition.patch} | 0 ...p-wasting-resources-on-JsonList-get.patch} | 0 ...patch => 0043-ProxyForwardDataEvent.patch} | 0 ...ns-when-constructing-InventoryEnder.patch} | 0 ...0045-Fix-Unable-to-save-chunk-error.patch} | 0 ...atch => 0046-Give-them-items-motion.patch} | 0 ...Fix-LightEngineThreaded-memory-leak.patch} | 0 ...espect-PlayerKickEvent-leaveMessage.patch} | 0 ...0049-Shutdown-Bootstrap-thread-pool.patch} | 0 patches/server/0050-Optimize-Villagers.patch | 188 ++++++++++++++++++ 25 files changed, 271 insertions(+), 8 deletions(-) rename patches/{ => removed}/server/0030-Optimize-Villagers.patch (100%) rename patches/server/{0031-Use-block-distance-in-portal-search-radius.patch => 0030-Use-block-distance-in-portal-search-radius.patch} (82%) rename patches/server/{0032-Add-timings-for-Pathfinder.patch => 0031-Add-timings-for-Pathfinder.patch} (100%) rename patches/server/{0033-Send-more-packets-immediately.patch => 0032-Send-more-packets-immediately.patch} (100%) rename patches/server/{0034-Use-offline-uuids-if-we-need-to.patch => 0033-Use-offline-uuids-if-we-need-to.patch} (100%) rename patches/server/{0035-lithium-collision-optimizations.patch => 0034-lithium-collision-optimizations.patch} (100%) rename patches/server/{0036-lithium-VoxelShapesMixin.patch => 0035-lithium-VoxelShapesMixin.patch} (100%) rename patches/server/{0037-lithium-MixinChunkSection.patch => 0036-lithium-MixinChunkSection.patch} (100%) rename patches/server/{0038-Fix-recipe-crash.patch => 0037-Fix-recipe-crash.patch} (100%) rename patches/server/{0039-Load-also-the-chunk-that-you-re-teleporting-to.patch => 0038-Load-also-the-chunk-that-you-re-teleporting-to.patch} (100%) rename patches/server/{0040-Highly-optimize-VillagePlace-filtering.patch => 0039-Highly-optimize-VillagePlace-filtering.patch} (95%) rename patches/server/{0041-Nuke-streams-off-BlockPosition.patch => 0040-Nuke-streams-off-BlockPosition.patch} (100%) rename patches/server/{0042-Nuke-streams-off-SectionPosition.patch => 0041-Nuke-streams-off-SectionPosition.patch} (100%) rename patches/server/{0043-Stop-wasting-resources-on-JsonList-get.patch => 0042-Stop-wasting-resources-on-JsonList-get.patch} (100%) rename patches/server/{0044-ProxyForwardDataEvent.patch => 0043-ProxyForwardDataEvent.patch} (100%) rename patches/server/{0045-Respect-permissions-when-constructing-InventoryEnder.patch => 0044-Respect-permissions-when-constructing-InventoryEnder.patch} (100%) rename patches/server/{0046-Fix-Unable-to-save-chunk-error.patch => 0045-Fix-Unable-to-save-chunk-error.patch} (100%) rename patches/server/{0047-Give-them-items-motion.patch => 0046-Give-them-items-motion.patch} (100%) rename patches/server/{0048-Fix-LightEngineThreaded-memory-leak.patch => 0047-Fix-LightEngineThreaded-memory-leak.patch} (100%) rename patches/server/{0049-Respect-PlayerKickEvent-leaveMessage.patch => 0048-Respect-PlayerKickEvent-leaveMessage.patch} (100%) rename patches/server/{0050-Shutdown-Bootstrap-thread-pool.patch => 0049-Shutdown-Bootstrap-thread-pool.patch} (100%) create mode 100644 patches/server/0050-Optimize-Villagers.patch diff --git a/.gitignore b/.gitignore index f56f3f71..097d0505 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,4 @@ target/site/surefire-report.html !/patches/Rainforest/api.txt !/patches/Origami/server.txt !/patches/Origami/api.txt -yatopia-1.16.2-paperclip.jar +yatopia-1.16.3-paperclip.jar diff --git a/PATCHES.md b/PATCHES.md index c9d28260..04ddbf31 100644 --- a/PATCHES.md +++ b/PATCHES.md @@ -81,7 +81,7 @@ # Patches | server | Nuke streams off SectionPosition | Ivan Pekov | | | server | Optimize BehaviorController | MrIvanPlays | | | server | Optimize TileEntity load/unload | tr7zw | | -| server | Optimize Villagers | Aikar | MrIvanPlays | +| server | Optimize Villagers | Ivan Pekov | | | server | Optimize inventory API item handling | Phoenix616 | | | server | Optimize player loops around weather | MrIvanPlays | | | server | Option for simpler Villagers | tr7zw | | diff --git a/patches/server/0030-Optimize-Villagers.patch b/patches/removed/server/0030-Optimize-Villagers.patch similarity index 100% rename from patches/server/0030-Optimize-Villagers.patch rename to patches/removed/server/0030-Optimize-Villagers.patch diff --git a/patches/server/0001-Yatopia-Server-Fixes.patch b/patches/server/0001-Yatopia-Server-Fixes.patch index 20516f11..3b816b13 100644 --- a/patches/server/0001-Yatopia-Server-Fixes.patch +++ b/patches/server/0001-Yatopia-Server-Fixes.patch @@ -159,6 +159,18 @@ index 02f5ccf54210776770d3215afb7c8e82f750d57e..00000000000000000000000000000000 - public int pigmenPortalSpawn = 2000; - public double pigmenPortalBoost = 0.0; - public boolean pigmenFarmsWaterAi = false; +diff --git a/src/main/java/net/minecraft/server/BaseBlockPosition.java b/src/main/java/net/minecraft/server/BaseBlockPosition.java +index e811295b4d6afcd920f60e0ce5440e43300d9085..d1064bd1c76eb23ce12e4a0703ce9f2622952897 100644 +--- a/src/main/java/net/minecraft/server/BaseBlockPosition.java ++++ b/src/main/java/net/minecraft/server/BaseBlockPosition.java +@@ -111,6 +111,7 @@ public class BaseBlockPosition implements Comparable { + return this.distanceSquared((double) baseblockposition.getX(), (double) baseblockposition.getY(), (double) baseblockposition.getZ(), false) < d0 * d0; + } + ++ public final boolean distanceSquared(IPosition pos, double dist) { return a(pos, dist); } // Yatopia - OBFHELPER + public boolean a(IPosition iposition, double d0) { + return this.distanceSquared(iposition.getX(), iposition.getY(), iposition.getZ(), true) < d0 * d0; + } diff --git a/src/main/java/net/minecraft/server/Behavior.java b/src/main/java/net/minecraft/server/Behavior.java index 0490f6bb798b94ce69a40f8a940caaa545c4a3c0..65cbe8ea9551ee804ca35a594680e845eebbacac 100644 --- a/src/main/java/net/minecraft/server/Behavior.java @@ -207,7 +219,7 @@ index c3d129452b4f6ff2069bc066e594b1c632ceb0d4..00000000000000000000000000000000 - - public Behavior.Status a() { diff --git a/src/main/java/net/minecraft/server/BehaviorInteractDoor.java b/src/main/java/net/minecraft/server/BehaviorInteractDoor.java -index 685351f11497a33ef4ba99055fa7da3a8de18af2..5c19047bbc464869a6d65ef02e7955eabac92809 100644 +index 685351f11497a33ef4ba99055fa7da3a8de18af2..31f9001142ff8507499098f7da013b2b61d6847b 100644 --- a/src/main/java/net/minecraft/server/BehaviorInteractDoor.java +++ b/src/main/java/net/minecraft/server/BehaviorInteractDoor.java @@ -127,6 +127,17 @@ public class BehaviorInteractDoor extends Behavior { @@ -218,7 +230,7 @@ index 685351f11497a33ef4ba99055fa7da3a8de18af2..5c19047bbc464869a6d65ef02e7955ea + if (!behaviorcontroller.hasMemory(MemoryModuleType.MOBS)) return false; + for (EntityLiving entity : behaviorcontroller.getMemory(MemoryModuleType.MOBS).get()) { + if (entity.getEntityType() == entityliving.getEntityType() -+ && blockposition.a(entity.getPositionVector(), 2.0D) ++ && blockposition.distanceSquared(entity.getPositionVector(), 2.0D) + && b(worldserver, entity, blockposition)) { + return true; + } @@ -3083,6 +3095,43 @@ index bae899f354afe1819c7850f30d827a33696b00fa..74aa903d3c362351f688979daa0c4f41 + } + // Purpur end } +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java.rej b/src/main/java/org/bukkit/craftbukkit/CraftServer.java.rej +deleted file mode 100644 +index bd0dcb52322f39c6f82864b480c2fece8bd6be3a..0000000000000000000000000000000000000000 +--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java.rej ++++ /dev/null +@@ -1,31 +0,0 @@ +-diff a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java (rejected hunks) +-@@ -854,6 +854,7 @@ public final class CraftServer implements Server { +- +- org.spigotmc.SpigotConfig.init((File) console.options.valueOf("spigot-settings")); // Spigot +- com.destroystokyo.paper.PaperConfig.init((File) console.options.valueOf("paper-settings")); // Paper +-+ com.proximyst.rainforest.RainforestConfig.init((File) console.options.valueOf("rainforest-settings")); // Rainforest +- for (WorldServer world : console.getWorlds()) { +- world.worldDataServer.setDifficulty(config.difficulty); +- world.setSpawnFlags(config.spawnMonsters, config.spawnAnimals); +-@@ -888,6 +889,7 @@ public final class CraftServer implements Server { +- } +- world.spigotConfig.init(); // Spigot +- world.paperConfig.init(); // Paper +-+ world.rainforestConfig.init(); // Rainforest +- } +- +- Plugin[] pluginClone = pluginManager.getPlugins().clone(); // Paper +-@@ -2239,6 +2241,13 @@ public final class CraftServer implements Server { +- return com.destroystokyo.paper.PaperConfig.config; +- } +- +-+ // Rainforest start +-+ @Override +-+ public YamlConfiguration getRainforestConfig() { +-+ return com.proximyst.rainforest.RainforestConfig.config; +-+ } +-+ // Rainforest end +-+ +- @Override +- public void restart() { +- org.spigotmc.RestartCommand.restart(); diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java index 210cb10ea75b99d3b5d7b5bce5cea44e3cc0fc20..1acfbf3a63ee0e8d4bd4773f06b4be1e4961f527 100644 --- a/src/main/java/org/bukkit/craftbukkit/Main.java diff --git a/patches/server/0031-Use-block-distance-in-portal-search-radius.patch b/patches/server/0030-Use-block-distance-in-portal-search-radius.patch similarity index 82% rename from patches/server/0031-Use-block-distance-in-portal-search-radius.patch rename to patches/server/0030-Use-block-distance-in-portal-search-radius.patch index a62c38de..c6ece2a3 100644 --- a/patches/server/0031-Use-block-distance-in-portal-search-radius.patch +++ b/patches/server/0030-Use-block-distance-in-portal-search-radius.patch @@ -47,3 +47,15 @@ index 67018d2abcca8f9dd71fc3a6bfff19c85e8bcef0..d861368550a8811eb442c30c508023f6 Optional optional = Optional.empty(); if (!list.isEmpty()) { list.sort(comparator); +diff --git a/src/main/java/net/minecraft/server/VillagePlaceRecord.java b/src/main/java/net/minecraft/server/VillagePlaceRecord.java +index 0b40c2f4dada7d8432e3f91e9cf206c2bda3b24b..c8c231f3d5e8e495ebb9a27ae18f7665cb263330 100644 +--- a/src/main/java/net/minecraft/server/VillagePlaceRecord.java ++++ b/src/main/java/net/minecraft/server/VillagePlaceRecord.java +@@ -62,6 +62,7 @@ public class VillagePlaceRecord { + return this.c != this.b.b(); + } + ++ public final BlockPosition getPosition() { return f(); } // Yatopia - OBFHELPER + public BlockPosition f() { + return this.a; + } diff --git a/patches/server/0032-Add-timings-for-Pathfinder.patch b/patches/server/0031-Add-timings-for-Pathfinder.patch similarity index 100% rename from patches/server/0032-Add-timings-for-Pathfinder.patch rename to patches/server/0031-Add-timings-for-Pathfinder.patch diff --git a/patches/server/0033-Send-more-packets-immediately.patch b/patches/server/0032-Send-more-packets-immediately.patch similarity index 100% rename from patches/server/0033-Send-more-packets-immediately.patch rename to patches/server/0032-Send-more-packets-immediately.patch diff --git a/patches/server/0034-Use-offline-uuids-if-we-need-to.patch b/patches/server/0033-Use-offline-uuids-if-we-need-to.patch similarity index 100% rename from patches/server/0034-Use-offline-uuids-if-we-need-to.patch rename to patches/server/0033-Use-offline-uuids-if-we-need-to.patch diff --git a/patches/server/0035-lithium-collision-optimizations.patch b/patches/server/0034-lithium-collision-optimizations.patch similarity index 100% rename from patches/server/0035-lithium-collision-optimizations.patch rename to patches/server/0034-lithium-collision-optimizations.patch diff --git a/patches/server/0036-lithium-VoxelShapesMixin.patch b/patches/server/0035-lithium-VoxelShapesMixin.patch similarity index 100% rename from patches/server/0036-lithium-VoxelShapesMixin.patch rename to patches/server/0035-lithium-VoxelShapesMixin.patch diff --git a/patches/server/0037-lithium-MixinChunkSection.patch b/patches/server/0036-lithium-MixinChunkSection.patch similarity index 100% rename from patches/server/0037-lithium-MixinChunkSection.patch rename to patches/server/0036-lithium-MixinChunkSection.patch diff --git a/patches/server/0038-Fix-recipe-crash.patch b/patches/server/0037-Fix-recipe-crash.patch similarity index 100% rename from patches/server/0038-Fix-recipe-crash.patch rename to patches/server/0037-Fix-recipe-crash.patch diff --git a/patches/server/0039-Load-also-the-chunk-that-you-re-teleporting-to.patch b/patches/server/0038-Load-also-the-chunk-that-you-re-teleporting-to.patch similarity index 100% rename from patches/server/0039-Load-also-the-chunk-that-you-re-teleporting-to.patch rename to patches/server/0038-Load-also-the-chunk-that-you-re-teleporting-to.patch diff --git a/patches/server/0040-Highly-optimize-VillagePlace-filtering.patch b/patches/server/0039-Highly-optimize-VillagePlace-filtering.patch similarity index 95% rename from patches/server/0040-Highly-optimize-VillagePlace-filtering.patch rename to patches/server/0039-Highly-optimize-VillagePlace-filtering.patch index c78e41bd..4ee18370 100644 --- a/patches/server/0040-Highly-optimize-VillagePlace-filtering.patch +++ b/patches/server/0039-Highly-optimize-VillagePlace-filtering.patch @@ -106,7 +106,7 @@ index d861368550a8811eb442c30c508023f6029daa4a..e337b62eafafba3dcb5d0bddf16237c7 if (world.origamiConfig.useBlockDistanceInPortalSearchRadius) { list.removeIf(villagePlaceRecord -> { diff --git a/src/main/java/net/minecraft/server/SectionPosition.java b/src/main/java/net/minecraft/server/SectionPosition.java -index cf5b25d9375724ea2afcf5cd59e0ccd302cdf45e..65efa530125e883b8dec3aab5edb1eeac585cb92 100644 +index f95925f1c5d091f1a129d0437bb6e175c6ac080f..6796b1a832779b65d337c63d6b600e2a3b5e9559 100644 --- a/src/main/java/net/minecraft/server/SectionPosition.java +++ b/src/main/java/net/minecraft/server/SectionPosition.java @@ -159,6 +159,7 @@ public class SectionPosition extends BaseBlockPosition { @@ -117,7 +117,12 @@ index cf5b25d9375724ea2afcf5cd59e0ccd302cdf45e..65efa530125e883b8dec3aab5edb1eea public ChunkCoordIntPair r() { return new ChunkCoordIntPair(this.a(), this.c()); } -@@ -178,6 +179,7 @@ public class SectionPosition extends BaseBlockPosition { +@@ -173,10 +174,12 @@ public class SectionPosition extends BaseBlockPosition { + return (((long) i & 4194303L) << 42) | (((long) j & 1048575L)) | (((long) k & 4194303L) << 20); // Paper - Simplify to reduce instruction count + } + ++ public final long asLong() { return s(); } // Yatopia - OBFHELPER + public long s() { return (((long) getX() & 4194303L) << 42) | (((long) getY() & 1048575L)) | (((long) getZ() & 4194303L) << 20); // Paper - Simplify to reduce instruction count } @@ -125,7 +130,7 @@ index cf5b25d9375724ea2afcf5cd59e0ccd302cdf45e..65efa530125e883b8dec3aab5edb1eea public Stream t() { return BlockPosition.a(this.d(), this.e(), this.f(), this.g(), this.h(), this.i()); } -@@ -190,6 +192,18 @@ public class SectionPosition extends BaseBlockPosition { +@@ -189,6 +192,18 @@ public class SectionPosition extends BaseBlockPosition { return a(chunkcoordintpair.x - i, 0, chunkcoordintpair.z - i, chunkcoordintpair.x + i, 15, chunkcoordintpair.z + i); // Paper - simplify/inline } @@ -305,9 +310,18 @@ index 6ab80cf7908437309a7346d71e42cf128a6f13d9..07a36d1955037524715181461cc2aa5d final class a extends LightEngineGraphSection { diff --git a/src/main/java/net/minecraft/server/VillagePlaceSection.java b/src/main/java/net/minecraft/server/VillagePlaceSection.java -index d4018b9b615dae2b9e30517be51322656601b171..0ab4999a829c0125753171fd85c2d2eb6f7ef2bf 100644 +index 77c66bc9952542d2444b402896a3d9f622ca2ff9..b47abdabb592cfff6a4bf9ee638dd72f8a825499 100644 --- a/src/main/java/net/minecraft/server/VillagePlaceSection.java +++ b/src/main/java/net/minecraft/server/VillagePlaceSection.java +@@ -28,7 +28,7 @@ public class VillagePlaceSection { + private boolean e; + + public static Codec a(Runnable runnable) { +- Codec codec = RecordCodecBuilder.create((instance) -> { ++ Codec codec = RecordCodecBuilder.create((instance) -> { // Yatopia - decompile fix + return instance.group(RecordCodecBuilder.point(runnable), Codec.BOOL.optionalFieldOf("Valid", false).forGetter((villageplacesection) -> { + return villageplacesection.e; + }), VillagePlaceRecord.a(runnable).listOf().fieldOf("Records").forGetter((villageplacesection) -> { @@ -55,6 +55,17 @@ public class VillagePlaceSection { list.forEach(this::a); } diff --git a/patches/server/0041-Nuke-streams-off-BlockPosition.patch b/patches/server/0040-Nuke-streams-off-BlockPosition.patch similarity index 100% rename from patches/server/0041-Nuke-streams-off-BlockPosition.patch rename to patches/server/0040-Nuke-streams-off-BlockPosition.patch diff --git a/patches/server/0042-Nuke-streams-off-SectionPosition.patch b/patches/server/0041-Nuke-streams-off-SectionPosition.patch similarity index 100% rename from patches/server/0042-Nuke-streams-off-SectionPosition.patch rename to patches/server/0041-Nuke-streams-off-SectionPosition.patch diff --git a/patches/server/0043-Stop-wasting-resources-on-JsonList-get.patch b/patches/server/0042-Stop-wasting-resources-on-JsonList-get.patch similarity index 100% rename from patches/server/0043-Stop-wasting-resources-on-JsonList-get.patch rename to patches/server/0042-Stop-wasting-resources-on-JsonList-get.patch diff --git a/patches/server/0044-ProxyForwardDataEvent.patch b/patches/server/0043-ProxyForwardDataEvent.patch similarity index 100% rename from patches/server/0044-ProxyForwardDataEvent.patch rename to patches/server/0043-ProxyForwardDataEvent.patch diff --git a/patches/server/0045-Respect-permissions-when-constructing-InventoryEnder.patch b/patches/server/0044-Respect-permissions-when-constructing-InventoryEnder.patch similarity index 100% rename from patches/server/0045-Respect-permissions-when-constructing-InventoryEnder.patch rename to patches/server/0044-Respect-permissions-when-constructing-InventoryEnder.patch diff --git a/patches/server/0046-Fix-Unable-to-save-chunk-error.patch b/patches/server/0045-Fix-Unable-to-save-chunk-error.patch similarity index 100% rename from patches/server/0046-Fix-Unable-to-save-chunk-error.patch rename to patches/server/0045-Fix-Unable-to-save-chunk-error.patch diff --git a/patches/server/0047-Give-them-items-motion.patch b/patches/server/0046-Give-them-items-motion.patch similarity index 100% rename from patches/server/0047-Give-them-items-motion.patch rename to patches/server/0046-Give-them-items-motion.patch diff --git a/patches/server/0048-Fix-LightEngineThreaded-memory-leak.patch b/patches/server/0047-Fix-LightEngineThreaded-memory-leak.patch similarity index 100% rename from patches/server/0048-Fix-LightEngineThreaded-memory-leak.patch rename to patches/server/0047-Fix-LightEngineThreaded-memory-leak.patch diff --git a/patches/server/0049-Respect-PlayerKickEvent-leaveMessage.patch b/patches/server/0048-Respect-PlayerKickEvent-leaveMessage.patch similarity index 100% rename from patches/server/0049-Respect-PlayerKickEvent-leaveMessage.patch rename to patches/server/0048-Respect-PlayerKickEvent-leaveMessage.patch diff --git a/patches/server/0050-Shutdown-Bootstrap-thread-pool.patch b/patches/server/0049-Shutdown-Bootstrap-thread-pool.patch similarity index 100% rename from patches/server/0050-Shutdown-Bootstrap-thread-pool.patch rename to patches/server/0049-Shutdown-Bootstrap-thread-pool.patch diff --git a/patches/server/0050-Optimize-Villagers.patch b/patches/server/0050-Optimize-Villagers.patch new file mode 100644 index 00000000..7df25aee --- /dev/null +++ b/patches/server/0050-Optimize-Villagers.patch @@ -0,0 +1,188 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Ivan Pekov +Date: Sat, 12 Sep 2020 19:17:05 +0300 +Subject: [PATCH] Optimize Villagers + +These changes aim to fix the following: +- Villagers trying to push farther POIs (Points Of Interest) +- Villagers ignoring doors most of the times +- Villagers pushing POIs (Points Of Interest) to unloaded chunks + +The following has been done to fix the mentioned problems: +- Replaced stream off BehaviorFindPosition +- Made sure that chunks are loaded for the POIs (Points Of Interest) that are gonna be tried. +- Added a profession cache, which followed by a stream removal. +- Added a config option, villagers-only-open-doors-if-attacked-by-mobs , the default of is "true", defaulting to + vanilla behavior. If the specified option is false, then if the villager is not going to a path, he will try + to go to the nearest door. + +diff --git a/src/main/java/de/minebench/origami/OrigamiConfig.java b/src/main/java/de/minebench/origami/OrigamiConfig.java +index 9549b857020bb749c039420950684c74c1108945..d3fd3c41092dbd80f9ae774f57bca0716d71cd95 100644 +--- a/src/main/java/de/minebench/origami/OrigamiConfig.java ++++ b/src/main/java/de/minebench/origami/OrigamiConfig.java +@@ -170,6 +170,11 @@ public final class OrigamiConfig { + private void useBlockDistanceInPortalSearchRadius() { + useBlockDistanceInPortalSearchRadius = getBoolean("use-block-distance-in-portal-search-radius", false); + } ++ ++ public boolean villagersOnlyOpenDoorsIfAttackedByMobs = true; ++ private void villagersOnlyOpenDoorsIfAttackedByMobs() { ++ villagersOnlyOpenDoorsIfAttackedByMobs = getBoolean("villagers-only-open-doors-if-attacked-by-mobs", true); ++ } + // Yatopia end + } + +diff --git a/src/main/java/net/minecraft/server/BehaviorFindPosition.java b/src/main/java/net/minecraft/server/BehaviorFindPosition.java +index 63a761ebef80d4af09cdc2682e496d78492c4a3a..047910f441b5e8ad97024177afbac703a0d0c5e9 100644 +--- a/src/main/java/net/minecraft/server/BehaviorFindPosition.java ++++ b/src/main/java/net/minecraft/server/BehaviorFindPosition.java +@@ -48,7 +48,7 @@ public class BehaviorFindPosition extends Behavior { + if (this.d && entitycreature.isBaby()) { + return false; + } else if (this.f == 0L) { +- this.f = entitycreature.world.getTime() + (long) worldserver.random.nextInt(20); ++ this.f = entitycreature.world.getTime() + (long) java.util.concurrent.ThreadLocalRandom.current().nextInt(20); // Yatopia + return false; + } else { + return worldserver.getTime() >= this.f; +@@ -56,7 +56,7 @@ public class BehaviorFindPosition extends Behavior { + } + + protected void a(WorldServer worldserver, EntityCreature entitycreature, long i) { +- this.f = i + 20L + (long) worldserver.getRandom().nextInt(20); ++ this.f = i + 20L + (long) java.util.concurrent.ThreadLocalRandom.current().nextInt(20); // Yatopia + VillagePlace villageplace = worldserver.y(); + + this.g.long2ObjectEntrySet().removeIf((entry) -> { +@@ -66,15 +66,32 @@ public class BehaviorFindPosition extends Behavior { + BehaviorFindPosition.a behaviorfindposition_a = (BehaviorFindPosition.a) this.g.get(blockposition.asLong()); + + if (behaviorfindposition_a == null) { +- return true; ++ return worldserver.getChunkIfLoaded(blockposition.getX() >> 4, blockposition.getZ() >> 4) != null; // Yatopia + } else if (!behaviorfindposition_a.c(i)) { + return false; + } else { ++ // Yatopia start - make sure chunks are loaded ++ int chunkX = blockposition.getX() >> 4; ++ int chunkZ = blockposition.getZ() >> 4; ++ if (worldserver.getChunkIfLoaded(chunkX, chunkZ) != null) { + behaviorfindposition_a.a(i); + return true; ++ } else { ++ return false; ++ } ++ // Yatopia end + } + }; +- Set set = (Set) villageplace.b(this.b.c(), predicate, entitycreature.getChunkCoordinates(), 48, VillagePlace.Occupancy.HAS_SPACE).limit(5L).collect(Collectors.toSet()); ++ // Yatopia start - replace stream ++ //Set set = (Set) villageplace.b(this.b.c(), predicate, entitycreature.getChunkCoordinates(), 48, VillagePlace.Occupancy.HAS_SPACE).limit(5L).collect(Collectors.toSet()); ++ Set set = new java.util.HashSet<>(); ++ int limit = 5; ++ for (BlockPosition pos : villageplace.bList(this.b.getCompletionCondition(), predicate, entitycreature.getChunkCoordinates(), 48, VillagePlace.Occupancy.HAS_SPACE)) { ++ set.add(pos); ++ limit--; ++ if (limit == 0) break; ++ } ++ // Yatopia end + PathEntity pathentity = entitycreature.getNavigation().a(set, this.b.d()); + + if (pathentity != null && pathentity.j()) { +@@ -84,7 +101,7 @@ public class BehaviorFindPosition extends Behavior { + villageplace.a(this.b.c(), (blockposition1) -> { + return blockposition1.equals(blockposition); + }, blockposition, 1); +- entitycreature.getBehaviorController().setMemory(this.c, (Object) GlobalPos.create(worldserver.getDimensionKey(), blockposition)); ++ entitycreature.getBehaviorController().setMemory(this.c, GlobalPos.create(worldserver.getDimensionKey(), blockposition)); // Yatopia - decompile fix + this.e.ifPresent((obyte) -> { + worldserver.broadcastEntityEffect(entitycreature, obyte); + }); +@@ -98,7 +115,7 @@ public class BehaviorFindPosition extends Behavior { + BlockPosition blockposition1 = (BlockPosition) iterator.next(); + + this.g.computeIfAbsent(blockposition1.asLong(), (j) -> { +- return new BehaviorFindPosition.a(entitycreature.world.random, i); ++ return new BehaviorFindPosition.a(java.util.concurrent.ThreadLocalRandom.current(), i); // Yatopia + }); + } + } +diff --git a/src/main/java/net/minecraft/server/BehaviorInteractDoor.java b/src/main/java/net/minecraft/server/BehaviorInteractDoor.java +index 31f9001142ff8507499098f7da013b2b61d6847b..eb1df4046a81a011901d2763b51f2b5885e2095f 100644 +--- a/src/main/java/net/minecraft/server/BehaviorInteractDoor.java ++++ b/src/main/java/net/minecraft/server/BehaviorInteractDoor.java +@@ -128,6 +128,12 @@ public class BehaviorInteractDoor extends Behavior { + BehaviorController behaviorcontroller = entityliving.getBehaviorController(); + + // Yatopia start - replaced logic ++ if (!worldserver.origamiConfig.villagersOnlyOpenDoorsIfAttackedByMobs) { ++ if (b(worldserver, entityliving, blockposition)) { ++ return false; ++ } ++ return blockposition.distanceSquared(entityliving.getPositionVector(), 2.0D); ++ } else { + if (!behaviorcontroller.hasMemory(MemoryModuleType.MOBS)) return false; + for (EntityLiving entity : behaviorcontroller.getMemory(MemoryModuleType.MOBS).get()) { + if (entity.getEntityType() == entityliving.getEntityType() +@@ -137,6 +143,7 @@ public class BehaviorInteractDoor extends Behavior { + } + } + return false; ++ } + /* + return !behaviorcontroller.hasMemory(MemoryModuleType.MOBS) ? false : (behaviorcontroller.getMemory(MemoryModuleType.MOBS).get()).stream().filter((entityliving1) -> { // CraftBukkit - decompile error + return entityliving1.getEntityType() == entityliving.getEntityType(); +diff --git a/src/main/java/net/minecraft/server/VillagePlaceType.java b/src/main/java/net/minecraft/server/VillagePlaceType.java +index a5718af9b614ae505067131f04ebb490617d6aa4..2ea0cfad4b35264cd3b70b930dd28de58c77d0c0 100644 +--- a/src/main/java/net/minecraft/server/VillagePlaceType.java ++++ b/src/main/java/net/minecraft/server/VillagePlaceType.java +@@ -14,11 +14,20 @@ import java.util.stream.Collectors; + + public class VillagePlaceType { + ++ static Set professionCache; // Yatopia + private static final Supplier> y = Suppliers.memoize(() -> { + return (Set) IRegistry.VILLAGER_PROFESSION.g().map(VillagerProfession::b).collect(Collectors.toSet()); + }); + public static final Predicate a = (villageplacetype) -> { +- return ((Set) VillagePlaceType.y.get()).contains(villageplacetype); ++ // Yatopia start ++ if (professionCache == null) { ++ professionCache = new java.util.HashSet<>(); ++ for (VillagerProfession profession : IRegistry.VILLAGER_PROFESSION) { ++ professionCache.add(profession.getPlaceType()); ++ } ++ } ++ return professionCache.contains(villageplacetype); ++ // Yatopia end + }; + public static final Predicate b = (villageplacetype) -> { + return true; +@@ -83,6 +92,7 @@ public class VillagePlaceType { + return this.D; + } + ++ public final Predicate getCompletionCondition() { return c(); } // Yatopia - OBFHELPER + public Predicate c() { + return this.E; + } +diff --git a/src/main/java/net/minecraft/server/VillagerProfession.java b/src/main/java/net/minecraft/server/VillagerProfession.java +index 3c60da7ac6faebe9d964e893974e42613c59b4c1..1b012914cb3fcbc4bb456195ade96668b6742cfd 100644 +--- a/src/main/java/net/minecraft/server/VillagerProfession.java ++++ b/src/main/java/net/minecraft/server/VillagerProfession.java +@@ -35,6 +35,7 @@ public class VillagerProfession { + this.t = soundeffect; + } + ++ public final VillagePlaceType getPlaceType() { return b(); } // Yatopia - OBFHELPER + public VillagePlaceType b() { + return this.q; + } +@@ -61,6 +62,7 @@ public class VillagerProfession { + } + + static VillagerProfession a(String s, VillagePlaceType villageplacetype, ImmutableSet immutableset, ImmutableSet immutableset1, @Nullable SoundEffect soundeffect) { ++ VillagePlaceType.professionCache = null; // Yatopia + return (VillagerProfession) IRegistry.a((IRegistry) IRegistry.VILLAGER_PROFESSION, new MinecraftKey(s), (Object) (new VillagerProfession(s, villageplacetype, immutableset, immutableset1, soundeffect))); + } + }