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();
    }
  }