Improve random ticking behaviour - Fixes #3181

This commit is contained in:
Spottedleaf 2020-04-19 06:07:57 -07:00 committed by Aikar
parent a6ac47e502
commit ab36835ca0
No known key found for this signature in database
GPG Key ID: 401ADFC9891FAAFE
6 changed files with 91 additions and 139 deletions

View File

@ -1,4 +1,4 @@
From 9cd5be8ad18822109b1121921ab8ac3b08cb475d Mon Sep 17 00:00:00 2001
From 2356450c9a501c6a5e3957a2fe1e3c6284e74cd2 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Mon, 27 Jan 2020 21:28:00 -0800
Subject: [PATCH] Optimise random block ticking
@ -20,7 +20,7 @@ remains the same.
diff --git a/src/main/java/com/destroystokyo/paper/util/math/ThreadUnsafeRandom.java b/src/main/java/com/destroystokyo/paper/util/math/ThreadUnsafeRandom.java
new file mode 100644
index 00000000..3edc8e52
index 0000000000..3edc8e52e0
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/util/math/ThreadUnsafeRandom.java
@@ -0,0 +1,46 @@
@ -71,7 +71,7 @@ index 00000000..3edc8e52
+ }
+}
diff --git a/src/main/java/net/minecraft/server/Block.java b/src/main/java/net/minecraft/server/Block.java
index e29ec958..e40375b6 100644
index e29ec958b3..e40375b67a 100644
--- a/src/main/java/net/minecraft/server/Block.java
+++ b/src/main/java/net/minecraft/server/Block.java
@@ -109,8 +109,8 @@ public class Block implements IMaterial {
@ -86,7 +86,7 @@ index e29ec958..e40375b6 100644
}
diff --git a/src/main/java/net/minecraft/server/BlockFluids.java b/src/main/java/net/minecraft/server/BlockFluids.java
index 6d351f09..a44f65f4 100644
index 6d351f0979..a44f65f40d 100644
--- a/src/main/java/net/minecraft/server/BlockFluids.java
+++ b/src/main/java/net/minecraft/server/BlockFluids.java
@@ -27,7 +27,7 @@ public class BlockFluids extends Block implements IFluidSource {
@ -99,7 +99,7 @@ index 6d351f09..a44f65f4 100644
@Override
diff --git a/src/main/java/net/minecraft/server/BlockPosition.java b/src/main/java/net/minecraft/server/BlockPosition.java
index e76528f1..e650a2e4 100644
index e76528f199..e650a2e48d 100644
--- a/src/main/java/net/minecraft/server/BlockPosition.java
+++ b/src/main/java/net/minecraft/server/BlockPosition.java
@@ -450,6 +450,7 @@ public class BlockPosition extends BaseBlockPosition implements MinecraftSeriali
@ -111,38 +111,10 @@ index e76528f1..e650a2e4 100644
return this.d(baseblockposition.getX(), baseblockposition.getY(), baseblockposition.getZ());
}
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index 03c25eae..92bb009b 100644
index 29cfef1605..8fc26aa4b8 100644
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -52,6 +52,8 @@ public class Chunk implements IChunkAccess {
private final ChunkCoordIntPair loc; public final long coordinateKey; // Paper - cache coordinate key
private volatile boolean x;
+ final com.destroystokyo.paper.util.maplist.IBlockDataList tickingList = new com.destroystokyo.paper.util.maplist.IBlockDataList(); // Paper
+
public Chunk(World world, ChunkCoordIntPair chunkcoordintpair, BiomeStorage biomestorage) {
this(world, chunkcoordintpair, biomestorage, ChunkConverter.a, TickListEmpty.b(), TickListEmpty.b(), 0L, (ChunkSection[]) null, (Consumer) null);
}
@@ -124,6 +126,18 @@ public class Chunk implements IChunkAccess {
this.v = consumer;
if (achunksection != null) {
if (this.sections.length == achunksection.length) {
+ // Paper start - maintain a list of ticking blocks in a chunk
+ for (ChunkSection section : achunksection) {
+ if (section != null) {
+ section.chunk = this;
+ int offset = com.destroystokyo.paper.util.maplist.IBlockDataList.getLocationKey(0, section.yPos, 0);
+ for (it.unimi.dsi.fastutil.longs.LongIterator iterator = section.tickingList.getRawIterator(); iterator.hasNext();) {
+ long raw = iterator.nextLong();
+ this.tickingList.add(com.destroystokyo.paper.util.maplist.IBlockDataList.getLocationFromRaw(raw) + offset, com.destroystokyo.paper.util.maplist.IBlockDataList.getBlockDataFromRaw(raw));
+ }
+ }
+ }
+ // Paper end
System.arraycopy(achunksection, 0, this.sections, 0, this.sections.length);
} else {
Chunk.LOGGER.warn("Could not set level chunk sections, array length is {} instead of {}", achunksection.length, this.sections.length);
@@ -572,8 +586,8 @@ public class Chunk implements IChunkAccess {
@@ -572,8 +572,8 @@ public class Chunk implements IChunkAccess {
this.entities.remove(entity); // Paper
}
@ -154,7 +126,7 @@ index 03c25eae..92bb009b 100644
}
diff --git a/src/main/java/net/minecraft/server/ChunkSection.java b/src/main/java/net/minecraft/server/ChunkSection.java
index 4526527a..8b28fb5e 100644
index 4526527aca..3eaf893cdf 100644
--- a/src/main/java/net/minecraft/server/ChunkSection.java
+++ b/src/main/java/net/minecraft/server/ChunkSection.java
@@ -5,12 +5,15 @@ import javax.annotation.Nullable;
@ -187,44 +159,31 @@ index 4526527a..8b28fb5e 100644
}
public IBlockData getType(int i, int j, int k) {
@@ -69,6 +77,12 @@ public class ChunkSection {
@@ -69,6 +77,9 @@ public class ChunkSection {
--this.nonEmptyBlockCount;
if (iblockdata1.q()) {
--this.tickingBlockCount;
+ // Paper start
+ this.tickingList.remove(i, j, k);
+ if (this.chunk != null) {
+ this.chunk.tickingList.remove(i, j + this.yPos, k);
+ }
+ // Paper end
}
}
@@ -80,6 +94,12 @@ public class ChunkSection {
@@ -80,6 +91,9 @@ public class ChunkSection {
++this.nonEmptyBlockCount;
if (iblockdata.q()) {
++this.tickingBlockCount;
+ // Paper start
+ this.tickingList.add(i, j, k, iblockdata);
+ if (this.chunk != null) {
+ this.chunk.tickingList.add(i, j + this.yPos, k, iblockdata);
+ }
+ // Paper end
}
}
@@ -115,23 +135,39 @@ public class ChunkSection {
@@ -115,23 +129,29 @@ public class ChunkSection {
}
public void recalcBlockCounts() {
+ // Paper start
+ int offset = com.destroystokyo.paper.util.maplist.IBlockDataList.getLocationKey(0, this.yPos, 0);
+ if (this.chunk != null) {
+ for (it.unimi.dsi.fastutil.longs.LongIterator iterator = this.tickingList.getRawIterator(); iterator.hasNext();) {
+ long raw = iterator.nextLong();
+ this.chunk.tickingList.remove(com.destroystokyo.paper.util.maplist.IBlockDataList.getLocationFromRaw(raw) + offset);
+ }
+ }
+ this.tickingList.clear();
+ // Paper end
this.nonEmptyBlockCount = 0;
@ -242,9 +201,6 @@ index 4526527a..8b28fb5e 100644
+ this.tickingBlockCount = (short) (this.tickingBlockCount + 1); // Paper
+ // Paper start
+ this.tickingList.add(location, iblockdata);
+ if (this.chunk != null) {
+ this.chunk.tickingList.add(location + offset, iblockdata);
+ }
+ // Paper end
}
}
@ -259,7 +215,7 @@ index 4526527a..8b28fb5e 100644
}
diff --git a/src/main/java/net/minecraft/server/DataBits.java b/src/main/java/net/minecraft/server/DataBits.java
index f9680b68..a61cffa3 100644
index f9680b6830..a61cffa3f4 100644
--- a/src/main/java/net/minecraft/server/DataBits.java
+++ b/src/main/java/net/minecraft/server/DataBits.java
@@ -127,4 +127,46 @@ public class DataBits {
@ -310,7 +266,7 @@ index f9680b68..a61cffa3 100644
+ // Paper end
}
diff --git a/src/main/java/net/minecraft/server/DataPaletteBlock.java b/src/main/java/net/minecraft/server/DataPaletteBlock.java
index 44aed672..fa664897 100644
index 44aed67274..fa664897fb 100644
--- a/src/main/java/net/minecraft/server/DataPaletteBlock.java
+++ b/src/main/java/net/minecraft/server/DataPaletteBlock.java
@@ -287,6 +287,14 @@ public class DataPaletteBlock<T> implements DataPaletteExpandable<T> {
@ -329,7 +285,7 @@ index 44aed672..fa664897 100644
public interface a<T> {
diff --git a/src/main/java/net/minecraft/server/EntityTurtle.java b/src/main/java/net/minecraft/server/EntityTurtle.java
index dd02cb34..b24a5100 100644
index dd02cb3485..b24a5100b4 100644
--- a/src/main/java/net/minecraft/server/EntityTurtle.java
+++ b/src/main/java/net/minecraft/server/EntityTurtle.java
@@ -29,7 +29,7 @@ public class EntityTurtle extends EntityAnimal {
@ -342,7 +298,7 @@ index dd02cb34..b24a5100 100644
public final BlockPosition getHome() { return this.es(); } // Paper - OBFHELPER
diff --git a/src/main/java/net/minecraft/server/IBlockData.java b/src/main/java/net/minecraft/server/IBlockData.java
index de438816..e821c236 100644
index de43881653..e821c236b4 100644
--- a/src/main/java/net/minecraft/server/IBlockData.java
+++ b/src/main/java/net/minecraft/server/IBlockData.java
@@ -22,11 +22,15 @@ public class IBlockData extends BlockDataAbstract<Block, IBlockData> implements
@ -395,7 +351,7 @@ index de438816..e821c236 100644
public final SoundEffectType getStepSound() { return this.r(); } // Paper - OBFHELPER
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 28b6c9a0..d554d4cf 100644
index 5036348abf..5e6481f115 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -1557,10 +1557,19 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
@ -420,21 +376,23 @@ index 28b6c9a0..d554d4cf 100644
public boolean isSavingDisabled() {
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
index 71f5e3ce..ed41c814 100644
index 62fabb7ad5..9a2b4fa7a2 100644
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
@@ -531,6 +531,11 @@ public class WorldServer extends World {
@@ -531,7 +531,12 @@ public class WorldServer extends World {
});
}
- public void a(Chunk chunk, int i) {
+ // Paper start - optimise random block ticking
+ private final BlockPosition.MutableBlockPosition chunkTickMutablePosition = new BlockPosition.MutableBlockPosition();
+ private final com.destroystokyo.paper.util.math.ThreadUnsafeRandom randomTickRandom = new com.destroystokyo.paper.util.math.ThreadUnsafeRandom();
+ // Paper end
+
public void a(Chunk chunk, int i) {
+ public void a(Chunk chunk, int i) { final int randomTickSpeed = i; // Paper
ChunkCoordIntPair chunkcoordintpair = chunk.getPos();
boolean flag = this.isRaining();
int j = chunkcoordintpair.d();
@@ -539,10 +544,10 @@ public class WorldServer extends World {
GameProfilerFiller gameprofilerfiller = this.getMethodProfiler();
@ -449,7 +407,7 @@ index 71f5e3ce..ed41c814 100644
if (this.isRainingAt(blockposition)) {
DifficultyDamageScaler difficultydamagescaler = this.getDamageScaler(blockposition);
boolean flag1 = this.getGameRules().getBoolean(GameRules.DO_MOB_SPAWNING) && this.random.nextDouble() < (double) difficultydamagescaler.b() * paperConfig.skeleHorseSpawnChance; // Paper
@@ -561,61 +566,81 @@ public class WorldServer extends World {
@@ -561,61 +566,79 @@ public class WorldServer extends World {
}
gameprofilerfiller.exitEnter("iceandsnow");
@ -491,75 +449,69 @@ index 71f5e3ce..ed41c814 100644
- gameprofilerfiller.exitEnter("tickBlocks");
- timings.chunkTicksBlocks.startTiming(); // Paper
- if (i > 0) {
- ChunkSection[] achunksection = chunk.getSections();
- int l = achunksection.length;
-
- for (int i1 = 0; i1 < l; ++i1) {
- ChunkSection chunksection = achunksection[i1];
-
- if (chunksection != Chunk.a && chunksection.d()) {
- int j1 = chunksection.getYPosition();
+ // Paper start - optimise random block ticking
+ gameprofilerfiller.exit();
+ int blocks = chunk.tickingList.size();
+ if (i > 0 && blocks > 0) {
+ if ((this.randomTickRandom.nextInt() & (16 * 16 * 256 - 1)) > blocks) {
+ // we optimise random block ticking by realising that most of the blocks we will try to tick
+ // are not tickable. Instead we only tick tickable blocks, but only if the above
+ // statement is true
+ // Note: The number of blocks that get ticked per tick still REMAIN the same.
+ return;
+ }
+ gameprofilerfiller.enter("tickBlocks");
if (i > 0) {
- ChunkSection[] achunksection = chunk.getSections();
- int l = achunksection.length;
+ gameprofilerfiller.enter("randomTick");
+ timings.chunkTicksBlocks.startTiming(); // Paper
- for (int i1 = 0; i1 < l; ++i1) {
- ChunkSection chunksection = achunksection[i1];
+ ChunkSection[] sections = chunk.getSections();
- if (chunksection != Chunk.a && chunksection.d()) {
- int j1 = chunksection.getYPosition();
+ for (int sectionIndex = 0; sectionIndex < 16; ++sectionIndex) {
+ ChunkSection section = sections[sectionIndex];
+ if (section == null || section.tickingList.size() == 0) {
+ continue;
+ }
- for (int k1 = 0; k1 < i; ++k1) {
- BlockPosition blockposition2 = this.a(j, j1, k, 15);
+ int toTick = i << 4; // i * 16
+ int yPos = sectionIndex << 4;
- gameprofilerfiller.enter("randomTick");
- IBlockData iblockdata = chunksection.getType(blockposition2.getX() - j, blockposition2.getY() - j1, blockposition2.getZ() - k);
+ gameprofilerfiller.enter("randomTick");
+ for (int tick = 0; tick < toTick; ++tick) {
+ int tickingSize = chunk.tickingList.size();
+ if (tickingSize == 0) {
+ break;
+ }
+ for (int a = 0; a < randomTickSpeed; ++a) {
+ int tickingBlocks = section.tickingList.size();
+ int index = this.randomTickRandom.nextInt(16 * 16 * 16);
+ if (index >= tickingBlocks) {
+ continue;
+ }
- if (iblockdata.q()) {
- iblockdata.getBlock().randomTick = true; // Paper - fix MC-113809
- iblockdata.b(this, blockposition2, this.random);
- iblockdata.getBlock().randomTick = false; // Paper - fix MC-113809
- }
+ int index = this.randomTickRandom.nextInt(tickingSize);
+ long raw = chunk.tickingList.getRaw(index);
+ int location = com.destroystokyo.paper.util.maplist.IBlockDataList.getLocationFromRaw(raw);
+ int randomX = location & 15;
+ int randomY = (location >>> (4 + 4)) & 255;
+ int randomZ = (location >>> 4) & 15;
+ long raw = section.tickingList.getRaw(index);
+ int location = com.destroystokyo.paper.util.maplist.IBlockDataList.getLocationFromRaw(raw);
+ int randomX = location & 15;
+ int randomY = ((location >>> (4 + 4)) & 255) | yPos;
+ int randomZ = (location >>> 4) & 15;
- Fluid fluid = iblockdata.getFluid();
+ BlockPosition blockposition2 = blockposition.setValues(j + randomX, randomY, k + randomZ);
+ IBlockData iblockdata = com.destroystokyo.paper.util.maplist.IBlockDataList.getBlockDataFromRaw(raw);
+ BlockPosition blockposition2 = blockposition.setValues(j + randomX, randomY, k + randomZ);
+ IBlockData iblockdata = com.destroystokyo.paper.util.maplist.IBlockDataList.getBlockDataFromRaw(raw);
- if (fluid.h()) {
- fluid.b(this, blockposition2, this.random);
- }
+ iblockdata.getBlock().randomTick = true; // Paper - fix MC-113809
+ iblockdata.b(this, blockposition2, this.randomTickRandom);
+ iblockdata.getBlock().randomTick = false; // Paper - fix MC-113809
+ iblockdata.getBlock().randomTick = true; // Paper - fix MC-113809
+ iblockdata.b(this, blockposition2, this.randomTickRandom);
+ iblockdata.getBlock().randomTick = false; // Paper - fix MC-113809
- gameprofilerfiller.exit();
- }
- }
+ // We drop the fluid tick since LAVA is ALREADY TICKED by the above method.
+ // TODO CHECK ON UPDATE
+ // We drop the fluid tick since LAVA is ALREADY TICKED by the above method.
+ // TODO CHECK ON UPDATE
}
}
+
+ gameprofilerfiller.exit();
+ timings.chunkTicksBlocks.stopTiming(); // Paper
+ gameprofilerfiller.exit();
+ // Paper end
}
- timings.chunkTicksBlocks.stopTiming(); // Paper
@ -568,5 +520,5 @@ index 71f5e3ce..ed41c814 100644
protected BlockPosition a(BlockPosition blockposition) {
--
2.25.1.windows.1
2.25.1

View File

@ -1,4 +1,4 @@
From 5fd4592210f6d4fc991f1f24f09450472eff01fe Mon Sep 17 00:00:00 2001
From 0db5cf9de4d36d8d583b66f58a63c952e2c3df43 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Tue, 14 Jan 2020 14:59:08 -0800
Subject: [PATCH] Optimise Chunk#getFluid
@ -8,10 +8,10 @@ faster on its own, however removing the try catch makes it
easier to inline due to code size
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index 92bb009b..719c6f3e 100644
index 8fc26aa4b8..8695845445 100644
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -379,17 +379,20 @@ public class Chunk implements IChunkAccess {
@@ -365,17 +365,20 @@ public class Chunk implements IChunkAccess {
}
public Fluid a(int i, int j, int k) {
@ -39,7 +39,7 @@ index 92bb009b..719c6f3e 100644
CrashReport crashreport = CrashReport.a(throwable, "Getting fluid state");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Block being got");
@@ -398,6 +401,7 @@ public class Chunk implements IChunkAccess {
@@ -384,6 +387,7 @@ public class Chunk implements IChunkAccess {
});
throw new ReportedException(crashreport);
}
@ -48,7 +48,7 @@ index 92bb009b..719c6f3e 100644
// CraftBukkit start
diff --git a/src/main/java/net/minecraft/server/ChunkSection.java b/src/main/java/net/minecraft/server/ChunkSection.java
index 8b28fb5e..426221f7 100644
index 3eaf893cdf..cda718bba0 100644
--- a/src/main/java/net/minecraft/server/ChunkSection.java
+++ b/src/main/java/net/minecraft/server/ChunkSection.java
@@ -46,7 +46,7 @@ public class ChunkSection {
@ -61,5 +61,5 @@ index 8b28fb5e..426221f7 100644
public void a() {
--
2.25.1.windows.1
2.25.1

View File

@ -1,4 +1,4 @@
From 3d8c3f58220937447eb6d9710b628c636c98d17a Mon Sep 17 00:00:00 2001
From 45ecc86e6bc96656bd8fc6509032739dac6978f6 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 29 Mar 2020 18:26:14 -0400
Subject: [PATCH] Ensure Entity is never double registered
@ -11,7 +11,7 @@ Vs behavior of non ticking of just overwriting state.
We will now simply log a warning when this happens instead of crashing the server.
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 16f2e32d..9cb4e5a1 100644
index 16f2e32d23..9cb4e5a1e6 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -59,6 +59,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
@ -23,7 +23,7 @@ index 16f2e32d..9cb4e5a1 100644
private boolean locked = false;
@Override
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
index 9d35d650..d239afea 100644
index de24b487d2..e198b8c565 100644
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
@@ -520,6 +520,7 @@ public class WorldServer extends World {
@ -34,7 +34,7 @@ index 9d35d650..d239afea 100644
this.registerEntity(entity);
}
} // Paper - timings
@@ -1344,6 +1345,19 @@ public class WorldServer extends World {
@@ -1342,6 +1343,19 @@ public class WorldServer extends World {
public void unregisterEntity(Entity entity) {
org.spigotmc.AsyncCatcher.catchOp("entity unregister"); // Spigot
@ -54,7 +54,7 @@ index 9d35d650..d239afea 100644
// Spigot start
if ( entity instanceof EntityHuman )
{
@@ -1405,9 +1419,21 @@ public class WorldServer extends World {
@@ -1403,9 +1417,21 @@ public class WorldServer extends World {
private void registerEntity(Entity entity) {
org.spigotmc.AsyncCatcher.catchOp("entity register"); // Spigot
@ -78,5 +78,5 @@ index 9d35d650..d239afea 100644
if (entity instanceof EntityEnderDragon) {
EntityComplexPart[] aentitycomplexpart = ((EntityEnderDragon) entity).eo();
--
2.25.1.windows.1
2.25.1

View File

@ -1,4 +1,4 @@
From f285d3fdf296a363f5a1aad7871a095a98ca9943 Mon Sep 17 00:00:00 2001
From 3b90bd5d0498f4f789321cae8e45861b623847a3 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Tue, 31 Mar 2020 03:01:45 -0400
Subject: [PATCH] Fix unregistering entities from unloading chunks
@ -15,10 +15,10 @@ Combine that with a buggy detail of the previous implementation of
the Dupe UUID patch, then this was the likely source of the "Ghost entities"
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
index d239afea..a9cb5245 100644
index e198b8c565..b3e1e3686b 100644
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
@@ -1498,9 +1498,9 @@ public class WorldServer extends World {
@@ -1496,9 +1496,9 @@ public class WorldServer extends World {
}
private void removeEntityFromChunk(Entity entity) {
@ -31,5 +31,5 @@ index d239afea..a9cb5245 100644
}
--
2.25.1.windows.1
2.25.1

View File

@ -1,4 +1,4 @@
From a3fc9acd793ff194a4a64945d08799f360af077d Mon Sep 17 00:00:00 2001
From feee85c5270a67f4b6c53789ecf8509aeaf81ec3 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Thu, 2 Apr 2020 01:42:39 -0400
Subject: [PATCH] Prevent Double PlayerChunkMap adds crashing server
@ -7,7 +7,7 @@ Suspected case would be around the technique used in .stopRiding
Stack will identify any causer of this and warn instead of crashing.
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
index 0186ab9e..e1e4ea79 100644
index 0186ab9e40..e1e4ea793a 100644
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
@@ -1484,6 +1484,14 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
@ -26,10 +26,10 @@ index 0186ab9e..e1e4ea79 100644
if (!(entity instanceof EntityLightning)) {
EntityTypes<?> entitytypes = entity.getEntityType();
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
index a9cb5245..969c6aad 100644
index b3e1e3686b..142770bcd6 100644
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
@@ -1464,7 +1464,7 @@ public class WorldServer extends World {
@@ -1462,7 +1462,7 @@ public class WorldServer extends World {
}
}
@ -38,7 +38,7 @@ index a9cb5245..969c6aad 100644
// CraftBukkit start - SPIGOT-5278
if (entity instanceof EntityDrowned) {
this.navigators.add(((EntityDrowned) entity).navigationWater);
@@ -1475,6 +1475,7 @@ public class WorldServer extends World {
@@ -1473,6 +1473,7 @@ public class WorldServer extends World {
this.navigators.add(((EntityInsentient) entity).getNavigation());
}
entity.valid = true; // CraftBukkit
@ -47,5 +47,5 @@ index a9cb5245..969c6aad 100644
if (entity.origin == null) {
entity.origin = entity.getBukkitEntity().getLocation();
--
2.25.1.windows.1
2.25.1

View File

@ -1,4 +1,4 @@
From 10e05a26c3962896fd2bba8a9cc939c59c668093 Mon Sep 17 00:00:00 2001
From 0467c06a3ef19731b946d4240eb9ab19b22de245 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Wed, 15 Apr 2020 18:08:53 -0700
Subject: [PATCH] Optimise entity hard collision checking
@ -11,10 +11,10 @@ Less crammed entities are likely to show significantly less benefit.
Effectively, this patch optimises crammed entity situations.
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index 719c6f3e..d745eae4 100644
index 8695845445..32c342d313 100644
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -92,6 +92,54 @@ public class Chunk implements IChunkAccess {
@@ -90,6 +90,54 @@ public class Chunk implements IChunkAccess {
private final int[] inventoryEntityCounts = new int[16];
// Paper end
@ -69,7 +69,7 @@ index 719c6f3e..d745eae4 100644
public Chunk(World world, ChunkCoordIntPair chunkcoordintpair, BiomeStorage biomestorage, ChunkConverter chunkconverter, TickList<Block> ticklist, TickList<FluidType> ticklist1, long i, @Nullable ChunkSection[] achunksection, @Nullable Consumer<Chunk> consumer) {
this.sections = new ChunkSection[16];
this.e = Maps.newHashMap();
@@ -539,7 +587,7 @@ public class Chunk implements IChunkAccess {
@@ -525,7 +573,7 @@ public class Chunk implements IChunkAccess {
entity.chunkY = k;
entity.chunkZ = this.loc.z;
this.entities.add(entity); // Paper - per chunk entity list
@ -78,7 +78,7 @@ index 719c6f3e..d745eae4 100644
// Paper start
if (entity instanceof EntityItem) {
itemCounts[k]++;
@@ -576,7 +624,7 @@ public class Chunk implements IChunkAccess {
@@ -562,7 +610,7 @@ public class Chunk implements IChunkAccess {
entity.entitySlice = null;
entity.inChunk = false;
}
@ -88,7 +88,7 @@ index 719c6f3e..d745eae4 100644
}
if (entity instanceof EntityItem) {
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 9cb4e5a1..96a47dd1 100644
index 9cb4e5a1e6..96a47dd1c2 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -210,6 +210,40 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
@ -133,7 +133,7 @@ index 9cb4e5a1..96a47dd1 100644
this.id = Entity.entityCount.incrementAndGet();
this.passengers = Lists.newArrayList();
diff --git a/src/main/java/net/minecraft/server/EntityEnderDragon.java b/src/main/java/net/minecraft/server/EntityEnderDragon.java
index af10fc36..2887cb14 100644
index af10fc36e0..2887cb14e4 100644
--- a/src/main/java/net/minecraft/server/EntityEnderDragon.java
+++ b/src/main/java/net/minecraft/server/EntityEnderDragon.java
@@ -847,6 +847,7 @@ public class EntityEnderDragon extends EntityInsentient implements IMonster {
@ -145,7 +145,7 @@ index af10fc36..2887cb14 100644
return this.children;
}
diff --git a/src/main/java/net/minecraft/server/IEntityAccess.java b/src/main/java/net/minecraft/server/IEntityAccess.java
index 4157e50e..5135308f 100644
index 4157e50e4d..5135308fb6 100644
--- a/src/main/java/net/minecraft/server/IEntityAccess.java
+++ b/src/main/java/net/minecraft/server/IEntityAccess.java
@@ -42,17 +42,26 @@ public interface IEntityAccess {
@ -178,7 +178,7 @@ index 4157e50e..5135308f 100644
return stream.filter(axisalignedbb1::c).map(VoxelShapes::a);
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 46e19d91..09b03aff 100644
index d530508b61..1a3c7c148b 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -1172,6 +1172,32 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
@ -215,5 +215,5 @@ index 46e19d91..09b03aff 100644
public List<Entity> getEntities(@Nullable Entity entity, AxisAlignedBB axisalignedbb, @Nullable Predicate<? super Entity> predicate) {
this.getMethodProfiler().c("getEntities");
--
2.25.1.windows.1
2.25.1