Search in sources :

Example 1 with SSetPassengersPacket

use of net.minecraft.network.play.server.SSetPassengersPacket in project Arclight by IzzelAliz.

the class TrackedEntityMixin method a.

public void a(final Consumer<IPacket<?>> consumer, final ServerPlayerEntity entityplayer) {
    if (this.trackedEntity.removed) {
        return;
    }
    final IPacket<?> packet = this.trackedEntity.createSpawnPacket();
    this.encodedRotationYawHead = MathHelper.floor(this.trackedEntity.getRotationYawHead() * 256.0f / 360.0f);
    consumer.accept(packet);
    if (!this.trackedEntity.getDataManager().isEmpty()) {
        consumer.accept(new SEntityMetadataPacket(this.trackedEntity.getEntityId(), this.trackedEntity.getDataManager(), true));
    }
    boolean flag = this.sendVelocityUpdates;
    if (this.trackedEntity instanceof LivingEntity) {
        final AttributeMap attributemapserver = (AttributeMap) ((LivingEntity) this.trackedEntity).getAttributes();
        final Collection<IAttributeInstance> collection = attributemapserver.getWatchedAttributes();
        if (this.trackedEntity.getEntityId() == entityplayer.getEntityId()) {
            ((ServerPlayerEntityBridge) this.trackedEntity).bridge$getBukkitEntity().injectScaledMaxHealth(collection, false);
        }
        if (!collection.isEmpty()) {
            consumer.accept(new SEntityPropertiesPacket(this.trackedEntity.getEntityId(), collection));
        }
        if (((LivingEntity) this.trackedEntity).isElytraFlying()) {
            flag = true;
        }
    }
    this.velocity = this.trackedEntity.getMotion();
    if (flag && !(packet instanceof SSpawnMobPacket)) {
        consumer.accept(new SEntityVelocityPacket(this.trackedEntity.getEntityId(), this.velocity));
    }
    if (this.trackedEntity instanceof LivingEntity) {
        for (final EquipmentSlotType enumitemslot : EquipmentSlotType.values()) {
            final ItemStack itemstack = ((LivingEntity) this.trackedEntity).getItemStackFromSlot(enumitemslot);
            if (!itemstack.isEmpty()) {
                consumer.accept(new SEntityEquipmentPacket(this.trackedEntity.getEntityId(), enumitemslot, itemstack));
            }
        }
    }
    this.encodedRotationYawHead = MathHelper.floor(this.trackedEntity.getRotationYawHead() * 256.0f / 360.0f);
    consumer.accept(new SEntityHeadLookPacket(this.trackedEntity, (byte) this.encodedRotationYawHead));
    if (this.trackedEntity instanceof LivingEntity) {
        final LivingEntity entityliving = (LivingEntity) this.trackedEntity;
        for (final EffectInstance mobeffect : entityliving.getActivePotionEffects()) {
            consumer.accept(new SPlayEntityEffectPacket(this.trackedEntity.getEntityId(), mobeffect));
        }
    }
    if (!this.trackedEntity.getPassengers().isEmpty()) {
        consumer.accept(new SSetPassengersPacket(this.trackedEntity));
    }
    if (this.trackedEntity.isPassenger()) {
        consumer.accept(new SSetPassengersPacket(this.trackedEntity.getRidingEntity()));
    }
    if (this.trackedEntity instanceof MobEntity) {
        MobEntity mobentity = (MobEntity) this.trackedEntity;
        if (mobentity.getLeashed()) {
            consumer.accept(new SMountEntityPacket(mobentity, mobentity.getLeashHolder()));
        }
    }
}
Also used : SEntityPropertiesPacket(net.minecraft.network.play.server.SEntityPropertiesPacket) EquipmentSlotType(net.minecraft.inventory.EquipmentSlotType) SEntityHeadLookPacket(net.minecraft.network.play.server.SEntityHeadLookPacket) SSetPassengersPacket(net.minecraft.network.play.server.SSetPassengersPacket) IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) SMountEntityPacket(net.minecraft.network.play.server.SMountEntityPacket) SPlayEntityEffectPacket(net.minecraft.network.play.server.SPlayEntityEffectPacket) SEntityEquipmentPacket(net.minecraft.network.play.server.SEntityEquipmentPacket) SSpawnMobPacket(net.minecraft.network.play.server.SSpawnMobPacket) LivingEntity(net.minecraft.entity.LivingEntity) SEntityVelocityPacket(net.minecraft.network.play.server.SEntityVelocityPacket) AttributeMap(net.minecraft.entity.ai.attributes.AttributeMap) SEntityMetadataPacket(net.minecraft.network.play.server.SEntityMetadataPacket) ItemStack(net.minecraft.item.ItemStack) EffectInstance(net.minecraft.potion.EffectInstance) MobEntity(net.minecraft.entity.MobEntity)

