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

[BUG] Item.give() doesn't work because of the new format #111

Open
patrykduda2005 opened this issue Jul 26, 2024 · 1 comment
Open

[BUG] Item.give() doesn't work because of the new format #111

patrykduda2005 opened this issue Jul 26, 2024 · 1 comment
Assignees
Labels
Type: Bug Something isn't working

Comments

@patrykduda2005
Copy link

Describe the bug

Item.give(...); puts its nbts in old format

To Reproduce

  1. write proper Item.create() and Item.give()
  2. compile

Expected behavior

nbt should be put in "[]" instead of "{}" and values should use "=" instead of ":"

Screenshots

image
image
image

Desktop

  • Linux
@patrykduda2005 patrykduda2005 added the Type: Bug Something isn't working label Jul 26, 2024
@Nico314159
Copy link
Contributor

Nico314159 commented Jul 27, 2024

Yeah, this feature is very hard to update. I'll try to see what I can do, but I can't make any promises because I have a lot of other things I need to do. For now, I have two workarounds.

Option 1: #define

In an .hjmc file, type

#define dummy_cooked_cod enchanted_book[max_stack_size=64,custom_name='"Cooked Cod"',lore=['"DUMMY"'],rarity="common",custom_model_data=421]

Then, if you type

give @a dummy_cooked_cod 10;

in your main file, it will give you the expected result.

Option 2: Loot Tables

Use the following syntax to create a loot table:

new loot_table(dummy_cooked_cod) {
	"pools": [
		{
			"rolls": 1,
			"entries": [
				{
					"type": "minecraft:item",
					"name": "minecraft:enchanted_book",
					"functions": [
						{
							"function": "minecraft:set_name",
							"name": "Cooked Cod"
						},
						{
							"function": "minecraft:set_lore",
							"lore": ["DUMMY"],
							"mode": "replace_all"
						},
						{
							"function": "minecraft:set_count",
							"count": 10
						},
						{
							"function": "minecraft:set_components",
							"components": {
								"minecraft:rarity": "common",
								"minecraft:max_stack_size": 64
							}
						}
					]
				}
			]
		}
	]
}

Then, you can use loot give @a loot namespace:dummy_cooked_cod; anywhere in your code and it will have the result you wanted above.

I actually recommend loot tables a lot, because they can do powerful things that the item command simply cannot (ex: if later on in your project, you wanted to make the count based on some score or variable instead of a fixed number, you can do that.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants