package com.whammich.sstow.block;

import com.whammich.sstow.SoulShardsTOW;
import com.whammich.sstow.item.ItemSoulShard;
import com.whammich.sstow.registry.ModItems;
import net.minecraft.entity.item.EntityItem;
import tehnut.lib.annot.ModBlock;
import tehnut.lib.annot.Used;
import tehnut.lib.block.base.BlockBoolean;
import com.whammich.sstow.tile.TileEntityCage;
import com.whammich.sstow.util.Utils;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

@ModBlock(name = "BlockCage", tileEntity = TileEntityCage.class)
@Used
public class BlockCage extends BlockBoolean {

    public BlockCage() {
        super(Material.iron, "shard");
        setUnlocalizedName(SoulShardsTOW.MODID + ".cage");
        setCreativeTab(SoulShardsTOW.soulShardsTab);
        blockHardness = 3.0F;
        blockResistance = 3.0F;
    }

    @Override
    public boolean hasComparatorInputOverride() {
        return true;
    }

    @Override
    public int getComparatorInputOverride(World world, BlockPos pos) {
        TileEntityCage tile = (TileEntityCage) world.getTileEntity(pos);
        if (tile.getStackInSlot(0) != null) {
            ItemStack shard = tile.getStackInSlot(0);
            int tier = Utils.getShardTier(shard);
            switch (tier) {
                case 1: return 2;
                case 2: return 5;
                case 3: return 7;
                case 4: return 10;
                case 5: return 15;
                default: return 0;
            }
        } else {
            return 0;
        }
    }

    @Override
    public boolean canConnectRedstone(IBlockAccess world, BlockPos pos, EnumFacing facing) {
        return true;
    }

    @Override
    public void breakBlock(World world, BlockPos blockPos, IBlockState blockState) {
        TileEntityCage tileCage = (TileEntityCage) world.getTileEntity(blockPos);
        if (tileCage != null)
            tileCage.dropItems();

        super.breakBlock(world, blockPos, blockState);
    }

    @Override
    public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing facing, float hitX, float hitY, float hitZ) {
        TileEntity tile = world.getTileEntity(pos);

        if (tile != null && tile instanceof TileEntityCage) {
            TileEntityCage cage = (TileEntityCage) tile;
            if (player.getHeldItem() != null && cage.getStackInSlot(0) == null && cage.isItemValidForSlot(0, player.getHeldItem()) && !player.isSneaking()) {
                cage.setInventorySlotContents(0, player.getHeldItem().copy());
                cage.setTier(Utils.getShardTier(player.getHeldItem()));
                cage.setEntName(Utils.getShardBoundEnt(player.getHeldItem()));
                player.getHeldItem().stackSize--;
                return true;
            } else if ( cage.getStackInSlot(0) != null && player.getHeldItem() == null && player.isSneaking()) {
                cage.setTier(0);
                cage.setEntName("");
                cage.setActiveTime(0);
                if (!world.isRemote) {
                    EntityItem invItem = new EntityItem(world, player.posX, player.posY + 0.25, player.posZ, cage.getStackInSlot(0));
                    world.spawnEntityInWorld(invItem);
                }
                cage.clear();
                return true;
            }
        }

        return false;
    }

//    @Override
//    public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) {
//        TileEntity tile = world.getTileEntity(pos);
//
//        if (tile instanceof TileEntityCage)
//            ((TileEntityCage) tile).checkRedstone();
//    }

    @Override
    public boolean isOpaqueCube() {
        return false;
    }

    @Override
    public boolean hasTileEntity(IBlockState state) {
        return true;
    }

        @Override
    public TileEntity createTileEntity(World world, IBlockState state) {
        return new TileEntityCage();
    }
}

@@ -160,16 +160,86 @@
 dItems;%0A
+import net.minecraft.block.Block;%0Aimport net.minecraft.entity.Entity;%0A
 import n
@@ -946,23 +946,16 @@
 ds Block
-Boolean
  %7B%0A%0A    
@@ -1006,17 +1006,8 @@
 iron
-, %22shard%22
 );%0A 
@@ -3732,281 +3732,8 @@
  %7D%0A%0A
-//    @Override%0A//    public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) %7B%0A//        TileEntity tile = world.getTileEntity(pos);%0A//%0A//        if (tile instanceof TileEntityCage)%0A//            ((TileEntityCage) tile).checkRedstone();%0A//    %7D%0A%0A
     

Remove variant from Cage