Guest User

Untitled

a guest
Jul 9th, 2020
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.36 KB | None | 0 0
  1. package me.hasunemiku2015.mikumsp;
  2.  
  3. import org.bukkit.Location;
  4. import org.bukkit.Material;
  5. import org.bukkit.util.Vector;
  6.  
  7. import java.util.ArrayList;
  8. import java.util.List;
  9.  
  10. public class RTX {
  11.     static Material[] rail = new Material[]{Material.ACTIVATOR_RAIL, Material.POWERED_RAIL, Material.DETECTOR_RAIL,
  12.             Material.RAIL};
  13.  
  14.     public static List<Object> railtest(MovingCart cart, Location next) {
  15.         //1. norailtest 2.next
  16.         List<Object> output = new ArrayList<>();
  17.  
  18.  
  19.         State state = cart.getState();
  20.  
  21.         Location location = cart.getMinecart().getLocation();
  22.         int oldx = cart.getMinecart().getLocation().getBlockX();
  23.         int oldz = cart.getMinecart().getLocation().getBlockZ();
  24.         int newx = next.getBlockX();
  25.         int newz = next.getBlockZ();
  26.  
  27.         Vector distance_temp = next.toVector().subtract(cart.getMinecart().getLocation().toVector());
  28.         double distance =  distance_temp.length();
  29.         System.out.println(distance);
  30.  
  31.         Vector valueadd = null;
  32.         boolean norailtest = true;
  33.         try {
  34.             valueadd = motion(location, cart.getState(), distance);
  35.             System.out.println(valueadd);
  36.             location.add(valueadd);
  37.         } catch (Exception e) {
  38.             norailtest = false;
  39.         }
  40.  
  41.         output.add(norailtest);
  42.         output.add(location);
  43.         return output;
  44.  
  45.  
  46. //        boolean norailtest = false;
  47. //        int[] test1 = Util.arrayfromnumberplusminusc(oldx, newx, 0);
  48. //        for (int i : test1) {
  49. //            Location miku = cart.getMinecart().getLocation();
  50. //            miku.setX(i);
  51. //            Material railtest_material = miku.getBlock().getType();
  52. //            boolean blockisrail = false;
  53. //            for (Material raill : rail) {
  54. //                if (railtest_material.equals(raill)) {
  55. //                    blockisrail = true;
  56. //                    break;
  57. //                }
  58. //            }
  59. //
  60. //            if (blockisrail) {
  61. //                Vector valueadd = motion(location, cart.getState(), distance);
  62. //                System.out.println(valueadd);
  63. //                location.add(valueadd);
  64. //                output.add(norailtest);
  65. //                output.add(location);
  66. //
  67. //                return output;
  68. //
  69. //            }else {
  70. //                norailtest = true;
  71. //                output.add(norailtest);
  72. //                output.add(location);
  73. //                return output;
  74. //            }
  75.  
  76. //            if (blockisrail) {
  77. //                try {
  78. //                    String str = miku.getBlock().getBlockData().getAsString();
  79. //                    System.out.println(str);
  80. //                    if (str.contains("shape=east_west")) {
  81. //                        System.out.println("Good");
  82. //                    } else {
  83. //                        System.out.println("Bad");
  84. //                    }
  85. //                } catch (Exception ignored) {
  86. //                }
  87. //            }
  88. //            if (!blockisrail) {
  89. //                norailtest = true;
  90. //            }
  91. //        }
  92. //        int[] test2 = Util.arrayfromnumberplusminusc(oldz, newz, 0);
  93. //        for (int i : test2) {
  94. //            Location miku = cart.getMinecart().getLocation();
  95. //            miku.setZ(i);
  96. //            Material railtest_material = miku.getBlock().getType();
  97. //            boolean blockisrail = false;
  98. //            for (Material raill : rail) {
  99. //                if (railtest_material.equals(raill)) {
  100. //                    blockisrail = true;
  101. //                    break;
  102. //                }
  103. //            }
  104. //            if (blockisrail) {
  105. //                Vector valueadd = motion(location, cart.getState(), distance);
  106. //                location.add(valueadd);
  107. //                output.add(norailtest);
  108. //                output.add(location);
  109. //
  110. //                return output;
  111. //
  112. //            }else {
  113. //                norailtest = true;
  114. //                output.add(norailtest);
  115. //                output.add(location);
  116. //                return output;
  117. //            }
  118. //       }
  119. //       return new ArrayList<>();
  120.     }
  121.  
  122.     public static Vector motion(Location l , State direction , double distance){
  123.         Vector pos = l.toVector();
  124.         Vector v = new Vector(0,0,0);
  125.         Vector v2 = new Vector(0,0,0);
  126. //        String s = direction.toString();
  127.  
  128.         //range is ceiling of distance
  129.         int range = (int) (distance + 1);
  130.  
  131.         for(int i = 1; i <= range; i++ ){
  132.             switch (direction){
  133.                 case EAST: {
  134.                     switch (TrackState.getTrackState(l.add(v2).getBlock().getBlockData().getAsString())){
  135.                         case X_STRAIGHT:
  136.                             v.add(new Vector(1,0,0)); v2.setX(1); v2.setY(0); v2.setZ(0); break;
  137.                         case SOUTH_WEST:
  138.                             v.add(new Vector(1,0,1)); v2.setX(1); v2.setY(0); v2.setZ(1); direction = State.SOUTH; break;
  139.                         case NORTH_WEST:
  140.                             v.add(new Vector(1,0,-1)); v2.setX(1); v2.setY(0); v2.setZ(-1); direction = State.NORTH; break;
  141.                         case EAST_SLOPE:
  142.                             v.add(new Vector(1,1,0)); v2.setX(1); v2.setY(1); v2.setZ(0); break;
  143.                         default:
  144.                             if(TrackState.getTrackState(l.add(v).add(0,-1,0).getBlock().getBlockData().getAsString()) == TrackState.EAST_SLOPE){
  145.                                 v.add(new Vector(1,-1,0)); v2.setX(1); v2.setY(-1); v2.setZ(0);
  146.                             } else {
  147.                                 throw new IllegalArgumentException();
  148.                             }
  149.                     }
  150.                     break;
  151.                 }
  152.  
  153.                 case WEST: {
  154.                     System.out.println(l.add(v2));
  155.                     System.out.println(TrackState.getTrackState(l.add(v2).getBlock().getBlockData().getAsString()));
  156.                     switch (TrackState.getTrackState(l.add(v2).getBlock().getBlockData().getAsString())){
  157.                         case X_STRAIGHT:
  158.                             v.add(new Vector(-1,0,0)); v2.setX(-1); v2.setY(0); v2.setZ(0); break;
  159.                         case SOUTH_EAST:
  160.                             v.add(new Vector(-1,0,1)); direction = State.SOUTH; v2.setX(-1); v2.setY(0); v2.setZ(1); break;
  161.                         case NORTH_EAST:
  162.                             v.add(new Vector(-1,0,-1)); direction = State.NORTH; v2.setX(-1); v2.setY(0); v2.setZ(-1); break;
  163.                         case WEST_SLOPE:
  164.                             v.add(new Vector(-1,1,0)); v2.setX(-1); v2.setY(1); v2.setZ(0); break;
  165.                         default:
  166.                             if(TrackState.getTrackState(l.add(v).add(0,-1,0).getBlock().getBlockData().getAsString()) == TrackState.WEST_SLOPE){
  167.                                 v.add(new Vector(-1,-1,0)); v2.setX(-1); v2.setY(-1); v2.setZ(0);
  168.                             } else {
  169.                                 throw new IllegalArgumentException();
  170.                             }
  171.                     }
  172.                     break;
  173.                 }
  174.  
  175.                 case SOUTH:  {
  176.                     switch (TrackState.getTrackState(l.add(v).getBlock().getBlockData().getAsString())){
  177.                         case Z_STRAIGHT:
  178.                             v.add(new Vector(0,0,1)); break;
  179.                         case NORTH_EAST:
  180.                             v.add(new Vector(1,0,1)); direction = State.EAST; break;
  181.                         case NORTH_WEST:
  182.                             v.add(new Vector(-1,0,1)); direction = State.WEST; break;
  183.                         case SOUTH_SLOPE:
  184.                             v.add(new Vector(0,1,1)); break;
  185.                         default:
  186.                             if(TrackState.getTrackState(l.add(v).add(0,-1,0).getBlock().getBlockData().getAsString()) == TrackState.SOUTH_SLOPE){
  187.                                 v.add(new Vector(0,-1,1));
  188.                             } else {
  189.                                 throw new IllegalArgumentException();
  190.                             }
  191.                     }
  192.                     break;
  193.                 }
  194.  
  195.                 case NORTH: {
  196.                     switch (TrackState.getTrackState(l.add(v).getBlock().getBlockData().getAsString())){
  197.                         case Z_STRAIGHT:
  198.                             v.add(new Vector(0,0,-1)); break;
  199.                         case SOUTH_EAST:
  200.                             v.add(new Vector(1,0,-1)); direction = State.EAST; break;
  201.                         case SOUTH_WEST:
  202.                             v.add(new Vector(-1,0,-1)); direction = State.WEST; break;
  203.                         case NORTH_SLOPE:
  204.                             v.add(new Vector(0,1,-1)); break;
  205.                         default:
  206.                             if(TrackState.getTrackState(l.add(v).add(0,-1,0).getBlock().getBlockData().getAsString()) == TrackState.NORTH_SLOPE){
  207.                                 v.add(new Vector(0,-1,-1));
  208.                             } else {
  209.                                 throw new IllegalArgumentException();
  210.                             }
  211.                         break;
  212.                     }
  213.                 }
  214.             }
  215.         }
  216.  
  217.         int deltaY = (int) v.getY();
  218.         Vector rectified = v.normalize().multiply(distance);
  219.         rectified.setY(deltaY);
  220.         return rectified;
  221.     }
  222. }
Add Comment
Please, Sign In to add comment