Example 2 with SSetPassengersPacket

use of net.minecraft.network.play.server.SSetPassengersPacket in project Arclight by IzzelAliz.

the class TrackedEntityMixin method tick.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void tick() {
    List<Entity> list = this.trackedEntity.getPassengers();
    if (!list.equals(this.passengers)) {
        this.passengers = list;
        this.sendPacket(new SSetPassengersPacket(this.trackedEntity));
    }
    if (this.trackedEntity instanceof ItemFrameEntity) {
        ItemFrameEntity entityitemframe = (ItemFrameEntity) this.trackedEntity;
        ItemStack itemstack = entityitemframe.getDisplayedItem();
        if (this.updateCounter % 10 == 0 && itemstack.getItem() instanceof FilledMapItem) {
            MapData worldmap = FilledMapItem.getMapData(itemstack, this.world);
            for (ServerPlayerEntity entityplayer : this.trackedPlayers) {
                worldmap.updateVisiblePlayers(entityplayer, itemstack);
                IPacket<?> packet = ((FilledMapItem) itemstack.getItem()).getUpdatePacket(itemstack, this.world, entityplayer);
                if (packet != null) {
                    entityplayer.connection.sendPacket(packet);
                }
            }
        }
        this.sendMetadata();
    }
    if (this.updateCounter % this.updateFrequency == 0 || this.trackedEntity.isAirBorne || this.trackedEntity.getDataManager().isDirty()) {
        if (this.trackedEntity.isPassenger()) {
            int i = MathHelper.floor(this.trackedEntity.rotationYaw * 256.0f / 360.0f);
            int j = MathHelper.floor(this.trackedEntity.rotationPitch * 256.0f / 360.0f);
            boolean flag = Math.abs(i - this.encodedRotationYaw) >= 1 || Math.abs(j - this.encodedRotationPitch) >= 1;
            if (flag) {
                this.packetConsumer.accept(new SEntityPacket.LookPacket(this.trackedEntity.getEntityId(), (byte) i, (byte) j, this.trackedEntity.onGround));
                this.encodedRotationYaw = i;
                this.encodedRotationPitch = j;
            }
            this.updateEncodedPosition();
            this.sendMetadata();
            this.riding = true;
        } else {
            ++this.ticksSinceAbsoluteTeleport;
            int i = MathHelper.floor(this.trackedEntity.rotationYaw * 256.0f / 360.0f);
            int j = MathHelper.floor(this.trackedEntity.rotationPitch * 256.0f / 360.0f);
            Vec3d vec3d = this.trackedEntity.getPositionVec().subtract(SEntityPacket.func_218744_a(this.encodedPosX, this.encodedPosY, this.encodedPosZ));
            boolean flag2 = vec3d.lengthSquared() >= 7.62939453125E-6;
            IPacket<?> packet2 = null;
            boolean flag3 = flag2 || this.updateCounter % 60 == 0;
            boolean flag4 = Math.abs(i - this.encodedRotationYaw) >= 1 || Math.abs(j - this.encodedRotationPitch) >= 1;
            if (flag3) {
                this.updateEncodedPosition();
            }
            if (flag4) {
                this.encodedRotationYaw = i;
                this.encodedRotationPitch = j;
            }
            if (this.updateCounter > 0 || this.trackedEntity instanceof AbstractArrowEntity) {
                long k = SEntityPacket.func_218743_a(vec3d.x);
                long l = SEntityPacket.func_218743_a(vec3d.y);
                long i2 = SEntityPacket.func_218743_a(vec3d.z);
                boolean flag5 = k < -32768L || k > 32767L || l < -32768L || l > 32767L || i2 < -32768L || i2 > 32767L;
                if (!flag5 && this.ticksSinceAbsoluteTeleport <= 400 && !this.riding && this.onGround == this.trackedEntity.onGround) {
                    if ((!flag3 || !flag4) && !(this.trackedEntity instanceof AbstractArrowEntity)) {
                        if (flag3) {
                            packet2 = new SEntityPacket.RelativeMovePacket(this.trackedEntity.getEntityId(), (short) k, (short) l, (short) i2, this.trackedEntity.onGround);
                        } else if (flag4) {
                            packet2 = new SEntityPacket.LookPacket(this.trackedEntity.getEntityId(), (byte) i, (byte) j, this.trackedEntity.onGround);
                        }
                    } else {
                        packet2 = new SEntityPacket.MovePacket(this.trackedEntity.getEntityId(), (short) k, (short) l, (short) i2, (byte) i, (byte) j, this.trackedEntity.onGround);
                    }
                } else {
                    this.onGround = this.trackedEntity.onGround;
                    this.ticksSinceAbsoluteTeleport = 0;
                    packet2 = new SEntityTeleportPacket(this.trackedEntity);
                }
            }
            if ((this.sendVelocityUpdates || this.trackedEntity.isAirBorne || (this.trackedEntity instanceof LivingEntity && ((LivingEntity) this.trackedEntity).isElytraFlying())) && this.updateCounter > 0) {
                Vec3d vec3d2 = this.trackedEntity.getMotion();
                double d0 = vec3d2.squareDistanceTo(this.velocity);
                if (d0 > 1.0E-7 || (d0 > 0.0 && vec3d2.lengthSquared() == 0.0)) {
                    this.velocity = vec3d2;
                    this.packetConsumer.accept(new SEntityVelocityPacket(this.trackedEntity.getEntityId(), this.velocity));
                }
            }
            if (packet2 != null) {
                this.packetConsumer.accept(packet2);
            }
            this.sendMetadata();
            this.riding = false;
        }
        int i = MathHelper.floor(this.trackedEntity.getRotationYawHead() * 256.0f / 360.0f);
        if (Math.abs(i - this.encodedRotationYawHead) >= 1) {
            this.packetConsumer.accept(new SEntityHeadLookPacket(this.trackedEntity, (byte) i));
            this.encodedRotationYawHead = i;
        }
        this.trackedEntity.isAirBorne = false;
    }
    ++this.updateCounter;
    if (this.trackedEntity.velocityChanged) {
        boolean cancelled = false;
        if (this.trackedEntity instanceof ServerPlayerEntity) {
            Player player = ((ServerPlayerEntityBridge) this.trackedEntity).bridge$getBukkitEntity();
            Vector velocity = player.getVelocity();
            PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone());
            Bukkit.getPluginManager().callEvent(event);
            if (event.isCancelled()) {
                cancelled = true;
            } else if (!velocity.equals(event.getVelocity())) {
                player.setVelocity(event.getVelocity());
            }
        }
        if (!cancelled) {
            this.sendPacket(new SEntityVelocityPacket(this.trackedEntity));
        }
        this.trackedEntity.velocityChanged = false;
    }
}
Also used : AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) LivingEntity(net.minecraft.entity.LivingEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ItemFrameEntity(net.minecraft.entity.item.ItemFrameEntity) MobEntity(net.minecraft.entity.MobEntity) Entity(net.minecraft.entity.Entity) TrackedEntity(net.minecraft.world.TrackedEntity) PlayerVelocityEvent(org.bukkit.event.player.PlayerVelocityEvent) SEntityHeadLookPacket(net.minecraft.network.play.server.SEntityHeadLookPacket) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) LivingEntity(net.minecraft.entity.LivingEntity) SEntityVelocityPacket(net.minecraft.network.play.server.SEntityVelocityPacket) MapData(net.minecraft.world.storage.MapData) FilledMapItem(net.minecraft.item.FilledMapItem) SEntityTeleportPacket(net.minecraft.network.play.server.SEntityTeleportPacket) Vector(org.bukkit.util.Vector) Player(org.bukkit.entity.Player) SEntityPacket(net.minecraft.network.play.server.SEntityPacket) SEntityHeadLookPacket(net.minecraft.network.play.server.SEntityHeadLookPacket) SSetPassengersPacket(net.minecraft.network.play.server.SSetPassengersPacket) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Vec3d(net.minecraft.util.math.Vec3d) ItemFrameEntity(net.minecraft.entity.item.ItemFrameEntity) ItemStack(net.minecraft.item.ItemStack) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 3 with SSetPassengersPacket

