Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom NBT data for loot #351

Closed
bakaschwarz opened this issue May 10, 2021 · 9 comments
Closed

Allow custom NBT data for loot #351

bakaschwarz opened this issue May 10, 2021 · 9 comments
Labels
Enhancement New feature or request Needs More Info Further information is requested

Comments

@bakaschwarz
Copy link

bakaschwarz commented May 10, 2021

Is your feature request related to a problem? Please describe.

It is currently not possible to describe loot which has custom NBT data attached to it.
NBT is die primary way for other plugins to define a custom item (AdvancedEnchantments, Items Adder, MMOItems, etc.)

Those plugins come with their own ways to define loottables, but i think they don't work with Iris, because it sets it's own loot tables, right?

Describe the solution you'd like

A normal definiton for loot in a loot.json file is as follows:

    "loot": [
        {
            "type": "wooden_sword",
            "rarity": 3,
            "slotTypes": "STORAGE",
            "minAmount": 1,
            "maxAmount": 3,
            "displayName": "Le Slap",
            "enchantments": [
                {
                    "enchantment": "KNOCKBACK",
                    "chance": 0.2,
                    "minLevel": 1,
                    "maxLevel": 2
                }
            ]
        }
    ]

It would be perfect, if we could have an extra field called customNbt which accepts an escaped string of raw NBT data.
Using the command /data get entity @p SelectedItem i can print out the NBT data of a hold item. It returns something like this:

{id: "minecraft:ink_sac", tag: {CustomModelData: 4, display: {Name: '{"extra":[{"bold":true,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"gold","text":"Holy White Scroll"}],"text":""}', Lore: ['{"extra":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"yellow","text":"A legendary reward that can"}],"text":""}', '{"extra":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"yellow","text":"be applied to armor/weapons,"}],"text":""}', '{"extra":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"yellow","text":"gives a 100% chance of not losing"}],"text":""}', '{"extra":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"yellow","text":"the blessed item on death."}],"text":""}']}, holywhitescroll: "true"}, Count: 1b}

but we only really need whats coming after tag and before , Count: 1b} at the end:

{CustomModelData: 4, display: {Name: '{"extra":[{"bold":true,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"gold","text":"Holy White Scroll"}],"text":""}', Lore: ['{"extra":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"yellow","text":"A legendary reward that can"}],"text":""}', '{"extra":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"yellow","text":"be applied to armor/weapons,"}],"text":""}', '{"extra":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"yellow","text":"gives a 100% chance of not losing"}],"text":""}', '{"extra":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"yellow","text":"the blessed item on death."}],"text":""}']}, holywhitescroll: "true"}

This is the NBT data you'd need to pass to the give command to spawn a holy white scroll from AdvancedEnchantments when you give yourself an item. In my case the base item was an ink sack, but thats not important.

The only problem here is that minecraft tends to mix " and ' and does not return valid JSON. One possible way would be to simply
escape all instances of " inside the NBT string. Following my idea the above loot definition could look like this:

    "loot": [
        {
            "type": "ink_sac",
            "rarity": 3,
            "slotTypes": "STORAGE",
            "minAmount": 1,
            "maxAmount": 3,
            "customNbt": "{CustomModelData: 4, display: {Name: '{\"extra\":[{\"bold\":true,\"italic\":false,\"underlined\":false,\"strikethrough\":false,\"obfuscated\":false,\"color\":\"gold\",\"text\":\"Holy White Scroll\"}],\"text\":\"\"}', Lore: ['{\"extra\":[{\"bold\":false,\"italic\":false,\"underlined\":false,\"strikethrough\":false,\"obfuscated\":false,\"color\":\"yellow\",\"text\":\"A legendary reward that can\"}],\"text\":\"\"}', '{\"extra\":[{\"bold\":false,\"italic\":false,\"underlined\":false,\"strikethrough\":false,\"obfuscated\":false,\"color\":\"yellow\",\"text\":\"be applied to armor/weapons,\"}],\"text\":\"\"}', '{\"extra\":[{\"bold\":false,\"italic\":false,\"underlined\":false,\"strikethrough\":false,\"obfuscated\":false,\"color\":\"yellow\",\"text\":\"gives a 100% chance of not losing\"}],\"text\":\"\"}', '{\"extra\":[{\"bold\":false,\"italic\":false,\"underlined\":false,\"strikethrough\":false,\"obfuscated\":false,\"color\":\"yellow\",\"text\":\"the blessed item on death.\"}],\"text\":\"\"}']}, holywhitescroll: \"true\"}"
        }
    ]

Describe alternatives you've considered

An alternative would be to include an customNbt field where you can set custom NBT data in a more JSON friendly fashion. This would have the merit of being way easier to read, but you could not just copy and paste NBT data. Coming from the example above it would look something like this (without the text formatting for the name and lore):

    "loot": [
        {
            "type": "ink_sac",
            "rarity": 3,
            "slotTypes": "STORAGE",
            "minAmount": 1,
            "maxAmount": 3,
            "customNbt": {
                "CustomModelData": 4,
                "holywhitescroll": "true"
            }
        }
    ]
@bakaschwarz bakaschwarz added the Enhancement New feature or request label May 10, 2021
@bakaschwarz
Copy link
Author

I just realized that loot is defined as JSON, not YAML. I will correct the issue text ASAP.

@PaintsplattersMC
Copy link

It would be nice to be able to import mmoitems defined in the same format as usual in the plugin

type.name - so for eg. MATERIAL.silver-ingot

It would pull the nbt from MMOItems and generate it

@svdgoor
Copy link
Collaborator

svdgoor commented Jul 14, 2021

@StrangeOne101 Has this already been implemented with your changes?

@svdgoor
Copy link
Collaborator

svdgoor commented Jul 25, 2021

@StrangeOne101 :)

@svdgoor svdgoor added the Needs More Info Further information is requested label Jul 25, 2021
@StrangeOne101
Copy link
Contributor

@CocoTheOwner Custom NBT is not yet supported. It is probably something we will support when we do loot v3

@svdgoor
Copy link
Collaborator

svdgoor commented Aug 2, 2021

@StrangeOne101 is #46 a duplicate of this or are they clearly separate? if (dupe) close a or close b

@StrangeOne101
Copy link
Contributor

@StrangeOne101 is #46 a duplicate of this or are they clearly separate? if (dupe) close a or close b

They are not duplicates, no. One is for NBT support for objects/blocks and one is for supporting NBT in loot tables

@cyberpwnn
Copy link
Collaborator

This wouldnt be custom support for loot talbles, it's support for custom NBT in items. A loot table is really just a list of Items (in iris). But yes, we should add this.

@NextdoorPsycho
Copy link
Contributor

NextdoorPsycho commented Mar 12, 2022

Added in latest, done like this.

    "name": "Global Clutter",
    "rarity": 1,
    "maxPicked": 2,
    "minPicked": 1,
    "loot": [
        {
            "type": "stone",
            "maxAmount": 3,
            "slotTypes": "STORAGE",
            "displayName": "Test Item",
            "customNbt": {
                "meme": true,
                "funny": -2,
                "appliesTo": ["Player1", "Player2", "Player3"],
                "title": "Jerma985",
                "misc": {
                    "value1": "tets",
                    "value328": false
                }
            }
        }
    ]
}```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request Needs More Info Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants