Yatopia/patches/server/0032-Optimize-Villagers.patch
Simon Gardling e01705826c
Upstream (#484)
* Updated Upstream and Sidestream(s) (Paper/Purpur/Empirecraft)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Paper Changes:
2a67a9e51 Fix missing CraftMetaBook#toBuilder override
48aa06106 Add more Wandering Trader API (#5020)
8cec462a5 [CI-SKIP] Remove Astei from the MIT list (#5577)
21fbc3196 [CI-SKIP] Add Other textarea to issue templates (#5562)
453e983e4 fix isProxyOnlineMode coverage, don't lookup UUIDs in offline mode (Fixes #2011)
81cc4f928 Send empty commands if tab completion is disabled (Closes #5519)
9ed3e470d Keep moveToWorld with old method signature
99a66a583 [Auto] Updated Upstream (CraftBukkit)
976c6d425 [CI-SKIP] [Auto] Rebuild Patches
51deec726 Drop unneeded portal patch (#5566)
07a18c457 [Auto] Updated Upstream (CraftBukkit)
6733d7875 [Auto] Updated Upstream (Bukkit)
9958447cb [Auto] Updated Upstream (Bukkit)
840e72091 [CI-SKIP] [Auto] Rebuild Patches
a33232d4a Add beacon activation and deactivation events (#5121)

Purpur Changes:
ebc0765 Updated Upstream (Paper)
5bc5dfd Fix #318 - Stonecutter does not damage when sneaking
8366582 Resolve #286 - Add config and API for item immunity to lightning
a86555b Updated Upstream (Paper)
8b2607c Config for only sending advancements to affected players (#312)
7ee3393 Add config for the piston push limit (#311)
a30e5ac Add config for void damage dealt
786382b Updated Upstream (Paper)
60d8411 [ci-skip] fix patch name
b64f536 Config for changing the blocks that turn into paths (#303)
1d3f710 Updated Upstream (Paper)
3af86ad Oopsie
4b0342a Gamemode extra permissions
17c8573 [CI-SKIP] Don't pass ping to demo command output
c3481c0 Initialize the credits command output in config
a176fe6 Add credits command

Empirecraft Changes:
b2879a24 Updated Paper

* Updated Upstream and Sidestream(s) (Paper/Tuinity/Airplane/Purpur/Empirecraft)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Paper Changes:
b3cc88799 Add the ability to clear entities from block storage (#5598)
f50171f3b Add missing rarity method on ItemStack (#5594)
aeb6e7dd2 Updated Upstream (Bukkit/CraftBukkit/Spigot) (#5601)
b0a4f353b fix cancelling block falling causing client desync (fixes #5386) (#5419)
8ed45920c Don't annotate type parameters using JetBrains annotations (#5600)
d7625d926 Add new methods from PlayerMoveEvent to EntityMoveEvent (#5591)
29785297b Allow for Component suggestion tooltips in AsyncTabCompleteEvent (#5504)
0aea6c2ff Use JsonSerializationContext#serialize instead of recursion for AdventureComponents - fixes #5580 and #5371
8fcef3c1f Return after sending empty commands (#5586)

Tuinity Changes:
3350246 Updated Upstream (Paper)
f773caf Fix rare ticket level recursion crash
0fa8a0e Starlight Handle concurrent chunk generation and lighting better

Airplane Changes:
fad74c2 Fix JB annotations for gradle (credit jpenilla)
d02f034 Updated Upstream (Tuinity)

Purpur Changes:
adfe5d3 Updated Upstream (Paper)
7a728f8 Fix #325 - Fix SPIGOT-6278
f5c3dae Updated Upstream (Paper)
a80e5b6 Dont create item meta when checking if meta properties exist
90339c5 Add missing netherite from Material#isArmor
bedac18 Updated Upstream (Paper, Tuinity, & Airplane)
3b1531a [ci-skip] Add wrapper validation step to actions
73ab4e6 Update the "changing the blocks that turn into paths" defaults to reflect the vanilla defaults. (#322)
a24b31b Updated Upstream (Paper)

Empirecraft Changes:
87ceb204 Updated Paper
a3497a7e Fix some patches
2ed9e7fa Updated Paper
d5a47a3d Updated Paper

* Updated Upstream and Sidestream(s) (Tuinity)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Tuinity Changes:
1382473 Null check chunk in block changes for Starlight
2021-05-10 23:16:50 -04:00

117 lines
6.3 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ivan Pekov <ivan@mrivanplays.com>
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.
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorFindPosition.java b/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorFindPosition.java
index 09133c5822bc1386bc3d8a5f3c94196420bbfaea..5397a74e244e9cd6886068e0dfe283ec12ccd922 100644
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorFindPosition.java
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorFindPosition.java
@@ -58,7 +58,7 @@ public class BehaviorFindPosition extends Behavior<EntityCreature> {
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;
@@ -66,7 +66,7 @@ public class BehaviorFindPosition extends Behavior<EntityCreature> {
}
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
if (entitycreature.getNavigation().isStuck()) this.f += 200L; // Airplane - wait an additional 10s to check again if they're stuck
VillagePlace villageplace = worldserver.y();
@@ -77,12 +77,20 @@ public class BehaviorFindPosition extends Behavior<EntityCreature> {
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 {
- behaviorfindposition_a.a(i);
- return true;
+ // 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
}
};
// Tuinity start - optimise POI access
@@ -113,7 +121,7 @@ public class BehaviorFindPosition extends Behavior<EntityCreature> {
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/world/entity/ai/village/poi/VillagePlaceType.java b/src/main/java/net/minecraft/world/entity/ai/village/poi/VillagePlaceType.java
index 6a45ab049a4beeeaf7b3b5acf2946767f6e1198f..4af526ecbed506161cb021ea320b0f21112d7bf0 100644
--- a/src/main/java/net/minecraft/world/entity/ai/village/poi/VillagePlaceType.java
+++ b/src/main/java/net/minecraft/world/entity/ai/village/poi/VillagePlaceType.java
@@ -23,11 +23,20 @@ import net.minecraft.world.level.block.state.properties.BlockPropertyBedPart;
public class VillagePlaceType {
+ public static Set<VillagePlaceType> professionCache; // Yatopia
private static final Supplier<Set<VillagePlaceType>> y = Suppliers.memoize(() -> {
return (Set) IRegistry.VILLAGER_PROFESSION.g().map(VillagerProfession::b).collect(Collectors.toSet());
});
public static final Predicate<VillagePlaceType> 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<VillagePlaceType> b = (villageplacetype) -> {
return true;
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 dd9b678481620856fb7eaaa04c3b812c861e892a..d8fc1795b07945b41bd7368529db92fe5cdc4c19 100644
--- a/src/main/java/net/minecraft/world/entity/npc/VillagerProfession.java
+++ b/src/main/java/net/minecraft/world/entity/npc/VillagerProfession.java
@@ -44,6 +44,7 @@ public class VillagerProfession {
this.t = soundeffect;
}
+ public final VillagePlaceType getPlaceType() { return b(); } // Yatopia - OBFHELPER
public VillagePlaceType b() {
return this.q;
}
@@ -70,6 +71,7 @@ public class VillagerProfession {
}
static VillagerProfession a(String s, VillagePlaceType villageplacetype, ImmutableSet<Item> immutableset, ImmutableSet<Block> 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)));
}
}