Skip to content

Instantly share code, notes, and snippets.

@codetaylor
Last active July 20, 2019 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codetaylor/33022b98c33ec3c007fe5f67968ede8a to your computer and use it in GitHub Desktop.
Save codetaylor/33022b98c33ec3c007fe5f67968ede8a to your computer and use it in GitHub Desktop.

Goal: Match against held item NBT and replace block drops with items that have NBT.

Dropt supports NBT matching on held items and also supports dropping items with NBT.

Warning: If the player renames an item, enchants an item, or if the item's NBT is altered in any way, its NBT will no longer match.

In the example below, we've set up the rule to match a held item, specifically a Diamond Pickaxe with some NBT.

"minecraft:diamond_pickaxe:*#{RepairCost:0,display:{Name:\"Pick Astley\"}}"

This string is the result of using an anvil to name a fresh Diamond Pickaxe and running the /dropt hand command while holding it. Note the RepairCost: 0 tag.


ZenScript

import mods.dropt.Dropt;

Dropt.list("list_name")

  .add(Dropt.rule()
      .matchBlocks(["minecraft:stone"])
      .matchHarvester(Dropt.harvester()
          .type("PLAYER")
          .mainHand([
              <minecraft:diamond_pickaxe:*>.withTag({RepairCost: 0, display: {Name: "Pick Astley"}})
          ])
      )
      .addDrop(Dropt.drop()
          .items([
              <minecraft:cobblestone>.withTag({display: {Name: "Never"}}),
              <minecraft:cobblestone>.withTag({display: {Name: "Gonna"}}),
              <minecraft:cobblestone>.withTag({display: {Name: "Give"}}),
              <minecraft:cobblestone>.withTag({display: {Name: "You"}}),
              <minecraft:cobblestone>.withTag({display: {Name: "Stone"}})
          ])
      )
  );

JSON

{
  "rules": [
    {
      "match": {
        "blocks": {
          "blocks": [
            "minecraft:stone"
          ]
        },
        "harvester": {
          "type": "PLAYER",
          "heldItemMainHand": {
            "items": [
              "minecraft:diamond_pickaxe:*#{RepairCost:0,display:{Name:\"Pick Astley\"}}"
            ]
          }
        }
      },
      "drops": [{
        "item": {
          "items": [
            "minecraft:cobblestone:0#{display:{Name:\"Never\"}}",
            "minecraft:cobblestone:0#{display:{Name:\"Gonna\"}}",
            "minecraft:cobblestone:0#{display:{Name:\"Give\"}}",
            "minecraft:cobblestone:0#{display:{Name:\"You\"}}",
            "minecraft:cobblestone:0#{display:{Name:\"Stone\"}}"
          ]
        }
      }]
    }
  ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment