Search in sources :

Example 1 with ChunkMapAccessor

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);
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ServerWorldProperties(org.spongepowered.api.world.server.storage.ServerWorldProperties) ChunkMapAccessor(org.spongepowered.common.accessor.server.level.ChunkMapAccessor) SerializationBehavior(org.spongepowered.api.world.SerializationBehavior) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 2 with ChunkMapAccessor

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;
    });
}
Also used : ChunkMap_TrackedEntityAccessor(org.spongepowered.common.accessor.server.level.ChunkMap_TrackedEntityAccessor) ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) Painting(net.minecraft.world.entity.decoration.Painting) Launch(org.spongepowered.common.launch.Launch) ChunkMapAccessor(org.spongepowered.common.accessor.server.level.ChunkMapAccessor) SpongeGameConfigs(org.spongepowered.common.config.SpongeGameConfigs) SpongeCommon(org.spongepowered.common.SpongeCommon) ArtType(org.spongepowered.api.data.type.ArtType) ServerLevel(net.minecraft.server.level.ServerLevel) ArrayList(java.util.ArrayList) HangingEntityAccessor(org.spongepowered.common.accessor.world.entity.decoration.HangingEntityAccessor) ServerPlayer(net.minecraft.server.level.ServerPlayer) Keys(org.spongepowered.api.data.Keys) List(java.util.List) DataProviderRegistrator(org.spongepowered.common.data.provider.DataProviderRegistrator) Task(org.spongepowered.api.scheduler.Task) SpongeTicks(org.spongepowered.common.util.SpongeTicks) Motive(net.minecraft.world.entity.decoration.Motive) ClientboundAddPaintingPacket(net.minecraft.network.protocol.game.ClientboundAddPaintingPacket) ServerLevel(net.minecraft.server.level.ServerLevel) ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) ClientboundAddPaintingPacket(net.minecraft.network.protocol.game.ClientboundAddPaintingPacket) ChunkMapAccessor(org.spongepowered.common.accessor.server.level.ChunkMapAccessor) ArrayList(java.util.ArrayList) Painting(net.minecraft.world.entity.decoration.Painting) HangingEntityAccessor(org.spongepowered.common.accessor.world.entity.decoration.HangingEntityAccessor) Motive(net.minecraft.world.entity.decoration.Motive) ArtType(org.spongepowered.api.data.type.ArtType) ChunkMap_TrackedEntityAccessor(org.spongepowered.common.accessor.server.level.ChunkMap_TrackedEntityAccessor) ServerPlayer(net.minecraft.server.level.ServerPlayer) SpongeTicks(org.spongepowered.common.util.SpongeTicks)

Example 3 with ChunkMapAccessor

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();
}
Also used : ChunkSource(net.minecraft.world.level.chunk.ChunkSource) LevelAccessor(net.minecraft.world.level.LevelAccessor) ChunkMapAccessor(org.spongepowered.common.accessor.server.level.ChunkMapAccessor) WorldChunk(org.spongepowered.api.world.chunk.WorldChunk) ArrayList(java.util.ArrayList) ServerChunkCache(net.minecraft.server.level.ServerChunkCache)

Aggregations

ChunkMapAccessor (org.spongepowered.common.accessor.server.level.ChunkMapAccessor)3 ArrayList (java.util.ArrayList)2 ServerLevel (net.minecraft.server.level.ServerLevel)2 List (java.util.List)1 ClientboundAddPaintingPacket (net.minecraft.network.protocol.game.ClientboundAddPaintingPacket)1 ClientboundRemoveEntitiesPacket (net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket)1 ServerChunkCache (net.minecraft.server.level.ServerChunkCache)1 ServerPlayer (net.minecraft.server.level.ServerPlayer)1 Motive (net.minecraft.world.entity.decoration.Motive)1 Painting (net.minecraft.world.entity.decoration.Painting)1 LevelAccessor (net.minecraft.world.level.LevelAccessor)1 ChunkSource (net.minecraft.world.level.chunk.ChunkSource)1 Keys (org.spongepowered.api.data.Keys)1 ArtType (org.spongepowered.api.data.type.ArtType)1 Task (org.spongepowered.api.scheduler.Task)1 SerializationBehavior (org.spongepowered.api.world.SerializationBehavior)1 WorldChunk (org.spongepowered.api.world.chunk.WorldChunk)1 ServerWorldProperties (org.spongepowered.api.world.server.storage.ServerWorldProperties)1 Redirect (org.spongepowered.asm.mixin.injection.Redirect)1 SpongeCommon (org.spongepowered.common.SpongeCommon)1