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

Add support for custom tags in item meta #1366

Merged

Conversation

PseudoKnight
Copy link
Contributor

@PseudoKnight PseudoKnight commented Sep 16, 2023

This is a proposal solution for adding custom tags from Bukkit's PersistentDataContainers in item meta. This is for preserving tags added by other plugins as well as allowing scripters more control over their own custom data stored in items.

I'm using array objects to store NBT types along with the values. Due to API limitations we're not able to tell what type of data is under each key, so all types are checked, ordered by an estimation of frequency of use. This can be optimized later, but performance actually seemed adequate and doesn't rely on reflection.

API naming worth discussing is "type", "value", and "tags". We could also go for something like "custom" instead of "tags", "data" instead of "value"

Item array example:

{
	"name": "IRON_PICKAXE",
	"meta": {
		"tags": {
			"commandhelper:mytag": {
				"type": "STRING",
				"value": "something or other",
			},
			"mcmmo:super_ability_boosted": {
				"type": "INTEGER",
				"value": 0,
			}
		}
	}
}

Explosive pick example:

bind('block_break', null, null, @event) {
	@item = pinv(player(), null);
	if(@item 
	&& string_ends_with(@item['name'], 'PICKAXE')
	&& @item['meta'] 
	&& @item['meta']['tags'] 
	&& array_index_exists(@item['meta']['tags'], 'commandhelper:explosive_pick')) {
		@size = @item['meta']['tags']['commandhelper:explosive_pick']['value'];
		explosion(@event['location'], @size, false, false, puuid());
	}
}

Creating explosive pick:

pgive_item(array(
	name: 'DIAMOND_PICKAXE',
	meta: array(
		tags: array(
			'explosive_pick': array( // commandhelper namespace is added by default
				type: 'BYTE', 
				value: 1
			)
		)
	)
))

@PseudoKnight PseudoKnight reopened this Sep 20, 2023
@PseudoKnight PseudoKnight merged commit 1f6deb1 into EngineHub:master Oct 4, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants