2020-09-01 17:31:48 +02:00
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.
2020-09-28 15:33:03 +02:00
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
2020-09-29 12:36:29 +02:00
index f3224ea636fef95d368b934ed4b3e9060c4b10a2..f2d5878d235fdbfc11c74f87b95f029330c70309 100644
2020-09-28 15:33:03 +02:00
--- a/src/main/java/me/jellysquid/mods/lithium/common/util/Producer.java
+++ b/src/main/java/me/jellysquid/mods/lithium/common/util/Producer.java
2020-09-29 12:36:29 +02:00
@@ -46,6 +46,16 @@ public interface Producer<T> {
2020-09-28 15:33:03 +02:00
}
}
+ // also checks contains and is thus only 1 generic
+ 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")
2020-09-01 17:31:48 +02:00
diff --git a/src/main/java/net/minecraft/server/BlockPosition.java b/src/main/java/net/minecraft/server/BlockPosition.java
2020-10-02 13:05:15 +02:00
index 6fcc7ed7c129e6a33386d65b37cbba4a44e96f0f..dbe6f7d555e8c851faba5cafee8831c516256c09 100644
2020-09-01 17:31:48 +02:00
--- a/src/main/java/net/minecraft/server/BlockPosition.java
+++ b/src/main/java/net/minecraft/server/BlockPosition.java
@@ -341,6 +341,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) {
2020-10-02 13:05:15 +02:00
+ java.util.List<BlockPosition> ret = new net.yatopia.server.list.GlueList<>();
2020-09-01 17:31:48 +02:00
+ Iterable<BlockPosition> iterable = b(i, j, k, l, i1, j1);
+ net.yatopia.server.HoldingConsumer<BlockPosition> consumer = new net.yatopia.server.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/server/ChunkCoordIntPair.java b/src/main/java/net/minecraft/server/ChunkCoordIntPair.java
index dcaf9f8574a9c913b64ba3a1d8b02220db720225..3df4ae0f0921670c19abe17a115da428b4a1f534 100644
--- a/src/main/java/net/minecraft/server/ChunkCoordIntPair.java
+++ b/src/main/java/net/minecraft/server/ChunkCoordIntPair.java
@@ -116,6 +116,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 net.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/net/minecraft/server/EntityBee.java b/src/main/java/net/minecraft/server/EntityBee.java
2020-11-07 08:02:33 +01:00
index f73641ddb3e82bc653732105ef0a3d41a28e845f..f1d6239b834498dc12c1674b3e776d0c15215568 100644
2020-09-01 17:31:48 +02:00
--- a/src/main/java/net/minecraft/server/EntityBee.java
+++ b/src/main/java/net/minecraft/server/EntityBee.java
@@ -720,15 +720,24 @@ 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<VillagePlaceRecord> stream = villageplace.cList((villageplacetype) -> { // Yatopia
return villageplacetype == VillagePlaceType.t || villageplacetype == VillagePlaceType.u;
}, blockposition, 20, VillagePlace.Occupancy.ANY);
-
+ // Yatopia start
2020-10-02 13:05:15 +02:00
+ List<BlockPosition> ret = new net.yatopia.server.list.GlueList<>();
2020-09-01 17:31:48 +02:00
+ for (VillagePlaceRecord record : stream) {
+ BlockPosition pos = record.getPosition();
+ if (i(pos)) { ret.add(pos); }
+ }
+ ret.sort(Comparator.comparingDouble((pos1) -> pos1.distanceSquared(blockposition)));
+ return ret;
+ /*
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/server/PersistentRaid.java b/src/main/java/net/minecraft/server/PersistentRaid.java
2020-11-07 08:02:33 +01:00
index 826dcf9f7eedc3664d66170b97b2a19552a0dc60..81f9b2ec160a015ce7e82ba33dd684e0b3932877 100644
2020-09-01 17:31:48 +02:00
--- a/src/main/java/net/minecraft/server/PersistentRaid.java
+++ b/src/main/java/net/minecraft/server/PersistentRaid.java
@@ -68,7 +68,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;
2020-09-11 08:03:00 +02:00
Vec3D vec3d = Vec3D.ORIGIN;
2020-09-01 17:31:48 +02:00
diff --git a/src/main/java/net/minecraft/server/PortalTravelAgent.java b/src/main/java/net/minecraft/server/PortalTravelAgent.java
2020-10-08 13:04:22 +02:00
index eddf3dff9a00bf3c7318745e52befd4c04fa2af7..c47dc39dcdacbefa07c69f04601f7a125cfbb25c 100644
2020-09-01 17:31:48 +02:00
--- a/src/main/java/net/minecraft/server/PortalTravelAgent.java
+++ b/src/main/java/net/minecraft/server/PortalTravelAgent.java
2020-10-08 13:04:22 +02:00
@@ -29,7 +29,7 @@ public class PortalTravelAgent {
2020-09-02 19:58:08 +02:00
return villageplacerecord.f().getY();
2020-10-08 13:04:22 +02:00
}); // Yatopia
// Yatopia start
2020-09-01 17:31:48 +02:00
- java.util.List<VillagePlaceRecord> list = villageplace.b(type -> type == VillagePlaceType.v, blockposition, i, VillagePlace.Occupancy.ANY).collect(java.util.stream.Collectors.toList());
2020-10-08 13:04:22 +02:00
+ java.util.List<VillagePlaceRecord> list = villageplace.bList(type -> type == VillagePlaceType.v, blockposition, i, VillagePlace.Occupancy.ANY);
2020-09-01 17:31:48 +02:00
if (world.origamiConfig.useBlockDistanceInPortalSearchRadius) {
list.removeIf(villagePlaceRecord -> {
2020-10-08 13:04:22 +02:00
BlockPosition portalPosition = villagePlaceRecord.getPosition();
2020-09-01 17:31:48 +02:00
diff --git a/src/main/java/net/minecraft/server/SectionPosition.java b/src/main/java/net/minecraft/server/SectionPosition.java
2020-09-13 07:22:23 +02:00
index f95925f1c5d091f1a129d0437bb6e175c6ac080f..6796b1a832779b65d337c63d6b600e2a3b5e9559 100644
2020-09-01 17:31:48 +02:00
--- 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 {
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());
}
2020-09-13 07:22:23 +02:00
@@ -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() {
2020-09-01 17:31:48 +02:00
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());
}
2020-09-13 07:22:23 +02:00
@@ -189,6 +192,18 @@ public class SectionPosition extends BaseBlockPosition {
2020-09-01 17:31:48 +02:00
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 net.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/server/VillagePlace.java b/src/main/java/net/minecraft/server/VillagePlace.java
2020-11-07 08:02:33 +01:00
index 3c9668c9c30ea57c1608e32ece27ec56d580fc62..70337f6eb2b868e0c05be12a90471a86664ac3df 100644
2020-09-01 17:31:48 +02:00
--- a/src/main/java/net/minecraft/server/VillagePlace.java
+++ b/src/main/java/net/minecraft/server/VillagePlace.java
@@ -46,7 +46,7 @@ public class VillagePlace extends RegionFileSection<VillagePlaceSection> {
}
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) {
2020-10-06 17:59:16 +02:00
@@ -67,6 +67,29 @@ public class VillagePlace extends RegionFileSection<VillagePlaceSection> {
2020-09-01 17:31:48 +02:00
});
}
+ // Yatopia start
+ public java.util.List<VillagePlaceRecord> bList(Predicate<VillagePlaceType> filter, BlockPosition pos, int i, VillagePlace.Occupancy occupancy) {
+ int j = Math.floorDiv(i, 16) + 1;
+
+ java.util.List<ChunkCoordIntPair> list = ChunkCoordIntPair.streamList(new ChunkCoordIntPair(pos), j);
2020-10-02 13:05:15 +02:00
+ java.util.List<VillagePlaceRecord> ret = new net.yatopia.server.list.GlueList<>();
2020-09-01 17:31:48 +02:00
+ 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;
2020-10-02 13:05:15 +02:00
+ java.util.List<VillagePlaceRecord> ret = new net.yatopia.server.list.GlueList<>();
2020-09-01 17:31:48 +02:00
+ for (VillagePlaceRecord record : this.bList(predicate, pos, i, occupancy)) {
+ if (record.getPosition().distanceSquared(pos) <= j) { ret.add(record); }
+ }
+ return ret;
+ }
2020-10-06 17:59:16 +02:00
+ // Yatopia end
2020-09-01 17:31:48 +02:00
+
public Stream<VillagePlaceRecord> c(Predicate<VillagePlaceType> predicate, BlockPosition blockposition, int i, VillagePlace.Occupancy villageplace_occupancy) {
int j = i * i;
2020-10-06 19:04:03 +02:00
@@ -83,10 +106,28 @@ public class VillagePlace extends RegionFileSection<VillagePlaceSection> {
2020-09-01 17:31:48 +02:00
});
}
+ // Yatopia start
+ public java.util.List<BlockPosition> aList(Predicate<VillagePlaceType> predicate, Predicate<BlockPosition> posFilter, BlockPosition pos, int i, VillagePlace.Occupancy occupancy) {
2020-10-02 13:05:15 +02:00
+ java.util.List<BlockPosition> ret = new net.yatopia.server.list.GlueList<>();
2020-10-06 19:04:03 +02:00
+ int j = i * i;
+ for (VillagePlaceRecord record : this.bList(predicate, pos, i, occupancy)) {
2020-09-01 17:31:48 +02:00
+ BlockPosition recordPosition = record.getPosition();
2020-10-06 19:04:03 +02:00
+ if (recordPosition.distanceSquared(pos) <= j && posFilter.test(recordPosition)) { ret.add(recordPosition); }
2020-09-01 17:31:48 +02:00
+ }
+ 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;
+ }
2020-10-06 17:59:16 +02:00
+ // Yatopia end
2020-09-01 17:31:48 +02:00
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);
2020-10-08 13:04:22 +02:00
@@ -94,31 +135,68 @@ public class VillagePlace extends RegionFileSection<VillagePlaceSection> {
2020-09-01 17:31:48 +02:00
}
public Optional<BlockPosition> c(Predicate<VillagePlaceType> predicate, Predicate<BlockPosition> predicate1, BlockPosition blockposition, int i, VillagePlace.Occupancy villageplace_occupancy) {
- return this.a(predicate, predicate1, blockposition, i, villageplace_occupancy).findFirst();
+ // Yatopia start
2020-10-06 17:59:16 +02:00
+ for (VillagePlaceRecord record : this.cList(predicate, blockposition, i, villageplace_occupancy)) {
+ BlockPosition recordPosition = record.getPosition();
+ if (predicate1.test(recordPosition)) return Optional.of(recordPosition);
+ }
+ return Optional.empty();
2020-09-01 17:31:48 +02:00
+ // Yatopia end
}
public Optional<BlockPosition> d(Predicate<VillagePlaceType> predicate, BlockPosition blockposition, int i, VillagePlace.Occupancy villageplace_occupancy) {
+ // Yatopia start
+ VillagePlaceRecord best = null;
+ for (VillagePlaceRecord record : cList(predicate, blockposition, i, villageplace_occupancy)) {
2020-10-06 17:59:16 +02:00
+ BlockPosition recordPos = record.getPosition();
+ if (best == null || (recordPos.distanceSquared(blockposition) < best.getPosition().distanceSquared(blockposition))) {
2020-09-01 17:31:48 +02:00
+ best = record;
+ }
+ }
+ return best == null ? Optional.empty() : Optional.of(best.getPosition());
+ /*
return this.c(predicate, blockposition, i, villageplace_occupancy).map(VillagePlaceRecord::f).min(Comparator.comparingDouble((blockposition1) -> {
return blockposition1.j(blockposition);
}));
+ */ // Yatopia end
}
public Optional<BlockPosition> a(Predicate<VillagePlaceType> predicate, Predicate<BlockPosition> predicate1, BlockPosition blockposition, int i) {
+ // Yatopia start
2020-10-06 17:59:16 +02:00
+ int j = i * i;
+ for (VillagePlaceRecord record : this.bList(predicate, blockposition, i, VillagePlace.Occupancy.HAS_SPACE)) {
+ BlockPosition recordPos = record.getPosition();
+ if (recordPos.distanceSquared(blockposition) <= j && predicate1.test(recordPos)) {
+ record.b();
+ return Optional.of(recordPos);
2020-09-01 17:31:48 +02:00
+ }
+ }
2020-10-06 17:59:16 +02:00
+ return Optional.empty();
2020-09-01 17:31:48 +02:00
+ /*
return this.c(predicate, blockposition, i, VillagePlace.Occupancy.HAS_SPACE).filter((villageplacerecord) -> {
return predicate1.test(villageplacerecord.f());
}).findFirst().map((villageplacerecord) -> {
villageplacerecord.b();
return villageplacerecord.f();
});
2020-10-08 13:04:22 +02:00
+ */ // Yatopia end
2020-09-01 17:31:48 +02:00
}
public Optional<BlockPosition> a(Predicate<VillagePlaceType> predicate, Predicate<BlockPosition> predicate1, VillagePlace.Occupancy villageplace_occupancy, BlockPosition blockposition, int i, Random random) {
- List<VillagePlaceRecord> list = (List) this.c(predicate, blockposition, i, villageplace_occupancy).collect(Collectors.toList());
+ List<VillagePlaceRecord> list = this.cList(predicate, blockposition, i, villageplace_occupancy); // Yatopia
Collections.shuffle(list, random);
2020-10-08 13:04:22 +02:00
+ // Yatopia start - replace stream
+ for (VillagePlaceRecord record : list) {
+ BlockPosition recordPosition = record.getPosition();
+ if (predicate1.test(recordPosition)) return Optional.of(recordPosition);
+ }
+ return Optional.empty();
+ /*
return list.stream().filter((villageplacerecord) -> {
return predicate1.test(villageplacerecord.f());
}).findFirst().map(VillagePlaceRecord::f);
+ */
}
public boolean b(BlockPosition blockposition) {
@@ -211,7 +289,7 @@ public class VillagePlace extends RegionFileSection<VillagePlaceSection> {
2020-09-01 17:31:48 +02:00
}
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) -> {
2020-10-08 13:04:22 +02:00
@@ -221,6 +299,16 @@ public class VillagePlace extends RegionFileSection<VillagePlaceSection> {
2020-09-01 17:31:48 +02:00
}
public void a(IWorldReader iworldreader, BlockPosition blockposition, int i) {
+ // Yatopia start - WHY?
+ java.util.List<SectionPosition> posList = SectionPosition.getPosList(new ChunkCoordIntPair(blockposition), Math.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) -> {
2020-10-08 13:04:22 +02:00
@@ -232,6 +320,7 @@ public class VillagePlace extends RegionFileSection<VillagePlaceSection> {
2020-09-01 17:31:48 +02:00
}).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/server/VillagePlaceSection.java b/src/main/java/net/minecraft/server/VillagePlaceSection.java
2020-11-07 08:02:33 +01:00
index f43bc1f7d693d63c6bbdba976c048d2d0c8767b1..5e8297d096c2f2eae449801848422287051f146f 100644
2020-09-01 17:31:48 +02:00
--- a/src/main/java/net/minecraft/server/VillagePlaceSection.java
+++ b/src/main/java/net/minecraft/server/VillagePlaceSection.java
@@ -55,6 +55,17 @@ public class VillagePlaceSection {
list.forEach(this::a);
}
+ // Yatopia start
+ public java.util.List<VillagePlaceRecord> aList(Predicate<VillagePlaceType> predicate, VillagePlace.Occupancy occupancy) {
2020-10-02 13:05:15 +02:00
+ java.util.List<VillagePlaceRecord> ret = new net.yatopia.server.list.GlueList<>();
2020-09-01 17:31:48 +02:00
+ 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());
diff --git a/src/main/java/net/yatopia/server/YatopiaChunkPos.java b/src/main/java/net/yatopia/server/YatopiaChunkPos.java
new file mode 100644
2020-10-02 13:05:15 +02:00
index 0000000000000000000000000000000000000000..871e305356103f87c2c1ad1487c804b60e13c076
2020-09-01 17:31:48 +02:00
--- /dev/null
+++ b/src/main/java/net/yatopia/server/YatopiaChunkPos.java
@@ -0,0 +1,54 @@
+package net.yatopia.server;
+
+import java.util.List;
+import java.util.function.Consumer;
+import me.jellysquid.mods.lithium.common.util.Producer;
+import net.minecraft.server.ChunkCoordIntPair;
2020-10-02 13:05:15 +02:00
+import net.yatopia.server.list.GlueList;
2020-09-01 17:31:48 +02:00
+
+public class YatopiaChunkPos {
+
+ public static List<ChunkCoordIntPair> asList(ChunkCoordIntPair pos1, ChunkCoordIntPair pos2) {
2020-10-02 13:05:15 +02:00
+ List<ChunkCoordIntPair> list = new GlueList<>();
2020-09-01 17:31:48 +02:00
+ 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/net/yatopia/server/YatopiaChunkSectionPos.java b/src/main/java/net/yatopia/server/YatopiaChunkSectionPos.java
new file mode 100644
2020-10-02 13:05:15 +02:00
index 0000000000000000000000000000000000000000..134c761c7897f37c20b5209866374dd79dc5b0e4
2020-09-01 17:31:48 +02:00
--- /dev/null
+++ b/src/main/java/net/yatopia/server/YatopiaChunkSectionPos.java
@@ -0,0 +1,32 @@
+package net.yatopia.server;
+
+import java.util.List;
+import java.util.function.Consumer;
+import me.jellysquid.mods.lithium.common.util.Producer;
+import net.minecraft.server.CursorPosition;
+import net.minecraft.server.SectionPosition;
2020-10-02 13:05:15 +02:00
+import net.yatopia.server.list.GlueList;
2020-09-01 17:31:48 +02:00
+
+public class YatopiaChunkSectionPos {
+
+ public static List<SectionPosition> getChunkSectionPosList(int i, int j, int k, int l, int i1, int j1) {
2020-10-02 13:05:15 +02:00
+ List<SectionPosition> list = new GlueList<>();
2020-09-10 17:45:06 +02:00
+ Producer.fillList(getChunkSectionPosProducer(i, j, k, l, i1, j1), list);
2020-09-01 17:31:48 +02:00
+ 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;
+ }
+ };
+ }
+}