use of net.minecraft.network.play.server.SSetPassengersPacket in project Mekanism by mekanism.

the class TileEntityTeleporter method teleportEntityTo.

@Nullable
public static Entity teleportEntityTo(Entity entity, World targetWorld, BlockPos target) {
    if (entity.getCommandSenderWorld().dimension() == targetWorld.dimension()) {
        entity.teleportTo(target.getX() + 0.5, target.getY(), target.getZ() + 0.5);
        if (!entity.getPassengers().isEmpty()) {
            // Force re-apply any passengers so that players don't get "stuck" outside what they may be riding
            ((ServerChunkProvider) entity.getCommandSenderWorld().getChunkSource()).broadcast(entity, new SSetPassengersPacket(entity));
            Entity controller = entity.getControllingPassenger();
            if (controller != entity && controller instanceof ServerPlayerEntity && !(controller instanceof FakePlayer)) {
                ServerPlayerEntity player = (ServerPlayerEntity) controller;
                if (player.connection != null) {
                    // Force sync the fact that the vehicle moved to the client that is controlling it
                    // so that it makes sure to use the correct positions when sending move packets
                    // back to the server instead of running into moved wrongly issues
                    player.connection.send(new SMoveVehiclePacket(entity));
                }
            }
        }
        return entity;
    }
    Vector3d destination = new Vector3d(target.getX() + 0.5, target.getY(), target.getZ() + 0.5);
    // Note: We grab the passengers here instead of in placeEntity as changeDimension starts by removing any passengers
    List<Entity> passengers = entity.getPassengers();
    return entity.changeDimension((ServerWorld) targetWorld, new ITeleporter() {

        @Override
        public Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function<Boolean, Entity> repositionEntity) {
            Entity repositionedEntity = repositionEntity.apply(false);
            if (repositionedEntity != null) {
                // Teleport all passengers to the other dimension and then make them start riding the entity again
                for (Entity passenger : passengers) {
                    teleportPassenger(destWorld, destination, repositionedEntity, passenger);
                }
            }
            return repositionedEntity;
        }

        @Override
        public PortalInfo getPortalInfo(Entity entity, ServerWorld destWorld, Function<ServerWorld, PortalInfo> defaultPortalInfo) {
            return new PortalInfo(destination, entity.getDeltaMovement(), entity.yRot, entity.xRot);
        }

        @Override
        public boolean playTeleportSound(ServerPlayerEntity player, ServerWorld sourceWorld, ServerWorld destWorld) {
            return false;
        }
    });
}
Also used : ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Entity(net.minecraft.entity.Entity) PartEntity(net.minecraftforge.entity.PartEntity) SSetPassengersPacket(net.minecraft.network.play.server.SSetPassengersPacket) PortalInfo(net.minecraft.block.PortalInfo) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SMoveVehiclePacket(net.minecraft.network.play.server.SMoveVehiclePacket) FakePlayer(net.minecraftforge.common.util.FakePlayer) ServerWorld(net.minecraft.world.server.ServerWorld) Vector3d(net.minecraft.util.math.vector.Vector3d) ITeleporter(net.minecraftforge.common.util.ITeleporter) ServerChunkProvider(net.minecraft.world.server.ServerChunkProvider) Nullable(javax.annotation.Nullable)

