Beispiel #1
0
  public void refresh() {
    // Update this track piece based on environment
    this.neighbours.clear();
    this.genNeighbours(true);

    System.out.println("Refreshing: " + this.toString());

    if (this.neighbours.size() == 1) {
      // align tracks straight to face this direction
      MinecartTrackLogic to = this.neighbours.get(0);
      this.connect(to, null);
      to.connect();
    } else if (this.neighbours.size() == 2 || this.neighbours.size() == 4) {
      // try to make a fixed curve
      MinecartTrackLogic r1 = this.neighbours.get(0);
      MinecartTrackLogic r2 = this.neighbours.get(1);
      this.connect(r1, r2);
      r1.connect();
      r2.connect();
    } else if (this.neighbours.size() == 3) {
      // sort neighbours: middle at index 1
      BlockFace middle = this.neighbours.get(1).direction.getOpposite();
      if (middle == this.neighbours.get(2).direction) {
        // dirs[1] need to be swapped with dirs[2]
        Collections.swap(this.neighbours, 1, 2);
      } else if (middle == this.neighbours.get(0).direction) {
        // dirs[1] need to be swapped with dirs[0]
        Collections.swap(this.neighbours, 1, 0);
      }

      // this will ALWAYS be a curve leading to [1]
      // pick [0] or [2]?
      MinecartTrackLogic from = this.neighbours.get(1);
      MinecartTrackLogic to;
      if (this.isPowered) {
        to = this.neighbours.get(0);
      } else {
        to = this.neighbours.get(2);
      }
      this.connect(from, to);
      from.connect();
      to.connect();
    }
  }
Beispiel #2
0
 /**
  * Generates all neighbours around this rail
  *
  * @param deep whether to perform a deep search
  */
 public void genNeighbours(boolean deep) {
   if (deep) {
     for (BlockFace direction : BlockFaces.NESW) {
       MinecartTrackLogic logic = this.getLogic(direction);
       if (logic != null) {
         logic.parent = this;
         logic.direction = direction;
         // find out what connections this rail has
         logic.genNeighbours(false);
         if (logic.neighbours.size() >= 2) {
           continue; // already connected to two misc track pieces
         }
         MinecartTrackLogic self = logic.getLogic(logic.direction.getOpposite());
         self.parent = logic;
         self.direction = logic.direction.getOpposite();
         logic.neighbours.add(self);
         this.neighbours.add(logic);
       }
     }
   } else {
     for (BlockFace direction : this.getState().getDirections()) {
       if (direction == this.direction.getOpposite()) {
         continue;
       }
       MinecartTrackLogic logic = this.getLogic(direction);
       if (logic != null) {
         logic.parent = this;
         logic.direction = direction;
         if (logic.getState().isConnected(direction.getOpposite())) {
           this.neighbours.add(logic);
         }
       }
     }
   }
 }
 public void doTrackLogic(World world, int x, int y, int z) {
   MinecartTrackLogic logic = MinecartTrackLogic.create(world, x, y, z);
   if (logic != null) {
     logic.refresh();
   }
 }