//------------------------------------------------------------------------------------------------------------------------------------------------
// PA2 Extras - Tags Mapper
//------------------------------------------------------------------------------------------------------------------------------------------------
// Author: RicTheCoder
//
// Simple script to maps multiple tags to single targets instead of the other way around. If you don't want to remove an entry but want to
// stop it from working add a '!' before the id. Tags are also supported by prefixing with '#'
//------------------------------------------------------------------------------------------------------------------------------------------------

// Blocks mapped to their needed tags
// - Key is the block id, value is an array of tags to add
const blockToTags = {
	"minecraft:reinforced_deepslate": [
		"forge:mineable/paxel", "minecraft:mineable/mattock", "projecte:mineable/morning_star", 
		"projecte:mineable/hammer", "minecraft:mineable/pickaxe"
	],
	"trials:trial_spawner": [
		"forge:mineable/paxel", "minecraft:mineable/mattock", "projecte:mineable/morning_star", 
		"projecte:mineable/hammer", "minecraft:mineable/pickaxe"
	],
	"trials:trial_vault": [
		"forge:mineable/paxel", "minecraft:mineable/mattock", "projecte:mineable/morning_star", 
		"projecte:mineable/hammer", "minecraft:mineable/pickaxe"
	],
	"trials:trial_vault_ominous": [
		"forge:mineable/paxel", "minecraft:mineable/mattock", "projecte:mineable/morning_star", 
		"projecte:mineable/hammer", "minecraft:mineable/pickaxe"
	],
	
	// QUICK NOTE: Trial spawners and vaults are allowed to drop in the 'drop_fixes.js' but if they are dropped they will never work again, 
	// the purpose is to be cosmetic, as they are nice for some builds. The tags help getting the right tools to mine them.
}

// Items mapped to their needed tags
// - Key is the item id, value is an array of tags to add
const itemToTags = {
	"draconicevolution:deepslate_draconium_ore": [
		"forge:ores", "forge:ores/draconium", "balm:ores"
	]
}

// Remaps blocks with a tag to use another tag instead
// - Key is the tag to replace, value the tag to repalce with
const replaceBlockTags = {}

//---[CODE]---------------------------------------------------------------------------------------------------------------------------------------

// Applies the tags provided above
ServerEvents.tags("block", event => {
	Object.keys(blockToTags).forEach(item => {
		if (item.startsWith("!"))
			return;
		
		blockToTags[item].forEach(tag => {
			event.add(tag, item);
		});
	});
	
	Object.keys(replaceBlockTags).forEach(tag => {
		if (tag.startsWith("!"))
			return;
		
		event.get(tag).getObjectIds().forEach(item => {
			event.add(replaceBlockTags[tag], item);
		});
		
		event.removeAll(tag);
	});
})

ServerEvents.tags("item", event => {
	Object.keys(itemToTags).forEach(item => {
		if (item.startsWith("!"))
			return;
		
		itemToTags[item].forEach(tag => {
			event.add(tag, item);
		});
	});
})