Search in sources :

Example 1 with SEntityTeleportPacket

use of net.minecraft.network.play.server.SEntityTeleportPacket 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)

Aggregations

ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)1 Entity (net.minecraft.entity.Entity)1 LivingEntity (net.minecraft.entity.LivingEntity)1 MobEntity (net.minecraft.entity.MobEntity)1 ItemFrameEntity (net.minecraft.entity.item.ItemFrameEntity)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 AbstractArrowEntity (net.minecraft.entity.projectile.AbstractArrowEntity)1 FilledMapItem (net.minecraft.item.FilledMapItem)1 ItemStack (net.minecraft.item.ItemStack)1 SEntityHeadLookPacket (net.minecraft.network.play.server.SEntityHeadLookPacket)1 SEntityPacket (net.minecraft.network.play.server.SEntityPacket)1 SEntityTeleportPacket (net.minecraft.network.play.server.SEntityTeleportPacket)1 SEntityVelocityPacket (net.minecraft.network.play.server.SEntityVelocityPacket)1 SSetPassengersPacket (net.minecraft.network.play.server.SSetPassengersPacket)1 Vec3d (net.minecraft.util.math.Vec3d)1 TrackedEntity (net.minecraft.world.TrackedEntity)1 MapData (net.minecraft.world.storage.MapData)1 Player (org.bukkit.entity.Player)1 PlayerVelocityEvent (org.bukkit.event.player.PlayerVelocityEvent)1 Vector (org.bukkit.util.Vector)1