Skip to content

Commit d2259cb

Browse files
committed
Fix the fix fixing the fix that fixes fixes
yo dawg
1 parent 0a147f9 commit d2259cb

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/org/vivecraft/VivePlayer.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public class VivePlayer {
2828
boolean isVR;
2929
public byte activeHand;
3030
public boolean crawling;
31-
31+
32+
public Vec3D offset = new Vec3D(0, 0, 0);
3233
public Player player;
3334
public String version;
3435

@@ -200,7 +201,7 @@ public Location getHMDPos() {
200201

201202
da.close(); //needed?
202203

203-
return player.getLocation().add(lx, ly, lz);
204+
return player.getLocation().add(lx, ly, lz).add(offset.x, offset.y, offset.z);
204205
}else{
205206
}
206207
} catch (IOException e) {
@@ -234,7 +235,7 @@ public Location getControllerPos(int c) {
234235
return out;
235236
}
236237

237-
return player.getLocation().add(x, y, z);
238+
return player.getLocation().add(x, y, z).add(offset.x, offset.y, offset.z);
238239
}else{
239240
}
240241
} catch (IOException e) {

src/org/vivecraft/utils/AimFixHandler.java

+14-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public AimFixHandler(NetworkManager netManager) {
3030
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
3131
EntityPlayer player = ((PlayerConnection)netManager.i()).player;
3232
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;
3334

3435
if (!VSE.vivePlayers.containsKey(player.getProfile().getId()) || !VSE.vivePlayers.get(player.getProfile().getId()).isVR() || !isCapturedPacket || player.getMinecraftServer() == null) {
3536
// 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
4950
float oldPrevYawHead = player.aK; // field_70758_at
5051
float oldEyeHeight = player.getHeadHeight();
5152

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);
5758

5859
// Inject our custom orientation data
5960
player.setPositionRaw(pos.getX(), pos.getY(), pos.getZ());
@@ -65,6 +66,10 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
6566
player.lastPitch = player.pitch;
6667
player.lastYaw = player.aJ = player.aK = player.yaw;
6768
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());
6873
}
6974

7075
// Call the packet handler directly
@@ -94,6 +99,10 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
9499
player.lastYaw = oldPrevYaw;
95100
player.aK = oldPrevYawHead;
96101
VSE.setPrivateField("headHeight", Entity.class, player, oldEyeHeight);
102+
103+
// Reset offset
104+
if (data != null)
105+
data.offset = new Vec3D(0, 0, 0);
97106
});
98107
}
99108
}

0 commit comments

Comments
 (0)