Aggregations

SSetPassengersPacket (net.minecraft.network.play.server.SSetPassengersPacket)3 Entity (net.minecraft.entity.Entity)2 LivingEntity (net.minecraft.entity.LivingEntity)2 MobEntity (net.minecraft.entity.MobEntity)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 ItemStack (net.minecraft.item.ItemStack)2 SEntityHeadLookPacket (net.minecraft.network.play.server.SEntityHeadLookPacket)2 SEntityVelocityPacket (net.minecraft.network.play.server.SEntityVelocityPacket)2 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)1 Nullable (javax.annotation.Nullable)1 PortalInfo (net.minecraft.block.PortalInfo)1 AttributeMap (net.minecraft.entity.ai.attributes.AttributeMap)1 IAttributeInstance (net.minecraft.entity.ai.attributes.IAttributeInstance)1 ItemFrameEntity (net.minecraft.entity.item.ItemFrameEntity)1 AbstractArrowEntity (net.minecraft.entity.projectile.AbstractArrowEntity)1 EquipmentSlotType (net.minecraft.inventory.EquipmentSlotType)1 FilledMapItem (net.minecraft.item.FilledMapItem)1 SEntityEquipmentPacket (net.minecraft.network.play.server.SEntityEquipmentPacket)1 SEntityMetadataPacket (net.minecraft.network.play.server.SEntityMetadataPacket)1 SEntityPacket (net.minecraft.network.play.server.SEntityPacket)1