// priority: 0

settings.logAddedRecipes = true
settings.logRemovedRecipes = true
settings.logSkippedRecipes = false
settings.logErroringRecipes = true

console.info('Hello, World! (You will see this line every time server resources reload)')

onEvent('recipes', event => {
	// Change recipes here
	event.remove({output: 'morebows:multi_bow'})
	event.remove({output: 'morebows:gold_bow'})
	event.remove({output: 'morebows:frost_bow'})
	event.remove({output: 'morebows:flame_bow'})
	event.remove({output: 'morebows:ender_bow'})
	event.remove({output: 'morebows:diamond_bow'})
	event.remove({output: 'cgm:workbench'})

})

onEvent('item.tags', event => {
	// Get the #forge:cobblestone tag collection and add Diamond Ore to it
	// event.get('forge:cobblestone').add('minecraft:diamond_ore')

	// Get the #forge:cobblestone tag collection and remove Mossy Cobblestone from it
	// event.get('forge:cobblestone').remove('minecraft:mossy_cobblestone')
})
//
//
//
//
//
//
//
//
// breaking spawners in overworld dimension will spawn 1 zombie - 25% chance
// i stole this from Swedz on the lootjs discord :)
onEvent("lootjs", (event) => {
	event
		.addBlockLootModifier("minecraft:spawner")
		.anyDimension("minecraft:overworld") 
        .randomChance(0.25)
		.thenApply((context) => {
			var level = context.level
			var pos = context.blockPos
			var block = level.getBlock(pos)
	  
			block.set('minecraft:air')
	  
			var zombieSpawn = level.createEntity('minecraft:zombie')
			zombieSpawn.setPosition(pos.getX(), pos.getY(), pos.getZ())
			zombieSpawn.spawn()
		  });
})
// breaking spawners in mirror overworld dimension will spawn 5 zombies - 50% chance
onEvent("lootjs", (event) => {
	event
		.addBlockLootModifier("minecraft:spawner")
		.anyDimension("overworldmirror:overworld") 
        .randomChance(0.50)
		.thenApply((context) => {
			var level = context.level
			var pos = context.blockPos
			var block = level.getBlock(pos)
	  
			block.set('minecraft:air')
	  
			var zombieSpawn = level.createEntity('minecraft:zombie')
			zombieSpawn.setPosition(pos.getX(), pos.getY(), pos.getZ())
			zombieSpawn.spawn()
		  })
		.thenApply((context) => {
			var level = context.level
			var pos = context.blockPos
			var block = level.getBlock(pos)
	  
			block.set('minecraft:air')
	  
			var zombieSpawn = level.createEntity('minecraft:zombie')
			zombieSpawn.setPosition(pos.getX(), pos.getY(), pos.getZ())
			zombieSpawn.spawn()
		  })
		.thenApply((context) => {
			var level = context.level
			var pos = context.blockPos
			var block = level.getBlock(pos)
	  
			block.set('minecraft:air')
	  
			var zombieSpawn = level.createEntity('minecraft:zombie')
			zombieSpawn.setPosition(pos.getX(), pos.getY(), pos.getZ())
			zombieSpawn.spawn()
		  })
		.thenApply((context) => {
			var level = context.level
			var pos = context.blockPos
			var block = level.getBlock(pos)
	  
			block.set('minecraft:air')
	  
			var zombieSpawn = level.createEntity('minecraft:zombie')
			zombieSpawn.setPosition(pos.getX(), pos.getY(), pos.getZ())
			zombieSpawn.spawn()
		  })
		.thenApply((context) => {
			var level = context.level
			var pos = context.blockPos
			var block = level.getBlock(pos)
	  
			block.set('minecraft:air')
	  
			var zombieSpawn = level.createEntity('minecraft:zombie')
			zombieSpawn.setPosition(pos.getX(), pos.getY(), pos.getZ())
			zombieSpawn.spawn()
		  });
})

//
//
// adds dimdungeons key to all lootchests in overworld dimension - 3% chance
onEvent("lootjs", (event) => {
    event
		.addLootTypeModifier(LootType.CHEST)
		.anyDimension("minecraft:overworld") 
        .randomChance(0.03) 
		.thenAdd("dubl:item_portal_key");
});
// adds dimdungeons key to all lootchests in mining dimension - 10% chance
onEvent("lootjs", (event) => {
    event
		.addLootTypeModifier(LootType.CHEST)
		.anyDimension("mining_dimension:mining") 
        .randomChance(0.1) 
		.thenAdd("dubl:item_portal_key");
});
// adds dimdungeons key to all lootchests in nether - 10% chance
onEvent("lootjs", (event) => {
    event
		.addLootTypeModifier(LootType.CHEST)
		.anyDimension("minecraft:the_nether") 
        .randomChance(0.1) 
		.thenAdd("dubl:item_portal_key");
});
// adds dimdungeons key to all lootchests in mirror overworld dimension - 15% chance
onEvent("lootjs", (event) => {
    event
		.addLootTypeModifier(LootType.CHEST)
		.anyDimension("overworldmirror:overworld") 
        .randomChance(0.15) 
		.thenAdd("dubl:item_portal_key");
});
// adds catalysts to all lootchests in mirror overworld dimension - 0.5% chance
onEvent("lootjs", (event) => {
    event
		.addLootTypeModifier(LootType.CHEST)
		.anyDimension("overworldmirror:overworld") 
        .randomChance(0.005) 
		.thenAdd("dubl:skeletal_catalyst");
});
onEvent("lootjs", (event) => {
    event
		.addLootTypeModifier(LootType.CHEST)
		.anyDimension("overworldmirror:overworld") 
        .randomChance(0.005) 
		.thenAdd("dubl:nether_catalyst");
});
onEvent("lootjs", (event) => {
    event
		.addLootTypeModifier(LootType.CHEST)
		.anyDimension("overworldmirror:overworld") 
        .randomChance(0.005) 
		.thenAdd("dubl:void_catalyst");
});
// adds endless key to all lootchests in mirror overworld dimension - 0.5% chance
onEvent("lootjs", (event) => {
    event
		.addLootTypeModifier(LootType.CHEST)
		.anyDimension("overworldmirror:overworld") 
        .randomChance(0.005) 
		.thenAdd("dubl:endless_key");
});
// adds mob essences to all lootchests in mirror overworld dimension - 1% chance
onEvent("lootjs", (event) => {
    event
		.addLootTypeModifier(LootType.CHEST)
		.anyDimension("overworldmirror:overworld") 
        .randomChance(0.01) 
		.thenAdd("dubl:zombie_essence");
});
onEvent("lootjs", (event) => {
    event
		.addLootTypeModifier(LootType.CHEST)
		.anyDimension("overworldmirror:overworld") 
        .randomChance(0.01) 
		.thenAdd("dubl:skeleton_essence");
});
onEvent("lootjs", (event) => {
    event
		.addLootTypeModifier(LootType.CHEST)
		.anyDimension("overworldmirror:overworld") 
        .randomChance(0.01) 
		.thenAdd("dubl:creeper_essence");
});
onEvent("lootjs", (event) => {
    event
		.addLootTypeModifier(LootType.CHEST)
		.anyDimension("overworldmirror:overworld") 
        .randomChance(0.01) 
		.thenAdd("dubl:spider_essence");
});

