Search in sources :

Example 1 with SPacketDestroyEntities

use of net.minecraft.network.play.server.SPacketDestroyEntities in project SpongeCommon by SpongePowered.

the class EntityHuman method respawnOnClient.

private void respawnOnClient() {
    this.pushPackets(new SPacketDestroyEntities(this.getEntityId()), this.createPlayerListPacket(SPacketPlayerListItem.Action.ADD_PLAYER));
    this.pushPackets(this.createSpawnPacket());
    removeFromTabListDelayed(null, this.createPlayerListPacket(SPacketPlayerListItem.Action.REMOVE_PLAYER));
}
Also used : SPacketDestroyEntities(net.minecraft.network.play.server.SPacketDestroyEntities)

Example 2 with SPacketDestroyEntities

use of net.minecraft.network.play.server.SPacketDestroyEntities in project SpongeCommon by SpongePowered.

the class MixinEntity method spongeOnUpdate.

@Inject(method = "onUpdate", at = @At("RETURN"))
private void spongeOnUpdate(CallbackInfo callbackInfo) {
    if (this.pendingVisibilityUpdate && !this.world.isRemote) {
        final EntityTracker entityTracker = ((WorldServer) this.world).getEntityTracker();
        final EntityTrackerEntry lookup = entityTracker.trackedEntityHashTable.lookup(this.getEntityId());
        if (this.visibilityTicks % 4 == 0) {
            if (this.isVanished) {
                for (EntityPlayerMP entityPlayerMP : lookup.trackingPlayers) {
                    entityPlayerMP.connection.sendPacket(new SPacketDestroyEntities(this.getEntityId()));
                    if (((Object) this) instanceof EntityPlayerMP) {
                        entityPlayerMP.connection.sendPacket(new SPacketPlayerListItem(SPacketPlayerListItem.Action.REMOVE_PLAYER, (EntityPlayerMP) (Object) this));
                    }
                }
            } else {
                this.visibilityTicks = 1;
                this.pendingVisibilityUpdate = false;
                for (EntityPlayerMP entityPlayerMP : SpongeImpl.getServer().getPlayerList().getPlayers()) {
                    if (((Object) this) == entityPlayerMP) {
                        continue;
                    }
                    if (((Object) this) instanceof EntityPlayerMP) {
                        Packet<?> packet = new SPacketPlayerListItem(SPacketPlayerListItem.Action.ADD_PLAYER, (EntityPlayerMP) (Object) this);
                        entityPlayerMP.connection.sendPacket(packet);
                    }
                    // creates the spawn packet for us
                    Packet<?> newPacket = lookup.createSpawnPacket();
                    entityPlayerMP.connection.sendPacket(newPacket);
                }
            }
        }
        if (this.visibilityTicks > 0) {
            this.visibilityTicks--;
        } else {
            this.pendingVisibilityUpdate = false;
        }
    }
}
Also used : EntityTrackerEntry(net.minecraft.entity.EntityTrackerEntry) EntityTracker(net.minecraft.entity.EntityTracker) SPacketPlayerListItem(net.minecraft.network.play.server.SPacketPlayerListItem) WorldServer(net.minecraft.world.WorldServer) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SPacketDestroyEntities(net.minecraft.network.play.server.SPacketDestroyEntities) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with SPacketDestroyEntities

use of net.minecraft.network.play.server.SPacketDestroyEntities in project SpongeCommon by SpongePowered.

the class EntityUtil method refreshPainting.

public static boolean refreshPainting(EntityPainting painting, EntityPainting.EnumArt art) {
    EntityPainting.EnumArt oldArt = painting.art;
    painting.art = art;
    painting.updateFacingWithBoundingBox(painting.facingDirection);
    if (!painting.onValidSurface()) {
        painting.art = oldArt;
        painting.updateFacingWithBoundingBox(painting.facingDirection);
        return false;
    }
    final EntityTracker paintingTracker = ((WorldServer) painting.world).getEntityTracker();
    EntityTrackerEntry paintingEntry = paintingTracker.trackedEntityHashTable.lookup(painting.getEntityId());
    List<EntityPlayerMP> playerMPs = new ArrayList<>();
    for (EntityPlayerMP player : paintingEntry.trackingPlayers) {
        SPacketDestroyEntities packet = new SPacketDestroyEntities(painting.getEntityId());
        player.connection.sendPacket(packet);
        playerMPs.add(player);
    }
    for (EntityPlayerMP playerMP : playerMPs) {
        SpongeImpl.getGame().getScheduler().createTaskBuilder().delayTicks(SpongeImpl.getGlobalConfig().getConfig().getEntity().getPaintingRespawnDelaly()).execute(() -> {
            final SPacketSpawnPainting packet = new SPacketSpawnPainting(painting);
            playerMP.connection.sendPacket(packet);
        }).submit(SpongeImpl.getPlugin());
    }
    return true;
}
Also used : EntityTrackerEntry(net.minecraft.entity.EntityTrackerEntry) EntityTracker(net.minecraft.entity.EntityTracker) ArrayList(java.util.ArrayList) WorldServer(net.minecraft.world.WorldServer) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) IMixinEntityPlayerMP(org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayerMP) EntityPainting(net.minecraft.entity.item.EntityPainting) SPacketSpawnPainting(net.minecraft.network.play.server.SPacketSpawnPainting) SPacketDestroyEntities(net.minecraft.network.play.server.SPacketDestroyEntities)

Aggregations

SPacketDestroyEntities (net.minecraft.network.play.server.SPacketDestroyEntities)3 EntityTracker (net.minecraft.entity.EntityTracker)2 EntityTrackerEntry (net.minecraft.entity.EntityTrackerEntry)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 WorldServer (net.minecraft.world.WorldServer)2 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)2 ArrayList (java.util.ArrayList)1 EntityPainting (net.minecraft.entity.item.EntityPainting)1 SPacketPlayerListItem (net.minecraft.network.play.server.SPacketPlayerListItem)1 SPacketSpawnPainting (net.minecraft.network.play.server.SPacketSpawnPainting)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1 IMixinEntityPlayerMP (org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayerMP)1