This commit is contained in:
Jason Penilla 2021-06-13 23:45:29 -07:00
parent ba374d2485
commit 45c6df9648
No known key found for this signature in database
GPG key ID: 0E75A301420E48F8
9 changed files with 98 additions and 106 deletions

View file

@ -22,6 +22,8 @@ view distance holds on you.
Chunks in front of the player have higher priority, to help with
fast traveling players keep up with their movement.
1.17 update note: very big diff skipping for now, still needs to be updated
diff --git a/src/main/java/com/destroystokyo/paper/io/chunk/ChunkTaskManager.java b/src/main/java/com/destroystokyo/paper/io/chunk/ChunkTaskManager.java
index 499aff1f1e1ffc01ba8f9de43ca17899525a306f..97b85587525ddb62af9bfc8785b48727a6135599 100644
--- a/src/main/java/com/destroystokyo/paper/io/chunk/ChunkTaskManager.java

View file

@ -3,6 +3,10 @@ From: Aikar <aikar@aikar.co>
Date: Fri, 29 May 2020 23:32:14 -0400
Subject: [PATCH] Improve Chunk Status Transition Speed
1.17 Update note: Depends on not yet applied patch: Implement Chunk Priority / Urgency System for Chunks
When a chunk is loaded from disk that has already been generated,
the server has to promote the chunk through the system to reach
it's current desired status level.

View file

