use of net.minecraft.item.FilledMapItem 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;
}
}
Aggregations