refactor: adjust chunk sending (#2770)

- synchronise on the chunk GET object (when available)
 - kick it off to be run at some point on the main server thread
This commit is contained in:
Jordan 2024-06-10 20:11:04 +02:00 committed by dordsor21
parent c6e297942f
commit 62297f9479
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
22 changed files with 139 additions and 117 deletions

View File

@ -246,7 +246,7 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
return; return;
} }
for (IntPair chunk : toSend) { for (IntPair chunk : toSend) {
PaperweightPlatformAdapter.sendChunk(getLevel().getWorld().getHandle(), chunk.x(), chunk.z(), false); PaperweightPlatformAdapter.sendChunk(chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z());
} }
} }
}; };
@ -262,7 +262,7 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.UPDATE) sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.UPDATE)
)); ));
for (IntPair chunk : cachedChunksToSend) { for (IntPair chunk : cachedChunksToSend) {
PaperweightPlatformAdapter.sendChunk(getLevel().getWorld().getHandle(), chunk.x(), chunk.z(), false); PaperweightPlatformAdapter.sendChunk(chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z());
} }
} }
}; };

View File

@ -823,7 +823,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
nmsChunk.setUnsaved(true); nmsChunk.setUnsaved(true);
// send to player // send to player
if (Settings.settings().LIGHTING.MODE == 0 || !Settings.settings().LIGHTING.DELAY_PACKET_SENDING) { if (Settings.settings().LIGHTING.MODE == 0 || !Settings.settings().LIGHTING.DELAY_PACKET_SENDING) {
this.send(finalMask, finalLightUpdate); this.send();
} }
if (finalizer != null) { if (finalizer != null) {
finalizer.run(); finalizer.run();
@ -919,9 +919,9 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
@Override @Override
public void send(int mask, boolean lighting) { public void send() {
synchronized (sendLock) { synchronized (sendLock) {
PaperweightPlatformAdapter.sendChunk(serverLevel, chunkX, chunkZ, lighting); PaperweightPlatformAdapter.sendChunk(this, serverLevel, chunkX, chunkZ);
} }
} }

View File

@ -26,6 +26,7 @@ import net.minecraft.core.Holder;
import net.minecraft.core.IdMap; import net.minecraft.core.IdMap;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ChunkHolder; import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ChunkMap; import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@ -318,7 +319,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void sendChunk(ServerLevel nmsWorld, int chunkX, int chunkZ, boolean lighting) { public static void sendChunk(Object chunk, ServerLevel nmsWorld, int chunkX, int chunkZ) {
ChunkHolder chunkHolder = getPlayerChunk(nmsWorld, chunkX, chunkZ); ChunkHolder chunkHolder = getPlayerChunk(nmsWorld, chunkX, chunkZ);
if (chunkHolder == null) { if (chunkHolder == null) {
return; return;
@ -339,9 +340,10 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
if (levelChunk == null) { if (levelChunk == null) {
return; return;
} }
TaskManager.taskManager().task(() -> { MinecraftServer.getServer().execute(() -> {
ClientboundLevelChunkWithLightPacket packet; ClientboundLevelChunkWithLightPacket packet;
if (PaperLib.isPaper()) { if (PaperLib.isPaper()) {
synchronized (chunk) {
packet = new ClientboundLevelChunkWithLightPacket( packet = new ClientboundLevelChunkWithLightPacket(
levelChunk, levelChunk,
nmsWorld.getChunkSource().getLightEngine(), nmsWorld.getChunkSource().getLightEngine(),
@ -350,7 +352,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
true, true,
false // last false is to not bother with x-ray false // last false is to not bother with x-ray
); );
}
} else { } else {
synchronized (chunk) {
// deprecated on paper - deprecation suppressed // deprecated on paper - deprecation suppressed
packet = new ClientboundLevelChunkWithLightPacket( packet = new ClientboundLevelChunkWithLightPacket(
levelChunk, levelChunk,
@ -360,6 +364,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
true true
); );
} }
}
nearbyPlayers(nmsWorld, coordIntPair).forEach(p -> p.connection.send(packet)); nearbyPlayers(nmsWorld, coordIntPair).forEach(p -> p.connection.send(packet));
}); });
} }

View File

@ -67,7 +67,7 @@ public class PaperweightStarlightRelighter extends StarlightRelighter<ServerLeve
int x = pos.x; int x = pos.x;
int z = pos.z; int z = pos.z;
if (delay) { // we still need to send the block changes of that chunk if (delay) { // we still need to send the block changes of that chunk
PaperweightPlatformAdapter.sendChunk(serverLevel, x, z, false); PaperweightPlatformAdapter.sendChunk(pos, serverLevel, x, z);
} }
serverLevel.getChunkSource().removeTicketAtLevel(FAWE_TICKET, pos, LIGHT_LEVEL, Unit.INSTANCE); serverLevel.getChunkSource().removeTicketAtLevel(FAWE_TICKET, pos, LIGHT_LEVEL, Unit.INSTANCE);
} }

View File

@ -247,7 +247,7 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
return; return;
} }
for (IntPair chunk : toSend) { for (IntPair chunk : toSend) {
PaperweightPlatformAdapter.sendChunk(getLevel().getWorld().getHandle(), chunk.x(), chunk.z(), false); PaperweightPlatformAdapter.sendChunk(chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z());
} }
} }
}; };
@ -263,7 +263,7 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.UPDATE) sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.UPDATE)
)); ));
for (IntPair chunk : cachedChunksToSend) { for (IntPair chunk : cachedChunksToSend) {
PaperweightPlatformAdapter.sendChunk(getLevel().getWorld().getHandle(), chunk.x(), chunk.z(), false); PaperweightPlatformAdapter.sendChunk(chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z());
} }
} }
}; };

