package net.minecraft.world.item;

import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import javax.annotation.Nullable;
import net.minecraft.world.level.Level;
import net.minecraft.resources.ResourceLocation;

public class ClockItem extends Item {
    public ClockItem(final Properties a) {
        super(a);
        this.addProperty(new ResourceLocation("time"), new ItemPropertyFunction() {
            private double rotation;
            private double rota;
            private long lastUpdateTick;
            
            @Override
            public float call(final ItemStack ben, @Nullable Level bjw, @Nullable final LivingEntity akz) {
                final boolean boolean5 = akz != null;
                final Entity akq6 = boolean5 ? akz : ben.getFrame();
                if (bjw == null && akq6 != null) {
                    bjw = akq6.level;
                }
                if (bjw == null) {
                    return 0.0f;
                }
                double double7;
                if (bjw.dimension.isNaturalDimension()) {
                    double7 = bjw.getTimeOfDay(1.0f);
                }
                else {
                    double7 = Math.random();
                }
                double7 = this.wobble(bjw, double7);
                return (float)double7;
            }
            
            private double wobble(final Level bjw, final double double2) {
                if (bjw.getGameTime() != this.lastUpdateTick) {
                    this.lastUpdateTick = bjw.getGameTime();
                    double double3 = double2 - this.rotation;
                    double3 = Mth.positiveModulo(double3 + 0.5, 1.0) - 0.5;
                    this.rota += double3 * 0.1;
                    this.rota *= 0.9;
                    this.rotation = Mth.positiveModulo(this.rotation + this.rota, 1.0);
                }
                return this.rotation;
            }
        });
    }
}
