mirror of
https://github.com/SparklyPower/SparklyPaper.git
synced 2025-12-19 15:09:27 +00:00
735 lines
52 KiB
Diff
735 lines
52 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: MrPowerGamerBR <git@mrpowergamerbr.com>
|
|
Date: Sun, 25 May 2025 21:39:32 -0300
|
|
Subject: [PATCH] Parallel World Ticking
|
|
|
|
|
|
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java
|
|
index f473999938840562b1007a789600342e5796a123..cb62ac5ee7ed059adde7027156421bdbef0924f3 100644
|
|
--- a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java
|
|
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java
|
|
@@ -1116,7 +1116,7 @@ public final class ChunkHolderManager {
|
|
if (changedFullStatus.isEmpty()) {
|
|
return;
|
|
}
|
|
- if (!TickThread.isTickThread()) {
|
|
+ if (!TickThread.isTickThreadFor(world)) { // SparklyPaper - parallel world ticking
|
|
this.taskScheduler.scheduleChunkTask(() -> {
|
|
final ArrayDeque<NewChunkHolder> pendingFullLoadUpdate = ChunkHolderManager.this.pendingFullLoadUpdate;
|
|
for (int i = 0, len = changedFullStatus.size(); i < len; ++i) {
|
|
@@ -1142,7 +1142,7 @@ public final class ChunkHolderManager {
|
|
|
|
// note: never call while inside the chunk system, this will absolutely break everything
|
|
public void processUnloads() {
|
|
- TickThread.ensureTickThread("Cannot unload chunks off-main");
|
|
+ TickThread.ensureTickThread(world, "Cannot unload chunks off-main"); // SparklyPaper - parallel world ticking
|
|
|
|
if (BLOCK_TICKET_UPDATES.get() == Boolean.TRUE) {
|
|
throw new IllegalStateException("Cannot unload chunks recursively");
|
|
@@ -1424,7 +1424,7 @@ public final class ChunkHolderManager {
|
|
|
|
List<NewChunkHolder> changedFullStatus = null;
|
|
|
|
- final boolean isTickThread = TickThread.isTickThread();
|
|
+ final boolean isTickThread = TickThread.isTickThreadFor(world);
|
|
|
|
boolean ret = false;
|
|
final boolean canProcessFullUpdates = processFullUpdates & isTickThread;
|
|
diff --git a/net/minecraft/core/dispenser/DispenseItemBehavior.java b/net/minecraft/core/dispenser/DispenseItemBehavior.java
|
|
index ca02c4c71a0a5a1a0ae8bbb40f0b1b7eac64e6fd..7ce68f270d809ab0b2be45ffdd0346f053bd3b1e 100644
|
|
--- a/net/minecraft/core/dispenser/DispenseItemBehavior.java
|
|
+++ b/net/minecraft/core/dispenser/DispenseItemBehavior.java
|
|
@@ -401,8 +401,8 @@ public interface DispenseItemBehavior {
|
|
// CraftBukkit start
|
|
level.captureTreeGeneration = false;
|
|
if (!level.capturedBlockStates.isEmpty()) {
|
|
- org.bukkit.TreeType treeType = net.minecraft.world.level.block.SaplingBlock.treeType;
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = null;
|
|
+ org.bukkit.TreeType treeType = net.minecraft.world.level.block.SaplingBlock.treeTypeRT.get(); // SparklyPaper - parallel world ticking
|
|
+ net.minecraft.world.level.block.SaplingBlock.treeTypeRT.set(null); // SparklyPaper - parallel world ticking
|
|
org.bukkit.Location location = org.bukkit.craftbukkit.util.CraftLocation.toBukkit(blockPos, level.getWorld());
|
|
List<org.bukkit.block.BlockState> states = new java.util.ArrayList<>(level.capturedBlockStates.values());
|
|
level.capturedBlockStates.clear();
|
|
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
|
|
index 6f492b08d63eb6621383261361f94eaeb7e2f20c..f7d3804035d2c8daecef0b52b4346e9b20da12f2 100644
|
|
--- a/net/minecraft/server/MinecraftServer.java
|
|
+++ b/net/minecraft/server/MinecraftServer.java
|
|
@@ -304,6 +304,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
private final Set<String> pluginsBlockingSleep = new java.util.HashSet<>(); // Paper - API to allow/disallow tick sleeping
|
|
public static final long SERVER_INIT = System.nanoTime(); // Paper - Lag compensation
|
|
public final Set<net.minecraft.world.entity.Entity> entitiesWithScheduledTasks = java.util.concurrent.ConcurrentHashMap.newKeySet(); // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run (concurrent because plugins may schedule tasks async)
|
|
+ public java.util.concurrent.Semaphore serverLevelTickingSemaphore = null; // SparklyPaper - parallel world ticking
|
|
|
|
public static <S extends MinecraftServer> S spin(Function<Thread, S> threadFunction) {
|
|
ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry.init(); // Paper - rewrite data converter system
|
|
@@ -1719,6 +1720,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
}
|
|
|
|
this.isIteratingOverLevels = true; // Paper - Throw exception on world create while being ticked
|
|
+ // SparklyPaper start - parallel world ticking
|
|
+ java.util.ArrayDeque<java.util.concurrent.Future<ServerLevel>> tasks = new java.util.ArrayDeque<>();
|
|
+ try {
|
|
for (ServerLevel serverLevel : this.getAllLevels()) {
|
|
serverLevel.hasPhysicsEvent = org.bukkit.event.block.BlockPhysicsEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - BlockPhysicsEvent
|
|
serverLevel.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - Add EntityMoveEvent
|
|
@@ -1735,27 +1739,46 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
|
|
profilerFiller.push("tick");
|
|
|
|
- try {
|
|
- long i = Util.getNanos(); // SparklyPaper - track world's MSPT
|
|
- serverLevel.tick(hasTimeLeft);
|
|
- // SparklyPaper start - track world's MSPT
|
|
- long j = Util.getNanos() - i;
|
|
-
|
|
- // These are from the "tickServer" function
|
|
- serverLevel.tickTimes5s.add(this.tickCount, j);
|
|
- serverLevel.tickTimes10s.add(this.tickCount, j);
|
|
- serverLevel.tickTimes60s.add(this.tickCount, j);
|
|
- // SparklyPaper end
|
|
- } catch (Throwable var7) {
|
|
- CrashReport crashReport = CrashReport.forThrowable(var7, "Exception ticking world");
|
|
- serverLevel.fillReportDetails(crashReport);
|
|
- throw new ReportedException(crashReport);
|
|
- }
|
|
+ serverLevelTickingSemaphore.acquire();
|
|
+ tasks.add(
|
|
+ serverLevel.tickExecutor.submit(() -> {
|
|
+ try {
|
|
+ ca.spottedleaf.moonrise.common.util.TickThread.ServerLevelTickThread currentThread = (ca.spottedleaf.moonrise.common.util.TickThread.ServerLevelTickThread) Thread.currentThread();
|
|
+ currentThread.currentlyTickingServerLevel = serverLevel;
|
|
+
|
|
+ long i = Util.getNanos(); // SparklyPaper - track world's MSPT
|
|
+ serverLevel.tick(hasTimeLeft);
|
|
+ // SparklyPaper start - track world's MSPT
|
|
+ long j = Util.getNanos() - i;
|
|
+
|
|
+ // These are from the "tickServer" function
|
|
+ serverLevel.tickTimes5s.add(this.tickCount, j);
|
|
+ serverLevel.tickTimes10s.add(this.tickCount, j);
|
|
+ serverLevel.tickTimes60s.add(this.tickCount, j);
|
|
+ // SparklyPaper end
|
|
+ } catch (Throwable throwable) {
|
|
+ CrashReport crashreport = CrashReport.forThrowable(throwable, "Exception ticking world");
|
|
+
|
|
+ serverLevel.fillReportDetails(crashreport);
|
|
+ throw new ReportedException(crashreport);
|
|
+ } finally {
|
|
+ serverLevelTickingSemaphore.release();
|
|
+ }
|
|
+ }, serverLevel)
|
|
+ );
|
|
|
|
profilerFiller.pop();
|
|
profilerFiller.pop();
|
|
serverLevel.explosionDensityCache.clear(); // Paper - Optimize explosions
|
|
}
|
|
+
|
|
+ while (!tasks.isEmpty()) {
|
|
+ tasks.pop().get();
|
|
+ }
|
|
+ } catch (java.lang.InterruptedException | java.util.concurrent.ExecutionException e) {
|
|
+ throw new RuntimeException(e); // Propagate exception
|
|
+ }
|
|
+ // SparklyPaper end
|
|
this.isIteratingOverLevels = false; // Paper - Throw exception on world create while being ticked
|
|
|
|
profilerFiller.popPush("connection");
|
|
@@ -1846,6 +1869,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
Map<ResourceKey<Level>, ServerLevel> oldLevels = this.levels;
|
|
Map<ResourceKey<Level>, ServerLevel> newLevels = Maps.newLinkedHashMap(oldLevels);
|
|
newLevels.remove(level.dimension());
|
|
+ level.tickExecutor.shutdown(); // SparklyPaper - parallel world ticking (We remove it in here instead of ServerLevel.close() because ServerLevel.close() is never called!)
|
|
this.levels = Collections.unmodifiableMap(newLevels);
|
|
}
|
|
// CraftBukkit end
|
|
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
|
|
index c1f8bf904a099e80248d5970ce14fd810e683b4d..9034f43140cd92919d2d6eb7aec47f4bc8019e8c 100644
|
|
--- a/net/minecraft/server/dedicated/DedicatedServer.java
|
|
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
|
|
@@ -193,6 +193,10 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
|
}
|
|
net.sparklypower.sparklypaper.SparklyPaperCommands.INSTANCE.registerCommands(this);
|
|
// SparklyPaper end
|
|
+ // SparklyPaper start - parallel world ticking start
|
|
+ serverLevelTickingSemaphore = new java.util.concurrent.Semaphore(net.sparklypower.sparklypaper.configs.SparklyPaperConfigUtils.INSTANCE.getConfig().getParallelWorldTicking().getThreads());
|
|
+ DedicatedServer.LOGGER.info("Using " + serverLevelTickingSemaphore.availablePermits() + " permits for parallel world ticking"); // SparklyPaper - parallel world ticking
|
|
+ // SparklyPaper end
|
|
|
|
this.setPvpAllowed(properties.pvp);
|
|
this.setFlightAllowed(properties.allowFlight);
|
|
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
|
|
index 2882cd829d4d8e1f8615f085f6908efcdf68ac62..7b058fed0ca52b2f74f5cf4534df7b24c2da5c59 100644
|
|
--- a/net/minecraft/server/level/ServerChunkCache.java
|
|
+++ b/net/minecraft/server/level/ServerChunkCache.java
|
|
@@ -177,7 +177,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
|
|
|
|
// call mid-tick tasks for chunk system
|
|
if ((i & 7) == 0) {
|
|
- ((ca.spottedleaf.moonrise.patches.chunk_system.server.ChunkSystemMinecraftServer)this.level.getServer()).moonrise$executeMidTickTasks();
|
|
+ // ((ca.spottedleaf.moonrise.patches.chunk_system.server.ChunkSystemMinecraftServer)this.level.getServer()).moonrise$executeMidTickTasks(); // SparklyPaper - parallel world ticking (only run mid-tick at the end of each tick / fixes concurrency bugs related to executeMidTickTasks)
|
|
continue;
|
|
}
|
|
}
|
|
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
|
index ecfe237fbecde610d095647a1f2a10f7d426d786..7c178bd28880a8fea2bbae7cd0c81fa59448f439 100644
|
|
--- a/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/net/minecraft/server/level/ServerLevel.java
|
|
@@ -182,7 +182,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
private final MinecraftServer server;
|
|
public final net.minecraft.world.level.storage.PrimaryLevelData serverLevelData; // CraftBukkit - type
|
|
private int lastSpawnChunkRadius;
|
|
- final EntityTickList entityTickList = new EntityTickList();
|
|
+ final EntityTickList entityTickList = new EntityTickList(this); // SparklyPaper - parallel world ticking
|
|
private final ServerWaypointManager waypointManager;
|
|
// Paper - rewrite chunk system
|
|
private final GameEventDispatcher gameEventDispatcher;
|
|
@@ -207,6 +207,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
private final StructureCheck structureCheck;
|
|
private final boolean tickTime;
|
|
private final RandomSequences randomSequences;
|
|
+ public java.util.concurrent.ExecutorService tickExecutor; // SparklyPaper - parallel world ticking
|
|
|
|
// CraftBukkit start
|
|
public final LevelStorageSource.LevelStorageAccess levelStorageAccess;
|
|
@@ -681,6 +682,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
this.chunkDataController = new ca.spottedleaf.moonrise.patches.chunk_system.io.datacontroller.ChunkDataController((ServerLevel)(Object)this, this.chunkTaskScheduler);
|
|
// Paper end - rewrite chunk system
|
|
this.getCraftServer().addWorld(this.getWorld()); // CraftBukkit
|
|
+ this.tickExecutor = java.util.concurrent.Executors.newSingleThreadExecutor(new net.sparklypower.sparklypaper.ServerLevelTickExecutorThreadFactory(getWorld().getName())); // SparklyPaper - parallel world ticking
|
|
}
|
|
|
|
// Paper start
|
|
@@ -1233,7 +1235,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
}
|
|
// Paper start - rewrite chunk system
|
|
if ((++this.tickedBlocksOrFluids & 7L) != 0L) {
|
|
- ((ca.spottedleaf.moonrise.patches.chunk_system.server.ChunkSystemMinecraftServer)this.server).moonrise$executeMidTickTasks();
|
|
+ // ((ca.spottedleaf.moonrise.patches.chunk_system.server.ChunkSystemMinecraftServer)this.server).moonrise$executeMidTickTasks(); // SparklyPaper - parallel world ticking (only run mid-tick at the end of each tick / fixes concurrency bugs related to executeMidTickTasks)
|
|
}
|
|
// Paper end - rewrite chunk system
|
|
|
|
@@ -1246,7 +1248,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
}
|
|
// Paper start - rewrite chunk system
|
|
if ((++this.tickedBlocksOrFluids & 7L) != 0L) {
|
|
- ((ca.spottedleaf.moonrise.patches.chunk_system.server.ChunkSystemMinecraftServer)this.server).moonrise$executeMidTickTasks();
|
|
+ // ((ca.spottedleaf.moonrise.patches.chunk_system.server.ChunkSystemMinecraftServer)this.server).moonrise$executeMidTickTasks(); // SparklyPaper - parallel world ticking (only run mid-tick at the end of each tick / fixes concurrency bugs related to executeMidTickTasks)
|
|
}
|
|
// Paper end - rewrite chunk system
|
|
|
|
@@ -1520,6 +1522,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
}
|
|
|
|
private void addPlayer(ServerPlayer player) {
|
|
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this, "Cannot add player off-main"); // SparklyPaper - parallel world ticking (additional concurrency issues logs)
|
|
Entity entity = this.getEntity(player.getUUID());
|
|
if (entity != null) {
|
|
LOGGER.warn("Force-added player with duplicate UUID {}", player.getUUID());
|
|
@@ -1532,7 +1535,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
|
|
// CraftBukkit start
|
|
private boolean addEntity(Entity entity, @Nullable org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) {
|
|
- org.spigotmc.AsyncCatcher.catchOp("entity add"); // Spigot
|
|
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this, "Cannot add entity off-main"); // SparklyPaper - parallel world ticking (additional concurrency issues logs)
|
|
entity.generation = false; // Paper - Don't fire sync event during generation; Reset flag if it was added during a ServerLevel generation process
|
|
// Paper start - extra debug info
|
|
if (entity.valid) {
|
|
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
|
|
index 53f038e1b5e7a13a08a0c925c8bd3f8a40868195..d6212fb075c02cc7a9e15ff9040e406fc12e4c51 100644
|
|
--- a/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -461,6 +461,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
|
|
return this.viewDistanceHolder;
|
|
}
|
|
// Paper end - rewrite chunk system
|
|
+ public boolean hasTickedAtLeastOnceInNewWorld = false; // SparklyPaper - parallel world ticking (fixes bug in DreamResourceReset where the inventory is opened AFTER the player has changed worlds, if you click with the quick tp torch in a chest, because the inventory is opened AFTER the player has teleported)
|
|
|
|
public ServerPlayer(MinecraftServer server, ServerLevel level, GameProfile gameProfile, ClientInformation clientInformation) {
|
|
super(level, gameProfile);
|
|
@@ -741,6 +742,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
|
|
|
|
@Override
|
|
public void tick() {
|
|
+ hasTickedAtLeastOnceInNewWorld = true; // SparklyPaper - parallel world ticking (see: PARALLEL_NOTES.md - Opening an inventory after a world switch)
|
|
// CraftBukkit start
|
|
if (this.joining) {
|
|
this.joining = false;
|
|
@@ -1396,6 +1398,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
|
|
return this;
|
|
} else {
|
|
// CraftBukkit start
|
|
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureOnlyTickThread("Cannot change dimension of a player off-main, from world " + serverLevel().getWorld().getName() + " to world " + level.getWorld().getName()); // SparklyPaper - parallel world ticking (additional concurrency issues logs)
|
|
/*
|
|
this.isChangingDimension = true;
|
|
LevelData levelData = level.getLevelData();
|
|
@@ -1732,6 +1735,12 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
|
|
return OptionalInt.empty();
|
|
} else {
|
|
// CraftBukkit start
|
|
+ // SparklyPaper start - parallel world ticking (see: PARALLEL_NOTES.md - Opening an inventory after a world switch)
|
|
+ if (!hasTickedAtLeastOnceInNewWorld) {
|
|
+ MinecraftServer.LOGGER.warn("Ignoring request to open container " + abstractContainerMenu + " because we haven't ticked in the current world yet!", new Throwable());
|
|
+ return OptionalInt.empty();
|
|
+ }
|
|
+ // SparklyPaper end
|
|
this.containerMenu = abstractContainerMenu; // Moved up
|
|
if (!this.isImmobile())
|
|
this.connection
|
|
@@ -1796,6 +1805,11 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
|
|
}
|
|
@Override
|
|
public void closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
|
|
+ // SparklyPaper start - parallel world ticking (debugging)
|
|
+ if (net.sparklypower.sparklypaper.configs.SparklyPaperConfigUtils.INSTANCE.getLogContainerCreationStacktraces()) {
|
|
+ MinecraftServer.LOGGER.warn("Closing " + this.getBukkitEntity().getName() + " inventory that was created at", this.containerMenu.containerCreationStacktrace);
|
|
+ }
|
|
+ // SparklyPaper end
|
|
org.bukkit.craftbukkit.event.CraftEventFactory.handleInventoryCloseEvent(this, reason); // CraftBukkit
|
|
// Paper end - Inventory close reason
|
|
this.connection.send(new ClientboundContainerClosePacket(this.containerMenu.containerId));
|
|
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
|
|
index b1524279c02cd3be82338a6bd0320cb125a134d5..f628bd1fea97c2dba581f74c5aff5c5b888c4c9e 100644
|
|
--- a/net/minecraft/server/players/PlayerList.java
|
|
+++ b/net/minecraft/server/players/PlayerList.java
|
|
@@ -112,7 +112,7 @@ public abstract class PlayerList {
|
|
private static final SimpleDateFormat BAN_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
|
|
private final MinecraftServer server;
|
|
public final List<ServerPlayer> players = new java.util.concurrent.CopyOnWriteArrayList(); // CraftBukkit - ArrayList -> CopyOnWriteArrayList: Iterator safety
|
|
- private final Map<UUID, ServerPlayer> playersByUUID = Maps.newHashMap();
|
|
+ private final Map<UUID, ServerPlayer> playersByUUID = Maps.newHashMap(); // SparklyPaper - parallel world ticking (we don't need to replace the original map because we never iterate on top of this map)
|
|
private final UserBanList bans = new UserBanList(USERBANLIST_FILE);
|
|
private final IpBanList ipBans = new IpBanList(IPBANLIST_FILE);
|
|
private final ServerOpList ops = new ServerOpList(OPLIST_FILE);
|
|
@@ -133,7 +133,7 @@ public abstract class PlayerList {
|
|
|
|
// CraftBukkit start
|
|
private org.bukkit.craftbukkit.CraftServer cserver;
|
|
- private final Map<String,ServerPlayer> playersByName = new java.util.HashMap<>();
|
|
+ private final Map<String,ServerPlayer> playersByName = new java.util.HashMap<>(); // SparklyPaper - parallel world ticking (we don't need to replace the original map because we never iterate on top of this map)
|
|
public @Nullable String collideRuleTeamName; // Paper - Configurable player collision
|
|
|
|
public PlayerList(MinecraftServer server, LayeredRegistryAccess<RegistryLayer> registries, PlayerDataStorage playerIo, int maxPlayers) {
|
|
@@ -149,6 +149,7 @@ public abstract class PlayerList {
|
|
abstract public void loadAndSaveFiles(); // Paper - fix converting txt to json file; moved from DedicatedPlayerList constructor
|
|
|
|
public void placeNewPlayer(Connection connection, ServerPlayer player, CommonListenerCookie cookie) {
|
|
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureOnlyTickThread("Cannot place new player off-main"); // SparklyPaper - parallel world ticking (additional concurrency issues logs)
|
|
player.isRealPlayer = true; // Paper
|
|
player.loginTime = System.currentTimeMillis(); // Paper - Replace OfflinePlayer#getLastPlayed
|
|
GameProfile gameProfile = player.getGameProfile();
|
|
@@ -709,6 +710,12 @@ public abstract class PlayerList {
|
|
}
|
|
|
|
public ServerPlayer respawn(ServerPlayer player, boolean keepInventory, Entity.RemovalReason reason, @Nullable org.bukkit.event.player.PlayerRespawnEvent.RespawnReason eventReason, @Nullable org.bukkit.Location location) {
|
|
+ // SparklyPaper - parallel world ticking (additional concurrency issues logs)
|
|
+ if (location != null) // TODO: Is this really never null, or is IntelliJ IDEA tripping? Because I'm pretty sure that this can be null and there isn't any @NotNull annotations
|
|
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureOnlyTickThread("Cannot respawn player off-main, from world " + player.serverLevel().getWorld().getName() + " to world " + location.getWorld().getName());
|
|
+ else
|
|
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureOnlyTickThread("Cannot respawn player off-main, respawning in world " + player.serverLevel().getWorld().getName());
|
|
+ // SparklyPaper end
|
|
player.stopRiding(); // CraftBukkit
|
|
this.players.remove(player);
|
|
this.playersByName.remove(player.getScoreboardName().toLowerCase(java.util.Locale.ROOT)); // Spigot
|
|
@@ -719,6 +726,7 @@ public abstract class PlayerList {
|
|
ServerPlayer serverPlayer = player;
|
|
Level fromWorld = player.level();
|
|
player.wonGame = false;
|
|
+ serverPlayer.hasTickedAtLeastOnceInNewWorld = false; // SparklyPaper - parallel world ticking (see: PARALLEL_NOTES.md - Opening an inventory after a world switch)
|
|
// CraftBukkit end
|
|
serverPlayer.connection = player.connection;
|
|
serverPlayer.restoreFrom(player, keepInventory);
|
|
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
|
index 9344cdbad8415f6ff4d592d3f13390e85477a10d..51481f4fd09e03690182165d44a6cd88f34910fe 100644
|
|
--- a/net/minecraft/world/entity/Entity.java
|
|
+++ b/net/minecraft/world/entity/Entity.java
|
|
@@ -834,7 +834,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
// CraftBukkit start
|
|
public void postTick() {
|
|
// No clean way to break out of ticking once the entity has been copied to a new world, so instead we move the portalling later in the tick cycle
|
|
- if (!(this instanceof ServerPlayer) && this.isAlive()) { // Paper - don't attempt to teleport dead entities
|
|
+ if (false && !(this instanceof ServerPlayer) && this.isAlive()) { // Paper - don't attempt to teleport dead entities // SparklyPaper - parallel world ticking (see issue #9, this is executed in the server level tick for non-player entities)
|
|
this.handlePortal();
|
|
}
|
|
}
|
|
@@ -3999,6 +3999,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
}
|
|
|
|
private Entity teleportCrossDimension(ServerLevel oldLevel, ServerLevel newLevel, TeleportTransition teleportTransition) {
|
|
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(level, "Cannot teleport entity to another world off-main, from world " + this.level.getWorld().getName() + " to world " + level.getWorld().getName()); // SparklyPaper - parallel world ticking (additional concurrency issues logs)
|
|
List<Entity> passengers = this.getPassengers();
|
|
List<Entity> list = new ArrayList<>(passengers.size());
|
|
this.ejectPassengers();
|
|
diff --git a/net/minecraft/world/inventory/AbstractContainerMenu.java b/net/minecraft/world/inventory/AbstractContainerMenu.java
|
|
index 813417a09b4acc7d57e80a53d970767e230d75b1..b8ff46e7543f00d963a6aa87509a1173c0ee34ec 100644
|
|
--- a/net/minecraft/world/inventory/AbstractContainerMenu.java
|
|
+++ b/net/minecraft/world/inventory/AbstractContainerMenu.java
|
|
@@ -95,8 +95,14 @@ public abstract class AbstractContainerMenu {
|
|
|
|
public void startOpen() {}
|
|
// CraftBukkit end
|
|
+ public Throwable containerCreationStacktrace; // SparklyPaper - parallel world ticking (debugging)
|
|
|
|
protected AbstractContainerMenu(@Nullable MenuType<?> menuType, int containerId) {
|
|
+ // SparklyPaper - parallel world ticking (debugging)
|
|
+ if (net.sparklypower.sparklypaper.configs.SparklyPaperConfigUtils.INSTANCE.getLogContainerCreationStacktraces()) {
|
|
+ this.containerCreationStacktrace = new Throwable();
|
|
+ }
|
|
+ // SparklyPaper end
|
|
this.menuType = menuType;
|
|
this.containerId = containerId;
|
|
}
|
|
diff --git a/net/minecraft/world/item/ItemStack.java b/net/minecraft/world/item/ItemStack.java
|
|
index cf283389d9263ba29720bf296a778be9eaf308a7..403cc6642dad5ac46f989ebcfb042fa0a36bc035 100644
|
|
--- a/net/minecraft/world/item/ItemStack.java
|
|
+++ b/net/minecraft/world/item/ItemStack.java
|
|
@@ -398,8 +398,8 @@ public final class ItemStack implements DataComponentHolder {
|
|
if (interactionResult.consumesAction() && serverLevel.captureTreeGeneration && !serverLevel.capturedBlockStates.isEmpty()) {
|
|
serverLevel.captureTreeGeneration = false;
|
|
org.bukkit.Location location = org.bukkit.craftbukkit.util.CraftLocation.toBukkit(clickedPos, serverLevel.getWorld());
|
|
- org.bukkit.TreeType treeType = net.minecraft.world.level.block.SaplingBlock.treeType;
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = null;
|
|
+ org.bukkit.TreeType treeType = net.minecraft.world.level.block.SaplingBlock.treeTypeRT.get(); // SparklyPaper - parallel world ticking
|
|
+ net.minecraft.world.level.block.SaplingBlock.treeTypeRT.set(null);
|
|
List<org.bukkit.craftbukkit.block.CraftBlockState> blocks = new java.util.ArrayList<>(serverLevel.capturedBlockStates.values());
|
|
serverLevel.capturedBlockStates.clear();
|
|
org.bukkit.event.world.StructureGrowEvent structureEvent = null;
|
|
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
|
|
index 722dc48c88e7a7374e7b9aa5bcdc0ed2cc1775b4..0184cf93144246d464ed1654a1850f1729460ce6 100644
|
|
--- a/net/minecraft/world/level/Level.java
|
|
+++ b/net/minecraft/world/level/Level.java
|
|
@@ -161,6 +161,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
|
|
}
|
|
// Paper end - add paper world config
|
|
|
|
+ public io.papermc.paper.redstone.RedstoneWireTurbo turbo = new io.papermc.paper.redstone.RedstoneWireTurbo((net.minecraft.world.level.block.RedStoneWireBlock) net.minecraft.world.level.block.Blocks.REDSTONE_WIRE); // SparklyPaper - parallel world ticking (moved to world)
|
|
public static @Nullable BlockPos lastPhysicsProblem; // Spigot
|
|
private int tileTickPosition;
|
|
public final Map<ServerExplosion.CacheKey, Float> explosionDensityCache = new java.util.HashMap<>(); // Paper - Optimize explosions
|
|
@@ -1085,6 +1086,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
|
|
|
|
@Override
|
|
public boolean setBlock(BlockPos pos, BlockState state, int flags, int recursionLeft) {
|
|
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread((ServerLevel)this, pos, "Updating block asynchronously"); // SparklyPaper - parallel world ticking (additional concurrency issues logs)
|
|
// CraftBukkit start - tree generation
|
|
if (this.captureTreeGeneration) {
|
|
// Paper start - Protect Bedrock and End Portal/Frames from being destroyed
|
|
@@ -1466,7 +1468,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
|
|
tickingBlockEntity.tick();
|
|
// Paper start - rewrite chunk system
|
|
if ((++tickedEntities & 7) == 0) {
|
|
- ((ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemLevel)(Level)(Object)this).moonrise$midTickTasks();
|
|
+ // ((ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemLevel)(Level)(Object)this).moonrise$midTickTasks(); // SparklyPaper - parallel world ticking (only run mid-tick at the end of each tick / fixes concurrency bugs related to executeMidTickTasks)
|
|
}
|
|
// Paper end - rewrite chunk system
|
|
}
|
|
@@ -1489,7 +1491,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
|
|
entity.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DISCARD);
|
|
// Paper end - Prevent block entity and entity crashes
|
|
}
|
|
- this.moonrise$midTickTasks(); // Paper - rewrite chunk system
|
|
+ // this.moonrise$midTickTasks(); // Paper - rewrite chunk system // SparklyPaper - parallel world ticking (only run mid-tick at the end of each tick / fixes concurrency bugs related to executeMidTickTasks)
|
|
}
|
|
|
|
// Paper start - Option to prevent armor stands from doing entity lookups
|
|
@@ -1626,6 +1628,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
|
|
@Nullable
|
|
@Override
|
|
public BlockEntity getBlockEntity(BlockPos pos) {
|
|
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThreadOrAsyncThread((ServerLevel) this, "Cannot read world asynchronously"); // SparklyPaper - parallel world ticking
|
|
// Paper start - Perf: Optimize capturedTileEntities lookup
|
|
net.minecraft.world.level.block.entity.BlockEntity blockEntity;
|
|
if (!this.capturedTileEntities.isEmpty() && (blockEntity = this.capturedTileEntities.get(pos)) != null) {
|
|
@@ -1642,6 +1645,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
|
|
}
|
|
|
|
public void setBlockEntity(BlockEntity blockEntity) {
|
|
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread((ServerLevel) this, "Cannot modify world asynchronously"); // SparklyPaper - parallel world ticking
|
|
BlockPos blockPos = blockEntity.getBlockPos();
|
|
if (!this.isOutsideBuildHeight(blockPos)) {
|
|
// CraftBukkit start
|
|
@@ -1726,6 +1730,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
|
|
|
|
@Override
|
|
public List<Entity> getEntities(@Nullable Entity entity, AABB boundingBox, Predicate<? super Entity> predicate) {
|
|
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread((ServerLevel)this, boundingBox, "Cannot getEntities asynchronously"); // SparklyPaper - parallel world ticking (additional concurrency issues logs)
|
|
Profiler.get().incrementCounter("getEntities");
|
|
List<Entity> list = Lists.newArrayList();
|
|
|
|
@@ -2051,8 +2056,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
|
|
public abstract RecipeAccess recipeAccess();
|
|
|
|
public BlockPos getBlockRandomPos(int x, int y, int z, int yMask) {
|
|
- this.randValue = this.randValue * 3 + 1013904223;
|
|
- int i = this.randValue >> 2;
|
|
+ int i = this.random.nextInt() >> 2; // SparklyPaper - parallel world ticking
|
|
return new BlockPos(x + (i & 15), y + (i >> 16 & yMask), z + (i >> 8 & 15));
|
|
}
|
|
|
|
diff --git a/net/minecraft/world/level/block/FungusBlock.java b/net/minecraft/world/level/block/FungusBlock.java
|
|
index 9711efb088bd0da9168e9bcd0496bd7caddd2974..63da283d68c7e1184d1995aeb08cd8720f1b02ee 100644
|
|
--- a/net/minecraft/world/level/block/FungusBlock.java
|
|
+++ b/net/minecraft/world/level/block/FungusBlock.java
|
|
@@ -76,9 +76,9 @@ public class FungusBlock extends VegetationBlock implements BonemealableBlock {
|
|
// CraftBukkit start
|
|
.map((value) -> {
|
|
if (this == Blocks.WARPED_FUNGUS) {
|
|
- SaplingBlock.treeType = org.bukkit.TreeType.WARPED_FUNGUS;
|
|
+ SaplingBlock.treeTypeRT.set(org.bukkit.TreeType.WARPED_FUNGUS); // SparklyPaper - parallel world ticking
|
|
} else if (this == Blocks.CRIMSON_FUNGUS) {
|
|
- SaplingBlock.treeType = org.bukkit.TreeType.CRIMSON_FUNGUS;
|
|
+ SaplingBlock.treeTypeRT.set(org.bukkit.TreeType.CRIMSON_FUNGUS); // SparklyPaper - parallel world ticking
|
|
}
|
|
return value;
|
|
})
|
|
diff --git a/net/minecraft/world/level/block/MushroomBlock.java b/net/minecraft/world/level/block/MushroomBlock.java
|
|
index d306f5f524dc64618df94c9783c2168dc561a5e3..72363832a60a380869b60b1ec4a352a1e11608a8 100644
|
|
--- a/net/minecraft/world/level/block/MushroomBlock.java
|
|
+++ b/net/minecraft/world/level/block/MushroomBlock.java
|
|
@@ -93,7 +93,7 @@ public class MushroomBlock extends VegetationBlock implements BonemealableBlock
|
|
return false;
|
|
} else {
|
|
level.removeBlock(pos, false);
|
|
- SaplingBlock.treeType = (this == Blocks.BROWN_MUSHROOM) ? org.bukkit.TreeType.BROWN_MUSHROOM : org.bukkit.TreeType.RED_MUSHROOM; // CraftBukkit
|
|
+ SaplingBlock.treeTypeRT.set((this == Blocks.BROWN_MUSHROOM) ? org.bukkit.TreeType.BROWN_MUSHROOM : org.bukkit.TreeType.RED_MUSHROOM); // CraftBukkit // SparklyPaper - parallel world ticking
|
|
if (optional.get().value().place(level, level.getChunkSource().getGenerator(), random, pos)) {
|
|
return true;
|
|
} else {
|
|
diff --git a/net/minecraft/world/level/block/RedStoneWireBlock.java b/net/minecraft/world/level/block/RedStoneWireBlock.java
|
|
index 1943a6aad888647953e2d9dbbeedb0bd81c6f9df..2c4c57deead027fc78904e7e9bc8a2e213225960 100644
|
|
--- a/net/minecraft/world/level/block/RedStoneWireBlock.java
|
|
+++ b/net/minecraft/world/level/block/RedStoneWireBlock.java
|
|
@@ -267,7 +267,7 @@ public class RedStoneWireBlock extends Block {
|
|
|
|
// Paper start - Optimize redstone (Eigencraft)
|
|
// The bulk of the new functionality is found in RedstoneWireTurbo.java
|
|
- io.papermc.paper.redstone.RedstoneWireTurbo turbo = new io.papermc.paper.redstone.RedstoneWireTurbo(this);
|
|
+ // io.papermc.paper.redstone.RedstoneWireTurbo turbo = new io.papermc.paper.redstone.RedstoneWireTurbo(this); // SparklyPaper - parallel world ticking (moved to world)
|
|
|
|
/*
|
|
* Modified version of pre-existing updateSurroundingRedstone, which is called from
|
|
@@ -283,7 +283,7 @@ public class RedStoneWireBlock extends Block {
|
|
if (orientation != null) {
|
|
source = pos.relative(orientation.getFront().getOpposite());
|
|
}
|
|
- turbo.updateSurroundingRedstone(worldIn, pos, state, source);
|
|
+ worldIn.turbo.updateSurroundingRedstone(worldIn, pos, state, source); // SparklyPaper - parallel world ticking
|
|
return;
|
|
}
|
|
updatePowerStrength(worldIn, pos, state, orientation, blockAdded);
|
|
@@ -311,7 +311,7 @@ public class RedStoneWireBlock extends Block {
|
|
// [Space Walker] suppress shape updates and emit those manually to
|
|
// bypass the new neighbor update stack.
|
|
if (level.setBlock(pos, state, Block.UPDATE_KNOWN_SHAPE | Block.UPDATE_CLIENTS)) {
|
|
- turbo.updateNeighborShapes(level, pos, state);
|
|
+ level.turbo.updateNeighborShapes(level, pos, state); // SparklyPaper - parallel world ticking
|
|
}
|
|
}
|
|
}
|
|
diff --git a/net/minecraft/world/level/block/SaplingBlock.java b/net/minecraft/world/level/block/SaplingBlock.java
|
|
index a22cb810622e0ae97bc2a0d6390d026d9482b783..7934299d633524a9ef8c9d315a48c0f5bbe13b4c 100644
|
|
--- a/net/minecraft/world/level/block/SaplingBlock.java
|
|
+++ b/net/minecraft/world/level/block/SaplingBlock.java
|
|
@@ -25,7 +25,7 @@ public class SaplingBlock extends VegetationBlock implements BonemealableBlock {
|
|
public static final IntegerProperty STAGE = BlockStateProperties.STAGE;
|
|
private static final VoxelShape SHAPE = Block.column(12.0, 0.0, 12.0);
|
|
protected final TreeGrower treeGrower;
|
|
- public static @javax.annotation.Nullable org.bukkit.TreeType treeType; // CraftBukkit
|
|
+ public static final ThreadLocal<org.bukkit.TreeType> treeTypeRT = new ThreadLocal<>(); // SparklyPaper - parallel world ticking (from Folia)
|
|
|
|
@Override
|
|
public MapCodec<? extends SaplingBlock> codec() {
|
|
@@ -62,8 +62,8 @@ public class SaplingBlock extends VegetationBlock implements BonemealableBlock {
|
|
this.treeGrower.growTree(level, level.getChunkSource().getGenerator(), pos, state, random);
|
|
level.captureTreeGeneration = false;
|
|
if (!level.capturedBlockStates.isEmpty()) {
|
|
- org.bukkit.TreeType treeType = SaplingBlock.treeType;
|
|
- SaplingBlock.treeType = null;
|
|
+ org.bukkit.TreeType treeType = SaplingBlock.treeTypeRT.get(); // SparklyPaper - parallel world ticking
|
|
+ SaplingBlock.treeTypeRT.set(null);
|
|
org.bukkit.Location location = org.bukkit.craftbukkit.util.CraftLocation.toBukkit(pos, level.getWorld());
|
|
java.util.List<org.bukkit.block.BlockState> blocks = new java.util.ArrayList<>(level.capturedBlockStates.values());
|
|
level.capturedBlockStates.clear();
|
|
diff --git a/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java b/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java
|
|
index 5a094257a31f0500278a706a418e1697f8810ffb..2fde02112ae6e88ef017e8f148cf3ab543f43616 100644
|
|
--- a/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java
|
|
+++ b/net/minecraft/world/level/block/entity/BaseContainerBlockEntity.java
|
|
@@ -76,6 +76,12 @@ public abstract class BaseContainerBlockEntity extends BlockEntity implements Co
|
|
}
|
|
|
|
public static boolean canUnlock(Player player, LockCode code, Component displayName, @Nullable BlockEntity blockEntity) {
|
|
+ // SparklyPaper - parallel world ticking (see: PARALLEL_NOTES.md - Opening an inventory after a world switch)
|
|
+ if (player instanceof net.minecraft.server.level.ServerPlayer serverPlayer && blockEntity != null && blockEntity.getLevel() != serverPlayer.serverLevel()) {
|
|
+ net.minecraft.server.MinecraftServer.LOGGER.warn("Player " + serverPlayer.getScoreboardName() + " (" + serverPlayer.getStringUUID() + ") attempted to open a BlockEntity @ " + blockEntity.getLevel().getWorld().getName() + " " + blockEntity.getBlockPos().getX() + ", " + blockEntity.getBlockPos().getY() + ", " + blockEntity.getBlockPos().getZ() + " while they were in a different world " + serverPlayer.level().getWorld().getName() + " than the block themselves!");
|
|
+ return false;
|
|
+ }
|
|
+ // SparklyPaper end
|
|
if (player instanceof net.minecraft.server.level.ServerPlayer serverPlayer && blockEntity != null && blockEntity.getLevel() != null && blockEntity.getLevel().getBlockEntity(blockEntity.getBlockPos()) == blockEntity) {
|
|
final org.bukkit.block.Block block = org.bukkit.craftbukkit.block.CraftBlock.at(blockEntity.getLevel(), blockEntity.getBlockPos());
|
|
net.kyori.adventure.text.Component lockedMessage = net.kyori.adventure.text.Component.translatable("container.isLocked", io.papermc.paper.adventure.PaperAdventure.asAdventure(displayName));
|
|
diff --git a/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.java b/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.java
|
|
index 0a94670dc20bb9c521b0395633eb100393895f6a..4ad9c47862a9791f72a18835a343bf0e962c14c8 100644
|
|
--- a/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.java
|
|
+++ b/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.java
|
|
@@ -43,9 +43,7 @@ public class SculkCatalystBlockEntity extends BlockEntity implements GameEventLi
|
|
// Paper end - Fix NPE in SculkBloomEvent world access
|
|
|
|
public static void serverTick(Level level, BlockPos pos, BlockState state, SculkCatalystBlockEntity sculkCatalyst) {
|
|
- org.bukkit.craftbukkit.event.CraftEventFactory.sourceBlockOverride = sculkCatalyst.getBlockPos(); // CraftBukkit - SPIGOT-7068: Add source block override, not the most elegant way but better than passing down a BlockPosition up to five methods deep.
|
|
sculkCatalyst.catalystListener.getSculkSpreader().updateCursors(level, pos, level.getRandom(), true);
|
|
- org.bukkit.craftbukkit.event.CraftEventFactory.sourceBlockOverride = null; // CraftBukkit
|
|
}
|
|
|
|
@Override
|
|
diff --git a/net/minecraft/world/level/block/grower/TreeGrower.java b/net/minecraft/world/level/block/grower/TreeGrower.java
|
|
index d23f255de9208f42125fa358a9e8194c984fe4d3..54d64e77dc8c4bef25822d74a30be1a860cfec36 100644
|
|
--- a/net/minecraft/world/level/block/grower/TreeGrower.java
|
|
+++ b/net/minecraft/world/level/block/grower/TreeGrower.java
|
|
@@ -203,55 +203,57 @@ public final class TreeGrower {
|
|
|
|
// CraftBukkit start
|
|
private void setTreeType(Holder<ConfiguredFeature<?, ?>> feature) {
|
|
+ org.bukkit.TreeType treeType; // SparklyPaper - parallel world ticking
|
|
if (feature.is(TreeFeatures.OAK) || feature.is(TreeFeatures.OAK_BEES_005)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.TREE;
|
|
+ treeType = org.bukkit.TreeType.TREE; // SparklyPaper - parallel world ticking
|
|
} else if (feature.is(TreeFeatures.HUGE_RED_MUSHROOM)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.RED_MUSHROOM;
|
|
+ treeType = org.bukkit.TreeType.RED_MUSHROOM; // SparklyPaper - parallel world ticking
|
|
} else if (feature.is(TreeFeatures.HUGE_BROWN_MUSHROOM)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.BROWN_MUSHROOM;
|
|
+ treeType = org.bukkit.TreeType.BROWN_MUSHROOM; // SparklyPaper - parallel world ticking
|
|
} else if (feature.is(TreeFeatures.JUNGLE_TREE)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.COCOA_TREE;
|
|
+ treeType = org.bukkit.TreeType.COCOA_TREE; // SparklyPaper - parallel world ticking
|
|
} else if (feature.is(TreeFeatures.JUNGLE_TREE_NO_VINE)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.SMALL_JUNGLE;
|
|
+ treeType = org.bukkit.TreeType.SMALL_JUNGLE; // SparklyPaper - parallel world ticking
|
|
} else if (feature.is(TreeFeatures.PINE)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.TALL_REDWOOD;
|
|
+ treeType = org.bukkit.TreeType.TALL_REDWOOD; // SparklyPaper - parallel world ticking
|
|
} else if (feature.is(TreeFeatures.SPRUCE)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.REDWOOD;
|
|
+ treeType = org.bukkit.TreeType.REDWOOD; // SparklyPaper - parallel world ticking
|
|
} else if (feature.is(TreeFeatures.ACACIA)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.ACACIA;
|
|
+ treeType = org.bukkit.TreeType.ACACIA; // SparklyPaper - parallel world ticking
|
|
} else if (feature.is(TreeFeatures.BIRCH) || feature.is(TreeFeatures.BIRCH_BEES_005)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.BIRCH;
|
|
+ treeType = org.bukkit.TreeType.BIRCH; // SparklyPaper - parallel world ticking
|
|
} else if (feature.is(TreeFeatures.SUPER_BIRCH_BEES_0002)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.TALL_BIRCH;
|
|
+ treeType = org.bukkit.TreeType.TALL_BIRCH; // SparklyPaper - parallel world ticking
|
|
} else if (feature.is(TreeFeatures.SWAMP_OAK)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.SWAMP;
|
|
+ treeType = org.bukkit.TreeType.SWAMP; // SparklyPaper - parallel world ticking
|
|
} else if (feature.is(TreeFeatures.FANCY_OAK) || feature.is(TreeFeatures.FANCY_OAK_BEES_005)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.BIG_TREE;
|
|
+ treeType = org.bukkit.TreeType.BIG_TREE; // SparklyPaper - parallel world ticking
|
|
} else if (feature.is(TreeFeatures.JUNGLE_BUSH)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.JUNGLE_BUSH;
|
|
+ treeType = org.bukkit.TreeType.JUNGLE_BUSH; // SparklyPaper - parallel world ticking
|
|
} else if (feature.is(TreeFeatures.DARK_OAK)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.DARK_OAK;
|
|
+ treeType = org.bukkit.TreeType.DARK_OAK; // SparklyPaper - parallel world ticking
|
|
} else if (feature.is(TreeFeatures.MEGA_SPRUCE)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.MEGA_REDWOOD;
|
|
+ treeType = org.bukkit.TreeType.MEGA_REDWOOD; // SparklyPaper - parallel world ticking
|
|
} else if (feature.is(TreeFeatures.MEGA_PINE)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.MEGA_PINE;
|
|
+ treeType = org.bukkit.TreeType.MEGA_PINE; // SparklyPaper - parallel world ticking
|
|
} else if (feature.is(TreeFeatures.MEGA_JUNGLE_TREE)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.JUNGLE;
|
|
+ treeType = org.bukkit.TreeType.JUNGLE; // SparklyPaper - parallel world ticking
|
|
} else if (feature.is(TreeFeatures.AZALEA_TREE)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.AZALEA;
|
|
+ treeType = org.bukkit.TreeType.AZALEA; // SparklyPaper - parallel world ticking
|
|
} else if (feature.is(TreeFeatures.MANGROVE)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.MANGROVE;
|
|
+ treeType = org.bukkit.TreeType.MANGROVE; // SparklyPaper - parallel world ticking
|
|
} else if (feature.is(TreeFeatures.TALL_MANGROVE)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.TALL_MANGROVE;
|
|
+ treeType = org.bukkit.TreeType.TALL_MANGROVE; // SparklyPaper - parallel world ticking
|
|
} else if (feature.is(TreeFeatures.CHERRY) || feature.is(TreeFeatures.CHERRY_BEES_005)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.CHERRY;
|
|
+ treeType = org.bukkit.TreeType.CHERRY; // SparklyPaper - parallel world ticking
|
|
} else if (feature.is(TreeFeatures.PALE_OAK) || feature.is(TreeFeatures.PALE_OAK_BONEMEAL)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.PALE_OAK;
|
|
+ treeType = org.bukkit.TreeType.PALE_OAK; // SparklyPaper - parallel world ticking
|
|
} else if (feature.is(TreeFeatures.PALE_OAK_CREAKING)) {
|
|
- net.minecraft.world.level.block.SaplingBlock.treeType = org.bukkit.TreeType.PALE_OAK_CREAKING;
|
|
+ treeType = org.bukkit.TreeType.PALE_OAK_CREAKING; // SparklyPaper - parallel world ticking
|
|
} else {
|
|
throw new IllegalArgumentException("Unknown tree generator " + feature);
|
|
}
|
|
+ net.minecraft.world.level.block.SaplingBlock.treeTypeRT.set(treeType); // SparklyPaper - parallel world ticking
|
|
}
|
|
// CraftBukkit end
|
|
}
|
|
diff --git a/net/minecraft/world/level/chunk/LevelChunk.java b/net/minecraft/world/level/chunk/LevelChunk.java
|
|
index 75578e6ed7233a03d9b6cd3c6d3997f1c6148392..061218fc1fb0c4f4405eb4980ac17622c891aad6 100644
|
|
--- a/net/minecraft/world/level/chunk/LevelChunk.java
|
|
+++ b/net/minecraft/world/level/chunk/LevelChunk.java
|
|
@@ -360,6 +360,7 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
|
|
@Nullable
|
|
@Override
|
|
public BlockState setBlockState(BlockPos pos, BlockState state, int flags) {
|
|
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.level, pos, "Updating block asynchronously"); // SparklyPaper - parallel world ticking (additional concurrency issues logs)
|
|
int y = pos.getY();
|
|
LevelChunkSection section = this.getSection(this.getSectionIndex(y));
|
|
boolean hasOnlyAir = section.hasOnlyAir();
|
|
diff --git a/net/minecraft/world/level/entity/EntityTickList.java b/net/minecraft/world/level/entity/EntityTickList.java
|
|
index 423779a2b690f387a4f0bd07b97b50e0baefda76..24f9632e73d73c2ad68ebf30eb0e4cca7befae2d 100644
|
|
--- a/net/minecraft/world/level/entity/EntityTickList.java
|
|
+++ b/net/minecraft/world/level/entity/EntityTickList.java
|
|
@@ -10,17 +10,26 @@ import net.minecraft.world.entity.Entity;
|
|
|
|
public class EntityTickList {
|
|
private final ca.spottedleaf.moonrise.common.list.IteratorSafeOrderedReferenceSet<net.minecraft.world.entity.Entity> entities = new ca.spottedleaf.moonrise.common.list.IteratorSafeOrderedReferenceSet<>(); // Paper - rewrite chunk system
|
|
+ // SparklyPaper start - parallel world ticking
|
|
+ // Used to track async entity additions/removals/loops
|
|
+ private final net.minecraft.server.level.ServerLevel serverLevel;
|
|
+ public EntityTickList(net.minecraft.server.level.ServerLevel serverLevel) {
|
|
+ this.serverLevel = serverLevel;
|
|
+ }
|
|
+ // SparklyPaper end
|
|
|
|
private void ensureActiveIsNotIterated() {
|
|
// Paper - rewrite chunk system
|
|
}
|
|
|
|
public void add(Entity entity) {
|
|
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(entity, "Asynchronous entity ticklist addition"); // Paper // SparklyPaper - parallel world ticking (additional concurrency issues logs)
|
|
this.ensureActiveIsNotIterated();
|
|
this.entities.add(entity); // Paper - rewrite chunk system
|
|
}
|
|
|
|
public void remove(Entity entity) {
|
|
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(entity, "Asynchronous entity ticklist removal"); // Paper // SparklyPaper - parallel world ticking (additional concurrency issues logs)
|
|
this.ensureActiveIsNotIterated();
|
|
this.entities.remove(entity); // Paper - rewrite chunk system
|
|
}
|
|
@@ -30,6 +39,7 @@ public class EntityTickList {
|
|
}
|
|
|
|
public void forEach(Consumer<Entity> entity) {
|
|
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(serverLevel, "Asynchronous entity ticklist iteration"); // SparklyPaper - parallel world ticking (additional concurrency issues logs)
|
|
// Paper start - rewrite chunk system
|
|
// To ensure nothing weird happens with dimension travelling, do not iterate over new entries...
|
|
// (by dfl iterator() is configured to not iterate over new entries)
|
|
diff --git a/net/minecraft/world/level/saveddata/maps/MapIndex.java b/net/minecraft/world/level/saveddata/maps/MapIndex.java
|
|
index 06025d79cc2297119b22224d777aca79f9d3d9c1..c4c6e28b58ec921ebc18b427e562fbaa51da65c8 100644
|
|
--- a/net/minecraft/world/level/saveddata/maps/MapIndex.java
|
|
+++ b/net/minecraft/world/level/saveddata/maps/MapIndex.java
|
|
@@ -23,8 +23,10 @@ public class MapIndex extends SavedData {
|
|
}
|
|
|
|
public MapId getNextMapId() {
|
|
+ synchronized (TYPE) { // SparklyPaper start - parallel world ticking
|
|
MapId mapId = new MapId(++this.lastMapId);
|
|
this.setDirty();
|
|
return mapId;
|
|
+ } // SparklyPaper end
|
|
}
|
|
}
|