// adds better loot to ALL loot tables in mirror overworld dimension
function randomBetween(min, max) {
	return Math.floor(Math.random() * (max - min)) + min;
  }
  onEvent("lootjs", (event) => {
	  event
	  	.addLootTypeModifier(LootType.CHEST)
		  .anyDimension("overworldmirror:overworld") 
		  .randomChance(0.5) 
		  .thenApply(ctx => {
			  ctx.addLoot(Item.of("minecraft:emerald", randomBetween(1, 16)));
		  });
  });
  onEvent("lootjs", (event) => {
	event
		.addLootTypeModifier(LootType.CHEST)
		.anyDimension("overworldmirror:overworld") 
		.randomChance(0.2) 
		.thenApply(ctx => {
			ctx.addLoot(Item.of("minecraft:iron_ingot", randomBetween(1, 16)));
		});
	});
	onEvent("lootjs", (event) => {
		event
			.addLootTypeModifier(LootType.CHEST)
			.anyDimension("overworldmirror:overworld") 
			.randomChance(0.05) 
			.thenApply(ctx => {
				ctx.addLoot(Item.of("minecraft:diamond", randomBetween(1, 9)));
			});
		});
	onEvent("lootjs", (event) => {
		event
			.addLootTypeModifier(LootType.CHEST)
			.anyDimension("overworldmirror:overworld") 
			.randomChance(0.005) 
			.thenAdd("mmorpg:full_favor");
	});
	onEvent("lootjs", (event) => {
		event
			.addLootTypeModifier(LootType.CHEST)
			.anyDimension("overworldmirror:overworld") 
			.randomChance(0.05) 
			.thenApply(ctx => {
				ctx.addLoot(Item.of("mmorpg:currency/orb_of_transmutation", randomBetween(1, 3)));
			});
		});
	onEvent("lootjs", (event) => {
		event
			.addLootTypeModifier(LootType.CHEST)
			.anyDimension("overworldmirror:overworld") 
			.randomChance(0.03) 
			.thenApply(ctx => {
				ctx.addLoot(Item.of("mmorpg:currency/randomize_affixes", randomBetween(1, 2)));
			});
		});
	onEvent("lootjs", (event) => {
		event
			.addLootTypeModifier(LootType.CHEST)
			.anyDimension("overworldmirror:overworld") 
			.randomChance(0.01) 
			.thenAdd("mmorpg:currency/crystal_of_purification");
		});
	onEvent("lootjs", (event) => {
		event
			.addLootTypeModifier(LootType.CHEST)
			.anyDimension("overworldmirror:overworld") 
			.randomChance(0.02) 
			.thenApply(ctx => {
				ctx.addLoot(Item.of("mmorpg:currency/reroll_affix_numbers", randomBetween(1, 2)));
			});
		});
	onEvent("lootjs", (event) => {
		event
			.addLootTypeModifier(LootType.CHEST)
			.anyDimension("overworldmirror:overworld") 
			.randomChance(0.001) 
			.thenAdd("mmorpg:currency/stone_of_hope");
		});
	onEvent("lootjs", (event) => {
		event
			.addLootTypeModifier(LootType.CHEST)
			.anyDimension("overworldmirror:overworld") 
			.randomChance(0.01) 
			.thenApply(ctx => {
				ctx.addLoot(Item.of("mmorpg:currency/reroll_primary_stats_numbers", randomBetween(1, 2)));
			});
		});
	onEvent("lootjs", (event) => {
		event
			.addLootTypeModifier(LootType.CHEST)
			.anyDimension("overworldmirror:overworld") 
			.randomChance(0.005) 
			.thenAdd("mmorpg:currency/number_reroll");
		});
	onEvent("lootjs", (event) => {
		event
			.addLootTypeModifier(LootType.CHEST)
			.anyDimension("overworldmirror:overworld") 
			.randomChance(0.001) 
			.thenAdd("mmorpg:currency/reroll_unique_numbers");
		});
	onEvent("lootjs", (event) => {
		event
			.addLootTypeModifier(LootType.CHEST)
			.anyDimension("overworldmirror:overworld") 
			.randomChance(0.01) 
			.thenAdd("mmorpg:currency/clear_instability");
		});
	onEvent("lootjs", (event) => {
		event
			.addLootTypeModifier(LootType.CHEST)
			.anyDimension("overworldmirror:overworld") 
			.randomChance(0.01) 
			.thenAdd("mmorpg:currency/orb_of_corruption");
		});
	onEvent("lootjs", (event) => {
		event
			.addLootTypeModifier(LootType.CHEST)
			.anyDimension("overworldmirror:overworld") 
			.randomChance(0.005) 
			.thenAdd("mmorpg:currency/orb_of_infinity");
		});
	onEvent("lootjs", (event) => {
		event
			.addLootTypeModifier(LootType.CHEST)
			.anyDimension("overworldmirror:overworld") 
			.randomChance(0.2) 
			.thenAdd("mmorpg:currency/plus_one_upgrade");
		});
	onEvent("lootjs", (event) => {
		event
			.addLootTypeModifier(LootType.CHEST)
			.anyDimension("overworldmirror:overworld") 
			.randomChance(0.05) 
			.thenAdd("mmorpg:currency/plus_two_upgrade");
		});
	onEvent("lootjs", (event) => {
		event
			.addLootTypeModifier(LootType.CHEST)
			.anyDimension("overworldmirror:overworld") 
			.randomChance(0.01) 
			.thenAdd("mmorpg:currency/plus_three_upgrade");
		});

//
//
//
//
// adds dungeon coins to mob drops in dungeon dimension
onEvent("lootjs", (event) => {
    event
		.addLootTypeModifier(LootType.ENTITY)
		.anyDimension("dimdungeons:dungeon_dimension") 
        .randomChance(0.25) 
		.thenAdd("dubl:dungeon_coin");
});