Search in sources :

Example 1 with ChunkMap_TrackedEntityAccessor

use of org.spongepowered.common.accessor.server.level.ChunkMap_TrackedEntityAccessor in project SpongeCommon by SpongePowered.

the class EntityMixin method impl$updateVanishState.

@SuppressWarnings({ "ConstantConditions", "RedundantCast" })
@Inject(method = "tick", at = @At("RETURN"))
private void impl$updateVanishState(final CallbackInfo callbackInfo) {
    if (this.impl$pendingVisibilityUpdate && !this.level.isClientSide) {
        final ChunkMap_TrackedEntityAccessor trackerAccessor = ((ChunkMapAccessor) ((ServerWorld) this.level).chunkManager()).accessor$entityMap().get(this.shadow$getId());
        if (trackerAccessor != null && this.impl$visibilityTicks % 4 == 0) {
            if (this.bridge$vanishState().invisible()) {
                for (final ServerPlayer entityPlayerMP : trackerAccessor.accessor$seenBy()) {
                    entityPlayerMP.connection.send(new ClientboundRemoveEntitiesPacket(this.shadow$getId()));
                    if ((Entity) (Object) this instanceof ServerPlayer) {
                        entityPlayerMP.connection.send(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER, (ServerPlayer) (Object) this));
                    }
                }
            } else {
                this.impl$visibilityTicks = 1;
                this.impl$pendingVisibilityUpdate = false;
                for (final ServerPlayer entityPlayerMP : SpongeCommon.server().getPlayerList().getPlayers()) {
                    if ((Entity) (Object) this == entityPlayerMP) {
                        continue;
                    }
                    if ((Entity) (Object) this instanceof ServerPlayer) {
                        final Packet<?> packet = new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, (ServerPlayer) (Object) this);
                        entityPlayerMP.connection.send(packet);
                    }
                    trackerAccessor.accessor$updatePlayer(entityPlayerMP);
                }
            }
        }
        if (this.impl$visibilityTicks > 0) {
            this.impl$visibilityTicks--;
        } else {
            this.impl$pendingVisibilityUpdate = false;
        }
    }
}
Also used : ServerWorld(org.spongepowered.api.world.server.ServerWorld) ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) ChunkMap_TrackedEntityAccessor(org.spongepowered.common.accessor.server.level.ChunkMap_TrackedEntityAccessor) ServerPlayer(net.minecraft.server.level.ServerPlayer) ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with ChunkMap_TrackedEntityAccessor

use of org.spongepowered.common.accessor.server.level.ChunkMap_TrackedEntityAccessor 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

ClientboundRemoveEntitiesPacket (net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket)2 ServerPlayer (net.minecraft.server.level.ServerPlayer)2 ChunkMap_TrackedEntityAccessor (org.spongepowered.common.accessor.server.level.ChunkMap_TrackedEntityAccessor)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ClientboundAddPaintingPacket (net.minecraft.network.protocol.game.ClientboundAddPaintingPacket)1 ClientboundPlayerInfoPacket (net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket)1 ServerLevel (net.minecraft.server.level.ServerLevel)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 ServerWorld (org.spongepowered.api.world.server.ServerWorld)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1 SpongeCommon (org.spongepowered.common.SpongeCommon)1 ChunkMapAccessor (org.spongepowered.common.accessor.server.level.ChunkMapAccessor)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