Search in sources :

Example 1 with ArtType

use of org.spongepowered.api.data.type.ArtType 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)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 ClientboundAddPaintingPacket (net.minecraft.network.protocol.game.ClientboundAddPaintingPacket)1 ClientboundRemoveEntitiesPacket (net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 ServerPlayer (net.minecraft.server.level.ServerPlayer)1 Motive (net.minecraft.world.entity.decoration.Motive)1 Painting (net.minecraft.world.entity.decoration.Painting)1 Keys (org.spongepowered.api.data.Keys)1 ArtType (org.spongepowered.api.data.type.ArtType)1 Task (org.spongepowered.api.scheduler.Task)1 SpongeCommon (org.spongepowered.common.SpongeCommon)1 ChunkMapAccessor (org.spongepowered.common.accessor.server.level.ChunkMapAccessor)1 ChunkMap_TrackedEntityAccessor (org.spongepowered.common.accessor.server.level.ChunkMap_TrackedEntityAccessor)1 HangingEntityAccessor (org.spongepowered.common.accessor.world.entity.decoration.HangingEntityAccessor)1 SpongeGameConfigs (org.spongepowered.common.config.SpongeGameConfigs)1 DataProviderRegistrator (org.spongepowered.common.data.provider.DataProviderRegistrator)1 Launch (org.spongepowered.common.launch.Launch)1 SpongeTicks (org.spongepowered.common.util.SpongeTicks)1