#loader contenttweaker

import mods.contenttweaker.Color;
import mods.contenttweaker.VanillaFactory;
import mods.contenttweaker.IItemRightClick;
import mods.contenttweaker.Commands;
import mods.contenttweaker.BlockState;
import crafttweaker.block.IBlock;

var eldritchflower = VanillaFactory.createItem("eldritch_flower");

eldritchflower.maxStackSize = 1;
eldritchflower.itemRightClick = function(stack, world, player, hand) {
	# Return early in the function if the world is on the client side. Prevents serious desyncs.
    if(world.isRemote()) { return "PASS"; }

    var pos = player.position.asPosition3f();
    pos.y = pos.y - 1;
    pos.x = pos.x + 1;
    var blockPosBelowPlayer = pos.asBlockPos();

	# Check if the blockstate that is under the player matches obsidian.
    if(world.getBlockState(blockPosBelowPlayer) == <blockstate:minecraft:obsidian>) {
        Commands.call("give @p contenttweaker:lost_memory", player, world, false, true);
        return "PASS";
    } else {
        Commands.call("say Right click while standing in front of a Block of Obsidian (same level as the floor) looking east", player, world, false, true);
        return "FAIL";
    }
};
eldritchflower.register();


var solidifiedmemory = VanillaFactory.createItem("solidified_memory");
solidifiedmemory.maxStackSize = 1;
solidifiedmemory.itemRightClick = function(stack, world, player, hand) {
	Commands.call("thaumcraft warp @p add 50", player, world, true, true);
    Commands.call("thaumcraft warp @p add 20 perm", player, world, true, true);
    Commands.call("effect @p thaumcraft:thaumarhia 200 1", player, world, true, true);
    Commands.call("effect @p thaumcraft:deathgaze 200 1", player, world, true, true);
    Commands.call("effect @p thaumcraft:sunscorned 200 1", player, world, true, true);
    Commands.call("summon twilightforest:tower_ghast ~ ~ ~", player, world, true, true);
    Commands.call("give @p contenttweaker:human_imperfection", player, world, true, true);
	stack.shrink(1);
	return "Pass";
};
solidifiedmemory.register();

var evilinsinght = VanillaFactory.createItem("evil_insight");
evilinsinght.maxStackSize = 1;
evilinsinght.itemRightClick = function(stack, world, player, hand) {
	Commands.call("thaumcraft warp @p add 10", player, world, true, true);
    Commands.call("thaumcraft warp @p add 50 perm", player, world, true, true);
    Commands.call("effect @p minecraft:blindness 200 6", player, world, true, true);
    Commands.call("effect @p thaumcraft:deathgaze 200 1", player, world, true, true);
    Commands.call("effect @p thaumcraft:sunscorned 200 1", player, world, true, true);
    Commands.call("summon minecraft:witch ~ ~ ~", player, world, true, true);
    Commands.call("summon minecraft:witch ~ ~ ~", player, world, true, true);
    Commands.call("summon minecraft:witch ~ ~ ~", player, world, true, true);
    Commands.call("summon minecraft:witch ~ ~ ~", player, world, true, true);
    Commands.call("give @p contenttweaker:malum", player, world, true, true);
	return "Pass";
};
evilinsinght.register();

var deinthos = VanillaFactory.createItem("deinthos");
deinthos.maxStackSize = 1;
deinthos.itemRightClick = function(stack, world, player, hand) {
	Commands.call("thaumcraft warp @p add 5", player, world, true, true);
    Commands.call("thaumcraft warp @p add 5 perm", player, world, true, true);
    Commands.call("effect @p minecraft:blindness 200 6", player, world, true, true);
    Commands.call("effect @p thaumcraft:deathgaze 200 1", player, world, true, true);
    Commands.call("effect @p thaumcraft:sunscorned 200 1", player, world, true, true);
    Commands.call("summon abyssalcraft:lessershoggoth ~ ~ ~", player, world, true, true);
    Commands.call("summon abyssalcraft:lessershoggoth ~ ~ ~", player, world, true, true);
    Commands.call("summon abyssalcraft:lessershoggoth ~ ~ ~", player, world, true, true);
    Commands.call("summon abyssalcraft:lessershoggoth ~ ~ ~", player, world, true, true);
    Commands.call("summon minecraft:creeper ~ ~ ~", player, world, true, true);
    Commands.call("give @p contenttweaker:pure_warp", player, world, true, true);
	return "Pass";
};
deinthos.register();