View File

@ -821,7 +821,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
nmsChunk.setUnsaved(true); nmsChunk.setUnsaved(true);
// send to player // send to player
if (Settings.settings().LIGHTING.MODE == 0 || !Settings.settings().LIGHTING.DELAY_PACKET_SENDING) { if (Settings.settings().LIGHTING.MODE == 0 || !Settings.settings().LIGHTING.DELAY_PACKET_SENDING) {
this.send(finalMask, finalLightUpdate); this.send();
} }
if (finalizer != null) { if (finalizer != null) {
finalizer.run(); finalizer.run();
@ -917,9 +917,9 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
@Override @Override
public void send(int mask, boolean lighting) { public void send() {
synchronized (sendLock) { synchronized (sendLock) {
PaperweightPlatformAdapter.sendChunk(serverLevel, chunkX, chunkZ, lighting); PaperweightPlatformAdapter.sendChunk(this, serverLevel, chunkX, chunkZ);
} }
} }

View File

@ -26,6 +26,7 @@ import net.minecraft.core.Holder;
import net.minecraft.core.IdMap; import net.minecraft.core.IdMap;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ChunkHolder; import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ChunkMap; import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@ -342,7 +343,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void sendChunk(ServerLevel nmsWorld, int chunkX, int chunkZ, boolean lighting) { public static void sendChunk(Object chunk, ServerLevel nmsWorld, int chunkX, int chunkZ) {
ChunkHolder chunkHolder = getPlayerChunk(nmsWorld, chunkX, chunkZ); ChunkHolder chunkHolder = getPlayerChunk(nmsWorld, chunkX, chunkZ);
if (chunkHolder == null) { if (chunkHolder == null) {
return; return;
@ -363,17 +364,20 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
if (levelChunk == null) { if (levelChunk == null) {
return; return;
} }
TaskManager.taskManager().task(() -> { MinecraftServer.getServer().execute(() -> {
ClientboundLevelChunkWithLightPacket packet; ClientboundLevelChunkWithLightPacket packet;
if (PaperLib.isPaper()) { if (PaperLib.isPaper()) {
synchronized (chunk) {
packet = new ClientboundLevelChunkWithLightPacket( packet = new ClientboundLevelChunkWithLightPacket(
levelChunk, levelChunk,
nmsWorld.getChunkSource().getLightEngine(), nmsWorld.getChunkSource().getLightEngine(),
null, null,
null null,
// last false is to not bother with x-ray false // last false is to not bother with x-ray
); );
}
} else { } else {
synchronized (chunk) {
// deprecated on paper - deprecation suppressed // deprecated on paper - deprecation suppressed
packet = new ClientboundLevelChunkWithLightPacket( packet = new ClientboundLevelChunkWithLightPacket(
levelChunk, levelChunk,
@ -382,6 +386,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
null null
); );
} }
}
nearbyPlayers(nmsWorld, coordIntPair).forEach(p -> p.connection.send(packet)); nearbyPlayers(nmsWorld, coordIntPair).forEach(p -> p.connection.send(packet));
}); });
} }

View File

@ -67,7 +67,7 @@ public class PaperweightStarlightRelighter extends StarlightRelighter<ServerLeve
int x = pos.x; int x = pos.x;
int z = pos.z; int z = pos.z;
if (delay) { // we still need to send the block changes of that chunk if (delay) { // we still need to send the block changes of that chunk
PaperweightPlatformAdapter.sendChunk(serverLevel, x, z, false); PaperweightPlatformAdapter.sendChunk(pos, serverLevel, x, z);
} }
serverLevel.getChunkSource().removeTicketAtLevel(FAWE_TICKET, pos, LIGHT_LEVEL, Unit.INSTANCE); serverLevel.getChunkSource().removeTicketAtLevel(FAWE_TICKET, pos, LIGHT_LEVEL, Unit.INSTANCE);
} }

View File

@ -247,7 +247,7 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
return; return;
} }
for (IntPair chunk : toSend) { for (IntPair chunk : toSend) {
PaperweightPlatformAdapter.sendChunk(getLevel().getWorld().getHandle(), chunk.x(), chunk.z(), false); PaperweightPlatformAdapter.sendChunk(chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z());
} }
} }
}; };
@ -263,7 +263,7 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.UPDATE) sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.UPDATE)
)); ));
for (IntPair chunk : cachedChunksToSend) { for (IntPair chunk : cachedChunksToSend) {
PaperweightPlatformAdapter.sendChunk(getLevel().getWorld().getHandle(), chunk.x(), chunk.z(), false); PaperweightPlatformAdapter.sendChunk(chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z());
} }
} }
}; };

View File

@ -808,7 +808,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
nmsChunk.setUnsaved(true); nmsChunk.setUnsaved(true);
// send to player // send to player
if (Settings.settings().LIGHTING.MODE == 0 || !Settings.settings().LIGHTING.DELAY_PACKET_SENDING) { if (Settings.settings().LIGHTING.MODE == 0 || !Settings.settings().LIGHTING.DELAY_PACKET_SENDING) {
this.send(finalMask, finalLightUpdate); this.send();
} }
if (finalizer != null) { if (finalizer != null) {
finalizer.run(); finalizer.run();
@ -904,9 +904,9 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
@Override @Override
public void send(int mask, boolean lighting) { public void send() {
synchronized (sendLock) { synchronized (sendLock) {
PaperweightPlatformAdapter.sendChunk(serverLevel, chunkX, chunkZ, lighting); PaperweightPlatformAdapter.sendChunk(this, serverLevel, chunkX, chunkZ);
} }
} }

View File

@ -26,6 +26,7 @@ import net.minecraft.core.Holder;
import net.minecraft.core.IdMap; import net.minecraft.core.IdMap;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ChunkHolder; import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ChunkMap; import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@ -333,7 +334,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void sendChunk(ServerLevel nmsWorld, int chunkX, int chunkZ, boolean lighting) { public static void sendChunk(Object chunk, ServerLevel nmsWorld, int chunkX, int chunkZ) {
ChunkHolder chunkHolder = getPlayerChunk(nmsWorld, chunkX, chunkZ); ChunkHolder chunkHolder = getPlayerChunk(nmsWorld, chunkX, chunkZ);
if (chunkHolder == null) { if (chunkHolder == null) {
return; return;
@ -354,17 +355,20 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
if (levelChunk == null) { if (levelChunk == null) {
return; return;
} }
TaskManager.taskManager().task(() -> { MinecraftServer.getServer().execute(() -> {
ClientboundLevelChunkWithLightPacket packet; ClientboundLevelChunkWithLightPacket packet;
if (PaperLib.isPaper()) { if (PaperLib.isPaper()) {
synchronized (chunk) {
packet = new ClientboundLevelChunkWithLightPacket( packet = new ClientboundLevelChunkWithLightPacket(
levelChunk, levelChunk,
nmsWorld.getChunkSource().getLightEngine(), nmsWorld.getChunkSource().getLightEngine(),
null, null,
null null,
// last false is to not bother with x-ray false // last false is to not bother with x-ray
); );
}
} else { } else {
synchronized (chunk) {
// deprecated on paper - deprecation suppressed // deprecated on paper - deprecation suppressed
packet = new ClientboundLevelChunkWithLightPacket( packet = new ClientboundLevelChunkWithLightPacket(
levelChunk, levelChunk,
@ -373,6 +377,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
null null
); );
} }
}
nearbyPlayers(nmsWorld, coordIntPair).forEach(p -> p.connection.send(packet)); nearbyPlayers(nmsWorld, coordIntPair).forEach(p -> p.connection.send(packet));
}); });
} }

View File

@ -67,7 +67,7 @@ public class PaperweightStarlightRelighter extends StarlightRelighter<ServerLeve
int x = pos.x; int x = pos.x;
int z = pos.z; int z = pos.z;
if (delay) { // we still need to send the block changes of that chunk if (delay) { // we still need to send the block changes of that chunk
PaperweightPlatformAdapter.sendChunk(serverLevel, x, z, false); PaperweightPlatformAdapter.sendChunk(pos, serverLevel, x, z);
} }
serverLevel.getChunkSource().removeTicketAtLevel(FAWE_TICKET, pos, LIGHT_LEVEL, Unit.INSTANCE); serverLevel.getChunkSource().removeTicketAtLevel(FAWE_TICKET, pos, LIGHT_LEVEL, Unit.INSTANCE);
} }

View File

@ -246,7 +246,7 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
return; return;
} }
for (IntPair chunk : toSend) { for (IntPair chunk : toSend) {
PaperweightPlatformAdapter.sendChunk(getLevel().getWorld().getHandle(), chunk.x(), chunk.z(), false); PaperweightPlatformAdapter.sendChunk(chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z());
} }
} }
}; };
@ -262,7 +262,7 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.UPDATE) sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.UPDATE)
)); ));
for (IntPair chunk : cachedChunksToSend) { for (IntPair chunk : cachedChunksToSend) {
PaperweightPlatformAdapter.sendChunk(getLevel().getWorld().getHandle(), chunk.x(), chunk.z(), false); PaperweightPlatformAdapter.sendChunk(chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z());
} }
} }
}; };

