   ø  ô  ð  {"files":{"mod.js":{"size":3099,"offset":"0","integrity":{"algorithm":"SHA256","hash":"b5d9d1df4ef5cdd4352c2cb7cba4326fed526478e307cca35a5fdb64cf1cbd24","blockSize":4194304,"blocks":["b5d9d1df4ef5cdd4352c2cb7cba4326fed526478e307cca35a5fdb64cf1cbd24"]}},"mod.json":{"size":289,"offset":"3099","integrity":{"algorithm":"SHA256","hash":"de152e9ecb5fbebd036dd74e6702762f81267c6cf263d8cca7d558a98c12c12d","blockSize":4194304,"blocks":["de152e9ecb5fbebd036dd74e6702762f81267c6cf263d8cca7d558a98c12c12d"]}},"package-lock.json":{"size":531,"offset":"3388","integrity":{"algorithm":"SHA256","hash":"f586150d90f9180e8a7280b62e604b03aa5ada408fc676c35d8eaeee6374f4c9","blockSize":4194304,"blocks":["f586150d90f9180e8a7280b62e604b03aa5ada408fc676c35d8eaeee6374f4c9"]}},"package.json":{"size":111,"offset":"3919","integrity":{"algorithm":"SHA256","hash":"e9fa0d329990d3f04b7558e0f177f8b24a63ba2658587718f37269308ee88073","blockSize":4194304,"blocks":["e9fa0d329990d3f04b7558e0f177f8b24a63ba2658587718f37269308ee88073"]}}}}/// <reference types="shapez-ce-types" />

export default class extends shapez.Mod {
  init() {
    this.modInterface.replaceMethod(
      shapez.HUDBuildingPlacerLogic,
      "onMouseMove",
      function ($orig, pos) {
        pos = [...pos][0];
        //console.log(pos)
        if (
          this.currentMetaBuilding.get()?.id == "miner" &&
          this.currentVariant.get() == "chainable" &&
          this.lastDragTile &&
          !this.currentlyDeleting
        ) {
          // Mostly copied from the original method
          if (this.root.camera.getIsMapOverlayActive()) {
            return;
          }
          if (this.isDirectionLockActive) {
            return;
          }
          const oldPos = this.lastDragTile;
          let newPos = this.root.camera.screenToWorld(pos).toTileSpace();
          if (this.root.camera.desiredCenter) {
            this.lastDragTile = newPos;
            return;
          }
          if (!oldPos.equals(newPos)) {
            let x0 = oldPos.x;
            let y0 = oldPos.y;
            let x1 = newPos.x;
            let y1 = newPos.y;

            let dx = Math.abs(x1 - x0);
            let dy = Math.abs(y1 - y0);
            let sx = x0 < x1 ? 1 : -1;
            let sy = y0 < y1 ? 1 : -1;
            let err = dx - dy;
            while (this.currentMetaBuilding.get()) {
              this.tryPlaceCurrentBuildingAt(new shapez.Vector(x0, y0));
              if (x0 === x1 && y0 === y1) break;
              let e2 = 2 * err;

              let current = this.root.map.getLayerContentXY(
                x0,
                y0,
                this.root.currentLayer,
              );

              const doRotate =
                current.components.StaticMapEntity.getMetaBuilding().id ==
                  "miner" &&
                current.components.StaticMapEntity.getVariant() == "chainable";

              let flip = 1;
              if (
                this.root.keyMapper.getBinding(
                  shapez.KEYMAPPINGS.placementModifiers.placeInverse,
                ).pressed
              ) {
                flip = -1;
              }
              if (e2 > -dy) {
                err -= dy;
                x0 += sx;

                let rot = 180 - flip * 90 * Math.sign(sx);
                this.currentBaseRotation = rot;
                if (flip == 1 && doRotate) {
                  current.components.StaticMapEntity.rotation = rot;
                  this.root.signals.entityChanged.dispatch(current);
                }
              }
              if (e2 < dx) {
                err += dx;
                y0 += sy;

                let rot = 90 + flip * 90 * Math.sign(sy);
                this.currentBaseRotation = rot;
                if (flip == 1 && doRotate) {
                  current.components.StaticMapEntity.rotation = rot;
                  this.root.signals.entityChanged.dispatch(current);
                }
              }
            }
          }
          this.lastDragTile = newPos;
          return shapez.STOP_PROPAGATION;
        } else return $orig(pos);
      },
    );
  }
}
{
  "format": 1,
  "entry": "mod.js",
  "id": "chain-chainable-extractors",
  "name": "Chain Chainable Extractors",
  "description": "Makes chainable extractors chain into each other when dragged",
  "authors": [{ "name": "emanresu" }],
  "version": "1.0.0",
  "savegameResident": false
}
{
  "name": "test-thing",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "dependencies": {
        "shapez-ce-types": "https://skimnerphi.net/download/shapez-ce-types-0.0.0.tgz"
      }
    },
    "node_modules/shapez-ce-types": {
      "version": "0.0.0",
      "resolved": "https://skimnerphi.net/download/shapez-ce-types-0.0.0.tgz",
      "integrity": "sha512-bb9jdl4ABuEcAx4VLgBBkb6NmeerU1Ia+BgSrvjSjfgMzD7LQBTsiZGdl0mO3Ydm/TcFyCOnX6pBgC0UjXjZcw==",
      "license": "GPL-3.0-or-later"
    }
  }
}
{
  "dependencies": {
    "shapez-ce-types": "https://skimnerphi.net/download/shapez-ce-types-0.0.0.tgz"
  }
}
