Skip to content

Move Operation

EnderTurret edited this page Nov 5, 2024 · 1 revision

The move patch type moves an element to a new location. A similar operation is copy, which moves a copy of an element.

A move patch looks like this:

{
  "op": "move", // specifies this is a move patch
  "path": "/path/to/destination", // specifies the path to put the element
  "from": "/path/to/source/element" // specifies the path to the element to move
}

For example:

// simple_dungeon.json
{
  "pools": [
    {
      "entries": [
        // ...
        {
          "type": "minecraft:item",
          "name": "minecraft:book",
          // ...
        }
      ]
    },
    {
      // ...
    },
    {
      // ...
    }
  ]
}
// simple_dungeon.json.patch
{
  "op": "move",
  "path": "/pools/2/entries/-",
  "from": "/pools/0/entries/10"
}
// simple_dungeon.json (patched)
{
  "pools": [
    {
      "entries": [
        // ...
      ]
    },
    {
      // ...
    },
    {
      "entries": [
        // ...
        { // moved from /pools/0/entries/10 by file/CommonBookLoot
          "type": "minecraft:item",
          "name": "minecraft:book",
          // ...
        }
      ]
    }
  ]
}

One common use of move is to wrap an element. For example:

// claustrophobia.json
{
  // ...
  "condition": {
    "type": "apoli:block_collision",
    "block_condition": "apoli:allow",
    "offset_y": 1.0
  },
  // ...
}
// claustrophobia.json.patch
[
  {
    "op": "add",
    "path": "/temp",
    "value": {
      "type": "origins:or",
      "conditions": [
        {
          "type": "origins:equipped_item",
          "equipment_slot": "offhand",
          "item_condition": {
            "type": "origins:ingredient",
            "ingredient": {
              "item": "minecraft:bucket"
            }
          }
        }
      ]
    }
  },
  {
    "op": "move",
    "path": "/temp/conditions/0",
    "from": "/condition"
  },
  {
    "op": "move",
    "path": "/condition",
    "from": "/temp"
  }
]
// claustrophobia.json (patched)
{
  // ...
  "condition": { // moved from /temp by file/CalmingBucket
    "type": "origins:or",
    "conditions": [
	  { // moved from /condition by file/CalmingBucket
        "type": "apoli:block_collision",
        "block_condition": "apoli:allow",
        "offset_y": 1.0
      },
      {
        "type": "origins:equipped_item",
        "equipment_slot": "offhand",
        "item_condition": {
          "type": "origins:ingredient",
          "ingredient": {
            "item": "minecraft:bucket"
          }
        }
      }
	]
  },
  // ...
}