use of org.spongepowered.common.accessor.server.level.ChunkMapAccessor in project SpongeCommon by SpongePowered.
the class ServerChunkCacheMixin method impl$useSerializationBehaviorWhenSaving.
// @formatter:on
@Redirect(method = "save", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ChunkMap;saveAllChunks(Z)V"))
private void impl$useSerializationBehaviorWhenSaving(final ChunkMap chunkManager, final boolean flush) {
final ServerLevel world = this.level;
final SerializationBehavior serializationBehavior = ((ServerWorldProperties) world.getLevelData()).serializationBehavior();
if (serializationBehavior == SerializationBehavior.AUTOMATIC || serializationBehavior == SerializationBehavior.MANUAL) {
((ChunkMapAccessor) chunkManager).invoker$saveAllChunks(flush);
}
}
use of org.spongepowered.common.accessor.server.level.ChunkMapAccessor in project SpongeCommon by SpongePowered.
the class PaintingData method register.
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(Painting.class).create(Keys.ART_TYPE).get(h -> (ArtType) h.motive).setAnd((h, v) -> {
if (!h.level.isClientSide) {
final Motive oldArt = h.motive;
h.motive = (Motive) v;
((HangingEntityAccessor) h).invoker$setDirection(h.getDirection());
if (!h.survives()) {
h.motive = oldArt;
((HangingEntityAccessor) h).invoker$setDirection(h.getDirection());
return false;
}
final ChunkMapAccessor chunkManager = (ChunkMapAccessor) ((ServerLevel) h.level).getChunkSource().chunkMap;
final ChunkMap_TrackedEntityAccessor paintingTracker = chunkManager.accessor$entityMap().get(h.getId());
if (paintingTracker == null) {
return true;
}
final List<ServerPlayer> players = new ArrayList<>();
for (final ServerPlayer player : paintingTracker.accessor$seenBy()) {
final ClientboundRemoveEntitiesPacket packet = new ClientboundRemoveEntitiesPacket(h.getId());
player.connection.send(packet);
players.add(player);
}
for (final ServerPlayer player : players) {
SpongeCommon.serverScheduler().submit(Task.builder().plugin(Launch.instance().commonPlugin()).delay(new SpongeTicks(SpongeGameConfigs.getForWorld(h.level).get().entity.painting.respawnDelay)).execute(() -> {
final ClientboundAddPaintingPacket packet = new ClientboundAddPaintingPacket(h);
player.connection.send(packet);
}).build());
}
return true;
}
return true;
});
}
use of org.spongepowered.common.accessor.server.level.ChunkMapAccessor in project SpongeCommon by SpongePowered.
the class LevelMixin_API method loadedChunks.
@Override
public Iterable<WorldChunk> loadedChunks() {
final ChunkSource chunkProvider = ((LevelAccessor) this).getChunkSource();
if (chunkProvider instanceof ServerChunkCache) {
final ChunkMapAccessor chunkManager = (ChunkMapAccessor) ((ServerChunkCache) chunkProvider).chunkMap;
final List<WorldChunk> chunks = new ArrayList<>();
chunkManager.invoker$getChunks().forEach(holder -> {
final WorldChunk chunk = (WorldChunk) holder.getTickingChunk();
if (chunk != null) {
chunks.add(chunk);
}
});
return chunks;
}
return Collections.emptyList();
}
Aggregations