var unfathomablebreaker = VanillaFactory.createItem("unfathomable_breaker");
unfathomablebreaker.maxStackSize = 1;
unfathomablebreaker.itemRightClick = function(stack, world, player, hand) {
	# Return early in the function if the world is on the client side. Prevents serious desyncs.
    if(world.isRemote()) { return "PASS"; }

	# Get the blockpos that is under the player.
    var pos = player.position.asPosition3f();
    pos.y = pos.y - 1;
    var blockPosBelowPlayer = pos.asBlockPos();

	# Check if the blockstate that is under the player matches obsidian.
    if(world.getBlockState(blockPosBelowPlayer) == <blockstate:minecraft:bedrock>) {
        Commands.call("fill ~-1 ~-2 ~-1 ~1 ~-2 ~1 air 0 replace contenttweaker:unfathomable_stone 0", player, world, false, true);
        return "PASS";
    } else {
        Commands.call("say stand on the bedrock block on top of the demonic prison", player, world, false, true);
        return "FAIL";
    }
};
unfathomablebreaker.register();

var gaiatesseract = VanillaFactory.createItem("gaia_tesseract");
gaiatesseract.maxStackSize = 1;
gaiatesseract.itemRightClick = function(stack, world, player, hand) {
	Commands.call("tp @p ~ ~100 ~", player, world, true, true);
	return "Pass";
};
gaiatesseract.glowing = true;
gaiatesseract.register();

var limbowarper = VanillaFactory.createItem("limbo_warper");
limbowarper.maxStackSize = 1;
limbowarper.glowing = true;
limbowarper.itemRightClick = function(stack, world, player, hand) {
	Commands.call("cofh tpx @p 684", player, world, true, true);
	return "Pass";
};
limbowarper.register();

var vengefulkey = VanillaFactory.createItem("vengeful_key");
vengefulkey.maxStackSize = 1;
vengefulkey.itemRightClick = function(stack, world, player, hand) {
	# Return early in the function if the world is on the client side. Prevents serious desyncs.
    if(world.isRemote()) { return "PASS"; }

	# Get the blockpos that is under the player.
    var pos = player.position.asPosition3f();
    pos.y = pos.y - 1;
    var blockPosBelowPlayer = pos.asBlockPos();

	# Check if the blockstate that is under the player matches obsidian.
    if(world.getBlockState(blockPosBelowPlayer) == <blockstate:minecraft:netherrack>) {
        Commands.call("fill ~-1 ~-2 ~-1 ~1 ~2 ~1 air 0 replace contenttweaker:vengeful_portal 0", player, world, false, true);
        return "PASS";
    } else {
        Commands.call("say stand on the netherrack block in the middle of the will crystal monolith", player, world, false, true);
        return "FAIL";
    }
};
vengefulkey.register();

var retaliationkey = VanillaFactory.createItem("retaliation_key");
retaliationkey.maxStackSize = 1;
retaliationkey.itemRightClick = function(stack, world, player, hand) {
	# Return early in the function if the world is on the client side. Prevents serious desyncs.
    if(world.isRemote()) { return "PASS"; }

	# Get the blockpos that is under the player.
    var pos = player.position.asPosition3f();
    pos.y = pos.y - 1;
    var blockPosBelowPlayer = pos.asBlockPos();

	# Check if the blockstate that is under the player matches obsidian.
    if(world.getBlockState(blockPosBelowPlayer) == <blockstate:minecraft:netherrack>) {
        Commands.call("fill ~-1 ~1 ~-1 ~1 ~5 ~1 air 0 replace contenttweaker:retaliation_portal 0", player, world, false, true);
        return "PASS";
    } else {
        Commands.call("say stand on the netherrack block inside the the will crystal monolith", player, world, false, true);
        return "FAIL";
    }
};
retaliationkey.register();

var stafficeika = VanillaFactory.createItem("staff_of_iceika");
stafficeika.maxStackSize = 1;
stafficeika.itemRightClick = function(stack, world, player, hand) {
	# Return early in the function if the world is on the client side. Prevents serious desyncs.
    if(world.isRemote()) { return "PASS"; }

	# Get the blockpos that is under the player.
    var pos = player.position.asPosition3f();
    pos.y = pos.y - 1;
    var blockPosBelowPlayer = pos.asBlockPos();

	# Check if the blockstate that is under the player matches obsidian.
    if(world.getBlockState(blockPosBelowPlayer) == <blockstate:minecraft:bedrock>) {
        Commands.call("fill ~-2 ~1 ~-2 ~2 ~5 ~2 air 0 replace contenttweaker:icy_gateway 0", player, world, false, true);
        return "PASS";
    } else {
        Commands.call("say stand on the bedrock block inside the the Iceika Fortress", player, world, false, true);
        return "FAIL";
    }
};
stafficeika.register();