Search in sources :

Example 1 with EntityTracker

use of net.minecraft.entity.EntityTracker 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 2 with EntityTracker

use of net.minecraft.entity.EntityTracker 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)

Example 3 with EntityTracker

use of net.minecraft.entity.EntityTracker in project Random-Things by lumien231.

the class EntityProjectedItem method onCollideWithPlayer.

/**
 * Called by a player entity when they collide with an entity
 */
@Override
public void onCollideWithPlayer(EntityPlayer entityIn) {
    if (!this.world.isRemote && this.canBePickedUp) {
        ItemStack itemstack = this.getItem();
        int i = itemstack.getCount();
        if (i <= 0 || entityIn.inventory.addItemStackToInventory(itemstack)) {
            if (!this.isSilent()) {
                this.world.playSound((EntityPlayer) null, entityIn.posX, entityIn.posY, entityIn.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
            }
            entityIn.onItemPickup(this, i);
            if (!this.world.isRemote) {
                EntityTracker entitytracker = ((WorldServer) this.world).getEntityTracker();
                entitytracker.sendToTracking(this, new SPacketCollectItem(this.getEntityId(), entityIn.getEntityId(), this.getItem().getCount()));
            }
            if (itemstack.getCount() <= 0) {
                this.setDead();
            }
            entityIn.addStat(StatList.getObjectsPickedUpStats(itemstack.getItem()), i);
        }
    }
}
Also used : EntityTracker(net.minecraft.entity.EntityTracker) WorldServer(net.minecraft.world.WorldServer) ItemStack(net.minecraft.item.ItemStack) SPacketCollectItem(net.minecraft.network.play.server.SPacketCollectItem)

Aggregations

EntityTracker (net.minecraft.entity.EntityTracker)3 WorldServer (net.minecraft.world.WorldServer)3 EntityTrackerEntry (net.minecraft.entity.EntityTrackerEntry)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 SPacketDestroyEntities (net.minecraft.network.play.server.SPacketDestroyEntities)2 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)2 ArrayList (java.util.ArrayList)1 EntityPainting (net.minecraft.entity.item.EntityPainting)1 ItemStack (net.minecraft.item.ItemStack)1 SPacketCollectItem (net.minecraft.network.play.server.SPacketCollectItem)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