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()));
}
}
}
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;
}
}
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;
}
});
}
Aggregations