@ -1,35 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 7 Jun 2020 19:25:13 -0400
Subject: [PATCH] Use seed based lookup for Treasure Maps - Fixes lag from
carto/sunken maps
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index bf4e50cd1d561456c033cda2d5c5487c5e3fe1eb..61aee2c109614a014149ae5a15ad2a28c796cb9d 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -415,8 +415,8 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
this.worldDataServer.setThundering(thundering);
}
- @Override
- public Biome getUncachedNoiseBiome(int biomeX, int biomeY, int biomeZ) {
+ public Biome getBiomeBySeed(int i, int j, int k) { return getUncachedNoiseBiome(i, j, k); } // Paper - OBFHELPER
+ @Override public Biome getUncachedNoiseBiome(int biomeX, int biomeY, int biomeZ) {
return this.getChunkSource().getGenerator().getBiomeSource().getNoiseBiome(biomeX, biomeY, biomeZ);
}
diff --git a/src/main/java/net/minecraft/world/item/MapItem.java b/src/main/java/net/minecraft/world/item/MapItem.java
index 05759dc6edaa790a5e3f2ca2e0ae27e53cfa4397..550892bc769a58991583b16295a72a162ceea788 100644
--- a/src/main/java/net/minecraft/world/item/MapItem.java
+++ b/src/main/java/net/minecraft/world/item/MapItem.java
@@ -252,7 +252,7 @@ public class MapItem extends ComplexItem {
for (l = 0; l < 128 * i; ++l) {
for (i1 = 0; i1 < 128 * i; ++i1) {
- abiomebase[l * 128 * i + i1] = worldserver.getBiome(new BlockPos((j / i - 64) * i + i1, 0, (k / i - 64) * i + l));
+ abiomebase[l * 128 * i + i1] = worldserver.getBiomeBySeed((j / i - 64) * i + i1, 0, (k / i - 64) * i + l); // Paper
}
}

View file

@ -665,7 +665,7 @@ index bffc897cb88a54c36432c98264f3416051aeab17..14a0190ea5e9a387582736bb130c16a3
// Yes, this doesn't match Vanilla, but it's the best we can do for now.
diff --git a/src/main/java/net/minecraft/world/level/NaturalSpawner.java b/src/main/java/net/minecraft/world/level/NaturalSpawner.java
index 19d0ed5ff8569b0280117750f9ce05095afd9f70..490ff09c3c4f93dcafc1703b1df3fb2f7333add2 100644
index 19d0ed5ff8569b0280117750f9ce05095afd9f70..55b937f802ee7066cb13b9a497932038b2905ff0 100644
--- a/src/main/java/net/minecraft/world/level/NaturalSpawner.java
+++ b/src/main/java/net/minecraft/world/level/NaturalSpawner.java
@@ -17,6 +17,7 @@ import net.minecraft.core.Registry;
@ -778,7 +778,15 @@ index 19d0ed5ff8569b0280117750f9ce05095afd9f70..490ff09c3c4f93dcafc1703b1df3fb2f
int k = 0;
while (k < 3) {
@@ -248,7 +289,7 @@ public final class NaturalSpawner {
@@ -241,14 +282,14 @@ public final class NaturalSpawner {
// Paper start
Boolean doSpawning = isValidSpawnPostitionForType(world, group, structuremanager, chunkgenerator, biomesettingsmobs_c, blockposition_mutableblockposition, d2);
if (doSpawning == null) {
- return;
+ return j; // Paper
}
if (doSpawning && checker.test(biomesettingsmobs_c.type, blockposition_mutableblockposition, chunk)) {
// Paper end
Mob entityinsentient = NaturalSpawner.getMobForSpawn(world, biomesettingsmobs_c.type);
if (entityinsentient == null) {

View file

@ -11,10 +11,10 @@ This will drastically cut down on packet sending cost for worlds with
lots of players in them.
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index 168895dab31a0d5356eb96f2642399a1c99fccab..713cc88dd067c0d918f253b1845f42c0d9eb920f 100644
index c4242a1602bbb02541c330bc02016f15c8644358..7eb3088d47ff78198e01a3a12b0ce6abe9d6ca6b 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -1149,16 +1149,40 @@ public abstract class PlayerList {
@@ -1129,16 +1129,40 @@ public abstract class PlayerList {
}
public void broadcast(@Nullable net.minecraft.world.entity.player.Player player, double x, double y, double z, double distance, ResourceKey<Level> worldKey, Packet<?> packet) {
@ -32,7 +32,7 @@ index 168895dab31a0d5356eb96f2642399a1c99fccab..713cc88dd067c0d918f253b1845f42c0
+ if (world == null) {
+ world = server.getLevel(worldKey);
+ }
+ ChunkMap chunkMap = world != null ? world.getChunkSource().chunkMap : null;
+ net.minecraft.server.level.ChunkMap chunkMap = world != null ? world.getChunkSource().chunkMap : null;
+ Object[] backingSet;
+ if (chunkMap == null) {
+ // Really shouldn't happen...

View file

@ -6,7 +6,7 @@ Subject: [PATCH] Fix villager trading demand - MC-163962
Prevent demand from going negative and tending to negative infinity
diff --git a/src/main/java/net/minecraft/world/item/trading/MerchantOffer.java b/src/main/java/net/minecraft/world/item/trading/MerchantOffer.java
index 9ce1c1092970618a204f87c673144152afbade99..fa74813e0fe76612023830b2fc41d41aa0b4f10e 100644
index 3a59f610145504a096ccf4793ea4140120b00f48..75827fcad36a551d832f4be094167936092b6caf 100644
--- a/src/main/java/net/minecraft/world/item/trading/MerchantOffer.java
+++ b/src/main/java/net/minecraft/world/item/trading/MerchantOffer.java
@@ -109,7 +109,7 @@ public class MerchantOffer {

View file

@ -15,10 +15,10 @@ Previously maps would load all chunks in a certain radius depending on
five ticks that movement occur in anyways.
diff --git a/src/main/java/net/minecraft/world/item/MapItem.java b/src/main/java/net/minecraft/world/item/MapItem.java
index 1736d2eb33e5f2221210a0a4f3ceb8905555a162..05759dc6edaa790a5e3f2ca2e0ae27e53cfa4397 100644
index 044111a5ea88d3f938c08b027ac6836355eff7c2..994a3c0253c7298fef1471736b74bd34ec87738a 100644
--- a/src/main/java/net/minecraft/world/item/MapItem.java
+++ b/src/main/java/net/minecraft/world/item/MapItem.java
@@ -119,9 +119,9 @@ public class MapItem extends ComplexItem {
@@ -132,9 +132,9 @@ public class MapItem extends ComplexItem {
int k2 = (j / i + k1 - 64) * i;
int l2 = (k / i + l1 - 64) * i;
Multiset<MaterialColor> multiset = LinkedHashMultiset.create();

View file

@ -0,0 +1,20 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 7 Jun 2020 19:25:13 -0400
Subject: [PATCH] Use seed based lookup for Treasure Maps - Fixes lag from
carto/sunken maps
diff --git a/src/main/java/net/minecraft/world/item/MapItem.java b/src/main/java/net/minecraft/world/item/MapItem.java
index 994a3c0253c7298fef1471736b74bd34ec87738a..305c0b0ca23eea6b8b32778a4bbe8a2eacc78107 100644
--- a/src/main/java/net/minecraft/world/item/MapItem.java
+++ b/src/main/java/net/minecraft/world/item/MapItem.java
@@ -258,7 +258,7 @@ public class MapItem extends ComplexItem {
for (l = 0; l < 128 * i; ++l) {
for (i1 = 0; i1 < 128 * i; ++i1) {
- abiomebase[l * 128 * i + i1] = world.getBiome(new BlockPos((j / i - 64) * i + i1, 0, (k / i - 64) * i + l));
+ abiomebase[l * 128 * i + i1] = world.getUncachedNoiseBiome((j / i - 64) * i + i1, 0, (k / i - 64) * i + l); // Paper
}
}

View file

@ -7,25 +7,26 @@ Inline bit operations and reduce instruction count to make these hot
operations faster
diff --git a/src/main/java/net/minecraft/core/BlockPos.java b/src/main/java/net/minecraft/core/BlockPos.java
index 595abf528a7862478100770987906af1b13439fe..727af6ac84075db87615ebac51a024e6376fa3cb 100644
index dd1d76867ac3832ad515f304925c595c9a021c8f..fd5c22a3d281d8d913c353c8a668ec51b885066a 100644
--- a/src/main/java/net/minecraft/core/BlockPos.java
+++ b/src/main/java/net/minecraft/core/BlockPos.java
@@ -31,14 +31,16 @@ public class BlockPos extends Vec3i {
@@ -30,15 +30,16 @@ public class BlockPos extends Vec3i {
}).stable();
private static final Logger LOGGER = LogManager.getLogger();
public static final BlockPos ZERO = new BlockPos(0, 0, 0);
- private static final int PACKED_X_LENGTH = 1 + Mth.log2(Mth.smallestEncompassingPowerOfTwo(30000000));
- private static final int PACKED_Z_LENGTH = BlockPos.PACKED_X_LENGTH;
- private static final int PACKED_Y_LENGTH = 64 - BlockPos.PACKED_X_LENGTH - BlockPos.PACKED_Z_LENGTH;
- private static final long PACKED_X_MASK = (1L << BlockPos.PACKED_X_LENGTH) - 1L;
- private static final long PACKED_Y_MASK = (1L << BlockPos.PACKED_Y_LENGTH) - 1L;
- private static final long PACKED_Z_MASK = (1L << BlockPos.PACKED_Z_LENGTH) - 1L;
- private static final int Z_OFFSET = BlockPos.PACKED_Y_LENGTH;
- private static final int X_OFFSET = BlockPos.PACKED_Y_LENGTH + BlockPos.PACKED_Z_LENGTH;
- private static final int PACKED_Z_LENGTH = PACKED_X_LENGTH;
- public static final int PACKED_Y_LENGTH = 64 - PACKED_X_LENGTH - PACKED_Z_LENGTH;
- private static final long PACKED_X_MASK = (1L << PACKED_X_LENGTH) - 1L;
- private static final long PACKED_Y_MASK = (1L << PACKED_Y_LENGTH) - 1L;
- private static final long PACKED_Z_MASK = (1L << PACKED_Z_LENGTH) - 1L;
- private static final int Y_OFFSET = 0;
- private static final int Z_OFFSET = PACKED_Y_LENGTH;
- private static final int X_OFFSET = PACKED_Y_LENGTH + PACKED_Z_LENGTH;
+ // Paper start - static constants
+ private static final int PACKED_X_LENGTH = 26;
+ private static final int PACKED_Z_LENGTH = 26;
+ private static final int PACKED_Y_LENGTH = 12;
+ public static final int PACKED_Y_LENGTH = 12;
+ private static final long PACKED_X_MASK = 67108863;
+ private static final long PACKED_Y_MASK = 4095;
+ private static final long PACKED_Z_MASK = 67108863;
@ -35,7 +36,7 @@ index 595abf528a7862478100770987906af1b13439fe..727af6ac84075db87615ebac51a024e6
public BlockPos(int x, int y, int z) {
super(x, y, z);
@@ -60,28 +62,29 @@ public class BlockPos extends Vec3i {
@@ -60,28 +61,29 @@ public class BlockPos extends Vec3i {
this(pos.getX(), pos.getY(), pos.getZ());
}
@ -50,17 +51,17 @@ index 595abf528a7862478100770987906af1b13439fe..727af6ac84075db87615ebac51a024e6
}
public static int getX(long packedPos) {
- return (int) (packedPos << 64 - BlockPos.X_OFFSET - BlockPos.PACKED_X_LENGTH >> 64 - BlockPos.PACKED_X_LENGTH);
- return (int)(packedPos << 64 - X_OFFSET - PACKED_X_LENGTH >> 64 - PACKED_X_LENGTH);
+ return (int) (packedPos >> 38); // Paper - simplify/inline
}
public static int getY(long packedPos) {
- return (int) (packedPos << 64 - BlockPos.PACKED_Y_LENGTH >> 64 - BlockPos.PACKED_Y_LENGTH);
- return (int)(packedPos << 64 - PACKED_Y_LENGTH >> 64 - PACKED_Y_LENGTH);
+ return (int) ((packedPos << 52) >> 52); // Paper - simplify/inline
}
public static int getZ(long packedPos) {
- return (int) (packedPos << 64 - BlockPos.Z_OFFSET - BlockPos.PACKED_Z_LENGTH >> 64 - BlockPos.PACKED_Z_LENGTH);
- return (int)(packedPos << 64 - Z_OFFSET - PACKED_Z_LENGTH >> 64 - PACKED_Z_LENGTH);
+ return (int) ((packedPos << 26) >> 38); // Paper - simplify/inline
}
@ -70,25 +71,23 @@ index 595abf528a7862478100770987906af1b13439fe..727af6ac84075db87615ebac51a024e6
}
public long asLong() {
@@ -90,12 +93,7 @@ public class BlockPos extends Vec3i {
@@ -89,10 +91,7 @@ public class BlockPos extends Vec3i {
}
public static long asLong(int x, int y, int z) { return asLong(x, y, z); } // Paper - OBFHELPER
public static long asLong(int x, int y, int z) {
- long l = 0L;
-
- l |= ((long) x & BlockPos.PACKED_X_MASK) << BlockPos.X_OFFSET;
- l |= ((long) y & BlockPos.PACKED_Y_MASK) << 0;
- l |= ((long) z & BlockPos.PACKED_Z_MASK) << BlockPos.Z_OFFSET;
- return l;
- l = l | ((long)x & PACKED_X_MASK) << X_OFFSET;
- l = l | ((long)y & PACKED_Y_MASK) << 0;
- return l | ((long)z & PACKED_Z_MASK) << Z_OFFSET;
+ return (((long) x & (long) 67108863) << 38) | (((long) y & (long) 4095)) | (((long) z & (long) 67108863) << 12); // Paper - inline constants and simplify
}
public static long getFlatIndex(long y) {
diff --git a/src/main/java/net/minecraft/core/SectionPos.java b/src/main/java/net/minecraft/core/SectionPos.java
index 700e0d7b132242bd65d13ec61c1f7036905b2767..c4bf1bc383fbdfb8ec997883aececde38206c7dd 100644
index 4ea92289304bdad469e67164442bc0b837183e8a..b0c39895e10fab5acc609128d34aafdebc5520f9 100644
--- a/src/main/java/net/minecraft/core/SectionPos.java
+++ b/src/main/java/net/minecraft/core/SectionPos.java
@@ -19,7 +19,7 @@ public class SectionPos extends Vec3i {
@@ -37,7 +37,7 @@ public class SectionPos extends Vec3i {
}
public static SectionPos of(BlockPos pos) {
@ -97,7 +96,7 @@ index 700e0d7b132242bd65d13ec61c1f7036905b2767..c4bf1bc383fbdfb8ec997883aececde3
}
public static SectionPos of(ChunkPos chunkPos, int y) {
@@ -31,15 +31,23 @@ public class SectionPos extends Vec3i {
@@ -49,7 +49,7 @@ public class SectionPos extends Vec3i {
}
public static SectionPos of(long packed) {
@ -105,7 +104,8 @@ index 700e0d7b132242bd65d13ec61c1f7036905b2767..c4bf1bc383fbdfb8ec997883aececde3
+ return new SectionPos((int) (packed >> 42), (int) (packed << 44 >> 44), (int) (packed << 22 >> 42)); // Paper
}
public static long offset(long packed, Direction direction) {
public static SectionPos bottomOf(ChunkAccess chunk) {
@@ -60,8 +60,16 @@ public class SectionPos extends Vec3i {
return offset(packed, direction.getStepX(), direction.getStepY(), direction.getStepZ());
}
@ -122,48 +122,45 @@ index 700e0d7b132242bd65d13ec61c1f7036905b2767..c4bf1bc383fbdfb8ec997883aececde3
+ return (((long) ((int) (packed >> 42) + x) & 4194303L) << 42) | (((long) ((int) (packed << 44 >> 44) + y) & 1048575L)) | (((long) ((int) (packed << 22 >> 42) + z) & 4194303L) << 20); // Simplify to reduce instruction count
}
public static int blockToSectionCoord(int coord) {
@@ -51,11 +59,7 @@ public class SectionPos extends Vec3i {
public static int posToSectionCoord(double coord) {
@@ -77,10 +85,7 @@ public class SectionPos extends Vec3i {
}
public static short sectionRelativePos(BlockPos pos) {
- int i = sectionRelative(pos.getX());
- int j = sectionRelative(pos.getY());
- int k = sectionRelative(pos.getZ());
-
- return (short) (i << 8 | k << 4 | j << 0);
- return (short)(i << 8 | k << 4 | j << 0);
+ return (short) ((pos.getX() & 15) << 8 | (pos.getZ() & 15) << 4 | pos.getY() & 15); // Paper - simplify/inline
}
public static int sectionRelativeX(short packedLocalPos) {
@@ -114,16 +118,16 @@ public class SectionPos extends Vec3i {
@@ -143,16 +148,16 @@ public class SectionPos extends Vec3i {
return this.getZ();
}
- public int minBlockX() {
- return this.x() << 4;
+ public final int minBlockX() { // Paper
+ return this.getX() << 4; // Paper
- return sectionToBlockCoord(this.x());
+ public final int minBlockX() { // Paper - make final
+ return this.getX() << 4; // Paper - inline
}
- public int minBlockY() {
- return this.y() << 4;
+ public final int minBlockY() { // Paper
+ return this.getY() << 4; // Paper
- return sectionToBlockCoord(this.y());
+ public final int minBlockY() { // Paper - make final
+ return this.getY() << 4; // Paper - inline
}
- public int minBlockZ() {
- return this.z() << 4;
+ public final int minBlockZ() { // Paper
+ return this.getZ() << 4; // Paper
- return sectionToBlockCoord(this.z());
+ public int minBlockZ() { // Paper - make final
+ return this.getZ() << 4; // Paper - inline
}
public int maxBlockX() {
@@ -138,8 +142,10 @@ public class SectionPos extends Vec3i {
return (this.z() << 4) + 15;
@@ -168,7 +173,8 @@ public class SectionPos extends Vec3i {
}
+ public static long blockToSection(long i) { return blockToSection(i); } // Paper - OBFHELPER
public static long blockToSection(long blockPos) {
- return asLong(blockToSectionCoord(BlockPos.getX(blockPos)), blockToSectionCoord(BlockPos.getY(blockPos)), blockToSectionCoord(BlockPos.getZ(blockPos)));
+ // b(a(BlockPosition.b(i)), a(BlockPosition.c(i)), a(BlockPosition.d(i)));
@ -171,8 +168,8 @@ index 700e0d7b132242bd65d13ec61c1f7036905b2767..c4bf1bc383fbdfb8ec997883aececde3
}
public static long getZeroNode(long pos) {
@@ -160,17 +166,18 @@ public class SectionPos extends Vec3i {
return new ChunkPos(this.x(), this.z());
@@ -192,15 +198,18 @@ public class SectionPos extends Vec3i {
return asLong(blockToSectionCoord(pos.getX()), blockToSectionCoord(pos.getY()), blockToSectionCoord(pos.getZ()));
}
+ // Paper start
@ -180,14 +177,12 @@ index 700e0d7b132242bd65d13ec61c1f7036905b2767..c4bf1bc383fbdfb8ec997883aececde3
+ return (((long) (i >> 4) & 4194303L) << 42) | (((long) (j >> 4) & 1048575L)) | (((long) (k >> 4) & 4194303L) << 20);
+ }
+ // Paper end
+ public static long asLong(int i, int j, int k) { return asLong(i, j, k); } // Paper - OBFHELPER
+
public static long asLong(int x, int y, int z) {
- long l = 0L;
-
- l |= ((long) x & 4194303L) << 42;
- l |= ((long) y & 1048575L) << 0;
- l |= ((long) z & 4194303L) << 20;
- return l;
- l = l | ((long)x & 4194303L) << 42;
- l = l | ((long)y & 1048575L) << 0;
- return l | ((long)z & 4194303L) << 20;
+ return (((long) x & 4194303L) << 42) | (((long) y & 1048575L)) | (((long) z & 4194303L) << 20); // Paper - Simplify to reduce instruction count
}
@ -196,25 +191,23 @@ index 700e0d7b132242bd65d13ec61c1f7036905b2767..c4bf1bc383fbdfb8ec997883aececde3
+ return (((long) getX() & 4194303L) << 42) | (((long) getY() & 1048575L)) | (((long) getZ() & 4194303L) << 20); // Paper - Simplify to reduce instruction count
}
public Stream<BlockPos> blocksInside() {
@@ -178,18 +185,11 @@ public class SectionPos extends Vec3i {
@Override
@@ -213,16 +222,11 @@ public class SectionPos extends Vec3i {
}
public static Stream<SectionPos> cube(SectionPos center, int radius) {
- int j = center.x();
- int k = center.y();
- int l = center.z();
-
- return betweenClosedStream(j - radius, k - radius, l - radius, j + radius, k + radius, l + radius);
- int i = center.x();
- int j = center.y();
- int k = center.z();
- return betweenClosedStream(i - radius, j - radius, k - radius, i + radius, j + radius, k + radius);
+ return betweenClosedStream(center.getX() - radius, center.getY() - radius, center.getZ() - radius, center.getX() + radius, center.getY() + radius, center.getZ() + radius); // Paper - simplify/inline
}
public static Stream<SectionPos> aroundChunk(ChunkPos center, int radius) {
- int j = center.x;
- int k = center.z;
-
- return betweenClosedStream(j - radius, 0, k - radius, j + radius, 15, k + radius);
public static Stream<SectionPos> aroundChunk(ChunkPos center, int radius, int minY, int maxY) {
- int i = center.x;
- int j = center.z;
- return betweenClosedStream(i - radius, minY, j - radius, i + radius, maxY - 1, j + radius);
+ return betweenClosedStream(center.x - radius, 0, center.z - radius, center.x + radius, 15, center.z + radius); // Paper - simplify/inline
}
public static Stream<SectionPos> betweenClosedStream(final int minX, final int minY, final int minZ, final int maxX, final int maxY, final int maxZ) {
public static Stream<SectionPos> betweenClosedStream(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {