Yatopia/patches/server/0027-Highly-optimize-VillagePlace-filtering.patch
Simon Gardling ac524e348f
Updated Upstream and Sidestream(s) (Paper/Tuinity/Airplane/Purpur/Empirecraft) (#443)
* 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:
0641de2d4 [CI-SKIP] Change some fields to textara (#5405)
98a34ea47 [CI-SKIP] 🚀 Upgrade to new form-based templates (#5278)
bca97a8f7 replace spaces in world key (touches #5397)
de94f6485 Refactor chat message composition (#5396)
e27f334bb [CI-SKIP] Fix makemcdevsrc.sh for nms relocations (#5389)
ae15e85da Updated Upstream (CraftBukkit)
26fe0ac5a Only set despawnTimer for Wandering Traders spawned by MobSpawnerTrader (#5391)
b748eb7b8 Fix VanillaMobGoalTest#testBukkitMap (#5390)
18dbbb578 [Auto] Updated Upstream (CraftBukkit)
fac9cc5d5 [CI-SKIP] Ignore .gitignore
087aa70e7 Deprecate ItemStack#setLore(List<String>) and ItemStack#getLore, add Component based alternatives
9889c651c apply fixup
c310f0a61 Updated Upstream (Bukkit/CraftBukkit)
f17560ab0 wtf is this t file -jmp
347f3a9b8 fix compile
700e9e6a5 rebase
cf4dc464a Revert de5f4e469...c270abe96
6870db613 script & POM fix
743c6533c Replace ** with * (BSD/macOS)
376d7b097 Don't remove the .java
fcb3fd42a Fix macOS/BSD support
8cfc05249 Link correctly
ba1031ca7 Rename work dir
c8d844ab7 Actually fix preloading this time
e62aa5e3e Fix class preloading
1c03cf898 It's mojang math, not minecraft math
1034873df Apply fixups
39b125771 Use revision file
956150da7 Welcome to 1.16.5-R0.2
ccb217c01 Change cache keys
0d217001c more work
f6d820f07 It compiles
0f78e9525 More work
1718f61bf Updated Upstream (CraftBukkit/Spigot)
b28d46114 Update scripts for NMS repackaging
d4532f7e7 bug #5373 - fix AsyncChatEvent not being posted when processing a legacy APCE continuation
522ae1c51 Replace all block states of a specified block (#5055)
1cda67118 [Auto] Updated Upstream (CraftBukkit)
8c74d3126 Updated Upstream (Bukkit) (#5359)
fd3c66a91 bug #5362 - correctly pass "render type" when registering a new scoreboard objective

Tuinity Changes:
9bdcb9b Delete work dir when running jar
6351d7c Updated Upstream (Paper)
932c199 Generate mc-dev correctly
bf3e737 Make packet limiter work from IDE
1686f38 Fix packet limiter config
f40f7b4 Update README.md styling (#264)
da1c3ac GH Actions Changes (#213)
5f325ec Updated Upstream (Paper)
0f83fe4 Updated Upstream (Paper)
44e8e5d Do not load extra radius of chunks when loading a single chunk
31f9cae Revert custom table implementation for blockstate states
9ac33d1 Be aware of entity teleports when chunk checking entities
18c7f3f Always set impulse for projectiles to true, even if hit event failed

Airplane Changes:
f94d399 Merge pull request #18 from notOM3GA/upstream/nms-repackage
0fc6226 Force build for Flare update
08439d6 Updated Upstream (Tuinity)
0f80443 Updated Upstream (Tuinity)
2f6cbdc More debug for plugins not shutting down tasks
12e1b61 Updated Upstream (Tuinity)
fc778d3 Update README.md
db6b0eb Merge pull request #16 from DeadSteve51/patch-2
b23bee3 Remove debug
8157e98 Config style, flare style, disable tracker by def
98d0b58 Updates to README

Purpur Changes:
75b07a0 Fix stack overflow on armorstand movement
f754a7b Sneak to bulk process composter
1362f49 Updated Upstream (Paper, Tuinity, & Airplane)
5bf8615 [ci-skip] Conflict on change for adventure deprecations
114b37b Add purpur.yml to Flare (#204)
c6dce38 forgot the crops
c004236 Configurable ravager griefable blocks list
766246a [ci-skip] remove duplicate patch
ac93477 Config to make Creepers explode on death (#201)
297181e Updated Upstream (Paper, Tuinity, & Airplane)
45b9a18 Config to disable Llama caravans (#203)
a99a83b Allow fully disabling farmland trampling
3aa4f68 Tick fluids config
0e34d59 Add missing imports :/
3dd9f46 Updated Upstream (Paper, Tuinity, & Airplane)

Empirecraft Changes:
1b579407 Improve importmcdev script and fix first server patch
f597a82e Update generatesources script
218f5298 Fix patches - imported files
847cf558 Updated Paper
d51410c3 Updated Paper
fb3301fd Fix bow entity ai speed/distance
dbde1dc4 Add isJoined boolean to fake players
a23317f7 Update Fake Player API - misc changes
a970b77f Updated Paper

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

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:
7259c32ba [CI-SKIP] [Auto] Rebuild Patches
0e06e912e Fix annotations so Inventory#getContents returns non-null array with nullable type (#5350)
b90b4f8ad Properly apply Sign#isEditable to TEs when calling BlockState#update

Airplane Changes:
87d4a17 Track queue debug command

Purpur Changes:
d44f93e Fix tpsbar with naughty plugins

* Updated Upstream and Sidestream(s) (Purpur)

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.

Purpur Changes:
99f1ce6 Add enchantment target for bows and crossbows
af9181e Add configurable drowning settings (closes #221) (#222)
f72437b Remove mcdevimports.* (#228)
08de42d Add config for infinity on crossbows (#215)
5f76cb3 Add a config for villager trading (#210)
67ffa05 Add config for disabling skipping the night (#209)

* revert paper commit that made the build fail (CI still doesn't work)

* Update build.yml

* test2

* Update build.yml

* take7

* how often does md_5 change mappings?

this will come back to bite me in exactly 17 days

* Revert "how often does md_5 change mappings?"

This reverts commit 8b05c16d6c.

* Updated Upstream and Sidestream(s) (Paper/Purpur)

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:
6caa330c6 Add checkerframework nullness annotations to accepted list for AnnotationTest (#5409)

Purpur Changes:
96f5360 Config to allow for unsafe enchants (#235)
b6235af Rebase on latest Purpur (#230)
754948e Updated Upstream (Paper)
f55c0e9 Option to make doors require redstone (closes #171)
34d5818 Fix paper using wrong annotations
f31bcc6 Updated Upstream (Paper & Airplane)
55244dd Config to show Armor Stand arms on spawn (#231)
c726479 Config to disable hostile mob spawn on ice `:)` (closes #214) (#229)
26a0094 Break individual slabs when sneaking (closes #218)
c3de3ac Fix wart farmers plating vegetables on soul sand

* Updated Upstream and Sidestream(s) (Tuinity/Purpur)

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:
1b0d783 Updated Upstream (Paper)
2c16629 Fix NPE in NetworkManager#execute

Purpur Changes:
0d25d39 Add cache for slime max health (resolves #234)
39dd78a Fix #240 - Separate slab breaking triggers every single time
1ecb9ef Projectile offsets config (#237)
33ee1e7 Configurable sponge absorption (closes #232) (#236)
a0355eb Add Note Block to disabled block updates (#241)

* Updated Upstream and Sidestream(s) (Paper)

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:
8b47131da Optimize short circuit evaluation of sign check (#5348)
1a2fd12a5 Drop carried item when player has disconnected (#5036) (#5166)
68af93524 Use PaperAdventure.PLAIN instead of PlainComponentSerializer.plain() for AdventureComponent#getString (#5414)

* Updated Upstream and Sidestream(s) (Tuinity/Purpur)

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:
94f025a Updated Upstream (Paper)
ab00f31 Do not load chunks around fake players
a9599d8 Fix incorrect parsing of positive target-send-rate
2a6cd81 Make sure to remove correct TE during TE tick

Purpur Changes:
9dfc780 Config for powered rail activation distance (#248)

Co-authored-by: duplexsystem <duplexsys@protonmail.com>
2021-03-28 09:50:47 -05:00

480 lines
25 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ivan Pekov <ivan@mrivanplays.com>
Date: Thu, 27 Aug 2020 10:46:17 +0300
Subject: [PATCH] Highly optimize VillagePlace filtering
Replaced all streams I could. I expect this to be dropped in the next
major release and reimplemented again if mojang changes stuff with
villagers again.
diff --git a/src/main/java/me/jellysquid/mods/lithium/common/util/Producer.java b/src/main/java/me/jellysquid/mods/lithium/common/util/Producer.java
new file mode 100644
index 0000000000000000000000000000000000000000..e647624f4c9afe8bc603792ad88c807ed9f01250
--- /dev/null
+++ b/src/main/java/me/jellysquid/mods/lithium/common/util/Producer.java
@@ -0,0 +1,53 @@
+package me.jellysquid.mods.lithium.common.util;
+
+import java.util.List;
+import java.util.Spliterator;
+import java.util.Spliterators;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
+import org.yatopiamc.yatopia.server.util.HoldingConsumer;
+
+public interface Producer<T> {
+ /**
+ * Computes the next sequence of values in a collection. If a null value is passed for {@param consumer}, then
+ * the producer will only return whether or not elements existed.
+ *
+ * @param consumer The (nullable) consumer which will accept the computed values during this run.
+ * @return True if the producer produced any values, otherwise false
+ */
+ boolean computeNext(Consumer<? super T> consumer);
+
+ default <U> Producer<U> map(Function<T, U> mapper) {
+ return consumer -> {
+ Consumer<? super T> con = (t) -> consumer.accept(mapper.apply(t));
+ return Producer.this.computeNext(con);
+ };
+ }
+
+ static <T> Stream<T> asStream(Producer<T> producer) {
+ return StreamSupport.stream(new Spliterators.AbstractSpliterator<T>(Long.MAX_VALUE, Spliterator.ORDERED | Spliterator.NONNULL) {
+ @Override
+ public boolean tryAdvance(Consumer<? super T> action) {
+ return producer.computeNext(action);
+ }
+ }, false);
+ }
+
+ static <T> void fillList(Producer<T> producer, List<T> list) {
+ HoldingConsumer<T> consumer = new HoldingConsumer<>();
+ while (producer.computeNext(consumer)) {
+ T value = consumer.getValue();
+ if (value == null || list.contains(value)) { continue; }
+ list.add(value);
+ }
+ }
+
+ Producer<?> EMPTY_PRODUCER = consumer -> false;
+
+ @SuppressWarnings("unchecked")
+ static <T> Producer<T> empty() {
+ return (Producer<T>) EMPTY_PRODUCER;
+ }
+}
diff --git a/src/main/java/net/minecraft/core/BlockPosition.java b/src/main/java/net/minecraft/core/BlockPosition.java
index a01b69c43acf4beb65c8b7a8a800c44121068d46..bb520b56d797cabec86fce42dd4afff018e66fdd 100644
--- a/src/main/java/net/minecraft/core/BlockPosition.java
+++ b/src/main/java/net/minecraft/core/BlockPosition.java
@@ -348,6 +348,16 @@ public class BlockPosition extends BaseBlockPosition {
return a(MathHelper.floor(axisalignedbb.minX), MathHelper.floor(axisalignedbb.minY), MathHelper.floor(axisalignedbb.minZ), MathHelper.floor(axisalignedbb.maxX), MathHelper.floor(axisalignedbb.maxY), MathHelper.floor(axisalignedbb.maxZ));
}
+ // Yatopia start
+ public static java.util.List<BlockPosition> getPositions(int i, int j, int k, int l, int i1, int j1) {
+ java.util.List<BlockPosition> ret = new java.util.ArrayList<>();
+ Iterable<BlockPosition> iterable = b(i, j, k, l, i1, j1);
+ org.yatopiamc.yatopia.server.util.HoldingConsumer<BlockPosition> consumer = new org.yatopiamc.yatopia.server.util.HoldingConsumer<>();
+ java.util.Spliterator<BlockPosition> spliterator = iterable.spliterator();
+ while (spliterator.tryAdvance(consumer)) ret.add(consumer.getValue());
+ return ret;
+ }
+ // Yatopia end
public static Stream<BlockPosition> a(int i, int j, int k, int l, int i1, int j1) {
return StreamSupport.stream(b(i, j, k, l, i1, j1).spliterator(), false);
}
diff --git a/src/main/java/net/minecraft/core/SectionPosition.java b/src/main/java/net/minecraft/core/SectionPosition.java
index 427413c668865e1660f1d81daf6a3385f08a0e38..a206a729b3afa01bf591fa4da1e5c14902da4778 100644
--- a/src/main/java/net/minecraft/core/SectionPosition.java
+++ b/src/main/java/net/minecraft/core/SectionPosition.java
@@ -162,6 +162,7 @@ public class SectionPosition extends BaseBlockPosition {
return this.p().b(8, 8, 8);
}
+ public final ChunkCoordIntPair asChunkPos() { return r(); } // Yatopia - OBFHELPER
public ChunkCoordIntPair r() {
return new ChunkCoordIntPair(this.a(), this.c());
}
@@ -176,10 +177,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
}
+ public java.util.List<BlockPosition> tList() { return BlockPosition.getPositions(d(), e(), f(), g(), h(), i()); } // Yatopia
public Stream<BlockPosition> t() {
return BlockPosition.a(this.d(), this.e(), this.f(), this.g(), this.h(), this.i());
}
@@ -192,6 +195,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
}
+ // Yatopia start
+ public static java.util.List<SectionPosition> getPosList(SectionPosition pos, int i) {
+ return getPosList(pos.getX() - i, pos.getY() - i, pos.getZ() - i, pos.getX() + i, pos.getY() + i, pos.getZ() + i);
+ }
+ public static java.util.List<SectionPosition> getPosList(ChunkCoordIntPair chunkPos, int i) {
+ return getPosList(chunkPos.x - i, 0, chunkPos.z - i, chunkPos.x + i, 15, chunkPos.z + i);
+ }
+ public static java.util.List<SectionPosition> getPosList(int i, int j, int k, int l, int i1, int j1) {
+ return org.yatopiamc.yatopia.server.YatopiaChunkSectionPos.getChunkSectionPosList(i, j, k, l, i1, j1);
+ }
+ // Yatopia end
+
public static Stream<SectionPosition> a(final int i, final int j, final int k, final int l, final int i1, final int j1) {
return StreamSupport.stream(new AbstractSpliterator<SectionPosition>((long) ((l - i + 1) * (i1 - j + 1) * (j1 - k + 1)), 64) {
final CursorPosition a = new CursorPosition(i, j, k, l, i1, j1);
diff --git a/src/main/java/net/minecraft/world/entity/ai/village/poi/VillagePlace.java b/src/main/java/net/minecraft/world/entity/ai/village/poi/VillagePlace.java
index 6082eed2d28f3be65daa7e7eb6f2c2a89bb28ff1..29cd71efe86eea2227f373c15c39dc530e9e8199 100644
--- a/src/main/java/net/minecraft/world/entity/ai/village/poi/VillagePlace.java
+++ b/src/main/java/net/minecraft/world/entity/ai/village/poi/VillagePlace.java
@@ -193,7 +193,7 @@ public class VillagePlace extends RegionFileSection<VillagePlaceSection> {
public long count(Predicate<VillagePlaceType> predicate, BlockPosition blockposition, int i, VillagePlace.Occupancy villageplace_occupancy) { return a(predicate, blockposition, i, villageplace_occupancy); } // Purpur - OBFHELPER
public long a(Predicate<VillagePlaceType> predicate, BlockPosition blockposition, int i, VillagePlace.Occupancy villageplace_occupancy) {
- return this.c(predicate, blockposition, i, villageplace_occupancy).count();
+ return this.cList(predicate, blockposition, i, villageplace_occupancy).size(); // Yatopia
}
public boolean a(VillagePlaceType villageplacetype, BlockPosition blockposition) {
@@ -214,6 +214,39 @@ public class VillagePlace extends RegionFileSection<VillagePlaceSection> {
});
}
+ // Yatopia start
+ public java.util.List<VillagePlaceRecord> bList(Predicate<VillagePlaceType> filter, BlockPosition pos, int i, VillagePlace.Occupancy occupancy) {
+ int j = org.apache.commons.math3.util.FastMath.floorDiv(i, 16) + 1;
+
+ java.util.List<ChunkCoordIntPair> list = ChunkCoordIntPair.streamList(new ChunkCoordIntPair(pos), j);
+ java.util.List<VillagePlaceRecord> ret = new java.util.ArrayList<>();
+ for (ChunkCoordIntPair chunkPos : list) {
+ for (int k = 0; k < 16; k++) { // ITS THE LAW
+ this.d(SectionPosition.a(chunkPos, k).asLong()).ifPresent(section -> ret.addAll(section.aList(filter, occupancy)));
+ }
+ }
+ return ret;
+ }
+ public java.util.List<VillagePlaceRecord> cList(Predicate<VillagePlaceType> predicate, BlockPosition pos, int i, VillagePlace.Occupancy occupancy) {
+ int j = i * i;
+ java.util.List<VillagePlaceRecord> ret = new java.util.ArrayList<>();
+ for (VillagePlaceRecord record : this.bList(predicate, pos, i, occupancy)) {
+ if (record.getPosition().distanceSquared(pos) <= j) { ret.add(record); }
+ }
+ return ret;
+ }
+
+ public java.util.List<BlockPosition> cListPositions(Predicate<VillagePlaceType> predicate, Predicate<VillagePlaceRecord> recordFilter, BlockPosition pos, int i, VillagePlace.Occupancy occupancy) {
+ int j = i * i;
+ java.util.List<BlockPosition> ret = new java.util.ArrayList<>();
+ for (VillagePlaceRecord record : this.bList(predicate, pos, i, occupancy)) {
+ BlockPosition recordPosition = record.getPosition();
+ if (recordPosition.distanceSquared(pos) <= j && recordFilter.test(record)) { ret.add(recordPosition); }
+ }
+ return ret;
+ }
+ // Yatopia end
+
public Stream<VillagePlaceRecord> c(Predicate<VillagePlaceType> predicate, BlockPosition blockposition, int i, VillagePlace.Occupancy villageplace_occupancy) {
int j = i * i;
@@ -230,10 +263,28 @@ public class VillagePlace extends RegionFileSection<VillagePlaceSection> {
});
}
+ // Yatopia start
+ public java.util.List<BlockPosition> aList(Predicate<VillagePlaceType> predicate, Predicate<BlockPosition> posFilter, BlockPosition pos, int i, VillagePlace.Occupancy occupancy) {
+ java.util.List<BlockPosition> ret = new java.util.ArrayList<>();
+ int j = i * i;
+ for (VillagePlaceRecord record : this.bList(predicate, pos, i, occupancy)) {
+ BlockPosition recordPosition = record.getPosition();
+ if (recordPosition.distanceSquared(pos) <= j && posFilter.test(recordPosition)) { ret.add(recordPosition); }
+ }
+ return ret;
+ }
+ // Yatopia end
public Stream<BlockPosition> a(Predicate<VillagePlaceType> predicate, Predicate<BlockPosition> predicate1, BlockPosition blockposition, int i, VillagePlace.Occupancy villageplace_occupancy) {
return this.c(predicate, blockposition, i, villageplace_occupancy).map(VillagePlaceRecord::f).filter(predicate1);
}
+ // Yatopia start
+ public java.util.List<BlockPosition> bList(Predicate<VillagePlaceType> predicate, Predicate<BlockPosition> posFilter, BlockPosition pos, int i, VillagePlace.Occupancy occupancy) {
+ java.util.List<BlockPosition> ret = aList(predicate, posFilter, pos, i, occupancy);
+ ret.sort(Comparator.comparingDouble((pos1) -> pos1.distanceSquared(pos)));
+ return ret;
+ }
+ // Yatopia end
public Stream<BlockPosition> b(Predicate<VillagePlaceType> predicate, Predicate<BlockPosition> predicate1, BlockPosition blockposition, int i, VillagePlace.Occupancy villageplace_occupancy) {
return this.a(predicate, predicate1, blockposition, i, villageplace_occupancy).sorted(Comparator.comparingDouble((blockposition1) -> {
return blockposition1.j(blockposition);
@@ -381,7 +432,7 @@ public class VillagePlace extends RegionFileSection<VillagePlaceSection> {
}
private void a(ChunkSection chunksection, SectionPosition sectionposition, BiConsumer<BlockPosition, VillagePlaceType> biconsumer) {
- sectionposition.t().forEach((blockposition) -> {
+ sectionposition.tList().forEach((blockposition) -> { // Yatopia
IBlockData iblockdata = chunksection.getType(SectionPosition.b(blockposition.getX()), SectionPosition.b(blockposition.getY()), SectionPosition.b(blockposition.getZ()));
VillagePlaceType.b(iblockdata).ifPresent((villageplacetype) -> {
@@ -391,6 +442,16 @@ public class VillagePlace extends RegionFileSection<VillagePlaceSection> {
}
public void a(IWorldReader iworldreader, BlockPosition blockposition, int i) {
+ // Yatopia start - WHY?
+ java.util.List<SectionPosition> posList = SectionPosition.getPosList(new ChunkCoordIntPair(blockposition), org.apache.commons.math3.util.FastMath.floorDiv(i, 16));
+ for (SectionPosition pos : posList) {
+ boolean shouldContinue = this.d(pos.asLong()).map(VillagePlaceSection::a).orElse(false);
+ if (shouldContinue) {
+ ChunkCoordIntPair chunkPos = pos.asChunkPos();
+ if (b.add(chunkPos.pair())) { iworldreader.getChunkAt(chunkPos.x, chunkPos.z, ChunkStatus.EMPTY); }
+ }
+ }
+ /*
SectionPosition.b(new ChunkCoordIntPair(blockposition), Math.floorDiv(i, 16)).map((sectionposition) -> {
return Pair.of(sectionposition, this.d(sectionposition.s()));
}).filter((pair) -> {
@@ -402,6 +463,7 @@ public class VillagePlace extends RegionFileSection<VillagePlaceSection> {
}).forEach((chunkcoordintpair) -> {
iworldreader.getChunkAt(chunkcoordintpair.x, chunkcoordintpair.z, ChunkStatus.EMPTY);
});
+ */ // Yatopia end
}
final class a extends LightEngineGraphSection {
diff --git a/src/main/java/net/minecraft/world/entity/ai/village/poi/VillagePlaceSection.java b/src/main/java/net/minecraft/world/entity/ai/village/poi/VillagePlaceSection.java
index 41ffad7cbb6c77713736f37b3728b201d315f6d4..866e9a434423702d2edaf9b52fa0e6219e13c2d7 100644
--- a/src/main/java/net/minecraft/world/entity/ai/village/poi/VillagePlaceSection.java
+++ b/src/main/java/net/minecraft/world/entity/ai/village/poi/VillagePlaceSection.java
@@ -5,6 +5,10 @@ import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
+// Yatopia start
+import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
+import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
+// Yatopia end
import it.unimi.dsi.fastutil.shorts.Short2ObjectMap;
import it.unimi.dsi.fastutil.shorts.Short2ObjectOpenHashMap;
import java.util.List;
@@ -53,12 +57,23 @@ public class VillagePlaceSection {
private VillagePlaceSection(Runnable runnable, boolean flag, List<VillagePlaceRecord> list) {
this.b = new Short2ObjectOpenHashMap();
- this.c = Maps.newHashMap();
+ this.c = new Reference2ReferenceOpenHashMap<>(); // Yatopia
this.d = runnable;
this.e = flag;
list.forEach(this::a);
}
+ // Yatopia start
+ public java.util.List<VillagePlaceRecord> aList(Predicate<VillagePlaceType> predicate, VillagePlace.Occupancy occupancy) {
+ java.util.List<VillagePlaceRecord> ret = new java.util.ArrayList<>();
+ for (Map.Entry<VillagePlaceType, Set<VillagePlaceRecord>> entry : c.entrySet()) {
+ if (predicate.test(entry.getKey())) {
+ for (VillagePlaceRecord record : entry.getValue()) { if (occupancy.a().test(record)) ret.add(record); }
+ }
+ }
+ return ret;
+ }
+ // Yatopia end
public Stream<VillagePlaceRecord> a(Predicate<VillagePlaceType> predicate, VillagePlace.Occupancy villageplace_occupancy) {
return this.c.entrySet().stream().filter((entry) -> {
return predicate.test(entry.getKey());
@@ -101,7 +116,7 @@ public class VillagePlaceSection {
this.b.put(short0, villageplacerecord);
((Set) this.c.computeIfAbsent(villageplacetype, (villageplacetype1) -> {
- return Sets.newHashSet();
+ return new ObjectOpenHashSet<>(); // Yatopia
})).add(villageplacerecord);
return true;
}
diff --git a/src/main/java/net/minecraft/world/entity/animal/EntityBee.java b/src/main/java/net/minecraft/world/entity/animal/EntityBee.java
index c39a7a6d7f391debd632a199eeec8ded6189ad76..052960fde2318495e68dd3ea97b987e01e8c5547 100644
--- a/src/main/java/net/minecraft/world/entity/animal/EntityBee.java
+++ b/src/main/java/net/minecraft/world/entity/animal/EntityBee.java
@@ -857,15 +857,19 @@ public class EntityBee extends EntityAnimal implements IEntityAngerable, EntityB
private List<BlockPosition> j() {
BlockPosition blockposition = EntityBee.this.getChunkCoordinates();
VillagePlace villageplace = ((WorldServer) EntityBee.this.world).y();
- Stream<VillagePlaceRecord> stream = villageplace.c((villageplacetype) -> {
+ List<BlockPosition> stream = villageplace.cListPositions((villageplacetype) -> { // Yatopia
return villageplacetype == VillagePlaceType.t || villageplacetype == VillagePlaceType.u;
- }, blockposition, 20, VillagePlace.Occupancy.ANY);
-
+ }, (record) -> i(record.getPosition()), blockposition, 20, VillagePlace.Occupancy.ANY); // Yatopia
+ // Yatopia start
+ stream.sort(Comparator.comparingDouble((pos1) -> pos1.distanceSquared(blockposition)));
+ return stream;
+ /*
return (List) stream.map(VillagePlaceRecord::f).filter((blockposition1) -> {
return EntityBee.this.i(blockposition1);
}).sorted(Comparator.comparingDouble((blockposition1) -> {
return blockposition1.j(blockposition);
})).collect(Collectors.toList());
+ */ // Yatopia end
}
}
diff --git a/src/main/java/net/minecraft/world/entity/raid/PersistentRaid.java b/src/main/java/net/minecraft/world/entity/raid/PersistentRaid.java
index 11271762dcf5783c3179de1afc6a882c5330b4dd..a0321663a1cb410505e2b57397c6d0020433e6e1 100644
--- a/src/main/java/net/minecraft/world/entity/raid/PersistentRaid.java
+++ b/src/main/java/net/minecraft/world/entity/raid/PersistentRaid.java
@@ -98,7 +98,7 @@ public class PersistentRaid extends PersistentBase {
return null;
} else {
BlockPosition blockposition = entityplayer.getChunkCoordinates();
- List<VillagePlaceRecord> list = (List) this.b.y().c(VillagePlaceType.b, blockposition, 64, VillagePlace.Occupancy.IS_OCCUPIED).collect(Collectors.toList());
+ List<VillagePlaceRecord> list = this.b.y().cList(VillagePlaceType.b, blockposition, 64, VillagePlace.Occupancy.IS_OCCUPIED); // Yatopia
int i = 0;
Vec3D vec3d = Vec3D.ORIGIN;
diff --git a/src/main/java/net/minecraft/world/level/ChunkCoordIntPair.java b/src/main/java/net/minecraft/world/level/ChunkCoordIntPair.java
index 53eb5b65683a2ab208edfc3f3bbf78ffee61bc85..ab169a113e69305f97c69541bcd4beabd05f9ed8 100644
--- a/src/main/java/net/minecraft/world/level/ChunkCoordIntPair.java
+++ b/src/main/java/net/minecraft/world/level/ChunkCoordIntPair.java
@@ -119,6 +119,15 @@ public class ChunkCoordIntPair {
return a(new ChunkCoordIntPair(chunkcoordintpair.x - i, chunkcoordintpair.z - i), new ChunkCoordIntPair(chunkcoordintpair.x + i, chunkcoordintpair.z + i));
}
+ // Yatopia start
+ public static java.util.List<ChunkCoordIntPair> streamList(ChunkCoordIntPair center, int radius) {
+ return streamList(new ChunkCoordIntPair(center.x - radius, center.z - radius), new ChunkCoordIntPair(center.x + radius, center.z + radius));
+ }
+ public static java.util.List<ChunkCoordIntPair> streamList(ChunkCoordIntPair pos1, ChunkCoordIntPair pos2) {
+ return org.yatopiamc.yatopia.server.YatopiaChunkPos.asList(pos1, pos2);
+ }
+ // Yatopia end
+
public static Stream<ChunkCoordIntPair> a(final ChunkCoordIntPair chunkcoordintpair, final ChunkCoordIntPair chunkcoordintpair1) {
int i = Math.abs(chunkcoordintpair.x - chunkcoordintpair1.x) + 1;
int j = Math.abs(chunkcoordintpair.z - chunkcoordintpair1.z) + 1;
diff --git a/src/main/java/org/yatopiamc/yatopia/server/YatopiaChunkPos.java b/src/main/java/org/yatopiamc/yatopia/server/YatopiaChunkPos.java
new file mode 100644
index 0000000000000000000000000000000000000000..09700214355375b59697577253ac5df97608690b
--- /dev/null
+++ b/src/main/java/org/yatopiamc/yatopia/server/YatopiaChunkPos.java
@@ -0,0 +1,54 @@
+package org.yatopiamc.yatopia.server;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.function.Consumer;
+import me.jellysquid.mods.lithium.common.util.Producer;
+import net.minecraft.world.level.ChunkCoordIntPair;
+
+public class YatopiaChunkPos {
+
+ public static List<ChunkCoordIntPair> asList(ChunkCoordIntPair pos1, ChunkCoordIntPair pos2) {
+ List<ChunkCoordIntPair> list = new ArrayList<>();
+ Producer.fillList(getStreamProducer(pos1, pos2), list);
+ return list;
+ }
+
+ /**
+ * [VanillaCopy] but in a producer
+ *
+ * @param pos1 pos 1
+ * @param pos2 pos 2
+ * @return producer
+ */
+ private static Producer<ChunkCoordIntPair> getStreamProducer(ChunkCoordIntPair pos1, ChunkCoordIntPair pos2) {
+ final int k = pos1.x < pos2.x ? 1 : -1;
+ final int l = pos1.z < pos2.z ? 1 : -1;
+
+ return new Producer<ChunkCoordIntPair>() {
+ private ChunkCoordIntPair pair = null;
+
+ @Override
+ public boolean computeNext(Consumer<? super ChunkCoordIntPair> consumer) {
+ if (pair == null) {
+ pair = pos1;
+ } else {
+ int i1 = this.pair.x;
+ int j1 = this.pair.z;
+
+ if (i1 == pos2.x) {
+ if (j1 == pos2.z) {
+ return false;
+ }
+
+ this.pair = new ChunkCoordIntPair(pos1.x, j1 + l);
+ } else {
+ this.pair = new ChunkCoordIntPair(i1 + k, j1);
+ }
+ }
+ consumer.accept(pair);
+ return true;
+ }
+ };
+ }
+}
diff --git a/src/main/java/org/yatopiamc/yatopia/server/YatopiaChunkSectionPos.java b/src/main/java/org/yatopiamc/yatopia/server/YatopiaChunkSectionPos.java
new file mode 100644
index 0000000000000000000000000000000000000000..7dc7ef3b652ad7a4cbb1c08f25d938a79a8b0030
--- /dev/null
+++ b/src/main/java/org/yatopiamc/yatopia/server/YatopiaChunkSectionPos.java
@@ -0,0 +1,32 @@
+package org.yatopiamc.yatopia.server;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.function.Consumer;
+import me.jellysquid.mods.lithium.common.util.Producer;
+import net.minecraft.core.CursorPosition;
+import net.minecraft.core.SectionPosition;
+
+public class YatopiaChunkSectionPos {
+
+ public static List<SectionPosition> getChunkSectionPosList(int i, int j, int k, int l, int i1, int j1) {
+ List<SectionPosition> list = new ArrayList<>();
+ Producer.fillList(getChunkSectionPosProducer(i, j, k, l, i1, j1), list);
+ return list;
+ }
+
+ private static Producer<SectionPosition> getChunkSectionPosProducer(int i, int j, int k, int l, int i1, int j1) {
+ return new Producer<SectionPosition>() {
+ final CursorPosition cursorPos = new CursorPosition(i, j, k, l, i1, j1);
+
+ @Override
+ public boolean computeNext(Consumer<? super SectionPosition> consumer) {
+ if (cursorPos.a()) {
+ consumer.accept(SectionPosition.a(cursorPos.b(), cursorPos.c(), cursorPos.d()));
+ return true;
+ }
+ return false;
+ }
+ };
+ }
+}
diff --git a/src/main/java/org/yatopiamc/yatopia/server/util/HoldingConsumer.java b/src/main/java/org/yatopiamc/yatopia/server/util/HoldingConsumer.java
new file mode 100644
index 0000000000000000000000000000000000000000..adcbe5a009ef8156945b48c4d29d171ebffc4bec
--- /dev/null
+++ b/src/main/java/org/yatopiamc/yatopia/server/util/HoldingConsumer.java
@@ -0,0 +1,17 @@
+package org.yatopiamc.yatopia.server.util;
+
+import java.util.function.Consumer;
+
+public class HoldingConsumer<T> implements Consumer<T> {
+
+ private T value;
+
+ @Override
+ public void accept(T t) {
+ this.value = t;
+ }
+
+ public T getValue() {
+ return value;
+ }
+}