package com.zivilon.cinder_loe.blocks;

import lotr.common.LOTRCreativeTabs;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.world.World;
import net.minecraft.block.BlockPressurePlate;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.entity.player.EntityPlayer;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

import java.lang.reflect.Field;

public class ShadowTile extends BlockPressurePlate {

    public ShadowTile() {
        super("lotr:shadow_tile", Material.rock, BlockPressurePlate.Sensitivity.players);
        try {
            Field tabField = LOTRCreativeTabs.class.getDeclaredField("tabMisc"); // Stupid workaround because ForgeGradle tries to obfuscate field LOTRCreativeTabs.tabBlock when it's not supposed to
            LOTRCreativeTabs tab = (LOTRCreativeTabs)tabField.get(null);
            setCreativeTab((CreativeTabs)tab);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            e.printStackTrace();
        }
        setBlockTextureName("lotr:shadow_tile");
        setBlockName("lotr:shadowTile");
    }

    @Override
    public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
        if (entity instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer)entity;
            player.attackEntityFrom(new DamageSource("shadow"), 10.0F);
            player.addPotionEffect(new PotionEffect(15, 6*20, 0, false));
            world.setBlockToAir(x, y, z);
        }
    }
}
