@@ -30,6 +30,7 @@ public AimFixHandler(NetworkManager netManager) {
30
30
public void channelRead (ChannelHandlerContext ctx , Object msg ) throws Exception {
31
31
EntityPlayer player = ((PlayerConnection )netManager .i ()).player ;
32
32
boolean isCapturedPacket = msg instanceof PacketPlayInBlockPlace || msg instanceof PacketPlayInUseItem || msg instanceof PacketPlayInBlockDig ;
33
+ boolean useActiveHand = !(msg instanceof PacketPlayInBlockDig ) || ((PacketPlayInBlockDig )msg ).d () == PacketPlayInBlockDig .EnumPlayerDigType .RELEASE_USE_ITEM ;
33
34
34
35
if (!VSE .vivePlayers .containsKey (player .getProfile ().getId ()) || !VSE .vivePlayers .get (player .getProfile ().getId ()).isVR () || !isCapturedPacket || player .getMinecraftServer () == null ) {
35
36
// we don't need to handle this packet, just defer to the next handler in the pipeline
@@ -49,11 +50,11 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
49
50
float oldPrevYawHead = player .aK ; // field_70758_at
50
51
float oldEyeHeight = player .getHeadHeight ();
51
52
52
- // Check again in case of race condition
53
- if (VSE .vivePlayers .containsKey (player .getProfile ().getId ()) && VSE .vivePlayers .get (player .getProfile ().getId ()).isVR ()) {
54
- VivePlayer data = VSE .vivePlayers .get (player .getProfile ().getId ());
55
- Location pos = data .getControllerPos (0 );
56
- Vec3D aim = data .getControllerDir (0 );
53
+ VivePlayer data = null ;
54
+ if (VSE .vivePlayers .containsKey (player .getProfile ().getId ()) && VSE .vivePlayers .get (player .getProfile ().getId ()).isVR ()) { // Check again in case of race condition
55
+ data = VSE .vivePlayers .get (player .getProfile ().getId ());
56
+ Location pos = data .getControllerPos (useActiveHand ? data . activeHand : 0 );
57
+ Vec3D aim = data .getControllerDir (useActiveHand ? data . activeHand : 0 );
57
58
58
59
// Inject our custom orientation data
59
60
player .setPositionRaw (pos .getX (), pos .getY (), pos .getZ ());
@@ -65,6 +66,10 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
65
66
player .lastPitch = player .pitch ;
66
67
player .lastYaw = player .aJ = player .aK = player .yaw ;
67
68
VSE .setPrivateField ("headHeight" , Entity .class , player , 0 );
69
+
70
+ // Set up offset to fix relative positions
71
+ // P.S. Spigot mappings are stupid
72
+ data .offset = oldPos .add (-pos .getX (), -pos .getY (), -pos .getZ ());
68
73
}
69
74
70
75
// Call the packet handler directly
@@ -94,6 +99,10 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
94
99
player .lastYaw = oldPrevYaw ;
95
100
player .aK = oldPrevYawHead ;
96
101
VSE .setPrivateField ("headHeight" , Entity .class , player , oldEyeHeight );
102
+
103
+ // Reset offset
104
+ if (data != null )
105
+ data .offset = new Vec3D (0 , 0 , 0 );
97
106
});
98
107
}
99
108
}
0 commit comments