In my mod I create a new block class, which when right-clicked it should give the player an item. Well, I managed to get it working properly, but then I added more lines of code to it and it stopped working. I've tried removing everything but the required lines (as I think it was when it worked) and it is not working. I hope you can fin what I'm doing wrong in the code I attach (note that some method overrides are missing, I'm not attaching the whole code, just the needed).
package com.name.modid.objects.blocks;
//Imports here
public class ModBlock extends Block {
//Some missing methods here, don't mind. They exist in my code.
@ObjectHolder("modid:moditem")
public static final Item item_var = null;
ItemStack item_stack = new ItemStack(item_var);
@Override
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
player.inventory.addItemStackToInventory(item_stack);
return ActionResultType.SUCCESS;
}
}