Skip to content

Commit

Permalink
Fix the fix fixing the fix that fixes fixes
Browse files Browse the repository at this point in the history
yo dawg
  • Loading branch information
Techjar committed Aug 5, 2020
1 parent 0a147f9 commit d2259cb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/org/vivecraft/VivePlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public class VivePlayer {
boolean isVR;
public byte activeHand;
public boolean crawling;


public Vec3D offset = new Vec3D(0, 0, 0);
public Player player;
public String version;

Expand Down Expand Up @@ -200,7 +201,7 @@ public Location getHMDPos() {

da.close(); //needed?

return player.getLocation().add(lx, ly, lz);
return player.getLocation().add(lx, ly, lz).add(offset.x, offset.y, offset.z);
}else{
}
} catch (IOException e) {
Expand Down Expand Up @@ -234,7 +235,7 @@ public Location getControllerPos(int c) {
return out;
}

return player.getLocation().add(x, y, z);
return player.getLocation().add(x, y, z).add(offset.x, offset.y, offset.z);
}else{
}
} catch (IOException e) {
Expand Down
19 changes: 14 additions & 5 deletions src/org/vivecraft/utils/AimFixHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public AimFixHandler(NetworkManager netManager) {
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
EntityPlayer player = ((PlayerConnection)netManager.i()).player;
boolean isCapturedPacket = msg instanceof PacketPlayInBlockPlace || msg instanceof PacketPlayInUseItem || msg instanceof PacketPlayInBlockDig;
boolean useActiveHand = !(msg instanceof PacketPlayInBlockDig) || ((PacketPlayInBlockDig)msg).d() == PacketPlayInBlockDig.EnumPlayerDigType.RELEASE_USE_ITEM;

if (!VSE.vivePlayers.containsKey(player.getProfile().getId()) || !VSE.vivePlayers.get(player.getProfile().getId()).isVR() || !isCapturedPacket || player.getMinecraftServer() == null) {
// we don't need to handle this packet, just defer to the next handler in the pipeline
Expand All @@ -49,11 +50,11 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
float oldPrevYawHead = player.aK; // field_70758_at
float oldEyeHeight = player.getHeadHeight();

// Check again in case of race condition
if (VSE.vivePlayers.containsKey(player.getProfile().getId()) && VSE.vivePlayers.get(player.getProfile().getId()).isVR()) {
VivePlayer data = VSE.vivePlayers.get(player.getProfile().getId());
Location pos = data.getControllerPos(0);
Vec3D aim = data.getControllerDir(0);
VivePlayer data = null;
if (VSE.vivePlayers.containsKey(player.getProfile().getId()) && VSE.vivePlayers.get(player.getProfile().getId()).isVR()) { // Check again in case of race condition
data = VSE.vivePlayers.get(player.getProfile().getId());
Location pos = data.getControllerPos(useActiveHand ? data.activeHand : 0);
Vec3D aim = data.getControllerDir(useActiveHand ? data.activeHand : 0);

// Inject our custom orientation data
player.setPositionRaw(pos.getX(), pos.getY(), pos.getZ());
Expand All @@ -65,6 +66,10 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
player.lastPitch = player.pitch;
player.lastYaw = player.aJ = player.aK = player.yaw;
VSE.setPrivateField("headHeight", Entity.class, player, 0);

// Set up offset to fix relative positions
// P.S. Spigot mappings are stupid
data.offset = oldPos.add(-pos.getX(), -pos.getY(), -pos.getZ());
}

// Call the packet handler directly
Expand Down Expand Up @@ -94,6 +99,10 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
player.lastYaw = oldPrevYaw;
player.aK = oldPrevYawHead;
VSE.setPrivateField("headHeight", Entity.class, player, oldEyeHeight);

// Reset offset
if (data != null)
data.offset = new Vec3D(0, 0, 0);
});
}
}

0 comments on commit d2259cb

Please sign in to comment.