/
NorthCompassGetter.java
62 lines (54 loc) · 1.82 KB
/
NorthCompassGetter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package knightminer.inspirations.tools.client;
import javax.annotation.Nullable;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItemFrame;
import net.minecraft.item.IItemPropertyGetter;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumFacing.Axis;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class NorthCompassGetter implements IItemPropertyGetter {
double rotation;
double rota;
long lastUpdateTick;
@Override
@SideOnly(Side.CLIENT)
public float apply(ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity) {
if(stack.isOnItemFrame()) {
EntityItemFrame frame = stack.getItemFrame();
EnumFacing facing = frame.getHorizontalFacing();
// TODO: quark support
if(facing == null || facing.getAxis() == Axis.Y) {
return 0;
}
return MathHelper.positiveModulo(facing.getHorizontalIndex()/4f + 0.5f + frame.getRotation()/8f, 1);
}
if(entity == null) {
return 0;
}
if(world == null) {
world = entity.world;
if(entity.world == null) {
return 0;
}
}
double angle = MathHelper.positiveModulo(entity.rotationYaw/360, 1);
return (float) (entity instanceof EntityPlayerSP ? wobble(world, angle) : angle);
}
@SideOnly(Side.CLIENT)
private double wobble(World world, double time) {
if(world.getTotalWorldTime() != lastUpdateTick) {
lastUpdateTick = world.getTotalWorldTime();
double d0 = time - rotation;
d0 = MathHelper.positiveModulo(d0 + 0.5D, 1.0D) - 0.5D;
rota += d0 * 0.1D;
rota *= 0.9D;
rotation = MathHelper.positiveModulo(rotation + rota, 1.0D);
}
return rotation;
}
}