53 lines
2.0 KiB
Java
53 lines
2.0 KiB
Java
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 bek, @Nullable Level bjt, @Nullable final LivingEntity akw) {
|
|
final boolean boolean5 = akw != null;
|
|
final Entity akn6 = boolean5 ? akw : bek.getFrame();
|
|
if (bjt == null && akn6 != null) {
|
|
bjt = akn6.level;
|
|
}
|
|
if (bjt == null) {
|
|
return 0.0f;
|
|
}
|
|
double double7;
|
|
if (bjt.dimension.isNaturalDimension()) {
|
|
double7 = bjt.getTimeOfDay(1.0f);
|
|
}
|
|
else {
|
|
double7 = Math.random();
|
|
}
|
|
double7 = this.wobble(bjt, double7);
|
|
return (float)double7;
|
|
}
|
|
|
|
private double wobble(final Level bjt, final double double2) {
|
|
if (bjt.getGameTime() != this.lastUpdateTick) {
|
|
this.lastUpdateTick = bjt.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;
|
|
}
|
|
});
|
|
}
|
|
}
|