1515 * Created by cincodenada on 13-May-17.
1616 */
1717public class BackpackTracker {
18- float mouthtoEyeDistance =0.0f ;
19- float threshold =0.25f ;
20- public Item [] items = new Item [2 ];
2118 public boolean [] wasIn = new boolean [2 ];
22- public boolean [] wasPressed = new boolean [ 2 ] ;
23-
19+ public int previousSlot = - 1 ;
20+
2421 public boolean isActive (EntityPlayerSP p ){
2522 if (Minecraft .getMinecraft ().vrSettings .seated )
2623 return false ;
@@ -30,52 +27,46 @@ public boolean isActive(EntityPlayerSP p){
3027 return true ;
3128 }
3229
33- private Random r = new Random ();
34-
3530
36- public void doProcess (Minecraft minecraft , EntityPlayerSP player ){
37- if (!isActive (player )) {
38- return ;
39- }
40- IRoomscaleAdapter provider = minecraft .roomScale ;
31+ private Vec3 down = Vec3 .createVectorHelper (0 , -1 , 0 );
32+
33+ public void doProcess (Minecraft minecraft , EntityPlayerSP player ){
34+ if (!isActive (player )) {
35+ return ;
36+ }
37+ IRoomscaleAdapter provider = minecraft .roomScale ;
4138
42- Vec3 hmdPos =provider .getHMDPos_Room ();
39+ Vec3 hmdPos =provider .getHMDPos_Room ();
4340
44- for (int c =0 ; c <2 ; c ++) {
45- Vec3 controllerPos = MCOpenVR .controllerHistory [c ].averagePosition (0.333 ).add (provider .getCustomControllerVector (c , new Vec3 (0 , 0 , -0.1 )));
46- controllerPos = controllerPos .add (minecraft .roomScale .getControllerDir_Room (c ).scale (0.1 ));
41+ for (int c =0 ; c <1 ; c ++) { //just main for 1710, no dual wielding
42+ Vec3 controllerPos = provider .getControllerPos_Room (c );//.add(provider.getCustomControllerVector(c, new Vec3(0, 0, -0.1)));
43+ Vec3 controllerDir = minecraft .roomScale .getControllerDir_World (c );
44+ Vec3 hmddir = provider .getHMDDir_World ();
45+ Vec3 hmdpos = provider .getHMDPos_Room ();
46+ Vec3 delta = hmdPos .subtractProperly (controllerPos );
47+ double dot = controllerDir .dotProduct (down );
48+ double dotDelta = delta .dotProduct (hmddir );
4749
48- if (
49- (Math .abs (hmdPos .yCoord - controllerPos .yCoord ) < 0.25 )
50- && controllerPos .zCoord > hmdPos .zCoord
51- && ((controllerPos .zCoord - hmdPos .zCoord ) < 0.5 )
52- ) {
53- wasIn [c ] = true ;
54- if (!wasPressed [c ]) {
55- wasPressed [c ] = Minecraft .getMinecraft ().gameSettings .keyBindAttack .getIsKeyPressed ();
56- if (wasPressed [c ]) {
57- provider .triggerHapticPulse (c ,1500 );
58- }
59- }
60- } else {
61- // Only run once per zone entrance
62- if (wasIn [c ]) {
63- // If we pressed while in the zone
64- if (wasPressed [c ]) {
65- ItemStack heldStack = player .getHeldItem ();
66- this .items [c ] = (heldStack == null ? null : heldStack .getItem ());
67- } else {
68- if (this .items [c ] != null ) {
69- player .inventory .setCurrentItem (this .items [c ], 0 , false , player .capabilities .isCreativeMode );
70- provider .triggerHapticPulse (c , 1500 );
50+ if (
51+ ((hmdPos .yCoord - controllerPos .yCoord ) > 0.05 ) && //controller below hmd
52+ (dot > .8 ) && // pointing approx down
53+ (dotDelta > 0 ) // behind head
54+ ){
55+ if (!wasIn [c ]){
56+ if (player .inventory .currentItem != 0 ){
57+ previousSlot = player .inventory .currentItem ;
58+ player .inventory .currentItem = 0 ;
59+ } else {
60+ player .inventory .currentItem = previousSlot ;
61+ previousSlot = -1 ;
7162 }
63+ provider .triggerHapticPulse (c , 1500 );
64+ wasIn [c ] = true ;
7265 }
66+ } else {
67+ wasIn [c ] = false ;
7368 }
74- // Reset state
75- wasIn [c ] = false ;
76- wasPressed [c ] = false ;
7769 }
78- }
7970}
8071
8172}
0 commit comments