View File

@ -87,7 +87,6 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
private final Registry<Biome> biomeRegistry; private final Registry<Biome> biomeRegistry;
private final IdMap<Holder<Biome>> biomeHolderIdMap; private final IdMap<Holder<Biome>> biomeHolderIdMap;
private final ConcurrentHashMap<Integer, PaperweightGetBlocks_Copy> copies = new ConcurrentHashMap<>(); private final ConcurrentHashMap<Integer, PaperweightGetBlocks_Copy> copies = new ConcurrentHashMap<>();
private final Object sendLock = new Object();
private LevelChunkSection[] sections; private LevelChunkSection[] sections;
private LevelChunk levelChunk; private LevelChunk levelChunk;
private DataLayer[] blockLight; private DataLayer[] blockLight;
@ -808,7 +807,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
nmsChunk.setUnsaved(true); nmsChunk.setUnsaved(true);
// send to player // send to player
if (Settings.settings().LIGHTING.MODE == 0 || !Settings.settings().LIGHTING.DELAY_PACKET_SENDING) { if (Settings.settings().LIGHTING.MODE == 0 || !Settings.settings().LIGHTING.DELAY_PACKET_SENDING) {
this.send(finalMask, finalLightUpdate); this.send();
} }
if (finalizer != null) { if (finalizer != null) {
finalizer.run(); finalizer.run();
@ -904,10 +903,8 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
@Override @Override
public void send(int mask, boolean lighting) { public void send() {
synchronized (sendLock) { PaperweightPlatformAdapter.sendChunk(this, serverLevel, chunkX, chunkZ);
PaperweightPlatformAdapter.sendChunk(serverLevel, chunkX, chunkZ, lighting);
}
} }
/** /**

View File

@ -26,6 +26,7 @@ import net.minecraft.core.Holder;
import net.minecraft.core.IdMap; import net.minecraft.core.IdMap;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ChunkHolder; import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ChunkMap; import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@ -332,7 +333,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void sendChunk(ServerLevel nmsWorld, int chunkX, int chunkZ, boolean lighting) { public static void sendChunk(Object chunk, ServerLevel nmsWorld, int chunkX, int chunkZ) {
ChunkHolder chunkHolder = getPlayerChunk(nmsWorld, chunkX, chunkZ); ChunkHolder chunkHolder = getPlayerChunk(nmsWorld, chunkX, chunkZ);
if (chunkHolder == null) { if (chunkHolder == null) {
return; return;
@ -353,17 +354,20 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
if (levelChunk == null) { if (levelChunk == null) {
return; return;
} }
TaskManager.taskManager().task(() -> { MinecraftServer.getServer().execute(() -> {
ClientboundLevelChunkWithLightPacket packet; ClientboundLevelChunkWithLightPacket packet;
if (PaperLib.isPaper()) { if (PaperLib.isPaper()) {
synchronized (chunk) {
packet = new ClientboundLevelChunkWithLightPacket( packet = new ClientboundLevelChunkWithLightPacket(
levelChunk, levelChunk,
nmsWorld.getChunkSource().getLightEngine(), nmsWorld.getChunkSource().getLightEngine(),
null, null,
null null,
// last false is to not bother with x-ray false // last false is to not bother with x-ray
); );
}
} else { } else {
synchronized (chunk) {
// deprecated on paper - deprecation suppressed // deprecated on paper - deprecation suppressed
packet = new ClientboundLevelChunkWithLightPacket( packet = new ClientboundLevelChunkWithLightPacket(
levelChunk, levelChunk,
@ -372,6 +376,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
null null
); );
} }
}
nearbyPlayers(nmsWorld, coordIntPair).forEach(p -> p.connection.send(packet)); nearbyPlayers(nmsWorld, coordIntPair).forEach(p -> p.connection.send(packet));
}); });
} }

View File

@ -67,7 +67,7 @@ public class PaperweightStarlightRelighter extends StarlightRelighter<ServerLeve
int x = pos.x; int x = pos.x;
int z = pos.z; int z = pos.z;
if (delay) { // we still need to send the block changes of that chunk if (delay) { // we still need to send the block changes of that chunk
PaperweightPlatformAdapter.sendChunk(serverLevel, x, z, false); PaperweightPlatformAdapter.sendChunk(pos, serverLevel, x, z);
} }
serverLevel.getChunkSource().removeTicketAtLevel(FAWE_TICKET, pos, LIGHT_LEVEL, Unit.INSTANCE); serverLevel.getChunkSource().removeTicketAtLevel(FAWE_TICKET, pos, LIGHT_LEVEL, Unit.INSTANCE);
} }

View File

@ -247,7 +247,7 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
return; return;
} }
for (IntPair chunk : toSend) { for (IntPair chunk : toSend) {
PaperweightPlatformAdapter.sendChunk(getLevel().getWorld().getHandle(), chunk.x(), chunk.z(), false); PaperweightPlatformAdapter.sendChunk(chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z());
} }
} }
}; };
@ -263,7 +263,7 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.UPDATE) sideEffectSet != null && sideEffectSet.shouldApply(SideEffect.UPDATE)
)); ));
for (IntPair chunk : cachedChunksToSend) { for (IntPair chunk : cachedChunksToSend) {
PaperweightPlatformAdapter.sendChunk(getLevel().getWorld().getHandle(), chunk.x(), chunk.z(), false); PaperweightPlatformAdapter.sendChunk(chunk, getLevel().getWorld().getHandle(), chunk.x(), chunk.z());
} }
} }
}; };

View File

@ -810,7 +810,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
nmsChunk.setUnsaved(true); nmsChunk.setUnsaved(true);
// send to player // send to player
if (Settings.settings().LIGHTING.MODE == 0 || !Settings.settings().LIGHTING.DELAY_PACKET_SENDING) { if (Settings.settings().LIGHTING.MODE == 0 || !Settings.settings().LIGHTING.DELAY_PACKET_SENDING) {
this.send(finalMask, finalLightUpdate); this.send();
} }
if (finalizer != null) { if (finalizer != null) {
finalizer.run(); finalizer.run();
@ -906,9 +906,9 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
@Override @Override
public void send(int mask, boolean lighting) { public void send() {
synchronized (sendLock) { synchronized (sendLock) {
PaperweightPlatformAdapter.sendChunk(serverLevel, chunkX, chunkZ, lighting); PaperweightPlatformAdapter.sendChunk(this, serverLevel, chunkX, chunkZ);
} }
} }

View File

@ -26,6 +26,7 @@ import net.minecraft.core.Holder;
import net.minecraft.core.IdMap; import net.minecraft.core.IdMap;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ChunkHolder; import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ChunkMap; import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@ -332,7 +333,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void sendChunk(ServerLevel nmsWorld, int chunkX, int chunkZ, boolean lighting) { public static void sendChunk(Object chunk, ServerLevel nmsWorld, int chunkX, int chunkZ) {
ChunkHolder chunkHolder = getPlayerChunk(nmsWorld, chunkX, chunkZ); ChunkHolder chunkHolder = getPlayerChunk(nmsWorld, chunkX, chunkZ);
if (chunkHolder == null) { if (chunkHolder == null) {
return; return;
@ -351,17 +352,20 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
if (levelChunk == null) { if (levelChunk == null) {
return; return;
} }
TaskManager.taskManager().task(() -> { MinecraftServer.getServer().execute(() -> {
ClientboundLevelChunkWithLightPacket packet; ClientboundLevelChunkWithLightPacket packet;
if (PaperLib.isPaper()) { if (PaperLib.isPaper()) {
synchronized (chunk) {
packet = new ClientboundLevelChunkWithLightPacket( packet = new ClientboundLevelChunkWithLightPacket(
levelChunk, levelChunk,
nmsWorld.getChunkSource().getLightEngine(), nmsWorld.getChunkSource().getLightEngine(),
null, null,
null null,
// last false is to not bother with x-ray false // last false is to not bother with x-ray
); );
}
} else { } else {
synchronized (chunk) {
// deprecated on paper - deprecation suppressed // deprecated on paper - deprecation suppressed
packet = new ClientboundLevelChunkWithLightPacket( packet = new ClientboundLevelChunkWithLightPacket(
levelChunk, levelChunk,
@ -370,6 +374,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
null null
); );
} }
}
nearbyPlayers(nmsWorld, coordIntPair).forEach(p -> p.connection.send(packet)); nearbyPlayers(nmsWorld, coordIntPair).forEach(p -> p.connection.send(packet));
}); });
} }

View File

@ -67,7 +67,7 @@ public class PaperweightStarlightRelighter extends StarlightRelighter<ServerLeve
int x = pos.x; int x = pos.x;
int z = pos.z; int z = pos.z;
if (delay) { // we still need to send the block changes of that chunk if (delay) { // we still need to send the block changes of that chunk
PaperweightPlatformAdapter.sendChunk(serverLevel, x, z, false); PaperweightPlatformAdapter.sendChunk(pos, serverLevel, x, z);
} }
serverLevel.getChunkSource().removeTicketAtLevel(FAWE_TICKET, pos, LIGHT_LEVEL, Unit.INSTANCE); serverLevel.getChunkSource().removeTicketAtLevel(FAWE_TICKET, pos, LIGHT_LEVEL, Unit.INSTANCE);
} }

View File

@ -2,6 +2,6 @@ package com.fastasyncworldedit.bukkit.adapter;
public interface BukkitGetBlocks { public interface BukkitGetBlocks {
void send(int mask, boolean lighting); void send();
} }

View File

@ -137,7 +137,7 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
if (!(chunk instanceof BukkitGetBlocks)) { if (!(chunk instanceof BukkitGetBlocks)) {
throw new IllegalArgumentException("(IChunkGet) chunk not of type BukkitGetBlocks"); throw new IllegalArgumentException("(IChunkGet) chunk not of type BukkitGetBlocks");
} }
((BukkitGetBlocks) chunk).send(mask, lighting); ((BukkitGetBlocks) chunk).send();
} }
} }